mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-04 18:15:01 +02:00
Add:iOS support offline episode chapters #675
This commit is contained in:
parent
1da03cdd65
commit
ae37861f7d
5 changed files with 16 additions and 1 deletions
|
@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
|
|||
// Override point for customization after application launch.
|
||||
|
||||
let configuration = Realm.Configuration(
|
||||
schemaVersion: 8,
|
||||
schemaVersion: 9,
|
||||
migrationBlock: { [weak self] migration, oldSchemaVersion in
|
||||
if (oldSchemaVersion < 1) {
|
||||
self?.logger.log("Realm schema version was \(oldSchemaVersion)")
|
||||
|
|
|
@ -177,6 +177,7 @@ extension LocalLibraryItem {
|
|||
audioTracks.append(AudioTrack.detachCopy(of: track)!)
|
||||
duration = track.duration
|
||||
displayTitle = episode.title
|
||||
episode.chapters.forEach { chapter in chapters.append(Chapter.detachCopy(of: chapter)!) }
|
||||
} else if let tracks = self.media?.tracks {
|
||||
tracks.forEach { t in audioTracks.append(AudioTrack.detachCopy(of: t)!) }
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ class LocalPodcastEpisode: Object, Codable {
|
|||
@Persisted var desc: String?
|
||||
@Persisted var audioFile: AudioFile?
|
||||
@Persisted var audioTrack: AudioTrack?
|
||||
@Persisted var chapters = List<Chapter>()
|
||||
@Persisted var duration: Double = 0
|
||||
@Persisted var size: Int = 0
|
||||
@Persisted(indexed: true) var serverEpisodeId: String?
|
||||
|
|
|
@ -18,6 +18,7 @@ class PodcastEpisode: EmbeddedObject, Codable {
|
|||
@Persisted var desc: String?
|
||||
@Persisted var audioFile: AudioFile?
|
||||
@Persisted var audioTrack: AudioTrack?
|
||||
@Persisted var chapters = List<Chapter>()
|
||||
@Persisted var duration: Double?
|
||||
@Persisted var size: Int?
|
||||
var serverEpisodeId: String { self.id }
|
||||
|
@ -32,6 +33,7 @@ class PodcastEpisode: EmbeddedObject, Codable {
|
|||
desc = "description", // Fixes a collision with the base Swift object's field "description"
|
||||
audioFile,
|
||||
audioTrack,
|
||||
chapters,
|
||||
duration,
|
||||
size,
|
||||
serverEpisodeId
|
||||
|
@ -40,6 +42,7 @@ class PodcastEpisode: EmbeddedObject, Codable {
|
|||
override init() {}
|
||||
|
||||
required init(from decoder: Decoder) throws {
|
||||
super.init()
|
||||
let values = try decoder.container(keyedBy: CodingKeys.self)
|
||||
id = try values.decode(String.self, forKey: .id)
|
||||
index = try? values.decode(Int.self, forKey: .index)
|
||||
|
@ -50,6 +53,9 @@ class PodcastEpisode: EmbeddedObject, Codable {
|
|||
desc = try? values.decode(String.self, forKey: .desc)
|
||||
audioFile = try? values.decode(AudioFile.self, forKey: .audioFile)
|
||||
audioTrack = try? values.decode(AudioTrack.self, forKey: .audioTrack)
|
||||
if let chapterList = try? values.decode([Chapter].self, forKey: .chapters) {
|
||||
chapters.append(objectsIn: chapterList)
|
||||
}
|
||||
duration = try? values.decode(Double.self, forKey: .duration)
|
||||
size = try? values.decode(Int.self, forKey: .size)
|
||||
}
|
||||
|
@ -65,6 +71,7 @@ class PodcastEpisode: EmbeddedObject, Codable {
|
|||
try container.encode(desc, forKey: .desc)
|
||||
try container.encode(audioFile, forKey: .audioFile)
|
||||
try container.encode(audioTrack, forKey: .audioTrack)
|
||||
try container.encode(Array(chapters), forKey: .chapters)
|
||||
try container.encode(duration, forKey: .duration)
|
||||
try container.encode(size, forKey: .size)
|
||||
try container.encode(serverEpisodeId, forKey: .serverEpisodeId)
|
||||
|
|
|
@ -50,6 +50,12 @@ extension KeyedDecodingContainer {
|
|||
return Int(stringValue) ?? 0
|
||||
}
|
||||
}
|
||||
|
||||
// This will be called when any @Persisted List<> is decoded
|
||||
func decode<T: Decodable>(_ type: Persisted<List<T>>.Type, forKey key: Key) throws -> Persisted<List<T>> {
|
||||
// Use decode if present, falling back to an empty list
|
||||
try decodeIfPresent(type, forKey: key) ?? Persisted<List<T>>(wrappedValue: List<T>())
|
||||
}
|
||||
}
|
||||
|
||||
extension CAPPluginCall {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue