Skip to content

Commit 83ddee8

Browse files
MediaCategory: Add Play All button for the artists' collections
Add of a play all button to the artists' collections to allow the users to play the medias of the selected artist. Closes #836
1 parent 75aab6d commit 83ddee8

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

Resources/en.lproj/Localizable.strings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@
193193
"NEXT_BUTTON" = "Next";
194194
"PREV_BUTTON" = "Previous";
195195
"PLAY_ALL_BUTTON" = "Play all";
196+
"PLAY_ALL_HINT" = "Play all the medias in the collection";
196197

197198
"RESET_VIDEO_FILTERS" = "Do you want to reset the video filters?";
198199
"RESET_PLAYBACK_SPEED" = "Do you want to reset the playback speed?";

Sources/MediaCategories/MediaCategory.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,28 @@ class ArtistAlbumCategoryViewController: MediaCategoryViewController {
7575
}
7676

7777
class CollectionCategoryViewController: MediaCategoryViewController {
78+
private lazy var playAllButton: UIBarButtonItem = {
79+
let playAllButton = UIBarButtonItem(image: UIImage(named: "iconPlay"), style: .plain, target: self, action: #selector(handlePlayAll))
80+
playAllButton.accessibilityLabel = NSLocalizedString("PLAY_ALL_BUTTON", comment: "")
81+
playAllButton.accessibilityHint = NSLocalizedString("PLAY_ALL_HINT", comment: "")
82+
return playAllButton
83+
}()
84+
7885
init(_ services: Services, mediaCollection: MediaCollectionModel) {
7986
let model = CollectionModel(mediaService: services.medialibraryService, mediaCollection: mediaCollection)
8087
super.init(services: services, model: model)
8188
model.observable.addObserver(self)
8289
}
90+
91+
func getPlayAllButton() -> UIBarButtonItem {
92+
return playAllButton
93+
}
94+
95+
@objc private func handlePlayAll() {
96+
if let model = model as? CollectionModel,
97+
let collection = model.mediaCollection as? VLCMLArtist {
98+
let playbackService = PlaybackService.sharedInstance()
99+
playbackService.playCollection(collection.tracks())
100+
}
101+
}
83102
}

Sources/MediaViewControllers/MediaViewController.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,12 @@ class MediaViewController: VLCPagingViewController<VLCLabelCell> {
158158
mediaCategoryViewController = viewController
159159
}
160160

161+
if navigationController?.viewControllers.last is ArtistViewController,
162+
let viewController = viewControllers[currentIndex] as? CollectionCategoryViewController {
163+
let playButton = viewController.getPlayAllButton()
164+
rightBarButtons?.append(playButton)
165+
}
166+
161167
mediaCategoryViewController.navigationItem.leftBarButtonItems = showButtons ? leftBarButtons : nil
162168
mediaCategoryViewController.navigationItem.rightBarButtonItems = showButtons ? rightBarButtons : nil
163169
}

0 commit comments

Comments
 (0)