-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
43d664f
commit 547cc90
Showing
6 changed files
with
125 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// OfflineAsset.swift | ||
// TPStreamsSDK | ||
// | ||
// Created by Prithuvi on 08/01/24. | ||
// | ||
|
||
import Foundation | ||
import RealmSwift | ||
|
||
public class OfflineAsset: Object { | ||
@Persisted(primaryKey: true) var assetId: String = "" | ||
@Persisted var createdAt = Date() | ||
@Persisted var srcURL: String = "" | ||
@Persisted var downloadedPath: String = "" | ||
@Persisted var downloadedAt = Date() | ||
@Persisted var status:String = Status.notStarted.rawValue | ||
@Persisted var percentageCompleted: Float = 0.0 | ||
|
||
public static var manager = ObjectManager<OfflineAsset>() | ||
} | ||
|
||
extension OfflineAsset { | ||
internal func update(_ attributes: [String: Any]) { | ||
let realm = try! Realm() | ||
try! realm.write { | ||
for (key, value) in attributes { | ||
self[key] = value | ||
} | ||
} | ||
} | ||
} | ||
|
||
enum Status: String { | ||
case notStarted = "notStarted" | ||
case inProgress = "inProgress" | ||
case paused = "paused" | ||
case finished = "finished" | ||
case failed = "failed" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// ObjectManager.swift | ||
// TPStreamsSDK | ||
// | ||
// Created by Prithuvi on 09/01/24. | ||
// | ||
|
||
import Foundation | ||
import RealmSwift | ||
|
||
public class ObjectManager<T: Object> { | ||
let realm = try! Realm() | ||
|
||
func add(object: T) { | ||
try! realm.write { | ||
realm.add(object) | ||
} | ||
} | ||
|
||
func get(assetId: Any) -> T? { | ||
return realm.object(ofType: T.self, forPrimaryKey: assetId) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters