[Android] Accessibility: use an option item instead of a FAB for all fragments
Nicolas Pomepuy
git at videolan.org
Fri Jun 3 11:30:22 UTC 2022
vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Thu Jun 2 07:41:30 2022 +0200| [9594bc8cb92d0e004cb6d7a109aa6d3d4abb0e85] | committer: Nicolas Pomepuy
Accessibility: use an option item instead of a FAB for all fragments
> https://code.videolan.org/videolan/vlc-android/commit/9594bc8cb92d0e004cb6d7a109aa6d3d4abb0e85
---
.../resources/src/main/res/drawable/ic_am_shuffle.xml | 11 +++++++++++
application/vlc-android/res/menu/activity_option.xml | 8 ++++++++
.../videolan/vlc/gui/audio/AudioAlbumsSongsFragment.kt | 6 ++++++
.../org/videolan/vlc/gui/audio/AudioBrowserFragment.kt | 8 +++++++-
.../org/videolan/vlc/gui/browser/BaseBrowserFragment.kt | 16 ++++++++++------
.../videolan/vlc/gui/browser/NetworkBrowserFragment.kt | 2 +-
6 files changed, 43 insertions(+), 8 deletions(-)
diff --git a/application/resources/src/main/res/drawable/ic_am_shuffle.xml b/application/resources/src/main/res/drawable/ic_am_shuffle.xml
new file mode 100644
index 000000000..f79aab6d0
--- /dev/null
+++ b/application/resources/src/main/res/drawable/ic_am_shuffle.xml
@@ -0,0 +1,11 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:width="48dp"
+ android:height="48dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <path
+ android:fillColor="?attr/colorControlNormal"
+ android:pathData="M10.59,9.17L6.12,4.7c-0.39,-0.39 -1.02,-0.39 -1.41,0 -0.39,0.39 -0.39,1.02 0,1.41l4.46,4.46 1.42,-1.4zM15.35,4.85l1.19,1.19L4.7,17.88c-0.39,0.39 -0.39,1.02 0,1.41 0.39,0.39 1.02,0.39 1.41,0L17.96,7.46l1.19,1.19c0.31,0.31 0.85,0.09 0.85,-0.36L20,4.5c0,-0.28 -0.22,-0.5 -0.5,-0.5h-3.79c-0.45,0 -0.67,0.54 -0.36,0.85zM14.83,13.41l-1.41,1.41 3.13,3.13 -1.2,1.2c-0.31,0.31 -0.09,0.85 0.36,0.85h3.79c0.28,0 0.5,-0.22 0.5,-0.5v-3.79c0,-0.45 -0.54,-0.67 -0.85,-0.35l-1.19,1.19 -3.13,-3.14z"
+ tools:fillColor="#ffffff" />
+</vector>
diff --git a/application/vlc-android/res/menu/activity_option.xml b/application/vlc-android/res/menu/activity_option.xml
index 5b7a21a19..3817a4731 100644
--- a/application/vlc-android/res/menu/activity_option.xml
+++ b/application/vlc-android/res/menu/activity_option.xml
@@ -9,6 +9,14 @@
android:title="@string/play_all"
vlc:showAsAction="always"
android:visible="false"/>
+
+ <item
+ android:orderInCategory="0"
+ android:id="@+id/shuffle_all"
+ android:icon="@drawable/ic_am_shuffle"
+ android:title="@string/shuffle_all_title"
+ vlc:showAsAction="always"
+ android:visible="false"/>
<item
android:orderInCategory="1"
android:id="@+id/ml_menu_renderers"
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.kt
index 21ce00e38..43531b36e 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.kt
@@ -47,6 +47,7 @@ import org.videolan.vlc.gui.view.RecyclerSectionItemGridDecoration
import org.videolan.vlc.media.MediaUtils
import org.videolan.vlc.providers.medialibrary.MedialibraryProvider
import org.videolan.vlc.util.getScreenWidth
+import org.videolan.vlc.util.isTalkbackIsEnabled
import org.videolan.vlc.viewmodels.mobile.AlbumSongsViewModel
import org.videolan.vlc.viewmodels.mobile.getViewModel
@@ -182,6 +183,7 @@ class AudioAlbumsSongsFragment : BaseAudioBrowser<AlbumSongsViewModel>(), SwipeR
menu.findItem(R.id.ml_menu_display_grid).isVisible = !viewModel.providersInCard[currentTab]
menu.findItem(R.id.ml_menu_display_list).isVisible = viewModel.providersInCard[currentTab]
menu.findItem(R.id.ml_menu_sortby_media_number).isVisible = canSortByMediaNumber()
+ if (requireActivity().isTalkbackIsEnabled()) menu.findItem(R.id.play_all).isVisible = true
}
sortMenuTitles()
reopenSearchIfNeeded()
@@ -197,6 +199,10 @@ class AudioAlbumsSongsFragment : BaseAudioBrowser<AlbumSongsViewModel>(), SwipeR
Settings.getInstance(requireActivity()).putSingle(viewModel.displayModeKeys[currentTab], item.itemId == R.id.ml_menu_display_grid)
true
}
+ R.id.play_all -> {
+ onFabPlayClick(fastScroller)
+ true
+ }
else -> super.onOptionsItemSelected(item)
}
}
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt
index aab8bea75..2c244b1d4 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.kt
@@ -59,6 +59,7 @@ import org.videolan.vlc.gui.view.FastScroller
import org.videolan.vlc.media.MediaUtils
import org.videolan.vlc.providers.medialibrary.MedialibraryProvider
import org.videolan.vlc.util.Permissions
+import org.videolan.vlc.util.isTalkbackIsEnabled
import org.videolan.vlc.viewmodels.mobile.AudioBrowserViewModel
import org.videolan.vlc.viewmodels.mobile.getViewModel
@@ -257,7 +258,8 @@ class AudioBrowserFragment : BaseAudioBrowser<AudioBrowserViewModel>() {
}
sortMenuTitles(currentTab)
reopenSearchIfNeeded()
- }
+ if (requireActivity().isTalkbackIsEnabled()) menu.findItem(R.id.shuffle_all).isVisible = true
+ }
override fun onOptionsItemSelected(item: MenuItem): Boolean {
return when (item.itemId) {
@@ -276,6 +278,10 @@ class AudioBrowserFragment : BaseAudioBrowser<AudioBrowserViewModel>() {
viewModel.refresh()
true
}
+ R.id.shuffle_all -> {
+ onFabPlayClick(emptyView)
+ true
+ }
else -> super.onOptionsItemSelected(item)
}
}
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
index 9d266023e..fad826ff7 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.kt
@@ -69,6 +69,7 @@ import org.videolan.vlc.media.PlaylistManager
import org.videolan.vlc.repository.BrowserFavRepository
import org.videolan.vlc.util.Permissions
import org.videolan.vlc.util.isSchemeSupported
+import org.videolan.vlc.util.isTalkbackIsEnabled
import org.videolan.vlc.viewmodels.browser.BrowserModel
import java.util.*
@@ -82,7 +83,7 @@ private const val MSG_REFRESH = 3
private const val MSG_SHOW_ENQUEUING = 4
private const val MSG_HIDE_ENQUEUING = 5
-abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefreshable, SwipeRefreshLayout.OnRefreshListener, View.OnClickListener, IEventsHandler<MediaLibraryItem>, CtxActionReceiver, PathAdapterListener, BrowserContainer<MediaLibraryItem> {
+abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefreshable, SwipeRefreshLayout.OnRefreshListener, IEventsHandler<MediaLibraryItem>, CtxActionReceiver, PathAdapterListener, BrowserContainer<MediaLibraryItem> {
private lateinit var addPlaylistFolderOnly: MenuItem
protected val handler = BrowserFragmentHandler(this)
@@ -132,6 +133,7 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
val browserShowHiddenFiles = menu.findItem(R.id.browser_show_hidden_files)
browserShowHiddenFiles.isVisible = true
browserShowHiddenFiles.isChecked = Settings.getInstance(requireActivity()).getBoolean("browser_show_hidden_files", true)
+ if (requireActivity().isTalkbackIsEnabled()) menu.findItem(R.id.play_all).isVisible = true
}
protected open fun defineIsRoot() = mrl == null
@@ -302,10 +304,8 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
override fun refresh() = viewModel.refresh()
- override fun onClick(v: View) {
- when (v.id) {
- R.id.fab, R.id.fab_large -> playAll(null)
- }
+ override fun onFabPlayClick(view: View) {
+ playAll(null)
}
class BrowserFragmentHandler(owner: BaseBrowserFragment) : WeakHandler<BaseBrowserFragment>(owner) {
@@ -463,6 +463,10 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
currentMedia?.let { requireActivity().addToPlaylistAsync(it.uri.toString(), true) }
true
}
+ R.id.play_all -> {
+ onFabPlayClick(binding.root)
+ true
+ }
else -> super.onOptionsItemSelected(item)
}
}
@@ -614,7 +618,7 @@ abstract class BaseBrowserFragment : MediaBrowserFragment<BrowserModel>(), IRefr
fabPlay?.let {
if (adapter.mediaCount > 0 || viewModel.url?.startsWith("file") == true) {
setFabPlayVisibility(true)
- it.setOnClickListener(this)
+ it.setOnClickListener{onFabPlayClick(it)}
} else {
setFabPlayVisibility(false)
it.setOnClickListener(null)
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.kt
index 1ba46d60d..8ab91f93d 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/browser/NetworkBrowserFragment.kt
@@ -101,7 +101,7 @@ class NetworkBrowserFragment : BaseBrowserFragment(), IDialogManager {
super.onStart()
fabPlay?.setImageResource(if (isRootDirectory) R.drawable.ic_fab_add else R.drawable.ic_fab_play)
fabPlay?.contentDescription = getString(if (isRootDirectory) R.string.add else R.string.play)
- fabPlay?.setOnClickListener(this)
+ fabPlay?.setOnClickListener { onFabPlayClick(it) }
}
override fun refresh() {
More information about the Android
mailing list