Skip to content

Commit

Permalink
WaitingQueue: postpone feature
Browse files Browse the repository at this point in the history
  • Loading branch information
BLeeEZ committed Jan 27, 2022
1 parent 1163e8a commit b8c5b98
Show file tree
Hide file tree
Showing 22 changed files with 18 additions and 92 deletions.
6 changes: 3 additions & 3 deletions Amperfy/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
"author" : "xcode",
"version" : 1
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"scale" : "2x"
},
{
"filename" : "main_insert.png",
"filename" : "context_queue_append.png",
"idiom" : "universal",
"scale" : "3x"
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"scale" : "2x"
},
{
"filename" : "waiting_insert.png",
"filename" : "context_queue_insert.png",
"idiom" : "universal",
"scale" : "3x"
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"scale" : "2x"
},
{
"filename" : "main_append.png",
"filename" : "user_queue_append.png",
"idiom" : "universal",
"scale" : "3x"
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"scale" : "2x"
},
{
"filename" : "waiting_append.png",
"filename" : "user_queue_insert.png",
"idiom" : "universal",
"scale" : "3x"
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions Amperfy/Player/PlayerUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ enum PlayerQueueType: Int, CaseIterable {

var description : String {
switch self {
case .prev: return "Previous in Main Queue"
case .prev: return "Previous"
case .waitingQueue: return "Next in Waiting Queue"
case .next: return "Next in Main Queue"
case .next: return "Next"
}
}
}
Expand Down
47 changes: 6 additions & 41 deletions Amperfy/Screens/ViewController/BasicTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ typealias QueueSwipeCallback = (IndexPath, _ completionHandler: @escaping (_ pla

extension BasicTableViewController {
func createInsertNextQueueSwipeAction(indexPath: IndexPath, actionCallback: @escaping QueueSwipeCallback) -> UIContextualAction {
let action = UIContextualAction(style: .normal, title: "Insert into Next in Main Queue") { (action, view, completionHandler) in
let action = UIContextualAction(style: .normal, title: "Play Next") { (action, view, completionHandler) in
let generator = UINotificationFeedbackGenerator()
generator.notificationOccurred(.success)
actionCallback(indexPath) { playables in
Expand All @@ -44,49 +44,21 @@ extension BasicTableViewController {
completionHandler(true)
}
action.backgroundColor = .systemBlue
action.image = UIImage(named: "main_insert")?.invertedImage()
return action
}

func createInsertWaitingQueueSwipeAction(indexPath: IndexPath, actionCallback: @escaping QueueSwipeCallback) -> UIContextualAction {
let action = UIContextualAction(style: .normal, title: "Insert into Next in Waiting Queue") { (action, view, completionHandler) in
let generator = UIImpactFeedbackGenerator(style: .light)
generator.impactOccurred()
actionCallback(indexPath) { playables in
self.appDelegate.player.insertFirstToWaitingQueue(playables: playables.filterCached(dependigOn: self.appDelegate.persistentStorage.settings.isOfflineMode))
}
completionHandler(true)
}
action.backgroundColor = .systemOrange
action.image = UIImage(named: "waiting_insert")?.invertedImage()
action.image = UIImage(named: "context_queue_insert")?.invertedImage()
return action
}

func createAppendNextQueueSwipeAction(indexPath: IndexPath, actionCallback: @escaping QueueSwipeCallback) -> UIContextualAction {
let action = UIContextualAction(style: .normal, title: "Append to Next in Main Queue") { (action, view, completionHandler) in
let action = UIContextualAction(style: .normal, title: "Play Later") { (action, view, completionHandler) in
let generator = UINotificationFeedbackGenerator()
generator.notificationOccurred(.success)
actionCallback(indexPath) { playables in
self.appDelegate.player.appendToNextInMainQueue(playables: playables.filterCached(dependigOn: self.appDelegate.persistentStorage.settings.isOfflineMode))
}
completionHandler(true)
}
action.backgroundColor = .systemBlue
action.image = UIImage(named: "main_append")?.invertedImage()
return action
}

func createAppendWaitingQueueSwipeAction(indexPath: IndexPath, actionCallback: @escaping QueueSwipeCallback) -> UIContextualAction {
let action = UIContextualAction(style: .normal, title: "Append to Next in Waiting Queue") { (action, view, completionHandler) in
let generator = UIImpactFeedbackGenerator(style: .light)
generator.impactOccurred()
actionCallback(indexPath) { playables in
self.appDelegate.player.appendToWaitingQueue(playables: playables.filterCached(dependigOn: self.appDelegate.persistentStorage.settings.isOfflineMode))
}
completionHandler(true)
}
action.backgroundColor = .systemOrange
action.image = UIImage(named: "waiting_append")?.invertedImage()
action.image = UIImage(named: "context_queue_append")?.invertedImage()
return action
}
}
Expand Down Expand Up @@ -120,18 +92,11 @@ class BasicTableViewController: UITableViewController {
updateSearchResults(for: searchController)
}

override func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
guard let swipeCB = swipeCallback else { return nil }
return UISwipeActionsConfiguration(actions: [
createInsertNextQueueSwipeAction(indexPath: indexPath, actionCallback: swipeCB),
createInsertWaitingQueueSwipeAction(indexPath: indexPath, actionCallback: swipeCB)
])
}
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
guard let swipeCB = swipeCallback else { return nil }
return UISwipeActionsConfiguration(actions: [
createAppendNextQueueSwipeAction(indexPath: indexPath, actionCallback: swipeCB),
createAppendWaitingQueueSwipeAction(indexPath: indexPath, actionCallback: swipeCB)
createInsertNextQueueSwipeAction(indexPath: indexPath, actionCallback: swipeCB),
createAppendNextQueueSwipeAction(indexPath: indexPath, actionCallback: swipeCB)
])
}

Expand Down
19 changes: 2 additions & 17 deletions Amperfy/Screens/ViewController/DirectoriesVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,31 +80,16 @@ class DirectoriesVC: BasicTableViewController {
return 0.0
}
}

override func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
guard indexPath.section == 1 else { return nil }
let adjustedIndexPath = IndexPath(row: indexPath.row , section: 0)
return UISwipeActionsConfiguration(actions: [
createInsertNextQueueSwipeAction(indexPath: adjustedIndexPath) { (indexPath, completionHandler) in
let song = self.songsFetchedResultsController.getWrappedEntity(at: indexPath)
completionHandler([song])
},
createInsertWaitingQueueSwipeAction(indexPath: adjustedIndexPath) { (indexPath, completionHandler) in
let song = self.songsFetchedResultsController.getWrappedEntity(at: indexPath)
completionHandler([song])
}
])
}

override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
guard indexPath.section == 1 else { return nil }
let adjustedIndexPath = IndexPath(row: indexPath.row , section: 0)
return UISwipeActionsConfiguration(actions: [
createAppendNextQueueSwipeAction(indexPath: adjustedIndexPath) { (indexPath, completionHandler) in
createInsertNextQueueSwipeAction(indexPath: adjustedIndexPath) { (indexPath, completionHandler) in
let song = self.songsFetchedResultsController.getWrappedEntity(at: indexPath)
completionHandler([song])
},
createAppendWaitingQueueSwipeAction(indexPath: adjustedIndexPath) { (indexPath, completionHandler) in
createAppendNextQueueSwipeAction(indexPath: adjustedIndexPath) { (indexPath, completionHandler) in
let song = self.songsFetchedResultsController.getWrappedEntity(at: indexPath)
completionHandler([song])
}
Expand Down
26 changes: 1 addition & 25 deletions Amperfy/Screens/ViewController/PopupPlayerVC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -247,26 +247,7 @@ class PopupPlayerVC: UIViewController, UITableViewDelegate, UITableViewDataSourc

func refreshWaitingQueueSectionHeader() {
let waitingQueueSectionView = sectionViews[1]
if player.waitingQueue.isEmpty {
waitingQueueSectionView.hide()
} else {
waitingQueueSectionView.display(type: .waitingQueue, buttonTitle: "Clear") {
self.clearWaitingQueue()
}
}
}

func clearWaitingQueue() {
tableView.beginUpdates()
var indexPaths = [IndexPath]()
for i in 0...self.player.waitingQueue.count-1 {
indexPaths.append(IndexPath(row: i, section: 1))
}
tableView.deleteRows(at: indexPaths, with: .fade)
appDelegate.player.clearWaitingQueue()
tableView.endUpdates()
refreshWaitingQueueSectionHeader()
playerView?.refreshPlayer()
waitingQueueSectionView.hide()
}

// Override to support conditional rearranging of the table view.
Expand Down Expand Up @@ -307,11 +288,6 @@ class PopupPlayerVC: UIViewController, UITableViewDelegate, UITableViewDataSourc
self.reloadData()
self.playerView?.refreshPlayer()
}))
if !player.waitingQueue.isEmpty {
alert.addAction(UIAlertAction(title: "Clear Waiting Queue", style: .default, handler: { _ in
self.clearWaitingQueue()
}))
}
if appDelegate.persistentStorage.settings.isOnlineMode {
alert.addAction(UIAlertAction(title: "Add all songs to playlist", style: .default, handler: { _ in
let selectPlaylistVC = PlaylistSelectorVC.instantiateFromAppStoryboard()
Expand Down
Binary file modified Design/Playlist.xcf
Binary file not shown.
Binary file added Design/context_queue_append.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Design/context_queue_insert.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Design/user_queue_append.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Design/user_queue_insert.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b8c5b98

Please sign in to comment.