[Android] Remove breadcrumb last decoration
Nicolas Pomepuy
git at videolan.org
Tue Sep 24 16:29:43 CEST 2019
vlc-android | branch: 3.2.x | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Tue Sep 17 06:57:14 2019 +0200| [413ffaa62bd5de978adbd63b0bacd8e0b8b5926d] | committer: Geoffrey Métais
Remove breadcrumb last decoration
Refs #1032
(cherry picked from commit 52cb2ee46032788048415f857fc2f97c7354bdb7)
> https://code.videolan.org/videolan/vlc-android/commit/413ffaa62bd5de978adbd63b0bacd8e0b8b5926d
---
.../src/org/videolan/vlc/gui/InfoActivity.kt | 8 +--
.../vlc/gui/browser/BaseBrowserFragment.kt | 5 +-
.../vlc/gui/tv/browser/FileBrowserTvFragment.kt | 5 +-
.../vlc/gui/view/VLCDividerItemDecoration.kt | 82 ++++++++++++++++++++++
4 files changed, 91 insertions(+), 9 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/InfoActivity.kt b/vlc-android/src/org/videolan/vlc/gui/InfoActivity.kt
index 631c7595b..6ff43d540 100644
--- a/vlc-android/src/org/videolan/vlc/gui/InfoActivity.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/InfoActivity.kt
@@ -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
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
index 8b27d2622..c36b9bf95 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
@@ -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
@@ -145,9 +146,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
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/FileBrowserTvFragment.kt b/vlc-android/src/org/videolan/vlc/gui/tv/browser/FileBrowserTvFragment.kt
index 64147ea85..ea4d1364e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/FileBrowserTvFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/FileBrowserTvFragment.kt
@@ -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 at 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)
diff --git a/vlc-android/src/org/videolan/vlc/gui/view/VLCDividerItemDecoration.kt b/vlc-android/src/org/videolan/vlc/gui/view/VLCDividerItemDecoration.kt
new file mode 100644
index 000000000..1ff61f6d7
--- /dev/null
+++ b/vlc-android/src/org/videolan/vlc/gui/view/VLCDividerItemDecoration.kt
@@ -0,0 +1,82 @@
+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
More information about the Android
mailing list