Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor the use of the AutoDownloadStatus enums #2506

Open
wants to merge 7 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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]()
Expand Down Expand Up @@ -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]()
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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]()
Expand Down Expand Up @@ -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]()
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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 }
Expand All @@ -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 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"] ?? ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"] ?? ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Loading