Commit 52cb2ee4 authored by Nicolas Pomepuy's avatar Nicolas Pomepuy Committed by Geoffrey Métais
Browse files

Remove breadcrumb last decoration

Refs #1032
parent 88a55546
......@@ -2,6 +2,7 @@ package org.videolan.vlc.gui
import android.content.Context
import android.graphics.Bitmap
import android.graphics.Rect
import android.graphics.drawable.BitmapDrawable
import android.net.Uri
import android.os.Bundle
......@@ -17,6 +18,7 @@ import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModel
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.bottomsheet.BottomSheetBehavior
import kotlinx.coroutines.*
import org.videolan.libvlc.Media
......@@ -27,13 +29,13 @@ import org.videolan.medialibrary.interfaces.media.AbstractArtist
import org.videolan.medialibrary.interfaces.media.AbstractMediaWrapper
import org.videolan.medialibrary.media.MediaLibraryItem
import org.videolan.vlc.R
import org.videolan.vlc.VLCApplication
import org.videolan.vlc.databinding.InfoActivityBinding
import org.videolan.vlc.gui.browser.PathAdapter
import org.videolan.vlc.gui.browser.PathAdapterListener
import org.videolan.vlc.gui.helpers.AudioUtil
import org.videolan.vlc.gui.helpers.FloatingActionButtonBehavior
import org.videolan.vlc.gui.video.MediaInfoAdapter
import org.videolan.vlc.gui.view.VLCDividerItemDecoration
import org.videolan.vlc.media.MediaUtils
import org.videolan.vlc.util.*
import java.io.File
......@@ -132,9 +134,7 @@ class InfoActivity : AudioPlayerContainerActivity(), View.OnClickListener, PathA
binding.ariane.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)
binding.ariane.adapter = PathAdapter(this, media)
if (binding.ariane.itemDecorationCount == 0) {
val did = DividerItemDecoration(this, DividerItemDecoration.HORIZONTAL)
did.setDrawable(ContextCompat.getDrawable(this, R.drawable.ic_divider)!!)
binding.ariane.addItemDecoration(did)
binding.ariane.addItemDecoration(VLCDividerItemDecoration(this, DividerItemDecoration.HORIZONTAL, ContextCompat.getDrawable(this, R.drawable.ic_divider)!!))
}
} else binding.ariane.visibility = View.GONE
}
......
......@@ -51,6 +51,7 @@ import org.videolan.vlc.gui.dialogs.SavePlaylistDialog
import org.videolan.vlc.gui.dialogs.showContext
import org.videolan.vlc.gui.helpers.UiTools
import org.videolan.vlc.gui.helpers.hf.OTG_SCHEME
import org.videolan.vlc.gui.view.VLCDividerItemDecoration
import org.videolan.vlc.interfaces.IEventsHandler
import org.videolan.vlc.interfaces.IRefreshable
import org.videolan.vlc.media.MediaUtils
......@@ -154,9 +155,7 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
ariane.layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)
ariane.adapter = PathAdapter(this, media)
if (ariane.itemDecorationCount == 0) {
val did = DividerItemDecoration(requireContext(), DividerItemDecoration.HORIZONTAL)
did.setDrawable(ContextCompat.getDrawable(requireContext(), R.drawable.ic_divider)!!)
ariane.addItemDecoration(did)
ariane.addItemDecoration(VLCDividerItemDecoration(requireContext(), DividerItemDecoration.HORIZONTAL, ContextCompat.getDrawable(requireContext(), R.drawable.ic_divider)!!))
}
ariane.scrollToPosition(ariane.adapter!!.itemCount - 1)
} else ariane.visibility = View.GONE
......
......@@ -10,6 +10,7 @@ import androidx.core.content.ContextCompat
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import androidx.lifecycle.ViewModelProviders
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
......@@ -27,6 +28,7 @@ import org.videolan.vlc.gui.browser.PathAdapterListener
import org.videolan.vlc.gui.tv.FileTvItemAdapter
import org.videolan.vlc.gui.tv.TvItemAdapter
import org.videolan.vlc.gui.tv.TvUtil
import org.videolan.vlc.gui.view.VLCDividerItemDecoration
import org.videolan.vlc.interfaces.IEventsHandler
import org.videolan.vlc.providers.BrowserProvider
import org.videolan.vlc.repository.BrowserFavRepository
......@@ -161,7 +163,7 @@ class FileBrowserTvFragment : BaseBrowserTvFragment(), PathAdapterListener {
ariane.layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)
ariane.adapter = PathAdapter(this@FileBrowserTvFragment, this)
if (ariane.itemDecorationCount == 0) {
val did = object : DividerItemDecoration(requireContext(), HORIZONTAL) {
val did = object : VLCDividerItemDecoration(requireContext(), HORIZONTAL, ContextCompat.getDrawable(requireContext(), R.drawable.ic_divider)!!) {
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
val position = parent.getChildAdapterPosition(view)
// hide the divider for the last child
......@@ -172,7 +174,6 @@ class FileBrowserTvFragment : BaseBrowserTvFragment(), PathAdapterListener {
}
}
}
did.setDrawable(ContextCompat.getDrawable(requireContext(), org.videolan.vlc.R.drawable.ic_divider)!!)
ariane.addItemDecoration(did)
}
ariane.scrollToPosition(ariane.adapter!!.itemCount - 1)
......
package org.videolan.vlc.gui.view
import android.content.Context
import android.graphics.Canvas
import android.graphics.Rect
import android.graphics.drawable.Drawable
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.RecyclerView
open class VLCDividerItemDecoration(private val context: Context, private val orientation: Int, private val dividerDrawable: Drawable) : DividerItemDecoration(context, orientation) {
private val bounds = Rect()
init {
setDrawable(dividerDrawable)
}
override fun onDraw(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
if (parent.layoutManager == null || dividerDrawable == null) {
return
}
if (orientation == VERTICAL) {
drawVertical(c, parent)
} else {
drawHorizontal(c, parent)
}
}
private fun drawVertical(canvas: Canvas, parent: RecyclerView) {
canvas.save()
val left: Int
val right: Int
if (parent.clipToPadding) {
left = parent.paddingLeft
right = parent.width - parent.paddingRight
canvas.clipRect(left, parent.paddingTop, right,
parent.height - parent.paddingBottom)
} else {
left = 0
right = parent.width
}
val childCount = parent.childCount - 1
for (i in 0 until childCount) {
val child = parent.getChildAt(i)
parent.getDecoratedBoundsWithMargins(child, bounds)
val bottom = bounds.bottom + Math.round(child.translationY)
val top = bottom - dividerDrawable.intrinsicHeight
dividerDrawable.setBounds(left, top, right, bottom)
dividerDrawable.draw(canvas)
}
canvas.restore()
}
private fun drawHorizontal(canvas: Canvas, parent: RecyclerView) {
canvas.save()
val top: Int
val bottom: Int
if (parent.clipToPadding) {
top = parent.paddingTop
bottom = parent.height - parent.paddingBottom
canvas.clipRect(parent.paddingLeft, top,
parent.width - parent.paddingRight, bottom)
} else {
top = 0
bottom = parent.height
}
val childCount = parent.childCount - 1
for (i in 0 until childCount) {
val child = parent.getChildAt(i)
parent.layoutManager!!.getDecoratedBoundsWithMargins(child, bounds)
val right = bounds.right + Math.round(child.translationX)
val left = right - dividerDrawable.intrinsicWidth
dividerDrawable.setBounds(left, top, right, bottom)
dividerDrawable.draw(canvas)
}
canvas.restore()
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment