From 84250276899e4964f9182d48f7d3f7c68c4b1810 Mon Sep 17 00:00:00 2001 From: Ben Newcombe Date: Tue, 11 Jun 2019 20:28:35 +0100 Subject: [PATCH 1/4] Update dependencies --- Cartfile | 2 +- Cartfile.resolved | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cartfile b/Cartfile index b3aab402..3fca9cf4 100644 --- a/Cartfile +++ b/Cartfile @@ -9,5 +9,5 @@ github "bustoutsolutions/siesta" ~> 1.0 github "sparkle-project/Sparkle" ~> 1.17 -github "insidegui/ChromeCastCore" ~> 0.2.1 +github "insidegui/ChromeCastCore" ~> 0.3.2 github "insidegui/CloudKitCodable" ~> 0.1.3 diff --git a/Cartfile.resolved b/Cartfile.resolved index 34b4d704..8b2077ee 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -3,7 +3,7 @@ github "RxSwiftCommunity/RxRealm" "0.7.7" github "SwiftyJSON/SwiftyJSON" "4.3.0" github "apple/swift-protobuf" "1.5.0" github "bustoutsolutions/siesta" "1.4.3" -github "insidegui/ChromeCastCore" "0.2.1" +github "insidegui/ChromeCastCore" "0.3.2" github "insidegui/CloudKitCodable" "0.1.4" -github "realm/realm-cocoa" "v3.15.0" +github "realm/realm-cocoa" "v3.16.1" github "sparkle-project/Sparkle" "1.21.3" From 8133843b2cc803b460e8b1db1afa33ae656b9c55 Mon Sep 17 00:00:00 2001 From: Ben Newcombe Date: Tue, 11 Jun 2019 21:46:04 +0100 Subject: [PATCH 2/4] Add logic for auto-deletion of videos when playback reaches the end of the file --- WWDC/PlaybackViewModel.swift | 13 +++++++++++++ WWDC/Preferences.swift | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/WWDC/PlaybackViewModel.swift b/WWDC/PlaybackViewModel.swift index db98dbbb..e028d37a 100644 --- a/WWDC/PlaybackViewModel.swift +++ b/WWDC/PlaybackViewModel.swift @@ -126,6 +126,17 @@ final class PlaybackViewModel { if !d.isZero { self.nowPlayingInfo.value?.progress = p / d } } + + NotificationCenter.default.addObserver(self, selector: #selector(self.playerDidReachEndOfVideo(note:)), name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: nil) + } + } + + @objc func playerDidReachEndOfVideo(note: NSNotification) { + + let shouldDeleteVideo = UserDefaults.standard.bool(forKey: "autoDeleteVideosWhenWatched") + + if shouldDeleteVideo { + DownloadManager.shared.deleteDownloadedFile(for: sessionViewModel.session) } } @@ -134,6 +145,8 @@ final class PlaybackViewModel { player.removeTimeObserver(timeObserver) self.timeObserver = nil } + + NotificationCenter.default.removeObserver(self) } } diff --git a/WWDC/Preferences.swift b/WWDC/Preferences.swift index ceabcb3c..d5617d47 100644 --- a/WWDC/Preferences.swift +++ b/WWDC/Preferences.swift @@ -15,6 +15,7 @@ extension Notification.Name { static let RefreshPeriodicallyPreferenceDidChange = Notification.Name("RefreshPeriodicallyPreferenceDidChange") static let SkipBackAndForwardBy30SecondsPreferenceDidChange = Notification.Name("SkipBackAndForwardBy30SecondsPreferenceDidChange") static let SyncUserDataPreferencesDidChange = Notification.Name("SyncUserDataPreferencesDidChange") + static let AutoDeletePreferenceDidChange = Notification.Name("AutoDeletePreferenceDidChange") } final class Preferences { @@ -141,6 +142,17 @@ final class Preferences { } } + var autoDeleteVideosWhenWatched: Bool { + get { + return defaults.bool(forKey: #function) + } + set { + defaults.set(newValue, forKey: #function) + + NotificationCenter.default.post(name: .AutoDeletePreferenceDidChange, object: nil) + } + } + var syncUserData: Bool { get { return defaults.bool(forKey: #function) From c8b0e1ab48299966d4869f647e65a23572710e47 Mon Sep 17 00:00:00 2001 From: Ben Newcombe Date: Tue, 11 Jun 2019 21:53:25 +0100 Subject: [PATCH 3/4] Reorder Preference screen without changes --- WWDC/Preferences.storyboard | 157 ++++++++++++++++++------------------ 1 file changed, 78 insertions(+), 79 deletions(-) diff --git a/WWDC/Preferences.storyboard b/WWDC/Preferences.storyboard index 551f19e4..a80f3b7f 100644 --- a/WWDC/Preferences.storyboard +++ b/WWDC/Preferences.storyboard @@ -1,10 +1,9 @@ - + - + - @@ -15,15 +14,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - + + + + + + + + @@ -101,14 +164,9 @@ - - - - - - - - + + + @@ -140,68 +198,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + From 146dc4839c4a9bab163db17a75a0da35b44f29d4 Mon Sep 17 00:00:00 2001 From: Ben Newcombe Date: Wed, 12 Jun 2019 08:22:34 +0100 Subject: [PATCH 4/4] Remove unnecessary Notification for auto-deleting videos --- WWDC/Preferences.swift | 3 --- 1 file changed, 3 deletions(-) diff --git a/WWDC/Preferences.swift b/WWDC/Preferences.swift index d5617d47..e59a5326 100644 --- a/WWDC/Preferences.swift +++ b/WWDC/Preferences.swift @@ -15,7 +15,6 @@ extension Notification.Name { static let RefreshPeriodicallyPreferenceDidChange = Notification.Name("RefreshPeriodicallyPreferenceDidChange") static let SkipBackAndForwardBy30SecondsPreferenceDidChange = Notification.Name("SkipBackAndForwardBy30SecondsPreferenceDidChange") static let SyncUserDataPreferencesDidChange = Notification.Name("SyncUserDataPreferencesDidChange") - static let AutoDeletePreferenceDidChange = Notification.Name("AutoDeletePreferenceDidChange") } final class Preferences { @@ -148,8 +147,6 @@ final class Preferences { } set { defaults.set(newValue, forKey: #function) - - NotificationCenter.default.post(name: .AutoDeletePreferenceDidChange, object: nil) } }