From 5f80a1b8e90edd99c4dc7a5e60cad27b58e5a6b8 Mon Sep 17 00:00:00 2001 From: Daniel Barber Date: Sat, 27 Apr 2019 17:00:04 -0400 Subject: [PATCH] Reimplement reset album art --- Persephone.xcodeproj/project.pbxproj | 6 +++++- Persephone/Actions/ResetAlbumListArt.swift | 11 +++++++++++ .../Controllers/AlbumViewController.swift | 4 +--- .../Controllers/NotificationsController.swift | 1 - .../Controllers/QueueViewController.swift | 1 - Persephone/Controllers/WindowController.swift | 1 - Persephone/DataSources/AlbumDataSource.swift | 8 -------- .../{Actions => Protocols}/EnumEquatable.swift | 0 Persephone/Reducers/AlbumListReducer.swift | 17 +++++++++++++++++ 9 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 Persephone/Actions/ResetAlbumListArt.swift rename Persephone/{Actions => Protocols}/EnumEquatable.swift (100%) diff --git a/Persephone.xcodeproj/project.pbxproj b/Persephone.xcodeproj/project.pbxproj index 8df768f..7c43ecb 100644 --- a/Persephone.xcodeproj/project.pbxproj +++ b/Persephone.xcodeproj/project.pbxproj @@ -98,6 +98,7 @@ E4B11BA92274EDE30075461B /* Loading.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4B11BA82274EDE30075461B /* Loading.swift */; }; E4B11BAD2274F2E80075461B /* UpdateAlbumArt.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4B11BAC2274F2E80075461B /* UpdateAlbumArt.swift */; }; E4B11BB02274F71A0075461B /* EnumEquatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4B11BAF2274F71A0075461B /* EnumEquatable.swift */; }; + E4B11BB22274F9520075461B /* ResetAlbumListArt.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4B11BB12274F9520075461B /* ResetAlbumListArt.swift */; }; E4C8B53C22342005009A20F3 /* PreferencesWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4C8B53B22342005009A20F3 /* PreferencesWindowController.swift */; }; E4C8B53E22349002009A20F3 /* MPDIdle.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4C8B53D22349002009A20F3 /* MPDIdle.swift */; }; E4E8CC902204EC7F0024217A /* Delegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E4E8CC8F2204EC7F0024217A /* Delegate.swift */; }; @@ -287,6 +288,7 @@ E4B11BA82274EDE30075461B /* Loading.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Loading.swift; sourceTree = ""; }; E4B11BAC2274F2E80075461B /* UpdateAlbumArt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdateAlbumArt.swift; sourceTree = ""; }; E4B11BAF2274F71A0075461B /* EnumEquatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EnumEquatable.swift; sourceTree = ""; }; + E4B11BB12274F9520075461B /* ResetAlbumListArt.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResetAlbumListArt.swift; sourceTree = ""; }; E4C8B53B22342005009A20F3 /* PreferencesWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesWindowController.swift; sourceTree = ""; }; E4C8B53D22349002009A20F3 /* MPDIdle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MPDIdle.swift; sourceTree = ""; }; E4E8CC8F2204EC7F0024217A /* Delegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Delegate.swift; sourceTree = ""; }; @@ -616,7 +618,7 @@ E4B11B76226CC6BE0075461B /* UpdateQueuePosAction.swift */, E4B11B6E226A5C7A0075461B /* UpdateStatusAction.swift */, E4B11BAC2274F2E80075461B /* UpdateAlbumArt.swift */, - E4B11BAF2274F71A0075461B /* EnumEquatable.swift */, + E4B11BB12274F9520075461B /* ResetAlbumListArt.swift */, ); path = Actions; sourceTree = ""; @@ -624,6 +626,7 @@ E4B11BAE2274F7030075461B /* Protocols */ = { isa = PBXGroup; children = ( + E4B11BAF2274F71A0075461B /* EnumEquatable.swift */, ); path = Protocols; sourceTree = ""; @@ -934,6 +937,7 @@ E41E5312223EF74A00173814 /* AlbumArtService+Filesystem.swift in Sources */, E41E5301223BF99300173814 /* MPDClient+Queue.swift in Sources */, E4EB237B220F7CF1008C70C0 /* MPDAlbum.swift in Sources */, + E4B11BB22274F9520075461B /* ResetAlbumListArt.swift in Sources */, E41E5303223BF9C300173814 /* MPDClient+Idle.swift in Sources */, E4B11B53226928F20075461B /* AppState.swift in Sources */, E435E3E4221CD75D00184CFC /* NSImage.swift in Sources */, diff --git a/Persephone/Actions/ResetAlbumListArt.swift b/Persephone/Actions/ResetAlbumListArt.swift new file mode 100644 index 0000000..8cac2bb --- /dev/null +++ b/Persephone/Actions/ResetAlbumListArt.swift @@ -0,0 +1,11 @@ +// +// ResetAlbumListArt.swift +// Persephone +// +// Created by Daniel Barber on 2019/4/27. +// Copyright © 2019 Dan Barber. All rights reserved. +// + +import ReSwift + +struct ResetAlbumListArt: Action {} diff --git a/Persephone/Controllers/AlbumViewController.swift b/Persephone/Controllers/AlbumViewController.swift index d5cd9d8..85d9a91 100644 --- a/Persephone/Controllers/AlbumViewController.swift +++ b/Persephone/Controllers/AlbumViewController.swift @@ -75,15 +75,13 @@ class AlbumViewController: NSViewController, case "mpdLibraryDir": albumCollectionView.reloadData() case "fetchMissingArtworkFromInternet": - // dataSource.resetCoverArt() - albumCollectionView.reloadData() + AppDelegate.store.dispatch(ResetAlbumListArt()) default: break } } func newState(state: StoreSubscriberStateType) { - print("New album list state") if dataSource.albums == [] { dataSource.albums = state.albums albumCollectionView.reloadData() diff --git a/Persephone/Controllers/NotificationsController.swift b/Persephone/Controllers/NotificationsController.swift index 7362cf8..a747f76 100644 --- a/Persephone/Controllers/NotificationsController.swift +++ b/Persephone/Controllers/NotificationsController.swift @@ -49,7 +49,6 @@ class NotificationsController: MPDClientDelegate { } func didLoadAlbums(mpdClient: MPDClient, albums: [MPDClient.MPDAlbum]) { - print("Albums") DispatchQueue.main.async { AppDelegate.store.dispatch(UpdateAlbumListAction(albums: albums)) } diff --git a/Persephone/Controllers/QueueViewController.swift b/Persephone/Controllers/QueueViewController.swift index 1b3a349..4410cde 100644 --- a/Persephone/Controllers/QueueViewController.swift +++ b/Persephone/Controllers/QueueViewController.swift @@ -39,7 +39,6 @@ class QueueViewController: NSViewController, } func newState(state: StoreSubscriberStateType) { - print("New queue state") dataSource.setQueueIcon() queueView.reloadData() updateAlbumArt(state) diff --git a/Persephone/Controllers/WindowController.swift b/Persephone/Controllers/WindowController.swift index 80f78e8..c990b8d 100644 --- a/Persephone/Controllers/WindowController.swift +++ b/Persephone/Controllers/WindowController.swift @@ -48,7 +48,6 @@ class WindowController: NSWindowController, StoreSubscriber { } func newState(state: StoreSubscriberStateType) { - print("New player state") self.state = state.state DispatchQueue.main.async { diff --git a/Persephone/DataSources/AlbumDataSource.swift b/Persephone/DataSources/AlbumDataSource.swift index fc27270..659409b 100644 --- a/Persephone/DataSources/AlbumDataSource.swift +++ b/Persephone/DataSources/AlbumDataSource.swift @@ -15,14 +15,6 @@ class AlbumDataSource: NSObject, NSCollectionViewDataSource { func collectionView(_ collectionView: NSCollectionView, numberOfItemsInSection section: Int) -> Int { return albums.count } -// -// func resetCoverArt() { -// albums = AppDelegate.store.state.albumListState.albums.map { -// var album = $0 -// album.coverArtFetched = false -// return album -// } -// } func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem { let item = collectionView.makeItem(withIdentifier: .albumViewItem, for: indexPath) diff --git a/Persephone/Actions/EnumEquatable.swift b/Persephone/Protocols/EnumEquatable.swift similarity index 100% rename from Persephone/Actions/EnumEquatable.swift rename to Persephone/Protocols/EnumEquatable.swift diff --git a/Persephone/Reducers/AlbumListReducer.swift b/Persephone/Reducers/AlbumListReducer.swift index fcaf1c6..66257b8 100644 --- a/Persephone/Reducers/AlbumListReducer.swift +++ b/Persephone/Reducers/AlbumListReducer.swift @@ -14,10 +14,27 @@ func albumListReducer(action: Action, state: AlbumListState?) -> AlbumListState switch action { case let action as UpdateAlbumListAction: state.albums = action.albums.map { Album(mpdAlbum: $0) } + case let action as UpdateAlbumArt: state.albums[action.albumIndex].coverArt = .loaded(action.coverArt) + + case is ResetAlbumListArt: + state.albums = AppDelegate.store.state.albumListState.albums.map { + var album = $0 + switch album.coverArt { + case .loaded(let coverArt): + if coverArt == nil { + album.coverArt = .notAsked + } + default: + album.coverArt = .notAsked + } + return album + } + default: break + } return state