mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-31 23:20:35 +02:00
Refactor to use extensions for objects
This commit is contained in:
parent
b7725c455b
commit
52d0890032
4 changed files with 63 additions and 36 deletions
|
@ -37,6 +37,7 @@
|
||||||
A084ECDBA7D38E1E42DFC39D /* Pods_App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AF277DCFFFF123FFC6DF26C7 /* Pods_App.framework */; };
|
A084ECDBA7D38E1E42DFC39D /* Pods_App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = AF277DCFFFF123FFC6DF26C7 /* Pods_App.framework */; };
|
||||||
C4B265F5285A5A6600E1B5C3 /* LocalLibrary.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4B265F4285A5A6600E1B5C3 /* LocalLibrary.swift */; };
|
C4B265F5285A5A6600E1B5C3 /* LocalLibrary.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4B265F4285A5A6600E1B5C3 /* LocalLibrary.swift */; };
|
||||||
C4D0677528106D0C00B8F875 /* DataClasses.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4D0677428106D0C00B8F875 /* DataClasses.swift */; };
|
C4D0677528106D0C00B8F875 /* DataClasses.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4D0677428106D0C00B8F875 /* DataClasses.swift */; };
|
||||||
|
E99C8C932883A00F00E3279A /* LocalLibraryExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E99C8C922883A00F00E3279A /* LocalLibraryExtensions.swift */; };
|
||||||
/* End PBXBuildFile section */
|
/* End PBXBuildFile section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
|
@ -74,6 +75,7 @@
|
||||||
AF51FD2D460BCFE21FA515B2 /* Pods-App.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App.release.xcconfig"; path = "Pods/Target Support Files/Pods-App/Pods-App.release.xcconfig"; sourceTree = "<group>"; };
|
AF51FD2D460BCFE21FA515B2 /* Pods-App.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App.release.xcconfig"; path = "Pods/Target Support Files/Pods-App/Pods-App.release.xcconfig"; sourceTree = "<group>"; };
|
||||||
C4B265F4285A5A6600E1B5C3 /* LocalLibrary.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalLibrary.swift; sourceTree = "<group>"; };
|
C4B265F4285A5A6600E1B5C3 /* LocalLibrary.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalLibrary.swift; sourceTree = "<group>"; };
|
||||||
C4D0677428106D0C00B8F875 /* DataClasses.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataClasses.swift; sourceTree = "<group>"; };
|
C4D0677428106D0C00B8F875 /* DataClasses.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataClasses.swift; sourceTree = "<group>"; };
|
||||||
|
E99C8C922883A00F00E3279A /* LocalLibraryExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalLibraryExtensions.swift; sourceTree = "<group>"; };
|
||||||
FC68EB0AF532CFC21C3344DD /* Pods-App.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App.debug.xcconfig"; path = "Pods/Target Support Files/Pods-App/Pods-App.debug.xcconfig"; sourceTree = "<group>"; };
|
FC68EB0AF532CFC21C3344DD /* Pods-App.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App.debug.xcconfig"; path = "Pods/Target Support Files/Pods-App/Pods-App.debug.xcconfig"; sourceTree = "<group>"; };
|
||||||
/* End PBXFileReference section */
|
/* End PBXFileReference section */
|
||||||
|
|
||||||
|
@ -138,6 +140,7 @@
|
||||||
3ABF580828059BAE005DFBE5 /* PlaybackSession.swift */,
|
3ABF580828059BAE005DFBE5 /* PlaybackSession.swift */,
|
||||||
C4D0677428106D0C00B8F875 /* DataClasses.swift */,
|
C4D0677428106D0C00B8F875 /* DataClasses.swift */,
|
||||||
C4B265F4285A5A6600E1B5C3 /* LocalLibrary.swift */,
|
C4B265F4285A5A6600E1B5C3 /* LocalLibrary.swift */,
|
||||||
|
E99C8C922883A00F00E3279A /* LocalLibraryExtensions.swift */,
|
||||||
3A90295E280968E700E1D427 /* PlaybackReport.swift */,
|
3A90295E280968E700E1D427 /* PlaybackReport.swift */,
|
||||||
4DF74911287105C600AC7814 /* DeviceSettings.swift */,
|
4DF74911287105C600AC7814 /* DeviceSettings.swift */,
|
||||||
);
|
);
|
||||||
|
@ -338,6 +341,7 @@
|
||||||
C4D0677528106D0C00B8F875 /* DataClasses.swift in Sources */,
|
C4D0677528106D0C00B8F875 /* DataClasses.swift in Sources */,
|
||||||
4D66B954282EE87C008272D4 /* AbsDownloader.swift in Sources */,
|
4D66B954282EE87C008272D4 /* AbsDownloader.swift in Sources */,
|
||||||
3AB34055280832720039308B /* PlayerEvents.swift in Sources */,
|
3AB34055280832720039308B /* PlayerEvents.swift in Sources */,
|
||||||
|
E99C8C932883A00F00E3279A /* LocalLibraryExtensions.swift in Sources */,
|
||||||
);
|
);
|
||||||
runOnlyForDeploymentPostprocessing = 0;
|
runOnlyForDeploymentPostprocessing = 0;
|
||||||
};
|
};
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class AbsDownloader: CAPPlugin {
|
||||||
position, track -> LocalFile in startLibraryItemTrackDownload(item: item, position: position, track: track)
|
position, track -> LocalFile in startLibraryItemTrackDownload(item: item, position: position, track: track)
|
||||||
}
|
}
|
||||||
|
|
||||||
let localLibraryItem = LocalLibraryItem(item: item, localUrl: documentsDirectory, server: Store.serverConfig!, files: files)
|
let localLibraryItem = LocalLibraryItem(item, localUrl: documentsDirectory, server: Store.serverConfig!, files: files)
|
||||||
Database.shared.saveLocalLibraryItem(localLibraryItem: localLibraryItem)
|
Database.shared.saveLocalLibraryItem(localLibraryItem: localLibraryItem)
|
||||||
} else {
|
} else {
|
||||||
NSLog("No audio tracks for the supplied library item")
|
NSLog("No audio tracks for the supplied library item")
|
||||||
|
|
|
@ -25,34 +25,6 @@ class LocalLibraryItem: Object, Encodable {
|
||||||
@Persisted var serverAddress: String? = nil
|
@Persisted var serverAddress: String? = nil
|
||||||
@Persisted var serverUserId: String? = nil
|
@Persisted var serverUserId: String? = nil
|
||||||
@Persisted var libraryItemId: String? = nil
|
@Persisted var libraryItemId: String? = nil
|
||||||
|
|
||||||
override init() {
|
|
||||||
super.init()
|
|
||||||
}
|
|
||||||
|
|
||||||
init(item: LibraryItem, localUrl: URL, server: ServerConnectionConfig, files: [LocalFile]) {
|
|
||||||
super.init()
|
|
||||||
self.id = item.id
|
|
||||||
self.contentUrl = localUrl.absoluteString
|
|
||||||
self.mediaType = item.mediaType
|
|
||||||
self.media = LocalMediaType(mediaType: item.media)
|
|
||||||
self.localFiles.append(objectsIn: files)
|
|
||||||
// TODO: self.coverContentURL
|
|
||||||
// TODO: self.converAbsolutePath
|
|
||||||
self.libraryItemId = item.id
|
|
||||||
self.serverConnectionConfigId = server.id
|
|
||||||
self.serverAddress = server.address
|
|
||||||
self.serverUserId = server.userId
|
|
||||||
}
|
|
||||||
|
|
||||||
enum CodingKeys: CodingKey {
|
|
||||||
case id
|
|
||||||
}
|
|
||||||
|
|
||||||
func encode(to encoder: Encoder) throws {
|
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
||||||
try container.encode(id, forKey: .id)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class LocalMediaType: Object {
|
class LocalMediaType: Object {
|
||||||
|
@ -113,13 +85,10 @@ class LocalMetadata: Object {
|
||||||
@Persisted var narratorName: String? = ""
|
@Persisted var narratorName: String? = ""
|
||||||
@Persisted var seriesName: String? = ""
|
@Persisted var seriesName: String? = ""
|
||||||
@Persisted var feedUrl: String? = ""
|
@Persisted var feedUrl: String? = ""
|
||||||
|
}
|
||||||
override init() {
|
|
||||||
super.init()
|
extension LocalMetadata {
|
||||||
}
|
convenience init(metadata: Metadata) {
|
||||||
|
|
||||||
init(metadata: Metadata) {
|
|
||||||
super.init()
|
|
||||||
self.title = metadata.title
|
self.title = metadata.title
|
||||||
self.subtitle = metadata.subtitle
|
self.subtitle = metadata.subtitle
|
||||||
self.narrators.append(objectsIn: metadata.narrators ?? [])
|
self.narrators.append(objectsIn: metadata.narrators ?? [])
|
||||||
|
|
54
ios/App/Shared/models/LocalLibraryExtensions.swift
Normal file
54
ios/App/Shared/models/LocalLibraryExtensions.swift
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
//
|
||||||
|
// LocalLibraryExtensions.swift
|
||||||
|
// App
|
||||||
|
//
|
||||||
|
// Created by Ron Heft on 7/16/22.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
extension LocalLibraryItem {
|
||||||
|
enum CodingKeys: CodingKey {
|
||||||
|
case id
|
||||||
|
case basePath
|
||||||
|
case absolutePath
|
||||||
|
case contentUrl
|
||||||
|
case isInvalid
|
||||||
|
case mediaType
|
||||||
|
case media
|
||||||
|
case localFiles
|
||||||
|
case coverContentUrl
|
||||||
|
case coverAbsolutePath
|
||||||
|
case isLocal
|
||||||
|
case serverConnectionConfigId
|
||||||
|
case serverAddress
|
||||||
|
case serverUserId
|
||||||
|
case libraryItemId
|
||||||
|
}
|
||||||
|
|
||||||
|
func encode(to encoder: Encoder) throws {
|
||||||
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
|
try container.encode(id, forKey: .id)
|
||||||
|
try container.encode(basePath, forKey: .basePath)
|
||||||
|
try container.encode(absolutePath, forKey: .absolutePath)
|
||||||
|
try container.encode(contentUrl, forKey: .contentUrl)
|
||||||
|
try container.encode(isInvalid, forKey: .isInvalid)
|
||||||
|
try container.encode(mediaType, forKey: .mediaType)
|
||||||
|
//try container.encode(media, forKey: .media)
|
||||||
|
//try container.encode(localFiles, forKey: .localFiles)
|
||||||
|
}
|
||||||
|
|
||||||
|
convenience init(_ item: LibraryItem, localUrl: URL, server: ServerConnectionConfig, files: [LocalFile]) {
|
||||||
|
self.init()
|
||||||
|
self.contentUrl = localUrl.absoluteString
|
||||||
|
self.mediaType = item.mediaType
|
||||||
|
self.media = LocalMediaType(mediaType: item.media)
|
||||||
|
self.localFiles.append(objectsIn: files)
|
||||||
|
// TODO: self.coverContentURL
|
||||||
|
// TODO: self.converAbsolutePath
|
||||||
|
self.libraryItemId = item.id
|
||||||
|
self.serverConnectionConfigId = server.id
|
||||||
|
self.serverAddress = server.address
|
||||||
|
self.serverUserId = server.userId
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue