Fix:iOS local podcast episode progress #719

This commit is contained in:
advplyr 2023-06-24 10:37:56 -05:00
parent f42c624cba
commit 1ddb6eca00
3 changed files with 17 additions and 12 deletions

View file

@ -193,10 +193,14 @@ public class AbsDatabase: CAPPlugin {
@objc func updateLocalMediaProgressFinished(_ call: CAPPluginCall) { @objc func updateLocalMediaProgressFinished(_ call: CAPPluginCall) {
let localLibraryItemId = call.getString("localLibraryItemId") let localLibraryItemId = call.getString("localLibraryItemId")
let localEpisodeId = call.getString("localEpisodeId") let localEpisodeId = call.getString("localEpisodeId")
let localMediaProgressId = call.getString("localMediaProgressId")
let isFinished = call.getBool("isFinished", false) let isFinished = call.getBool("isFinished", false)
logger.log("updateLocalMediaProgressFinished \(localMediaProgressId ?? "Unknown") | Is Finished: \(isFinished)") var localMediaProgressId = localLibraryItemId ?? ""
if localEpisodeId != nil {
localMediaProgressId += "-\(localEpisodeId ?? "")"
}
logger.log("updateLocalMediaProgressFinished \(localMediaProgressId) | Is Finished: \(isFinished)")
do { do {
let localMediaProgress = try LocalMediaProgress.fetchOrCreateLocalMediaProgress(localMediaProgressId: localMediaProgressId, localLibraryItemId: localLibraryItemId, localEpisodeId: localEpisodeId) let localMediaProgress = try LocalMediaProgress.fetchOrCreateLocalMediaProgress(localMediaProgressId: localMediaProgressId, localLibraryItemId: localLibraryItemId, localEpisodeId: localEpisodeId)

View file

@ -111,6 +111,7 @@ extension LocalMediaProgress {
if let episode = episode { if let episode = episode {
self.id += "-\(episode.id)" self.id += "-\(episode.id)"
self.episodeId = episode.id self.episodeId = episode.id
self.localEpisodeId = episode.id
self.duration = episode.duration ?? 0.0 self.duration = episode.duration ?? 0.0
} }
} }
@ -133,6 +134,10 @@ extension LocalMediaProgress {
if self.isFinished != finished { if self.isFinished != finished {
self.progress = finished ? 1.0 : 0.0 self.progress = finished ? 1.0 : 0.0
} }
if finished {
self.currentTime = 0.0
}
if self.startedAt == 0 && finished { if self.startedAt == 0 && finished {
self.startedAt = Date().timeIntervalSince1970 * 1000 self.startedAt = Date().timeIntervalSince1970 * 1000
@ -149,7 +154,7 @@ extension LocalMediaProgress {
self.currentTime = playbackSession.currentTime self.currentTime = playbackSession.currentTime
self.progress = playbackSession.progress self.progress = playbackSession.progress
self.lastUpdate = Date().timeIntervalSince1970 * 1000 self.lastUpdate = Date().timeIntervalSince1970 * 1000
self.isFinished = playbackSession.progress >= 100.0 self.isFinished = playbackSession.progress >= 0.99
self.finishedAt = self.isFinished ? self.lastUpdate : nil self.finishedAt = self.isFinished ? self.lastUpdate : nil
} }
} }

View file

@ -12,16 +12,12 @@
</div> </div>
</div> </div>
<p class="text-lg font-semibold"> <p class="text-lg font-semibold">{{ title }}</p>
{{ title }}
</p>
<div v-if="episodeNumber || season || episodeType" class="flex py-2 items-center -mx-0.5"> <div v-if="episodeNumber || season || episodeType" class="flex py-2 items-center -mx-0.5">
<div v-if="episodeNumber" class="px-2 pt-px pb-0.5 mx-0.5 bg-primary bg-opacity-60 rounded-full text-xs font-light text-gray-200">Episode #{{ episodeNumber }}</div> <div v-if="episodeNumber" class="px-2 pt-px pb-0.5 mx-0.5 bg-primary bg-opacity-60 rounded-full text-xs font-light text-gray-200">Episode #{{ episodeNumber }}</div>
<div v-if="season" class="px-2 pt-px pb-0.5 mx-0.5 bg-primary bg-opacity-60 rounded-full text-xs font-light text-gray-200">Season #{{ season }}</div> <div v-if="season" class="px-2 pt-px pb-0.5 mx-0.5 bg-primary bg-opacity-60 rounded-full text-xs font-light text-gray-200">Season #{{ season }}</div>
<div v-if="episodeType" class="px-2 pt-px pb-0.5 mx-0.5 bg-primary bg-opacity-60 rounded-full text-xs font-light text-gray-200 capitalize"> <div v-if="episodeType" class="px-2 pt-px pb-0.5 mx-0.5 bg-primary bg-opacity-60 rounded-full text-xs font-light text-gray-200 capitalize">{{ episodeType }}</div>
{{ episodeType }}
</div>
</div> </div>
<!-- user progress card --> <!-- user progress card -->
@ -227,13 +223,13 @@ export default {
return this.$store.getters['user/getUserMediaProgress'](this.serverLibraryItemId, this.serverEpisodeId) return this.$store.getters['user/getUserMediaProgress'](this.serverLibraryItemId, this.serverEpisodeId)
}, },
progressPercent() { progressPercent() {
return this.userItemProgress ? this.userItemProgress.progress : 0 return this.userItemProgress?.progress || 0
}, },
userIsFinished() { userIsFinished() {
return this.userItemProgress ? !!this.userItemProgress.isFinished : false return !!this.userItemProgress?.isFinished
}, },
userProgressFinishedAt() { userProgressFinishedAt() {
return this.userItemProgress ? this.userItemProgress.finishedAt : 0 return this.userItemProgress?.finishedAt || 0
}, },
userTimeRemaining() { userTimeRemaining() {
if (!this.userItemProgress) return 0 if (!this.userItemProgress) return 0