Update:iOS saving progress for offline ebooks

This commit is contained in:
advplyr
2023-06-24 09:41:14 -05:00
parent f8fbeef9b7
commit f42c624cba
4 changed files with 50 additions and 2 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// Override point for customization after application launch.
let configuration = Realm.Configuration(
schemaVersion: 12,
schemaVersion: 13,
migrationBlock: { [weak self] migration, oldSchemaVersion in
if (oldSchemaVersion < 1) {
self?.logger.log("Realm schema version was \(oldSchemaVersion)")
+1
View File
@@ -25,4 +25,5 @@ CAP_PLUGIN(AbsDatabase, "AbsDatabase",
CAP_PLUGIN_METHOD(syncServerMediaProgressWithLocalMediaProgress, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(updateLocalMediaProgressFinished, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(updateDeviceSettings, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(updateLocalEbookProgress, CAPPluginReturnPromise);
)
+28
View File
@@ -251,4 +251,32 @@ public class AbsDatabase: CAPPlugin {
// call.resolve([ "value": [] ])
getDeviceData(call)
}
@objc func updateLocalEbookProgress(_ call: CAPPluginCall) {
let localLibraryItemId = call.getString("localLibraryItemId")
let ebookLocation = call.getString("ebookLocation", "")
let ebookProgress = call.getDouble("ebookProgress", 0.0)
logger.log("updateLocalEbookProgress \(localLibraryItemId ?? "Unknown") | ebookLocation: \(ebookLocation) | ebookProgress: \(ebookProgress)")
do {
let localMediaProgress = try LocalMediaProgress.fetchOrCreateLocalMediaProgress(localMediaProgressId: localLibraryItemId, localLibraryItemId: localLibraryItemId, localEpisodeId: nil)
guard let localMediaProgress = localMediaProgress else {
call.resolve(["error": "Library Item not found"])
return
}
// Update finished status
try localMediaProgress.updateEbookProgress(ebookLocation: ebookLocation, ebookProgress: ebookProgress)
// Build API response
let progressDictionary = try? localMediaProgress.asDictionary()
let response: [String: Any] = ["localMediaProgress": progressDictionary ?? ""]
call.resolve(response)
} catch {
debugPrint(error)
call.resolve(["error": "Failed to update ebook progress"])
return
}
}
}