diff --git a/Modules/DataModel/Sources/PocketCastsDataModel/Private/Managers/EpisodeDataManager.swift b/Modules/DataModel/Sources/PocketCastsDataModel/Private/Managers/EpisodeDataManager.swift index b4bf472710..81c18a63ed 100644 --- a/Modules/DataModel/Sources/PocketCastsDataModel/Private/Managers/EpisodeDataManager.swift +++ b/Modules/DataModel/Sources/PocketCastsDataModel/Private/Managers/EpisodeDataManager.swift @@ -560,9 +560,9 @@ class EpisodeDataManager { } func saveEpisode(playingStatus: PlayingStatus, episode: Episode, updateSyncFlag: Bool, dbQueue: FMDatabaseQueue) { - episode.playingStatus = playingStatus.rawValue + episode.playingStatus = playingStatus var fields = ["playingStatus"] - var values = [episode.playingStatus] as [Any] + var values = [episode.playingStatus.rawValue] as [Any] if updateSyncFlag { episode.playingStatusModified = DBUtils.currentUTCTimeInMillis() @@ -642,17 +642,17 @@ class EpisodeDataManager { func saveEpisode(downloadStatus: DownloadStatus, lastDownloadAttemptDate: Date, autoDownloadStatus: AutoDownloadStatus, episode: Episode, dbQueue: FMDatabaseQueue) { episode.episodeStatus = downloadStatus.rawValue episode.lastDownloadAttemptDate = lastDownloadAttemptDate - episode.autoDownloadStatus = autoDownloadStatus.rawValue + episode.autoDownloadStatus = autoDownloadStatus let fields = ["episodeStatus", "lastDownloadAttemptDate", "autoDownloadStatus"] - let values = [episode.episodeStatus, DBUtils.replaceNilWithNull(value: episode.lastDownloadAttemptDate), episode.autoDownloadStatus, episode.id] as [Any] + let values = [episode.episodeStatus, DBUtils.replaceNilWithNull(value: episode.lastDownloadAttemptDate), episode.autoDownloadStatus.rawValue, episode.id] as [Any] save(fields: fields, values: values, dbQueue: dbQueue) } func saveEpisode(autoDownloadStatus: AutoDownloadStatus, episode: Episode, dbQueue: FMDatabaseQueue) { - episode.autoDownloadStatus = autoDownloadStatus.rawValue - save(fieldName: "autoDownloadStatus", value: autoDownloadStatus, episodeId: episode.id, dbQueue: dbQueue) + episode.autoDownloadStatus = autoDownloadStatus + save(fieldName: "autoDownloadStatus", value: autoDownloadStatus.rawValue, episodeId: episode.id, dbQueue: dbQueue) } func saveEpisode(downloadStatus: DownloadStatus, downloadError: String?, downloadTaskId: String?, episode: Episode, dbQueue: FMDatabaseQueue) { @@ -784,7 +784,7 @@ class EpisodeDataManager { db.beginTransaction() for episode in episodes { - if episode.playingStatus == PlayingStatus.completed.rawValue { continue } + if episode.playingStatus == .completed { continue } var fields = [String]() var values = [Any]() @@ -816,7 +816,7 @@ class EpisodeDataManager { db.beginTransaction() for episode in episodes { - if episode.playingStatus == PlayingStatus.notPlayed.rawValue { continue } + if episode.playingStatus == .notPlayed { continue } var fields = [String]() var values = [Any]() @@ -868,7 +868,7 @@ class EpisodeDataManager { fields.append("cachedFrameCount") values.append(0) } - if markAsPlayed, episode.playingStatus != PlayingStatus.completed.rawValue { + if markAsPlayed, episode.playingStatus != .completed { fields.append("playingStatus") values.append(PlayingStatus.completed.rawValue) @@ -1023,8 +1023,8 @@ class EpisodeDataManager { values.append(episode.keepEpisode) values.append(episode.playedUpTo) values.append(episode.duration) - values.append(episode.playingStatus) - values.append(episode.autoDownloadStatus) + values.append(episode.playingStatus.rawValue) + values.append(episode.autoDownloadStatus.rawValue) values.append(DBUtils.nullIfNil(value: episode.publishedDate)) values.append(episode.sizeInBytes) values.append(episode.playingStatusModified) diff --git a/Modules/DataModel/Sources/PocketCastsDataModel/Private/Managers/UserEpisodeDataManager.swift b/Modules/DataModel/Sources/PocketCastsDataModel/Private/Managers/UserEpisodeDataManager.swift index 9d377cee0e..9047f1eef1 100644 --- a/Modules/DataModel/Sources/PocketCastsDataModel/Private/Managers/UserEpisodeDataManager.swift +++ b/Modules/DataModel/Sources/PocketCastsDataModel/Private/Managers/UserEpisodeDataManager.swift @@ -243,7 +243,7 @@ class UserEpisodeDataManager { } func saveEpisode(playingStatus: PlayingStatus, episode: UserEpisode, updateSyncFlag: Bool, dbQueue: FMDatabaseQueue) { - episode.playingStatus = playingStatus.rawValue + episode.playingStatus = playingStatus var fields = ["playingStatus"] var values = [episode.playingStatus] as [Any] @@ -280,8 +280,8 @@ class UserEpisodeDataManager { } func saveEpisode(autoDownloadStatus: AutoDownloadStatus, episode: UserEpisode, dbQueue: FMDatabaseQueue) { - episode.autoDownloadStatus = autoDownloadStatus.rawValue - save(fieldName: "autoDownloadStatus", value: autoDownloadStatus, episodeId: episode.id, dbQueue: dbQueue) + episode.autoDownloadStatus = autoDownloadStatus + save(fieldName: "autoDownloadStatus", value: autoDownloadStatus.rawValue, episodeId: episode.id, dbQueue: dbQueue) } func saveEpisode(downloadStatus: DownloadStatus, downloadTaskId: String?, episode: UserEpisode, dbQueue: FMDatabaseQueue) { @@ -346,10 +346,10 @@ class UserEpisodeDataManager { func saveEpisode(downloadStatus: DownloadStatus, lastDownloadAttemptDate: Date, autoDownloadStatus: AutoDownloadStatus, episode: UserEpisode, dbQueue: FMDatabaseQueue) { episode.episodeStatus = downloadStatus.rawValue episode.lastDownloadAttemptDate = lastDownloadAttemptDate - episode.autoDownloadStatus = autoDownloadStatus.rawValue + episode.autoDownloadStatus = autoDownloadStatus let fields = ["episodeStatus", "lastDownloadAttemptDate", "autoDownloadStatus"] - let values = [episode.episodeStatus, DBUtils.replaceNilWithNull(value: episode.lastDownloadAttemptDate), episode.autoDownloadStatus, episode.id] as [Any] + let values = [episode.episodeStatus, DBUtils.replaceNilWithNull(value: episode.lastDownloadAttemptDate), episode.autoDownloadStatus.rawValue, episode.id] as [Any] save(fields: fields, values: values, dbQueue: dbQueue) } @@ -389,7 +389,7 @@ class UserEpisodeDataManager { db.beginTransaction() for episode in episodes { - if episode.playingStatus == PlayingStatus.completed.rawValue { continue } + if episode.playingStatus == .completed { continue } var fields = [String]() var values = [Any]() @@ -421,7 +421,7 @@ class UserEpisodeDataManager { db.beginTransaction() for episode in episodes { - if episode.playingStatus == PlayingStatus.notPlayed.rawValue { continue } + if episode.playingStatus == .notPlayed { continue } var fields = [String]() var values = [Any]() @@ -570,8 +570,8 @@ class UserEpisodeDataManager { episode.playedUpTo = rs.double(forColumn: "playedUpTo") episode.duration = rs.double(forColumn: "duration") episode.durationModified = rs.longLongInt(forColumn: "durationModified") - episode.playingStatus = rs.int(forColumn: "playingStatus") - episode.autoDownloadStatus = rs.int(forColumn: "autoDownloadStatus") + episode.playingStatus = PlayingStatus(rawValue: rs.int(forColumn: "playingStatus")) ?? .notPlayed + episode.autoDownloadStatus = AutoDownloadStatus(rawValue: rs.int(forColumn: "autoDownloadStatus")) ?? .notSpecified episode.publishedDate = DBUtils.convertDate(value: rs.double(forColumn: "publishedDate")) episode.sizeInBytes = rs.longLongInt(forColumn: "sizeInBytes") episode.playingStatusModified = rs.longLongInt(forColumn: "playingStatusModified") @@ -604,7 +604,7 @@ class UserEpisodeDataManager { values.append(episode.playedUpTo) values.append(episode.duration) values.append(episode.playingStatus) - values.append(episode.autoDownloadStatus) + values.append(episode.autoDownloadStatus.rawValue) values.append(DBUtils.nullIfNil(value: episode.publishedDate)) values.append(episode.sizeInBytes) values.append(episode.playingStatusModified) diff --git a/Modules/DataModel/Sources/PocketCastsDataModel/Public/FilePathProtocol.swift b/Modules/DataModel/Sources/PocketCastsDataModel/Public/FilePathProtocol.swift index 2089ecb1ae..0616ca49ab 100644 --- a/Modules/DataModel/Sources/PocketCastsDataModel/Public/FilePathProtocol.swift +++ b/Modules/DataModel/Sources/PocketCastsDataModel/Public/FilePathProtocol.swift @@ -1,6 +1,6 @@ import Foundation -@objc public protocol FilePathProtocol { +public protocol FilePathProtocol { func tempPathForEpisode(_ episode: BaseEpisode) -> String func pathForEpisode(_ episode: BaseEpisode) -> String func streamingBufferPathForEpisode(_ episode: BaseEpisode) -> String diff --git a/Modules/DataModel/Sources/PocketCastsDataModel/Public/Model/BaseEpisode.swift b/Modules/DataModel/Sources/PocketCastsDataModel/Public/Model/BaseEpisode.swift index eda6d3f7fd..744bfa2b91 100644 --- a/Modules/DataModel/Sources/PocketCastsDataModel/Public/Model/BaseEpisode.swift +++ b/Modules/DataModel/Sources/PocketCastsDataModel/Public/Model/BaseEpisode.swift @@ -1,13 +1,13 @@ import Foundation -@objc public protocol BaseEpisode: AnyObject { +public protocol BaseEpisode: AnyObject { // MARK: - Properties var uuid: String { get set } var addedDate: Date? { get set } var publishedDate: Date? { get set } var cachedFrameCount: Int64 { get set } - var autoDownloadStatus: Int32 { get set } + var autoDownloadStatus: AutoDownloadStatus { get set } var downloadUrl: String? { get set } var fileType: String? { get set } var contentType: String? { get set } @@ -24,7 +24,7 @@ import Foundation var keepEpisode: Bool { get set } var episodeStatus: Int32 { get set } - var playingStatus: Int32 { get set } + var playingStatus: PlayingStatus { get set } var playedUpTo: Double { get set } var duration: Double { get set } diff --git a/Modules/DataModel/Sources/PocketCastsDataModel/Public/Model/Episode+Encoding.swift b/Modules/DataModel/Sources/PocketCastsDataModel/Public/Model/Episode+Encoding.swift index 0ef6ca9a5c..4ae95f1600 100644 --- a/Modules/DataModel/Sources/PocketCastsDataModel/Public/Model/Episode+Encoding.swift +++ b/Modules/DataModel/Sources/PocketCastsDataModel/Public/Model/Episode+Encoding.swift @@ -40,7 +40,7 @@ public extension Episode { keepEpisode = decodeBoolFromString(value: episodeMap["keepEpisode"]) playedUpTo = decodeDoubleFromString(value: episodeMap["playedUpTo"]) duration = decodeDoubleFromString(value: episodeMap["duration"]) - playingStatus = decodeInt32FromString(value: episodeMap["playingStatus"]) + playingStatus = PlayingStatus(rawValue: decodeInt32FromString(value: episodeMap["playingStatus"])) ?? .notPlayed publishedDate = decodeDateFromString(date: episodeMap["publishedDate"]) title = episodeMap["title"] uuid = episodeMap["uuid"] ?? "" diff --git a/Modules/DataModel/Sources/PocketCastsDataModel/Public/Model/Episode+fromDatabase.swift b/Modules/DataModel/Sources/PocketCastsDataModel/Public/Model/Episode+fromDatabase.swift index 5eed44ccec..d875863aab 100644 --- a/Modules/DataModel/Sources/PocketCastsDataModel/Public/Model/Episode+fromDatabase.swift +++ b/Modules/DataModel/Sources/PocketCastsDataModel/Public/Model/Episode+fromDatabase.swift @@ -18,8 +18,8 @@ extension Episode { episode.keepEpisode = rs.bool(forColumn: "keepEpisode") episode.playedUpTo = rs.double(forColumn: "playedUpTo") episode.duration = rs.double(forColumn: "duration") - episode.playingStatus = rs.int(forColumn: "playingStatus") - episode.autoDownloadStatus = rs.int(forColumn: "autoDownloadStatus") + episode.playingStatus = PlayingStatus(rawValue: rs.int(forColumn: "playingStatus")) ?? .notPlayed + episode.autoDownloadStatus = AutoDownloadStatus(rawValue: rs.int(forColumn: "autoDownloadStatus")) ?? .notSpecified episode.publishedDate = DBUtils.convertDate(value: rs.double(forColumn: "publishedDate")) episode.sizeInBytes = rs.longLongInt(forColumn: "sizeInBytes") episode.playingStatusModified = rs.longLongInt(forColumn: "playingStatusModified") diff --git a/Modules/DataModel/Sources/PocketCastsDataModel/Public/Model/Episode.swift b/Modules/DataModel/Sources/PocketCastsDataModel/Public/Model/Episode.swift index 090524167b..6b5f378788 100644 --- a/Modules/DataModel/Sources/PocketCastsDataModel/Public/Model/Episode.swift +++ b/Modules/DataModel/Sources/PocketCastsDataModel/Public/Model/Episode.swift @@ -19,8 +19,8 @@ public class Episode: NSObject, BaseEpisode { @objc public var keepEpisode = false @objc public var playedUpTo: Double = 0 @objc public var duration: Double = 0 - @objc public var playingStatus = 0 as Int32 - @objc public var autoDownloadStatus = 0 as Int32 + public var playingStatus: PlayingStatus = PlayingStatus.notPlayed + public var autoDownloadStatus: AutoDownloadStatus = AutoDownloadStatus.notSpecified @objc public var publishedDate: Date? @objc public var sizeInBytes = 0 as Int64 @objc public var playingStatusModified = 0 as Int64 @@ -119,19 +119,19 @@ public class Episode: NSObject, BaseEpisode { } public func inProgress() -> Bool { - playingStatus == PlayingStatus.inProgress.rawValue + playingStatus == PlayingStatus.inProgress } public func played() -> Bool { - playingStatus == PlayingStatus.completed.rawValue + playingStatus == PlayingStatus.completed } public func unplayed() -> Bool { - playingStatus == PlayingStatus.notPlayed.rawValue + playingStatus == PlayingStatus.notPlayed } public func exemptFromAutoDownload() -> Bool { - autoDownloadStatus == AutoDownloadStatus.userDeletedFile.rawValue || autoDownloadStatus == AutoDownloadStatus.userCancelledDownload.rawValue + (autoDownloadStatus == .userDeletedFile) || (autoDownloadStatus == .userCancelledDownload) } public func playbackError() -> Bool { diff --git a/Modules/DataModel/Sources/PocketCastsDataModel/Public/Model/UserEpisode+Encoding.swift b/Modules/DataModel/Sources/PocketCastsDataModel/Public/Model/UserEpisode+Encoding.swift index 269fb5aec3..753f3bb551 100644 --- a/Modules/DataModel/Sources/PocketCastsDataModel/Public/Model/UserEpisode+Encoding.swift +++ b/Modules/DataModel/Sources/PocketCastsDataModel/Public/Model/UserEpisode+Encoding.swift @@ -39,7 +39,7 @@ public extension UserEpisode { keepEpisode = decodeBoolFromString(value: episodeMap["keepEpisode"]) playedUpTo = decodeDoubleFromString(value: episodeMap["playedUpTo"]) duration = decodeDoubleFromString(value: episodeMap["duration"]) - playingStatus = decodeInt32FromString(value: episodeMap["playingStatus"]) + playingStatus = PlayingStatus(rawValue: decodeInt32FromString(value: episodeMap["playingStatus"])) ?? .notPlayed publishedDate = decodeDateFromString(date: episodeMap["publishedDate"]) title = episodeMap["title"] uuid = episodeMap["uuid"] ?? "" diff --git a/Modules/DataModel/Sources/PocketCastsDataModel/Public/Model/UserEpisode.swift b/Modules/DataModel/Sources/PocketCastsDataModel/Public/Model/UserEpisode.swift index 0d182c29de..a78859cf4b 100644 --- a/Modules/DataModel/Sources/PocketCastsDataModel/Public/Model/UserEpisode.swift +++ b/Modules/DataModel/Sources/PocketCastsDataModel/Public/Model/UserEpisode.swift @@ -13,8 +13,8 @@ public class UserEpisode: NSObject, BaseEpisode { @objc public var playedUpTo: Double = 0 @objc public var duration: Double = 0 @objc public var durationModified = 0 as Int64 - @objc public var playingStatus = 1 as Int32 - @objc public var autoDownloadStatus = 0 as Int32 + public var playingStatus: PlayingStatus = .notPlayed + public var autoDownloadStatus = AutoDownloadStatus.notSpecified @objc public var publishedDate: Date? @objc public var sizeInBytes = 0 as Int64 @objc public var playingStatusModified = 0 as Int64 @@ -106,19 +106,19 @@ public class UserEpisode: NSObject, BaseEpisode { } public func inProgress() -> Bool { - playingStatus == PlayingStatus.inProgress.rawValue + playingStatus == PlayingStatus.inProgress } public func played() -> Bool { - playingStatus == PlayingStatus.completed.rawValue + playingStatus == PlayingStatus.completed } public func unplayed() -> Bool { - playingStatus == PlayingStatus.notPlayed.rawValue + playingStatus == PlayingStatus.notPlayed } public func exemptFromAutoDownload() -> Bool { - autoDownloadStatus == AutoDownloadStatus.userDeletedFile.rawValue || autoDownloadStatus == AutoDownloadStatus.userCancelledDownload.rawValue + (autoDownloadStatus == .userDeletedFile) || (autoDownloadStatus == .userCancelledDownload) } public func playbackError() -> Bool { diff --git a/Modules/Server/Sources/PocketCastsServer/Private/API Tasks/PositionSyncTask.swift b/Modules/Server/Sources/PocketCastsServer/Private/API Tasks/PositionSyncTask.swift index 6a644e84c5..ae1350cf8e 100644 --- a/Modules/Server/Sources/PocketCastsServer/Private/API Tasks/PositionSyncTask.swift +++ b/Modules/Server/Sources/PocketCastsServer/Private/API Tasks/PositionSyncTask.swift @@ -24,7 +24,7 @@ class PositionSyncTask: ApiBaseTask { updateRequest.podcast = episode.podcastUuid let upToAsInt = Int32(upTo) updateRequest.position = Google_Protobuf_Int32Value(upToAsInt) - updateRequest.status = episode.playingStatus + updateRequest.status = episode.playingStatus.rawValue updateRequest.duration = Int32(duration) let data = try updateRequest.serializedData() diff --git a/Modules/Server/Sources/PocketCastsServer/Private/API Tasks/RetrieveCustomFilesTask.swift b/Modules/Server/Sources/PocketCastsServer/Private/API Tasks/RetrieveCustomFilesTask.swift index 071c41f407..4f381cdf00 100644 --- a/Modules/Server/Sources/PocketCastsServer/Private/API Tasks/RetrieveCustomFilesTask.swift +++ b/Modules/Server/Sources/PocketCastsServer/Private/API Tasks/RetrieveCustomFilesTask.swift @@ -131,7 +131,7 @@ class RetrieveCustomFilesTask: ApiBaseTask { episode.sizeInBytes = protoEpisode.size episode.duration = Double(protoEpisode.duration) episode.playedUpTo = Double(protoEpisode.playedUpTo) - episode.playingStatus = Int32(protoEpisode.playingStatus) + episode.playingStatus = PlayingStatus(rawValue: Int32(protoEpisode.playingStatus)) ?? .notPlayed episode.imageUrl = protoEpisode.imageURL episode.imageColor = protoEpisode.colour diff --git a/Modules/Server/Sources/PocketCastsServer/Private/API Tasks/UploadFilesUpdateTask.swift b/Modules/Server/Sources/PocketCastsServer/Private/API Tasks/UploadFilesUpdateTask.swift index 7d41e1a1f3..7ce3c89d46 100644 --- a/Modules/Server/Sources/PocketCastsServer/Private/API Tasks/UploadFilesUpdateTask.swift +++ b/Modules/Server/Sources/PocketCastsServer/Private/API Tasks/UploadFilesUpdateTask.swift @@ -33,7 +33,7 @@ class UploadFilesUpdateTask: ApiBaseTask { updateFile.playedUpTo = Google_Protobuf_Int32Value(Int32(episode.playedUpTo)) } if episode.playingStatusModified > 0 { - updateFile.playingStatus = Google_Protobuf_Int32Value(episode.playingStatus) + updateFile.playingStatus = Google_Protobuf_Int32Value(episode.playingStatus.rawValue) } if episode.durationModified > 0 { updateFile.duration = Google_Protobuf_Int64Value(Int64(episode.duration)) diff --git a/Modules/Server/Sources/PocketCastsServer/Public/Refresh/RefreshOperation.swift b/Modules/Server/Sources/PocketCastsServer/Public/Refresh/RefreshOperation.swift index 601773ff68..30a270d5ee 100644 --- a/Modules/Server/Sources/PocketCastsServer/Public/Refresh/RefreshOperation.swift +++ b/Modules/Server/Sources/PocketCastsServer/Public/Refresh/RefreshOperation.swift @@ -123,7 +123,7 @@ class RefreshOperation: Operation { let newEpisode = Episode() newEpisode.podcast_id = podcast.id newEpisode.podcastUuid = podcast.uuid - newEpisode.playingStatus = PlayingStatus.notPlayed.rawValue + newEpisode.playingStatus = .notPlayed newEpisode.episodeStatus = DownloadStatus.notDownloaded.rawValue newEpisode.addedDate = Date() newEpisode.populate(fromEpisode: episode) diff --git a/Modules/Server/Sources/PocketCastsServer/Public/ServerPodcastManager+Update.swift b/Modules/Server/Sources/PocketCastsServer/Public/ServerPodcastManager+Update.swift index 0a432aa3d6..497410d5ce 100644 --- a/Modules/Server/Sources/PocketCastsServer/Public/ServerPodcastManager+Update.swift +++ b/Modules/Server/Sources/PocketCastsServer/Public/ServerPodcastManager+Update.swift @@ -145,7 +145,7 @@ extension ServerPodcastManager { episode.addedDate = Date() episode.podcast_id = podcast.id episode.podcastUuid = podcast.uuid - episode.playingStatus = PlayingStatus.notPlayed.rawValue + episode.playingStatus = .notPlayed episode.episodeStatus = DownloadStatus.notDownloaded.rawValue episode.uuid = uuid episode.lastArchiveInteractionDate = Date() diff --git a/Modules/Server/Sources/PocketCastsServer/Public/ServerPodcastManager.swift b/Modules/Server/Sources/PocketCastsServer/Public/ServerPodcastManager.swift index c9946a7504..b92959af5e 100644 --- a/Modules/Server/Sources/PocketCastsServer/Public/ServerPodcastManager.swift +++ b/Modules/Server/Sources/PocketCastsServer/Public/ServerPodcastManager.swift @@ -165,7 +165,7 @@ public class ServerPodcastManager: NSObject { let episode = Episode() episode.addedDate = Date() episode.podcastUuid = podcast.uuid - episode.playingStatus = PlayingStatus.notPlayed.rawValue + episode.playingStatus = .notPlayed episode.episodeStatus = DownloadStatus.notDownloaded.rawValue episode.uuid = upNextItem.episodeUuid episode.title = upNextItem.title @@ -259,7 +259,7 @@ public class ServerPodcastManager: NSObject { episode.addedDate = Date() episode.podcast_id = podcast.id episode.podcastUuid = podcast.uuid - episode.playingStatus = PlayingStatus.notPlayed.rawValue + episode.playingStatus = .notPlayed episode.episodeStatus = DownloadStatus.notDownloaded.rawValue if let uuid = episodeJson["uuid"] as? String { episode.uuid = uuid @@ -319,7 +319,7 @@ public class ServerPodcastManager: NSObject { episode.addedDate = Date() episode.podcast_id = podcast.id episode.podcastUuid = podcast.uuid - episode.playingStatus = PlayingStatus.notPlayed.rawValue + episode.playingStatus = .notPlayed episode.episodeStatus = DownloadStatus.notDownloaded.rawValue episode.uuid = uuid if let title = firstEpisode["title"] as? String { diff --git a/Modules/Server/Sources/PocketCastsServer/Public/Sync/SyncTask+LocalChanges.swift b/Modules/Server/Sources/PocketCastsServer/Public/Sync/SyncTask+LocalChanges.swift index 10371d45ab..9d09eda07e 100644 --- a/Modules/Server/Sources/PocketCastsServer/Public/Sync/SyncTask+LocalChanges.swift +++ b/Modules/Server/Sources/PocketCastsServer/Public/Sync/SyncTask+LocalChanges.swift @@ -53,7 +53,7 @@ extension SyncTask { episodeRecord.uuid = episode.uuid if episode.playingStatusModified > 0 { - episodeRecord.playingStatus.value = episode.playingStatus + episodeRecord.playingStatus.value = episode.playingStatus.rawValue episodeRecord.playingStatusModified.value = episode.playingStatusModified } if episode.keepEpisodeModified > 0 { diff --git a/Modules/Server/Sources/PocketCastsServer/Public/Sync/SyncTask+ServerChanges.swift b/Modules/Server/Sources/PocketCastsServer/Public/Sync/SyncTask+ServerChanges.swift index 2ba4c03a6d..b6e501c67b 100644 --- a/Modules/Server/Sources/PocketCastsServer/Public/Sync/SyncTask+ServerChanges.swift +++ b/Modules/Server/Sources/PocketCastsServer/Public/Sync/SyncTask+ServerChanges.swift @@ -208,7 +208,7 @@ extension SyncTask { } } - if episodeItem.hasPlayingStatus, episode.playingStatus != episodeItem.playingStatus.value { + if episodeItem.hasPlayingStatus, episode.playingStatus.rawValue != episodeItem.playingStatus.value { if isPlayerPlaying(episode: episode) { // if we're actively playing this episode, mark the status as unsynced because ours is considered more current DataManager.sharedManager.saveEpisode(playingStatus: .inProgress, episode: episode, updateSyncFlag: true) diff --git a/Modules/Server/Tests/PocketCastsServerTests/SyncTaskTests+Episodes.swift b/Modules/Server/Tests/PocketCastsServerTests/SyncTaskTests+Episodes.swift index 281649d3a3..32c58e5488 100644 --- a/Modules/Server/Tests/PocketCastsServerTests/SyncTaskTests+Episodes.swift +++ b/Modules/Server/Tests/PocketCastsServerTests/SyncTaskTests+Episodes.swift @@ -50,7 +50,7 @@ private extension SyncTaskTests_EpisodeImport { episode.addedDate = Date() episode.podcast_id = 0 episode.podcastUuid = podcastUuid - episode.playingStatus = PlayingStatus.notPlayed.rawValue + episode.playingStatus = PlayingStatus.notPlayed episode.episodeStatus = DownloadStatus.notDownloaded.rawValue episode.uuid = episodeUuid diff --git a/Pocket Casts Watch App/WatchSyncManager+Autodownload.swift b/Pocket Casts Watch App/WatchSyncManager+Autodownload.swift index c6c8e6a067..92591880fc 100644 --- a/Pocket Casts Watch App/WatchSyncManager+Autodownload.swift +++ b/Pocket Casts Watch App/WatchSyncManager+Autodownload.swift @@ -21,7 +21,7 @@ extension WatchSyncManager { let downloadedEpisodes = DataManager.sharedManager.findDownloadedEpisodes() - let deleteCandidates = downloadedEpisodes.filter { $0.autoDownloadStatus == AutoDownloadStatus.autoDownloaded.rawValue } + let deleteCandidates = downloadedEpisodes.filter { $0.autoDownloadStatus == .autoDownloaded } for delete in deleteCandidates { if let upNextPosition = allQueued.firstIndex(where: { $0.uuid == delete.uuid }), upNextPosition < WatchDataManager.upNextAutoDeleteCount() { diff --git a/PocketCastsTests/Helpers/DBTestCase.swift b/PocketCastsTests/Helpers/DBTestCase.swift index b0385dd27f..5f5cb087d7 100644 --- a/PocketCastsTests/Helpers/DBTestCase.swift +++ b/PocketCastsTests/Helpers/DBTestCase.swift @@ -37,7 +37,7 @@ class DBTestCase: XCTestCase { episode.podcast_id = podcast.id episode.addedDate = podcast.addedDate episode.downloadUrl = "http://google.com" - episode.playingStatus = PlayingStatus.notPlayed.rawValue + episode.playingStatus = PlayingStatus.notPlayed dataManager.save(episode: episode) self.dataManager = dataManager diff --git a/podcasts/DownloadManager+URLSessionDelegate.swift b/podcasts/DownloadManager+URLSessionDelegate.swift index 3b4d0d426e..ad4dbf0add 100644 --- a/podcasts/DownloadManager+URLSessionDelegate.swift +++ b/podcasts/DownloadManager+URLSessionDelegate.swift @@ -31,7 +31,7 @@ extension DownloadManager: URLSessionDelegate, URLSessionDownloadDelegate { func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didWriteData bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64) { guard let downloadingEpisode = episodeForTask(downloadTask, forceReload: false) else { return } - let downloadingToStream = downloadingEpisode.autoDownloadStatus == AutoDownloadStatus.playerDownloadedForStreaming.rawValue + let downloadingToStream = downloadingEpisode.autoDownloadStatus == .playerDownloadedForStreaming if !downloadingToStream { progressManager.updateProgressForEpisode(downloadingEpisode.uuid, totalBytesWritten: totalBytesWritten, totalBytesExpected: totalBytesExpectedToWrite) } @@ -59,7 +59,7 @@ extension DownloadManager: URLSessionDelegate, URLSessionDownloadDelegate { return } - let downloadingToStream = downloadingEpisode.autoDownloadStatus == AutoDownloadStatus.playerDownloadedForStreaming.rawValue + let downloadingToStream = downloadingEpisode.autoDownloadStatus == .playerDownloadedForStreaming guard !downloadingToStream else { return } @@ -157,7 +157,7 @@ extension DownloadManager: URLSessionDelegate, URLSessionDownloadDelegate { return } - let autoDownloadStatus = AutoDownloadStatus(rawValue: episode.autoDownloadStatus)! + let autoDownloadStatus = episode.autoDownloadStatus let destinationPath = autoDownloadStatus == .playerDownloadedForStreaming ? streamingBufferPathForEpisode(episode) : pathForEpisode(episode) let destinationUrl = URL(fileURLWithPath: destinationPath) diff --git a/podcasts/DownloadManager.swift b/podcasts/DownloadManager.swift index e883451e72..2e924d7b0b 100644 --- a/podcasts/DownloadManager.swift +++ b/podcasts/DownloadManager.swift @@ -174,7 +174,7 @@ class DownloadManager: NSObject, FilePathProtocol { guard let episode = dataManager.findBaseEpisode(uuid: episodeUuid) else { return } - let downloadingToStream = autoDownloadStatus == AutoDownloadStatus.playerDownloadedForStreaming + let downloadingToStream = autoDownloadStatus == .playerDownloadedForStreaming // we already have a downloaded copy of this if !downloadingToStream, episode.downloaded(pathFinder: self) { return } @@ -191,14 +191,14 @@ class DownloadManager: NSObject, FilePathProtocol { #endif // download requested for something we already have buferred, just move it - if episode.bufferedForStreaming(), autoDownloadStatus != AutoDownloadStatus.playerDownloadedForStreaming { + if episode.bufferedForStreaming(), autoDownloadStatus != .playerDownloadedForStreaming { moveBufferedEpisodeCacheToEpisodeFile(episode: episode) return } let previousDownloadFailed = episode.episodeStatus == DownloadStatus.downloadFailed.rawValue if !downloadingToStream { episode.episodeStatus = DownloadStatus.queued.rawValue } - episode.autoDownloadStatus = autoDownloadStatus.rawValue + episode.autoDownloadStatus = autoDownloadStatus episode.downloadErrorDetails = nil episode.playbackErrorDetails = nil markUnplayedAndUnarchiveIfRequired(episode: episode, saveChanges: false) @@ -266,7 +266,7 @@ class DownloadManager: NSObject, FilePathProtocol { } var newItem: AVPlayerItem = playbackItem #if !os(watchOS) - if episode.autoDownloadStatus == AutoDownloadStatus.playerDownloadedForStreaming.rawValue || episode.autoDownloadStatus == AutoDownloadStatus.autoDownloaded.rawValue, + if (episode.autoDownloadStatus == .playerDownloadedForStreaming) || (episode.autoDownloadStatus == .autoDownloaded), let customDelegate = downloadAndStreamEpisodes[episode.uuid] { // We are already downloading this episode for streaming FileLog.shared.addMessage("DownloadManager stream and download: skipping because we are already exporting: \(episode.uuid)") @@ -284,7 +284,7 @@ class DownloadManager: NSObject, FilePathProtocol { self.removeFromQueue(episodeUuid: episode.uuid, fireNotification: false, userInitiated: false) episode.autoDownloadStatus = previousStatus } else { - episode.autoDownloadStatus = Settings.downloadUpNextEpisodes() ? AutoDownloadStatus.autoDownloaded.rawValue : AutoDownloadStatus.playerDownloadedForStreaming.rawValue + episode.autoDownloadStatus = Settings.downloadUpNextEpisodes() ? .autoDownloaded : .playerDownloadedForStreaming } let downloadTaskUUID = episode.uuid @@ -358,7 +358,7 @@ class DownloadManager: NSObject, FilePathProtocol { if episode.played() { FileLog.shared.addMessage("Marking episode as unplayed because it's getting added to the download queue: \(episode.displayableTitle())") - episode.playingStatus = PlayingStatus.notPlayed.rawValue + episode.playingStatus = .notPlayed episode.playingStatusModified = TimeFormatter.currentUTCTimeInMillis() episode.playedUpTo = 0 episode.playedUpToModified = TimeFormatter.currentUTCTimeInMillis() @@ -476,13 +476,13 @@ class DownloadManager: NSObject, FilePathProtocol { } if userInitiated { - episode.autoDownloadStatus = AutoDownloadStatus.userCancelledDownload.rawValue + episode.autoDownloadStatus = .userCancelledDownload saveRequired = true } if FeatureFlag.streamAndCachePlayingEpisode.enabled, downloadAndStreamEpisodes.keys.contains(episode.uuid) { episode.downloadTaskId = episode.uuid - episode.autoDownloadStatus = AutoDownloadStatus.playerDownloadedForStreaming.rawValue + episode.autoDownloadStatus = .playerDownloadedForStreaming saveRequired = true } @@ -500,10 +500,10 @@ class DownloadManager: NSObject, FilePathProtocol { guard let episode = dataManager.findBaseEpisode(uuid: episodeUuid) else { return false } if let taskId = episode.downloadTaskId, - episode.autoDownloadStatus == AutoDownloadStatus.playerDownloadedForStreaming.rawValue, + episode.autoDownloadStatus == .playerDownloadedForStreaming, autoDownloadStatus != .playerDownloadedForStreaming { // if the player was downloading an episode for streaming purposes, and now the user (or the app via auto download) is downloading it, change the status - episode.autoDownloadStatus = autoDownloadStatus.rawValue + episode.autoDownloadStatus = autoDownloadStatus episode.episodeStatus = DownloadStatus.downloading.rawValue dataManager.save(episode: episode) downloadingEpisodesCache[taskId] = episode diff --git a/podcasts/EpisodeDetailViewController+Actions.swift b/podcasts/EpisodeDetailViewController+Actions.swift index 2ad63bdaf5..afbde8a5b1 100644 --- a/podcasts/EpisodeDetailViewController+Actions.swift +++ b/podcasts/EpisodeDetailViewController+Actions.swift @@ -61,7 +61,7 @@ extension EpisodeDetailViewController { } else { dismiss(animated: true, completion: nil) if let timestamp = timestamp { - episode.playingStatus = PlayingStatus.inProgress.rawValue + episode.playingStatus = .inProgress episode.playedUpTo = timestamp DataManager.sharedManager.save(episode: episode) updateProgress() diff --git a/podcasts/EpisodeManager.swift b/podcasts/EpisodeManager.swift index 138b7e48af..7dd45f0235 100644 --- a/podcasts/EpisodeManager.swift +++ b/podcasts/EpisodeManager.swift @@ -104,7 +104,7 @@ class EpisodeManager: NSObject { if episode.episodeStatus != DownloadStatus.notDownloaded.rawValue { episode.episodeStatus = DownloadStatus.notDownloaded.rawValue - episode.autoDownloadStatus = AutoDownloadStatus.userDeletedFile.rawValue + episode.autoDownloadStatus = .userDeletedFile episode.cachedFrameCount = 0 DataManager.sharedManager.save(episode: episode) } diff --git a/podcasts/PlaybackManager.swift b/podcasts/PlaybackManager.swift index ca98ef28da..d2eb35ab2f 100644 --- a/podcasts/PlaybackManager.swift +++ b/podcasts/PlaybackManager.swift @@ -930,7 +930,7 @@ class PlaybackManager: ServerPlaybackDelegate { return timeToReturn } - if Int(episode.playingStatus) == PlayingStatus.inProgress.rawValue { + if episode.playingStatus == .inProgress { if episode.playedUpTo > 0 { return catchUpHelper.adjustStartTimeIfNeeded(for: episode) } @@ -1052,7 +1052,7 @@ class PlaybackManager: ServerPlaybackDelegate { autoplayIfNeeded() FileLog.shared.addMessage("Finished playing \(episode.displayableTitle())") - episode.playingStatus = PlayingStatus.completed.rawValue + episode.playingStatus = .completed episode.playedUpTo = episode.duration if SyncManager.isUserLoggedIn() { diff --git a/podcasts/PlaybackProtocol.swift b/podcasts/PlaybackProtocol.swift index 2361b66ee6..2a446d5b6d 100644 --- a/podcasts/PlaybackProtocol.swift +++ b/podcasts/PlaybackProtocol.swift @@ -1,7 +1,7 @@ import AVFoundation import PocketCastsDataModel -@objc protocol PlaybackProtocol: AnyObject { +protocol PlaybackProtocol: AnyObject { func loadEpisode(_ episode: BaseEpisode) func playing() -> Bool func buffering() -> Bool diff --git a/podcasts/PodcastManager.swift b/podcasts/PodcastManager.swift index f9e0b77034..dfb81a2967 100644 --- a/podcasts/PodcastManager.swift +++ b/podcasts/PodcastManager.swift @@ -101,7 +101,7 @@ class PodcastManager: NSObject { if NetworkUtils.shared.isConnectedToWifi() { let queuedEpisodes = dataManager.findEpisodesWhere(customWhere: "episodeStatus == ?", arguments: [DownloadStatus.waitingForWifi.rawValue]) for episode in queuedEpisodes { - downloadManager.addToQueue(episodeUuid: episode.uuid, fireNotification: false, autoDownloadStatus: AutoDownloadStatus(rawValue: episode.autoDownloadStatus) ?? .notSpecified) + downloadManager.addToQueue(episodeUuid: episode.uuid, fireNotification: false, autoDownloadStatus: episode.autoDownloadStatus) } } @@ -110,12 +110,12 @@ class PodcastManager: NSObject { for episode in stuckDownloadingEpisodes { if !downloadManager.isEpisodeDownloading(episode) { if Settings.autoDownloadMobileDataAllowed() || NetworkUtils.shared.isConnectedToWifi() { - downloadManager.addToQueue(episodeUuid: episode.uuid, fireNotification: false, autoDownloadStatus: AutoDownloadStatus(rawValue: episode.autoDownloadStatus) ?? .notSpecified) + downloadManager.addToQueue(episodeUuid: episode.uuid, fireNotification: false, autoDownloadStatus: episode.autoDownloadStatus) } else { // If we're not downloading over cellular, clear task id so its not removed by the "stuck download" cleaner, and queue it for later dataManager.clearDownloadTaskId(episode: episode) - downloadManager.queueForLaterDownload(episodeUuid: episode.uuid, fireNotification: false, autoDownloadStatus: AutoDownloadStatus(rawValue: episode.autoDownloadStatus) ?? .notSpecified) + downloadManager.queueForLaterDownload(episodeUuid: episode.uuid, fireNotification: false, autoDownloadStatus: episode.autoDownloadStatus) } } }