Skip to content
This repository has been archived by the owner on Apr 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #112 from einsteinx2/feature/loader_playlistView
Browse files Browse the repository at this point in the history
Feature/loader playlist view
  • Loading branch information
Ben Baron authored Dec 5, 2017
2 parents a2c7f61 + 35d69b0 commit 320bd8b
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 4 deletions.
57 changes: 57 additions & 0 deletions Classes/Server Loading/Loaders/CreatePlaylistLoader.swift
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() { }
}
9 changes: 5 additions & 4 deletions Classes/Server Loading/Loaders/PlaylistLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ final class PlaylistLoader: ApiLoader, PersistedItemLoader {
return songs
}

var associatedItem: Item? {
return PlaylistRepository.si.playlist(playlistId: playlistId, serverId: serverId)
}

init(playlistId: Int64, serverId: Int64) {
self.playlistId = playlistId
super.init(serverId: serverId)
Expand Down Expand Up @@ -105,8 +109,5 @@ final class PlaylistLoader: ApiLoader, PersistedItemLoader {
}
return false
}

var associatedItem: Item? {
return PlaylistRepository.si.playlist(playlistId: playlistId, serverId: serverId)
}

}
1 change: 1 addition & 0 deletions Classes/Server Loading/SubsonicURLRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum SubsonicURLAction: String {
case getArtist = "getArtist"
case getAlbum = "getAlbum"
case getPlaylist = "getPlaylist"
case createPlaylist = "createPlaylist"
case getCoverArt = "getCoverArt"
case stream = "stream"
case hls = "hls"
Expand Down
4 changes: 4 additions & 0 deletions iSub.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
40B3FCC11FCBCE530085BEBA /* CreatePlaylistLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 40B3FCC01FCBCE530085BEBA /* CreatePlaylistLoader.swift */; };
5301F5CF1A4938F300EEB25D /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 5301F5CC1A4938F300EEB25D /* Images.xcassets */; };
5306B6ED1FC1F2D000369EEF /* SubsonicItemParsing.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5306B6EC1FC1F2D000369EEF /* SubsonicItemParsing.swift */; };
5306B6EF1FC2129C00369EEF /* HTMLEntities.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5306B6EE1FC2129B00369EEF /* HTMLEntities.framework */; };
Expand Down Expand Up @@ -340,6 +341,7 @@
1D30AB110D05D00D00671497 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
1DF5F4DF0D08C38300B7A737 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
2892E40F0DC94CBA00A64D0F /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
40B3FCC01FCBCE530085BEBA /* CreatePlaylistLoader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreatePlaylistLoader.swift; sourceTree = "<group>"; };
5301F5CC1A4938F300EEB25D /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = Images/Images.xcassets; sourceTree = "<group>"; };
53030314116ADF8B00B0AF5D /* reload-table.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "reload-table.png"; path = "Images/Other/reload-table.png"; sourceTree = "<group>"; };
5305C2051157F4F800BC78F0 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Default.png; path = Images/Other/Default.png; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1208,6 +1210,7 @@
531B33141E24CF8A00811187 /* ArtistLoader.swift */,
531B33131E24CF8A00811187 /* AlbumLoader.swift */,
5355BFB51E2DBC9B00C6D27F /* PlaylistLoader.swift */,
40B3FCC01FCBCE530085BEBA /* CreatePlaylistLoader.swift */,
7D0032141FD1988A009EAAFE /* SearchLoader.swift */,
7D6B0F551FCE2F0600BC4050 /* UpdatePlaylistLoader.swift */,
7D0032161FD2158E009EAAFE /* RandomSongsLoader.swift */,
Expand Down Expand Up @@ -2013,6 +2016,7 @@
53808D311E7DE5DF0063B6D9 /* ArtistViewController.swift in Sources */,
5306B6ED1FC1F2D000369EEF /* SubsonicItemParsing.swift in Sources */,
53A179A51F65F0D300B46251 /* HLSProxyServer.swift in Sources */,
40B3FCC11FCBCE530085BEBA /* CreatePlaylistLoader.swift in Sources */,
53E042841E36AB4B0009DE79 /* Synchronized.swift in Sources */,
531B34661E24D3D500811187 /* Defines.swift in Sources */,
53808D431E7DF2D80063B6D9 /* RootServerItemViewModel.swift in Sources */,
Expand Down

0 comments on commit 320bd8b

Please sign in to comment.