[Android] Marquee effect for long names in directory browser.
Shivansh Saini
git at videolan.org
Tue May 7 15:08:53 CEST 2019
vlc-android | branch: master | Shivansh Saini <shivanshs9 at gmail.com> | Mon Apr 29 15:20:44 2019 +0530| [7b3b0830677010914d46b71558fbe7eb3c45f2af] | committer: Geoffrey Métais
Marquee effect for long names in directory browser.
> https://code.videolan.org/videolan/vlc-android/commit/7b3b0830677010914d46b71558fbe7eb3c45f2af
---
vlc-android/res/layout/browser_item.xml | 5 ++--
.../videolan/vlc/gui/browser/BaseBrowserAdapter.kt | 28 ++++++++++++++++++++++
2 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/vlc-android/res/layout/browser_item.xml b/vlc-android/res/layout/browser_item.xml
index 53a301718..37ef8ff4a 100644
--- a/vlc-android/res/layout/browser_item.xml
+++ b/vlc-android/res/layout/browser_item.xml
@@ -104,9 +104,10 @@
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/default_margin"
android:layout_marginLeft="@dimen/default_margin"
- android:ellipsize="end"
+ android:ellipsize="marquee"
+ android:marqueeRepeatLimit="1"
+ android:scrollHorizontally="true"
android:lineSpacingMultiplier="1.1"
- android:maxLines="1"
android:singleLine="true"
android:text="@{filename ?? item.title}"
android:textColor="?attr/list_title"
diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.kt b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.kt
index 8e37740ee..487dae2b2 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserAdapter.kt
@@ -30,6 +30,8 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.ViewDataBinding
+import androidx.recyclerview.widget.LinearLayoutManager
+import androidx.recyclerview.widget.RecyclerView
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.ObsoleteCoroutinesApi
import org.videolan.libvlc.util.AndroidUtil
@@ -104,6 +106,32 @@ open class BaseBrowserAdapter() : DiffUtilAdapter<MediaLibraryItem, BaseBrowserA
SeparatorViewHolder(BrowserItemSeparatorBinding.inflate(inflater, parent, false)) as ViewHolder<ViewDataBinding>
}
+ override fun onAttachedToRecyclerView(recyclerView: RecyclerView) {
+ super.onAttachedToRecyclerView(recyclerView)
+
+ val layoutManager = recyclerView.layoutManager
+ if (layoutManager is LinearLayoutManager) {
+ recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
+ override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
+ super.onScrollStateChanged(recyclerView, newState)
+
+ val doScroll = newState == RecyclerView.SCROLL_STATE_IDLE
+
+ val firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition()
+ val lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition()
+ for (i in firstVisibleItemPosition..lastVisibleItemPosition) {
+ val holder = recyclerView.findViewHolderForLayoutPosition(i)
+ if (holder is MediaViewHolder) {
+ // Show marquee effect only for those view holders which are visible.
+ // If not visible or dragging scroll state, then stop the marquee effect.
+ holder.binding.title.isSelected = doScroll
+ }
+ }
+ }
+ })
+ }
+ }
+
override fun onBindViewHolder(holder: ViewHolder<ViewDataBinding>, position: Int) {
val viewType = getItemViewType(position)
if (viewType == TYPE_MEDIA) {
More information about the Android
mailing list