From 64476a20b21348bf3a019dea01c9f46b692371dd Mon Sep 17 00:00:00 2001
From: Diogo Simao Marques <dogo@videolabs.io>
Date: Tue, 4 Mar 2025 15:43:49 +0100
Subject: [PATCH 1/7] MediaViewController: Add the sorting criteria in the menu
 for playlists

The sorting criteria are now displayed in the menu generated for the
playlists' content.
---
 .../MediaViewControllers/MediaViewController.swift    | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/Sources/Media Library/MediaViewControllers/MediaViewController.swift b/Sources/Media Library/MediaViewControllers/MediaViewController.swift
index 3077251a6..b6434d87c 100644
--- a/Sources/Media Library/MediaViewControllers/MediaViewController.swift	
+++ b/Sources/Media Library/MediaViewControllers/MediaViewController.swift	
@@ -513,11 +513,6 @@ extension MediaViewController {
 
         var rightMenuItems: [UIMenuElement] = [selectAction]
 
-        if let model = mediaCategoryViewController.model as? CollectionModel,
-           model.mediaCollection is VLCMLPlaylist {
-            return UIMenu(options: .displayInline, children: rightMenuItems)
-        }
-
         if let parentViewController = viewController?.parent,
            parentViewController is VideoViewController || parentViewController is AudioViewController {
             let historyMenu = generateHistoryMenu()
@@ -527,6 +522,12 @@ extension MediaViewController {
         let layoutSubMenu = generateLayoutMenu(with: mediaCategoryViewController)
         let sortSubMenu = generateSortMenu(with: mediaCategoryViewController)
 
+        if let model = mediaCategoryViewController.model as? CollectionModel,
+           model.mediaCollection is VLCMLPlaylist {
+            rightMenuItems.append(sortSubMenu)
+            return UIMenu(options: .displayInline, children: rightMenuItems)
+        }
+
         rightMenuItems.append(layoutSubMenu)
         rightMenuItems.append(sortSubMenu)
 
-- 
GitLab


From b18fcab98b136651e7df649a57e44c930c43aa3e Mon Sep 17 00:00:00 2001
From: Diogo Simao Marques <dogo@videolabs.io>
Date: Wed, 5 Mar 2025 10:53:15 +0100
Subject: [PATCH 2/7] Podfile: Update VLCMediaLibraryKit

The VLCMediaLibraryKit version has been updated to be able to use
the latest changes.
---
 Podfile      | 2 +-
 Podfile.lock | 8 ++++----
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/Podfile b/Podfile
index b568231e6..cbd4971f0 100644
--- a/Podfile
+++ b/Podfile
@@ -8,7 +8,7 @@ def shared_pods
   pod 'CocoaHTTPServer', :git => 'https://code.videolan.org/fkuehne/CocoaHTTPServer.git', :commit => '08f9b818'
   pod 'AFNetworking', :git => 'https://code.videolan.org/fkuehne/AFNetworking.git', :commit => 'ee51009a' # add visionOS support
   pod 'VLCKit', '4.0.0a10'
-  pod 'VLCMediaLibraryKit', '0.13.0a10'
+  pod 'VLCMediaLibraryKit', '0.13.0a11'
 end
 
 target 'VLC-iOS' do
diff --git a/Podfile.lock b/Podfile.lock
index 8cd1fb3e9..30aed5be3 100644
--- a/Podfile.lock
+++ b/Podfile.lock
@@ -73,7 +73,7 @@ PODS:
   - SimulatorStatusMagic (2.7)
   - SwiftLint (0.50.3)
   - VLCKit (4.0.0a10)
-  - VLCMediaLibraryKit (0.13.0a10):
+  - VLCMediaLibraryKit (0.13.0a11):
     - VLCKit (>= 4.0.0a10)
   - XKKeychain (1.0.1)
 
@@ -96,7 +96,7 @@ DEPENDENCIES:
   - SimulatorStatusMagic
   - SwiftLint (~> 0.50.3)
   - VLCKit (= 4.0.0a10)
-  - VLCMediaLibraryKit (= 0.13.0a10)
+  - VLCMediaLibraryKit (= 0.13.0a11)
   - XKKeychain (from `https://code.videolan.org/fkuehne/XKKeychain.git`, commit `40abb8f1`)
 
 SPEC REPOS:
@@ -200,9 +200,9 @@ SPEC CHECKSUMS:
   SimulatorStatusMagic: 4e15e56530b367e90dcd3b94fd272e833e9d8a44
   SwiftLint: 77f7cb2b9bb81ab4a12fcc86448ba3f11afa50c6
   VLCKit: e21135aece10e3aa89e34020b7112b73d7cc98e6
-  VLCMediaLibraryKit: 59c58376b7592e9a1b14106dfc24c40d854bb740
+  VLCMediaLibraryKit: 5bbd1dd300e88b8df607077b2b01b6952c8d48fb
   XKKeychain: 160ce5bfeff49e9fef091f7fc2b2fe5a5aa08e08
 
-PODFILE CHECKSUM: 08c77786bb3b3cd075029e8f71fc44c305f3f101
+PODFILE CHECKSUM: 65a7fa9ee482022fade614219df0522c6399aafe
 
 COCOAPODS: 1.15.2
-- 
GitLab


From 83634e989ed3a7715d25420755d1fd98d81737f2 Mon Sep 17 00:00:00 2001
From: Diogo Simao Marques <dogo@videolabs.io>
Date: Tue, 4 Mar 2025 15:51:30 +0100
Subject: [PATCH 3/7] PlaylistModel: Properly return the sorted array

Different sorting criteria can be applied to the array of media stored
in a playlist.

Closes #729
---
 Sources/Media Library/MediaLibraryModel/PlaylistModel.swift | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Sources/Media Library/MediaLibraryModel/PlaylistModel.swift b/Sources/Media Library/MediaLibraryModel/PlaylistModel.swift
index 25c1e9732..ad14f4dd1 100644
--- a/Sources/Media Library/MediaLibraryModel/PlaylistModel.swift	
+++ b/Sources/Media Library/MediaLibraryModel/PlaylistModel.swift	
@@ -216,7 +216,7 @@ extension VLCMLPlaylist: MediaCollectionModel {
 
     func files(with criteria: VLCMLSortingCriteria = .alpha,
                desc: Bool = false) -> [VLCMLMedia]? {
-        return media
+        return media(with: criteria, desc: desc)
     }
 
     func title() -> String {
-- 
GitLab


From f3dd1da4301466e65a1e18093d5410f49e3234c7 Mon Sep 17 00:00:00 2001
From: Diogo Simao Marques <dogo@videolabs.io>
Date: Tue, 4 Mar 2025 16:57:01 +0100
Subject: [PATCH 4/7] CollectionModel: Add the default sorting criteria to the
 playlists

The default sorting criteria is now explicitly added to the list.
---
 .../Media Library/MediaLibraryModel/CollectionModel.swift    | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/Sources/Media Library/MediaLibraryModel/CollectionModel.swift b/Sources/Media Library/MediaLibraryModel/CollectionModel.swift
index 9bd87f214..3624df87e 100644
--- a/Sources/Media Library/MediaLibraryModel/CollectionModel.swift	
+++ b/Sources/Media Library/MediaLibraryModel/CollectionModel.swift	
@@ -50,6 +50,11 @@ class CollectionModel: MLBaseModel {
         }
         self.medialibrary = mediaService
         self.mediaCollection = mediaCollection
+
+        if mediaCollection is VLCMLPlaylist {
+            sortModel.sortingCriteria.append(.default)
+        }
+
         self.sortModel = mediaCollection.sortModel() ?? self.sortModel
 
         var sortingCriteria: VLCMLSortingCriteria = .default
-- 
GitLab


From d887c02147a31929c80a70a296f894d0722baf9b Mon Sep 17 00:00:00 2001
From: Diogo Simao Marques <dogo@videolabs.io>
Date: Tue, 4 Mar 2025 16:59:30 +0100
Subject: [PATCH 5/7] EditController: Update the support a the custom playlist
 order

The feature allowing the user to change the order of a playlist's media
is now restricted to only the default sorting criteria.

This avoids any issue related to the loss of a the custom order when a
sorting criteria other than default was selected during the changes.
---
 Sources/Media Library/Editing/EditController.swift | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/Sources/Media Library/Editing/EditController.swift b/Sources/Media Library/Editing/EditController.swift
index 1d832e54a..ff47d4a51 100644
--- a/Sources/Media Library/Editing/EditController.swift	
+++ b/Sources/Media Library/Editing/EditController.swift	
@@ -393,7 +393,9 @@ extension EditController: UICollectionViewDataSource {
             if let cell = cell as? MediaCollectionViewCell {
                 cell.showCheckmark(true)
                 cell.disableScrollView()
-                if let collectionModel = model as? CollectionModel, collectionModel.mediaCollection is VLCMLPlaylist {
+                if let collectionModel = model as? CollectionModel,
+                   collectionModel.mediaCollection is VLCMLPlaylist,
+                   collectionModel.sortModel.currentSort == .default {
                     cell.dragIndicatorImageView.isHidden = false
                 } else if cell.media is VLCMLMediaGroup || cell.media is VLCMLPlaylist {
                     cell.dragIndicatorImageView.isHidden = true
@@ -427,9 +429,12 @@ extension EditController: UICollectionViewDataSource {
     }
 
     func collectionView(_ collectionView: UICollectionView, canMoveItemAt indexPath: IndexPath) -> Bool {
-        if let collectionModel = model as? CollectionModel, collectionModel.mediaCollection is VLCMLPlaylist {
+        if let collectionModel = model as? CollectionModel,
+           collectionModel.mediaCollection is VLCMLPlaylist,
+           collectionModel.sortModel.currentSort == .default {
             return true
         }
+
         return false
     }
 
-- 
GitLab


From 2d1ae60ce94f218bd62dad754c76bd72dae37de9 Mon Sep 17 00:00:00 2001
From: Diogo Simao Marques <dogo@videolabs.io>
Date: Tue, 4 Mar 2025 17:02:37 +0100
Subject: [PATCH 6/7] MediaViewController: Remove the descending indicator for
 the default criteria

The indicator is removed because the default criteria is not related to any
ascending or descending order.

The default criteria is only based on the user's interaction.
---
 .../MediaViewControllers/MediaViewController.swift        | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/Sources/Media Library/MediaViewControllers/MediaViewController.swift b/Sources/Media Library/MediaViewControllers/MediaViewController.swift
index b6434d87c..cc5a8ee18 100644
--- a/Sources/Media Library/MediaViewControllers/MediaViewController.swift	
+++ b/Sources/Media Library/MediaViewControllers/MediaViewController.swift	
@@ -452,8 +452,12 @@ extension MediaViewController {
         for (index, criterion) in sortModel.sortingCriteria.enumerated() {
             let currentSort: Bool = index == currentSortIndex
             let chevronImageName: String = sortModel.desc ? "chevron.down" : "chevron.up"
-            let actionImage: UIImage? = currentSort ?
-            UIImage(systemName: chevronImageName) : nil
+            var actionImage: UIImage? = currentSort ? UIImage(systemName: chevronImageName) : nil
+
+            // There is no need to display the desc image since it has no impact
+            if criterion == VLCMLSortingCriteria.default {
+                actionImage = nil
+            }
 
             let action = UIAction(title: String(describing: criterion),
                                   image: actionImage,
-- 
GitLab


From d8c4ee238f6587dcc1bf66acb6265a9ffafa4164 Mon Sep 17 00:00:00 2001
From: Diogo Simao Marques <dogo@videolabs.io>
Date: Tue, 4 Mar 2025 17:05:31 +0100
Subject: [PATCH 7/7] SortModel: Update the label of the default criteria

The default criteria's localized label is updated to "Custom" to match
its purpose.
---
 Resources/en.lproj/Localizable.strings                  | 1 +
 Sources/Media Library/MediaLibraryModel/SortModel.swift | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/Resources/en.lproj/Localizable.strings b/Resources/en.lproj/Localizable.strings
index 84b29ec73..05401c5a2 100644
--- a/Resources/en.lproj/Localizable.strings
+++ b/Resources/en.lproj/Localizable.strings
@@ -432,6 +432,7 @@
 "NB_ALBUM" = "Number of albums";
 "LAST_PLAYBACK_DATE" = "Last playback date";
 "TRACK_ID" = "Track ID";
+"CUSTOM" = "Custom";
 
 // MARK: - VLCNetworkLoginTVViewController
 
diff --git a/Sources/Media Library/MediaLibraryModel/SortModel.swift b/Sources/Media Library/MediaLibraryModel/SortModel.swift
index 3b22b81cb..806fd8ab8 100644
--- a/Sources/Media Library/MediaLibraryModel/SortModel.swift	
+++ b/Sources/Media Library/MediaLibraryModel/SortModel.swift	
@@ -71,7 +71,7 @@ extension VLCMLSortingCriteria: CustomStringConvertible {
         case .trackID:
             return NSLocalizedString("TRACK_ID", comment: "")
         case .default:
-            return NSLocalizedString("DEFAULT", comment: "")
+            return NSLocalizedString("CUSTOM", comment: "")
         @unknown default:
             return NSLocalizedString("DEFAULT", comment: "")
         }
-- 
GitLab