[Android] Albums: add show/hide track number setting

Duncan McNamara git at videolan.org
Wed Sep 21 05:32:01 UTC 2022


vlc-android | branch: master | Duncan McNamara <dcn.mcnamara at gmail.com> | Wed Sep 14 16:45:04 2022 +0200| [8440693786ecd57563343bb9232f4c9ed90b5c0d] | committer: Nicolas Pomepuy

Albums: add show/hide track number setting

> https://code.videolan.org/videolan/vlc-android/commit/8440693786ecd57563343bb9232f4c9ed90b5c0d
---

 .../resources/src/main/res/values/strings.xml        |  1 +
 .../src/main/java/org/videolan/tools/Settings.kt     |  5 +++++
 application/vlc-android/res/menu/playlist_option.xml |  7 +++++++
 .../org/videolan/vlc/gui/HeaderMediaListActivity.kt  | 20 +++++++++++++++++---
 .../vlc/gui/audio/AudioAlbumTracksAdapter.kt         |  5 ++++-
 5 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index ca707a1c8..ef61758cd 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -357,6 +357,7 @@
     <string name="popup_keepscreen_title">Keep screen ON in Pop-Up mode</string>
     <string name="popup_keepscreen_summary">Always keep screen ON while Pop-Up is displayed, even if video is paused.</string>
     <string name="browser_show_hidden_files_title">Show hidden files</string>
+    <string name="albums_show_track_numbers">Show track numbers</string>
     <string name="enable_video_screenshot">Take a screenshot</string>
 
     <string name="subtitles_prefs_category">Subtitles</string>
diff --git a/application/tools/src/main/java/org/videolan/tools/Settings.kt b/application/tools/src/main/java/org/videolan/tools/Settings.kt
index 1679e56ba..e6ecc9a68 100644
--- a/application/tools/src/main/java/org/videolan/tools/Settings.kt
+++ b/application/tools/src/main/java/org/videolan/tools/Settings.kt
@@ -27,6 +27,7 @@ object Settings : SingletonHolder<SharedPreferences, Context>({ init(it.applicat
     var audioJumpDelay = 10
     var audioLongJumpDelay = 20
     var showHiddenFiles = false
+    var showTrackNumber = true
     private var audioControlsChangeListener: (() -> Unit)? = null
     lateinit var device : DeviceInfo
         private set
@@ -47,6 +48,7 @@ object Settings : SingletonHolder<SharedPreferences, Context>({ init(it.applicat
         audioJumpDelay = prefs.getInt(KEY_AUDIO_JUMP_DELAY, 10)
         audioLongJumpDelay = prefs.getInt(KEY_AUDIO_LONG_JUMP_DELAY, 20)
         showHiddenFiles = prefs.getBoolean(BROWSER_SHOW_HIDDEN_FILES, true)
+        showTrackNumber = prefs.getBoolean(ALBUMS_SHOW_TRACK_NUMBER, true)
         return prefs
     }
 
@@ -180,6 +182,9 @@ const val CUSTOM_POPUP_HEIGHT = "custom_popup_height"
 //files
 const val BROWSER_SHOW_HIDDEN_FILES = "browser_show_hidden_files"
 
+// Albums
+const val ALBUMS_SHOW_TRACK_NUMBER = "albums_show_track_number"
+
 //widgets
 const val WIDGETS_PREVIEW_PLAYING = "widgets_preview_playing"
 
diff --git a/application/vlc-android/res/menu/playlist_option.xml b/application/vlc-android/res/menu/playlist_option.xml
index d7674df2c..cfa48cdf3 100644
--- a/application/vlc-android/res/menu/playlist_option.xml
+++ b/application/vlc-android/res/menu/playlist_option.xml
@@ -75,4 +75,11 @@
                     android:visible="false" />
         </menu>
     </item>
+    <item
+        android:orderInCategory="3"
+        android:title="@string/albums_show_track_numbers"
+        android:visible="false"
+        android:checkable="true"
+        app:showAsAction="never"
+        android:id="@+id/ml_menu_albums_show_track_numbers" />
 </menu>
\ No newline at end of file
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt b/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt
index b2722f1a6..71cacddba 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/HeaderMediaListActivity.kt
@@ -52,8 +52,7 @@ import org.videolan.medialibrary.interfaces.media.MediaWrapper
 import org.videolan.medialibrary.interfaces.media.Playlist
 import org.videolan.medialibrary.media.MediaLibraryItem
 import org.videolan.resources.*
-import org.videolan.tools.copy
-import org.videolan.tools.isStarted
+import org.videolan.tools.*
 import org.videolan.vlc.BuildConfig
 import org.videolan.vlc.R
 import org.videolan.vlc.databinding.HeaderMediaListActivityBinding
@@ -74,6 +73,7 @@ import org.videolan.vlc.interfaces.IListEventsHandler
 import org.videolan.vlc.media.MediaUtils
 import org.videolan.vlc.media.PlaylistManager
 import org.videolan.vlc.util.*
+import org.videolan.vlc.util.FileUtils
 import org.videolan.vlc.viewmodels.mobile.PlaylistViewModel
 import org.videolan.vlc.viewmodels.mobile.getViewModel
 import java.security.SecureRandom
@@ -194,7 +194,12 @@ open class HeaderMediaListActivity : AudioPlayerContainerActivity(), IEventsHand
     override fun onCreateOptionsMenu(menu: Menu): Boolean {
         super.onCreateOptionsMenu(menu)
         menuInflater.inflate(R.menu.playlist_option, menu)
-        if (!isPlaylist) menu.findItem(R.id.ml_menu_sortby).isVisible = true
+        if (!isPlaylist) {
+            menu.findItem(R.id.ml_menu_sortby).isVisible = true
+            val showTrackNumber = menu.findItem(R.id.ml_menu_albums_show_track_numbers)
+            showTrackNumber.isVisible = true
+            showTrackNumber.isChecked = Settings.showTrackNumber
+        }
         menu.findItem(R.id.ml_menu_sortby).isVisible = viewModel.canSortByName()
         menu.findItem(R.id.ml_menu_sortby_filename).isVisible = viewModel.canSortByFileNameName()
         menu.findItem(R.id.ml_menu_sortby_artist_name).isVisible = viewModel.canSortByArtist()
@@ -248,6 +253,15 @@ open class HeaderMediaListActivity : AudioPlayerContainerActivity(), IEventsHand
                 viewModel.sort(Medialibrary.SORT_ALBUM)
                 return true
             }
+            R.id.ml_menu_albums_show_track_numbers -> {
+                item.isChecked = !Settings.getInstance(this).getBoolean(
+                    ALBUMS_SHOW_TRACK_NUMBER, true)
+                Settings.getInstance(this).putSingle(ALBUMS_SHOW_TRACK_NUMBER, item.isChecked)
+                Settings.showTrackNumber = item.isChecked
+                audioBrowserAdapter.notifyDataSetChanged()
+                viewModel.refresh()
+                return true
+            }
             else -> return super.onOptionsItemSelected(item)
         }
     }
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumTracksAdapter.kt b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumTracksAdapter.kt
index 58948cf4d..ac5c443f6 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumTracksAdapter.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumTracksAdapter.kt
@@ -36,6 +36,7 @@ import org.videolan.libvlc.util.AndroidUtil
 import org.videolan.medialibrary.Tools
 import org.videolan.medialibrary.interfaces.media.MediaWrapper
 import org.videolan.medialibrary.media.MediaLibraryItem
+import org.videolan.tools.Settings
 import org.videolan.vlc.BR
 import org.videolan.vlc.databinding.AudioAlbumTrackItemBinding
 import org.videolan.vlc.interfaces.IEventsHandler
@@ -97,8 +98,10 @@ class AudioAlbumTracksAdapter @JvmOverloads constructor(
 
         override fun setItem(item: MediaLibraryItem?) {
             binding.item = item as MediaWrapper
-            if (item.trackNumber > 0)
+            if (item.trackNumber > 0 && Settings.showTrackNumber) {
                 binding.trackNumber.text = "${item.trackNumber}."
+                binding.trackNumber.visibility = View.VISIBLE
+            }
             else
                 binding.trackNumber.visibility = View.GONE
             binding.subtitle.text = MediaUtils.getMediaSubtitle(item)



More information about the Android mailing list