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" 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.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 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + diff --git a/WWDC/Preferences.swift b/WWDC/Preferences.swift index ceabcb3c..e59a5326 100644 --- a/WWDC/Preferences.swift +++ b/WWDC/Preferences.swift @@ -141,6 +141,15 @@ final class Preferences { } } + var autoDeleteVideosWhenWatched: Bool { + get { + return defaults.bool(forKey: #function) + } + set { + defaults.set(newValue, forKey: #function) + } + } + var syncUserData: Bool { get { return defaults.bool(forKey: #function)