This repository has been archived by the owner on Apr 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #112 from einsteinx2/feature/loader_playlistView
Feature/loader playlist view
- Loading branch information
Showing
4 changed files
with
67 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// CreatePlaylistLoader.swift | ||
// iSub Beta | ||
// | ||
// Created by Felipe Rolvar on 26/11/17. | ||
// Copyright © 2017 Ben Baron. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
class CreatePlaylistLoader: ApiLoader, ItemLoader { | ||
|
||
private var songs = [Song]() | ||
var playlistName: String | ||
|
||
var items: [Item] { | ||
return songs | ||
} | ||
|
||
var associatedItem: Item? { | ||
return PlaylistRepository.si.playlist(name: playlistName, serverId: serverId) | ||
} | ||
|
||
init(with name: String, and serverId: Int64) { | ||
self.playlistName = name | ||
super.init(serverId: serverId) | ||
} | ||
|
||
override func createRequest() -> URLRequest? { | ||
return URLRequest(subsonicAction: .createPlaylist, | ||
serverId: serverId, | ||
parameters: ["name": playlistName, | ||
"songId" : items.map { $0.itemId }]) | ||
} | ||
|
||
override func processResponse(root: RXMLElement) -> Bool { | ||
songs.removeAll() | ||
root.iterate("playlist.entry") { [weak self] in | ||
guard let serverId = self?.serverId, | ||
let song = Song(rxmlElement: $0, serverId: serverId) else { | ||
return | ||
} | ||
self?.songs.append(song) | ||
} | ||
return true | ||
} | ||
|
||
@discardableResult func loadModelsFromDatabase() -> Bool { | ||
guard let playlist = associatedItem as? Playlist else { return false } | ||
playlist.loadSubItems() | ||
songs = playlist.songs | ||
return songs.count > 0 | ||
} | ||
|
||
// MARK: - Nothing to implement | ||
func persistModels() { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters