[Android] Implement more sorting options for video groups

Nicolas Pomepuy git at videolan.org
Tue Apr 28 15:52:40 CEST 2020


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Apr 28 09:57:46 2020 +0200| [6d323cc81e8211a5b7765f0b646c6c342afa2bc5] | committer: Geoffrey Métais

Implement more sorting options for video groups

> https://code.videolan.org/videolan/vlc-android/commit/6d323cc81e8211a5b7765f0b646c6c342afa2bc5
---

 .../src/main/java/org/videolan/resources/util/Helpers.kt          | 2 ++
 application/resources/src/main/res/values/strings.xml             | 2 ++
 application/vlc-android/res/menu/activity_option.xml              | 5 +++++
 .../src/org/videolan/vlc/gui/browser/MediaBrowserFragment.kt      | 4 ++++
 .../videolan/vlc/providers/medialibrary/VideoGroupsProvider.kt    | 8 +++++++-
 application/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt | 2 ++
 .../src/org/videolan/vlc/viewmodels/MedialibraryViewModel.kt      | 2 ++
 7 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/application/resources/src/main/java/org/videolan/resources/util/Helpers.kt b/application/resources/src/main/java/org/videolan/resources/util/Helpers.kt
index 7dc801c9e..6cd642042 100644
--- a/application/resources/src/main/java/org/videolan/resources/util/Helpers.kt
+++ b/application/resources/src/main/java/org/videolan/resources/util/Helpers.kt
@@ -10,6 +10,7 @@ import org.videolan.libvlc.util.AndroidUtil
 import org.videolan.medialibrary.interfaces.media.Album
 import org.videolan.medialibrary.interfaces.media.MediaWrapper
 import org.videolan.medialibrary.interfaces.media.Playlist
+import org.videolan.medialibrary.interfaces.media.VideoGroup
 import org.videolan.medialibrary.media.MediaLibraryItem
 import org.videolan.resources.AppContextProvider
 import org.videolan.resources.R
@@ -45,6 +46,7 @@ fun MediaLibraryItem.isSpecialItem() = itemType == MediaLibraryItem.TYPE_ARTIST
 fun MediaLibraryItem.getLength() = when {
     itemType == MediaLibraryItem.TYPE_ALBUM -> (this as Album).duration
     itemType == MediaLibraryItem.TYPE_MEDIA -> (this as MediaWrapper).length
+    itemType == MediaLibraryItem.TYPE_VIDEO_GROUP -> (this as VideoGroup).duration()
     else -> 0L
 }
 
diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 87a786bca..29b3274d2 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -21,6 +21,8 @@
     <string name="sortby_date_desc">Date (desc)</string>
     <string name="sortby_last_modified_date">Recently added</string>
     <string name="sortby_last_modified_date_desc">Recently added (desc)</string>
+    <string name="sortby_media_number">Media number</string>
+    <string name="sortby_media_number_desc">Media number (desc)</string>
     <string name="sortby_number">Nb tracks</string>
     <string name="sortby_number_desc">Nb tracks (desc)</string>
     <string name="searchable_hint">Search…</string>
diff --git a/application/vlc-android/res/menu/activity_option.xml b/application/vlc-android/res/menu/activity_option.xml
index d96f6aeb9..a447fc12b 100644
--- a/application/vlc-android/res/menu/activity_option.xml
+++ b/application/vlc-android/res/menu/activity_option.xml
@@ -92,6 +92,11 @@
                     android:id="@+id/ml_menu_sortby_number"
                     android:title="@string/sortby_number"
                     android:visible="false"/>
+
+            <item
+                    android:orderInCategory="2"
+                    android:id="@+id/ml_menu_sortby_media_number"
+                    android:title="@string/sortby_media_number" />
         </menu>
     </item>
     <item
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.kt b/application/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.kt
index c1a99781a..c9473b68b 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/browser/MediaBrowserFragment.kt
@@ -205,6 +205,10 @@ abstract class MediaBrowserFragment<T : SortableModel> : BaseFragment(), Filtera
                 sortBy(Medialibrary.SORT_ALBUM)
                 return true
             }
+            R.id.ml_menu_sortby_media_number -> {
+                sortBy(Medialibrary.NbMedia)
+                return true
+            }
             R.id.ml_menu_sortby_number -> {
                 sortBy(Medialibrary.SORT_FILESIZE) //TODO
                 return super.onOptionsItemSelected(item)
diff --git a/application/vlc-android/src/org/videolan/vlc/providers/medialibrary/VideoGroupsProvider.kt b/application/vlc-android/src/org/videolan/vlc/providers/medialibrary/VideoGroupsProvider.kt
index 3d44ce585..1d833c730 100644
--- a/application/vlc-android/src/org/videolan/vlc/providers/medialibrary/VideoGroupsProvider.kt
+++ b/application/vlc-android/src/org/videolan/vlc/providers/medialibrary/VideoGroupsProvider.kt
@@ -4,15 +4,21 @@ import android.content.Context
 import org.videolan.medialibrary.interfaces.Medialibrary
 import org.videolan.medialibrary.interfaces.media.VideoGroup
 import org.videolan.medialibrary.media.MediaLibraryItem
+import org.videolan.tools.Settings
 import org.videolan.vlc.viewmodels.SortableModel
 
 
 class VideoGroupsProvider(context: Context, model: SortableModel) : MedialibraryProvider<MediaLibraryItem>(context, model) {
+    override fun canSortByDuration() = true
+    override fun canSortByInsertionDate() = true
+    override fun canSortByLastModified() = true
+    override fun canSortByMediaNumber() = true
+
     override fun getAll() : Array<MediaLibraryItem> = medialibrary.getVideoGroups(sort, desc, getTotalCount(), 0).extractSingles()
 
     override fun getTotalCount() = medialibrary.videoGroupsCount
 
-    override fun getPage(loadSize: Int, startposition: Int) : Array<MediaLibraryItem> = medialibrary.getVideoGroups(sort, desc, loadSize, startposition).extractSingles().also { completeHeaders(it, startposition) }
+    override fun getPage(loadSize: Int, startposition: Int) : Array<MediaLibraryItem> = medialibrary.getVideoGroups(sort, desc, loadSize, startposition).extractSingles().also { if (Settings.showTvUi) completeHeaders(it, startposition) }
 }
 
 private fun Array<VideoGroup>.extractSingles() = map {
diff --git a/application/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt b/application/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
index 420312ed1..824c568c7 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/ModelsHelper.kt
@@ -210,6 +210,7 @@ interface SortModule {
     fun canSortByAlbum ()= false
     fun canSortByPlayCount() = false
     fun canSortByTrackId() = false
+    fun canSortByMediaNumber() = false
     fun canSortBy(sort: Int) = when (sort) {
         SORT_DEFAULT -> true
         SORT_ALPHA -> canSortByName()
@@ -223,6 +224,7 @@ interface SortModule {
         SORT_ALBUM -> canSortByAlbum()
         SORT_PLAYCOUNT -> canSortByPlayCount()
         TrackId -> canSortByTrackId()
+        NbMedia -> canSortByMediaNumber()
         else -> false
     }
 }
\ No newline at end of file
diff --git a/application/vlc-android/src/org/videolan/vlc/viewmodels/MedialibraryViewModel.kt b/application/vlc-android/src/org/videolan/vlc/viewmodels/MedialibraryViewModel.kt
index 3df242f8d..47f2c22d3 100644
--- a/application/vlc-android/src/org/videolan/vlc/viewmodels/MedialibraryViewModel.kt
+++ b/application/vlc-android/src/org/videolan/vlc/viewmodels/MedialibraryViewModel.kt
@@ -51,6 +51,7 @@ abstract class MedialibraryViewModel(context: Context) : SortableModel(context),
     override fun canSortByArtist() = providers.any { it.canSortByArtist() }
     override fun canSortByAlbum () = providers.any { it.canSortByAlbum () }
     override fun canSortByPlayCount() = providers.any { it.canSortByPlayCount() }
+    override fun canSortByMediaNumber() = providers.any { it.canSortByMediaNumber() }
 }
 
 fun MedialibraryViewModel.prepareOptionsMenu(menu: Menu) {
@@ -61,6 +62,7 @@ fun MedialibraryViewModel.prepareOptionsMenu(menu: Menu) {
     menu.findItem(R.id.ml_menu_sortby_length).isVisible = canSortByDuration()
     menu.findItem(R.id.ml_menu_sortby_date).isVisible = canSortByReleaseDate()
     menu.findItem(R.id.ml_menu_sortby_last_modified).isVisible = canSortByLastModified()
+    menu.findItem(R.id.ml_menu_sortby_media_number).isVisible = canSortByMediaNumber()
     menu.findItem(R.id.ml_menu_sortby_number).isVisible = false
 }
 



More information about the Android mailing list