mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-08-16 19:58:09 +02:00
Added migration code for additionalData (NOTHING TESTED)
This commit is contained in:
@@ -69,7 +69,29 @@ class App {
|
|||||||
return 'ID: $id URL: $url INSTALLED: $installedVersion LATEST: $latestVersion APK: $apkUrls PREFERREDAPK: $preferredApkIndex ADDITIONALDATA: ${additionalData.toString()} LASTCHECK: ${lastUpdateCheck.toString()} PINNED $pinned';
|
return 'ID: $id URL: $url INSTALLED: $installedVersion LATEST: $latestVersion APK: $apkUrls PREFERREDAPK: $preferredApkIndex ADDITIONALDATA: ${additionalData.toString()} LASTCHECK: ${lastUpdateCheck.toString()} PINNED $pinned';
|
||||||
}
|
}
|
||||||
|
|
||||||
factory App.fromJson(Map<String, dynamic> json) => App(
|
factory App.fromJson(Map<String, dynamic> json) {
|
||||||
|
var formItems = SourceProvider()
|
||||||
|
.getSource(json['url'])
|
||||||
|
.additionalSourceAppSpecificFormItems
|
||||||
|
.reduce((value, element) => [...value, ...element]);
|
||||||
|
Map<String, String> additionalData =
|
||||||
|
getDefaultValuesFromFormItems([formItems]);
|
||||||
|
if (json['additionalData'] != null) {
|
||||||
|
try {
|
||||||
|
additionalData =
|
||||||
|
Map<String, String>.from(jsonDecode(json['additionalData']));
|
||||||
|
} catch (e) {
|
||||||
|
// Migrate old-style additionalData List to new-style Map
|
||||||
|
List<String> temp =
|
||||||
|
List<String>.from(jsonDecode(json['additionalData']));
|
||||||
|
temp.asMap().forEach((i, value) {
|
||||||
|
if (i < formItems.length) {
|
||||||
|
additionalData[formItems[i].key] = value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return App(
|
||||||
json['id'] as String,
|
json['id'] as String,
|
||||||
json['url'] as String,
|
json['url'] as String,
|
||||||
json['author'] as String,
|
json['author'] as String,
|
||||||
@@ -81,18 +103,17 @@ class App {
|
|||||||
json['apkUrls'] == null
|
json['apkUrls'] == null
|
||||||
? []
|
? []
|
||||||
: List<String>.from(jsonDecode(json['apkUrls'])),
|
: List<String>.from(jsonDecode(json['apkUrls'])),
|
||||||
json['preferredApkIndex'] == null ? 0 : json['preferredApkIndex'] as int,
|
json['preferredApkIndex'] == null
|
||||||
json['additionalData'] == null
|
? 0
|
||||||
? getDefaultValuesFromFormItems(SourceProvider()
|
: json['preferredApkIndex'] as int,
|
||||||
.getSource(json['url'])
|
additionalData,
|
||||||
.additionalSourceAppSpecificFormItems)
|
|
||||||
: Map<String, String>.from(jsonDecode(json['additionalData'])),
|
|
||||||
json['lastUpdateCheck'] == null
|
json['lastUpdateCheck'] == null
|
||||||
? null
|
? null
|
||||||
: DateTime.fromMicrosecondsSinceEpoch(json['lastUpdateCheck']),
|
: DateTime.fromMicrosecondsSinceEpoch(json['lastUpdateCheck']),
|
||||||
json['pinned'] ?? false,
|
json['pinned'] ?? false,
|
||||||
json['trackOnly'] ?? false,
|
json['trackOnly'] ?? false,
|
||||||
noVersionDetection: json['noVersionDetection'] ?? false);
|
noVersionDetection: json['noVersionDetection'] ?? false);
|
||||||
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => {
|
Map<String, dynamic> toJson() => {
|
||||||
'id': id,
|
'id': id,
|
||||||
|
Reference in New Issue
Block a user