[Android] Mitigate the d-pad fast scroll issue
Nicolas Pomepuy
git at videolan.org
Thu Apr 11 18:38:05 CEST 2019
vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Mon Apr 8 13:18:23 2019 +0200| [837f3c7278b373ebb5e25c86762dd730519afcda] | committer: Geoffrey Métais
Mitigate the d-pad fast scroll issue
> https://code.videolan.org/videolan/vlc-android/commit/837f3c7278b373ebb5e25c86762dd730519afcda
---
vlc-android/res/layout/audio_browser_tv_item.xml | 4 +--
.../vlc/gui/audio/AudioBrowserAdapter.java | 1 +
.../vlc/gui/tv/FocusableConstraintLayout.kt | 17 +++++++++++
.../vlc/gui/tv/browser/AudioBrowserTvFragment.kt | 35 +++++++++++++++-------
.../vlc/gui/tv/browser/VerticalGridActivity.java | 1 -
5 files changed, 45 insertions(+), 13 deletions(-)
diff --git a/vlc-android/res/layout/audio_browser_tv_item.xml b/vlc-android/res/layout/audio_browser_tv_item.xml
index a6a7886b4..acfb4f1d5 100644
--- a/vlc-android/res/layout/audio_browser_tv_item.xml
+++ b/vlc-android/res/layout/audio_browser_tv_item.xml
@@ -35,7 +35,7 @@
type="org.videolan.vlc.gui.audio.AudioBrowserAdapter.MediaItemTVViewHolder" />
</data>
- <androidx.constraintlayout.widget.ConstraintLayout
+ <org.videolan.vlc.gui.tv.FocusableConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/tv_card_background"
@@ -104,5 +104,5 @@
vlc:placeholder="@{item}" />
- </androidx.constraintlayout.widget.ConstraintLayout>
+ </org.videolan.vlc.gui.tv.FocusableConstraintLayout>
</layout>
\ No newline at end of file
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
index 2948f9409..c2d4ba7ec 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserAdapter.java
@@ -165,6 +165,7 @@ public class AudioBrowserAdapter extends PagedListAdapter<MediaLibraryItem, Audi
@Override
public void onViewRecycled(@NonNull AbstractMediaItemViewHolder h) {
h.recycle();
+ super.onViewRecycled(h);
}
private boolean isPositionValid(int position) {
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/FocusableConstraintLayout.kt b/vlc-android/src/org/videolan/vlc/gui/tv/FocusableConstraintLayout.kt
new file mode 100644
index 000000000..3933a8fb9
--- /dev/null
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/FocusableConstraintLayout.kt
@@ -0,0 +1,17 @@
+package org.videolan.vlc.gui.tv
+
+import android.content.Context
+import android.util.AttributeSet
+import androidx.constraintlayout.widget.ConstraintLayout
+
+class FocusableConstraintLayout : ConstraintLayout {
+ constructor(context: Context) : this(context, null)
+ constructor(context: Context, attrs: AttributeSet?) : this(context, attrs, 0)
+
+ constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
+
+ override fun clearFocus() {
+ if (parent != null)
+ super.clearFocus()
+ }
+}
\ No newline at end of file
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/AudioBrowserTvFragment.kt b/vlc-android/src/org/videolan/vlc/gui/tv/browser/AudioBrowserTvFragment.kt
index 86f7521b1..870b6d65f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/AudioBrowserTvFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/AudioBrowserTvFragment.kt
@@ -31,8 +31,7 @@ import android.os.Build
import android.os.Bundle
import android.os.Parcelable
import android.util.Log
-import android.view.KeyEvent.KEYCODE_BACK
-import android.view.KeyEvent.KEYCODE_MENU
+import android.view.KeyEvent.*
import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View
@@ -478,19 +477,35 @@ class AudioBrowserTvFragment : Fragment(), BrowserFragmentInterface, IEventsHand
}
+ private var lastDpadEventTime = 0L
override fun onKeyPressed(keyCode: Int): Boolean {
- if (keyCode == KEYCODE_MENU) {
- fabSettings.requestFocusFromTouch()
- expandExtendedFAB()
- return true
- }
- if (keyCode == KEYCODE_BACK) {
- if (headerListContainer.visibility == View.VISIBLE) {
- hideHeaderSelectionScreen()
+ when (keyCode) {
+ KEYCODE_MENU -> {
+ fabSettings.requestFocusFromTouch()
+ expandExtendedFAB()
+ return true
+ }
+ KEYCODE_BACK -> {
+ if (headerListContainer.visibility == View.VISIBLE) {
+ hideHeaderSelectionScreen()
+ return true
+ }
+ }
+ /**
+ * mitigate the perf issue when scrolling fast with d-pad
+ */
+ KEYCODE_DPAD_DOWN, KEYCODE_DPAD_LEFT, KEYCODE_DPAD_RIGHT, KEYCODE_DPAD_UP -> {
+ val now = System.currentTimeMillis()
+ if (now - lastDpadEventTime > 200) {
+ lastDpadEventTime = now
+ if (BuildConfig.DEBUG) Log.d("keydown", "Keydown propagated");
+ return false
+ }
return true
}
}
+
return false
}
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/browser/VerticalGridActivity.java b/vlc-android/src/org/videolan/vlc/gui/tv/browser/VerticalGridActivity.java
index bce1f1c15..d4a0ea9fe 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/browser/VerticalGridActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/browser/VerticalGridActivity.java
@@ -110,7 +110,6 @@ public class VerticalGridActivity extends BaseTvActivity implements BrowserActiv
}
-
@Override
public void showProgress(final boolean show){
runOnUiThread(new Runnable() {
More information about the Android
mailing list