Implemented censored names preference
Added case sensitivity preference Integer tags are not clearable anymore
This commit is contained in:
committed by
Kim Wittenburg
parent
e2bdcd21e5
commit
257a7811d6
@@ -24,37 +24,53 @@ public class AlbumCollection: CollectionType {
|
||||
|
||||
}
|
||||
|
||||
// MARK: Constants
|
||||
|
||||
/// Posted when an album is added to a collection. This notification is only
|
||||
/// posted if the album collection actually changed.
|
||||
public static let AlbumAddedNotificationName = "AlbumAddedNotificationName"
|
||||
|
||||
/// Posted when an album is removed from a collection. This notification is
|
||||
/// only posted if the album collection actually changed.
|
||||
public static let AlbumRemovedNotificationName = "AlbumRemovedNotificationName"
|
||||
|
||||
/// Posted when an album collection finished loading the tracks for an album.
|
||||
/// Receiving this notification does not mean that the tracks were actually
|
||||
/// loaded successfully. It just means that the network connection
|
||||
/// terminated. Use `errorForAlbum` to determine if an error occured while
|
||||
/// the tracks have been loaded.
|
||||
///
|
||||
/// - note: Since the actual `Album` instance in the album collection may
|
||||
/// change during loading its tracks it is preferred that you use the
|
||||
/// `AlbumIndexKey` of the notification to determine which album finished
|
||||
/// loading its tracks. You can however use the `AlbumKey` as well to access
|
||||
/// the `Album` instance that is currently present in the collection at the
|
||||
/// respective index.
|
||||
public static let AlbumFinishedLoadingNotificationName = "AlbumFinishedLoadingNotificationName"
|
||||
|
||||
/// Key in the `userInfo` dictionary of a notification. The associated value
|
||||
/// is an `Int` indicating the index of the album that is affected.
|
||||
public static let AlbumIndexKey = "AlbumIndexKey"
|
||||
|
||||
/// Key in the `userInfo` dictionary of a notification. The associated value
|
||||
/// is the `Album` instance that is affected.
|
||||
public static let AlbumKey = "AlbumKey"
|
||||
/// Notifications posted by an album collection. The `userInfo` of these
|
||||
/// notifications contains all keys specified in `Keys`.
|
||||
public struct Notifications {
|
||||
|
||||
/// Posted when an album is added to a collection. This notification is
|
||||
/// only posted if the album collection actually changed.
|
||||
public static let albumAdded = "AlbumAddedNotificationName"
|
||||
|
||||
/// Posted when an album is removed from a collection. This notification
|
||||
/// is only posted if the album collection actually changed.
|
||||
public static let albumRemoved = "AlbumRemovedNotificationName"
|
||||
|
||||
/// Posted when the album collection started a network request for an
|
||||
/// album's tracks.
|
||||
///
|
||||
/// Note that the values for the keys `Album` and `AlbumIndex` for the
|
||||
/// corresponding `AlbumFinishedLoading` notification may both be
|
||||
/// different.
|
||||
public static let albumStartedLoading = "AlbumStartedLoadingNotificationName"
|
||||
|
||||
/// Posted when an album collection finished loading the tracks for an
|
||||
/// album. Receiving this notification does not mean that the tracks were
|
||||
/// actually loaded successfully. It just means that the networ
|
||||
/// connection terminated. Use `errorForAlbum` to determine if an error
|
||||
/// occured while the tracks have been loaded.
|
||||
///
|
||||
/// - note: Since the actual `Album` instance in the album collection may
|
||||
/// change during loading its tracks it is preferred that you use the
|
||||
/// `AlbumIndexKey` of the notification to determine which album finished
|
||||
/// loading its tracks. You can however use the `AlbumKey` as well to
|
||||
/// access the `Album` instance that is currently present in the
|
||||
/// collection at the respective index.
|
||||
public static let albumFinishedLoading = "AlbumFinishedLoadingNotificationName"
|
||||
|
||||
/// These constants are available as keys in the `userInfo` dictionary
|
||||
/// for any notification an album collection may post.
|
||||
public struct Keys {
|
||||
|
||||
/// The `Album` instance affected by the notification.
|
||||
public static let album = "AlbumKey"
|
||||
|
||||
/// The index of the album affected by the notification.
|
||||
public static let albumIndex = "AlbumIndexKey"
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
@@ -94,10 +110,11 @@ public class AlbumCollection: CollectionType {
|
||||
public func addAlbum(album: Album, beginLoading flag: Bool = true) {
|
||||
if !albums.contains(album) {
|
||||
albums.append(album)
|
||||
let userInfo: [NSObject: AnyObject] = [AlbumCollection.Notifications.Keys.album: album, AlbumCollection.Notifications.Keys.albumIndex: albums.count-1]
|
||||
NSNotificationCenter.defaultCenter().postNotificationName(AlbumCollection.Notifications.albumAdded, object: self, userInfo: userInfo)
|
||||
if flag {
|
||||
beginLoadingTracksForAlbum(album)
|
||||
}
|
||||
NSNotificationCenter.defaultCenter().postNotificationName(AlbumCollection.AlbumAddedNotificationName, object: self, userInfo: [AlbumCollection.AlbumIndexKey: albums.count-1])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +132,8 @@ public class AlbumCollection: CollectionType {
|
||||
let album = self[index]
|
||||
setAlbumState(nil, forAlbum: album)
|
||||
albums.removeAtIndex(index)
|
||||
NSNotificationCenter.defaultCenter().postNotificationName(AlbumCollection.AlbumRemovedNotificationName, object: self, userInfo: [AlbumCollection.AlbumIndexKey: index])
|
||||
let userInfo: [NSObject: AnyObject] = [AlbumCollection.Notifications.Keys.album: album, AlbumCollection.Notifications.Keys.albumIndex: index]
|
||||
NSNotificationCenter.defaultCenter().postNotificationName(AlbumCollection.Notifications.albumRemoved, object: self, userInfo: userInfo)
|
||||
}
|
||||
|
||||
/// Begins to load the tracks for the specified album. If there is already a
|
||||
@@ -123,11 +141,15 @@ public class AlbumCollection: CollectionType {
|
||||
/// specified album have been loaded or an error occured, a
|
||||
/// `AlbumFinishedLoadingNotification` is posted.
|
||||
public func beginLoadingTracksForAlbum(album: Album) {
|
||||
guard let albumIndex = albums.indexOf(album) else {
|
||||
return
|
||||
}
|
||||
let url = iTunesAPI.createAlbumLookupURLForId(album.id)
|
||||
let task = urlSession.dataTaskWithURL(url) { (data, response, error) -> Void in
|
||||
var albumIndex = self.albums.indexOf(album)!
|
||||
var newAlbumIndex = self.albums.indexOf(album)!
|
||||
defer {
|
||||
NSNotificationCenter.defaultCenter().postNotificationName(AlbumCollection.AlbumFinishedLoadingNotificationName, object: self, userInfo: [AlbumCollection.AlbumIndexKey: albumIndex])
|
||||
let userInfo: [NSObject: AnyObject] = [AlbumCollection.Notifications.Keys.album: self.albums[albumIndex], AlbumCollection.Notifications.Keys.albumIndex: albumIndex]
|
||||
NSNotificationCenter.defaultCenter().postNotificationName(AlbumCollection.Notifications.albumFinishedLoading, object: self, userInfo: userInfo)
|
||||
}
|
||||
guard error == nil else {
|
||||
if error!.code != NSUserCancelledError {
|
||||
@@ -137,9 +159,8 @@ public class AlbumCollection: CollectionType {
|
||||
}
|
||||
do {
|
||||
let newAlbum = try iTunesAPI.parseAPIData(data!)[0]
|
||||
albumIndex = self.albums.indexOf(album)!
|
||||
self.albums.removeAtIndex(albumIndex)
|
||||
self.albums.insert(newAlbum, atIndex: albumIndex)
|
||||
self.albums.removeAtIndex(newAlbumIndex)
|
||||
self.albums.insert(newAlbum, atIndex: newAlbumIndex)
|
||||
self.setAlbumState(.Normal, forAlbum: album)
|
||||
} catch let error as NSError {
|
||||
self.setAlbumState(.Error(error), forAlbum: album)
|
||||
@@ -149,6 +170,9 @@ public class AlbumCollection: CollectionType {
|
||||
}
|
||||
setAlbumState(.Loading(task), forAlbum: album)
|
||||
task.resume()
|
||||
let userInfo: [NSObject: AnyObject] = [AlbumCollection.Notifications.Keys.album: album, AlbumCollection.Notifications.Keys.albumIndex: albumIndex]
|
||||
NSNotificationCenter.defaultCenter().postNotificationName(AlbumCollection.Notifications.albumStartedLoading, object: self, userInfo: userInfo)
|
||||
|
||||
}
|
||||
|
||||
/// Cancels the request to load the tracks for the specified album and sets
|
||||
|
||||
Reference in New Issue
Block a user