From a8a47bb153b820885cd0801a70acdec1b58e384d Mon Sep 17 00:00:00 2001 From: Imran Remtulla Date: Fri, 24 Feb 2023 22:48:30 -0500 Subject: [PATCH] Unified version detection setting --- assets/translations/de.json | 4 ++- assets/translations/en.json | 4 ++- assets/translations/fa.json | 4 ++- assets/translations/hu.json | 4 ++- assets/translations/it.json | 4 ++- assets/translations/ja.json | 4 ++- assets/translations/zh.json | 4 ++- lib/pages/add_app.dart | 15 +++------- lib/pages/app.dart | 21 ++++++-------- lib/pages/apps.dart | 2 +- lib/providers/apps_provider.dart | 4 +-- lib/providers/source_provider.dart | 44 ++++++++++++++++++------------ 12 files changed, 62 insertions(+), 52 deletions(-) diff --git a/assets/translations/de.json b/assets/translations/de.json index c88c168..780b5fa 100644 --- a/assets/translations/de.json +++ b/assets/translations/de.json @@ -213,11 +213,13 @@ "removeFromObtainium": "Aus Obtainium entfernen", "uninstallFromDevice": "Vom Gerät deinstallieren", "onlyWorksWithNonVersionDetectApps": "Funktioniert nur bei Apps mit deaktivierter Versionserkennung.", - "useReleaseDateAsVersion": "Veröffentlichungsdatum als Version verwenden", + "releaseDateAsVersion": "Veröffentlichungsdatum als Version verwenden", "releaseDateAsVersionExplanation": "Diese Option sollte nur für Apps verwendet werden, bei denen die Versionserkennung nicht korrekt funktioniert, aber ein Veröffentlichungsdatum verfügbar ist.", "changes": "Änderungen", "releaseDate": "Veröffentlichungsdatum", "importFromURLsInFile": "Import from URLs in File (like OPML)", + "versionDetection": "Version Detection", + "standardVersionDetection": "Standard version detection", "removeAppQuestion": { "one": "App entfernen?", "other": "App entfernen?" diff --git a/assets/translations/en.json b/assets/translations/en.json index c271c8f..a48c185 100644 --- a/assets/translations/en.json +++ b/assets/translations/en.json @@ -213,11 +213,13 @@ "removeFromObtainium": "Remove from Obtainium", "uninstallFromDevice": "Uninstall from Device", "onlyWorksWithNonVersionDetectApps": "Only works for Apps with version detection disabled.", - "useReleaseDateAsVersion": "Use Release Date as Version", + "releaseDateAsVersion": "Use Release Date as Version", "releaseDateAsVersionExplanation": "This option should only be used for Apps where version detection does not work correctly, but a release date is available.", "changes": "Changes", "releaseDate": "Release Date", "importFromURLsInFile": "Import from URLs in File (like OPML)", + "versionDetection": "Version Detection", + "standardVersionDetection": "Standard version detection", "removeAppQuestion": { "one": "Remove App?", "other": "Remove Apps?" diff --git a/assets/translations/fa.json b/assets/translations/fa.json index 452eedf..1371e88 100644 --- a/assets/translations/fa.json +++ b/assets/translations/fa.json @@ -213,11 +213,13 @@ "removeFromObtainium": "از Obtainium حذف کنید", "uninstallFromDevice": "حذف نصب از دستگاه", "onlyWorksWithNonVersionDetectApps": "فقط برای برنامه‌هایی کار می‌کند که تشخیص نسخه غیرفعال است.", - "useReleaseDateAsVersion": "Use Release Date as Version", + "releaseDateAsVersion": "Use Release Date as Version", "releaseDateAsVersionExplanation": "This option should only be used for Apps where version detection does not work correctly, but a release date is available.", "changes": "Changes", "releaseDate": "Release Date", "importFromURLsInFile": "Import from URLs in File (like OPML)", + "versionDetection": "Version Detection", + "standardVersionDetection": "Standard version detection", "removeAppQuestion": { "one": "برنامه حذف شود؟", "other": "برنامه ها حذف شوند؟" diff --git a/assets/translations/hu.json b/assets/translations/hu.json index 95dacf0..6427f71 100644 --- a/assets/translations/hu.json +++ b/assets/translations/hu.json @@ -212,11 +212,13 @@ "removeFromObtainium": "Eltávolítás az Obtainiumból", "uninstallFromDevice": "Eltávolítás a készülékről", "onlyWorksWithNonVersionDetectApps": "Csak azoknál az alkalmazásoknál működik, amelyeknél a verzióérzékelés le van tiltva.", - "useReleaseDateAsVersion": "Használja a Kiadás dátumát, mint verziót", + "releaseDateAsVersion": "Használja a Kiadás dátumát, mint verziót", "releaseDateAsVersionExplanation": "Ezt a beállítást csak olyan alkalmazásoknál szabad használni, ahol a verzió érzékelése nem működik megfelelően, de elérhető a kiadás dátuma.", "changes": "Változtatások", "releaseDate": "Kiadás dátuma", "importFromURLsInFile": "Import from URLs in File (like OPML)", + "versionDetection": "Version Detection", + "standardVersionDetection": "Standard version detection", "removeAppQuestion": { "one": "Eltávolítja az alkalmazást?", "other": "Eltávolítja az alkalmazást?" diff --git a/assets/translations/it.json b/assets/translations/it.json index ba3c839..120096e 100644 --- a/assets/translations/it.json +++ b/assets/translations/it.json @@ -213,11 +213,13 @@ "removeFromObtainium": "Rimuovi da Obtainium", "uninstallFromDevice": "Disinstalla dal dispositivo", "onlyWorksWithNonVersionDetectApps": "Funziona solo per le App con il rilevamento della versione disattivato.", - "useReleaseDateAsVersion": "Usa data di rilascio come versione", + "releaseDateAsVersion": "Usa data di rilascio come versione", "releaseDateAsVersionExplanation": "Questa opzione dovrebbe essere usata solo per le App in cui il rilevamento della versione non funziona correttamente, ma è disponibile una data di rilascio.", "changes": "Novità", "releaseDate": "Data di rilascio", "importFromURLsInFile": "Import from URLs in File (like OPML)", + "versionDetection": "Version Detection", + "standardVersionDetection": "Standard version detection", "removeAppQuestion": { "one": "Rimuovere l'App?", "other": "Rimuovere le App?" diff --git a/assets/translations/ja.json b/assets/translations/ja.json index 807ea30..276abc1 100644 --- a/assets/translations/ja.json +++ b/assets/translations/ja.json @@ -213,11 +213,13 @@ "removeFromObtainium": "Obtainiumから削除する", "uninstallFromDevice": "デバイスからアンインストールする", "onlyWorksWithNonVersionDetectApps": "バージョン検出を無効にしているアプリにのみ動作します。", - "useReleaseDateAsVersion": "リリース日をバージョンとして使用する", + "releaseDateAsVersion": "リリース日をバージョンとして使用する", "releaseDateAsVersionExplanation": "このオプションは、バージョン検出が正しく機能しないアプリで、リリース日が利用可能な場合にのみ使用する必要があります。", "changes": "変更点", "releaseDate": "リリース日", "importFromURLsInFile": "Import from URLs in File (like OPML)", + "versionDetection": "Version Detection", + "standardVersionDetection": "Standard version detection", "removeAppQuestion": { "one": "アプリを削除しますか?", "other": "アプリを削除しますか?" diff --git a/assets/translations/zh.json b/assets/translations/zh.json index f16798d..4f892ae 100644 --- a/assets/translations/zh.json +++ b/assets/translations/zh.json @@ -213,11 +213,13 @@ "filterAPKsByRegEx": "Filter APKs by Regular Expression", "removeFromObtainium": "Remove from Obtainium", "uninstallFromDevice": "Uninstall from Device", - "useReleaseDateAsVersion": "Use Release Date as Version", + "releaseDateAsVersion": "Use Release Date as Version", "releaseDateAsVersionExplanation": "This option should only be used for Apps where version detection does not work correctly, but a release date is available.", "changes": "Changes", "releaseDate": "Release Date", "importFromURLsInFile": "Import from URLs in File (like OPML)", + "versionDetection": "Version Detection", + "standardVersionDetection": "Standard version detection", "removeAppQuestion": { "one": "删除应用?", "other": "删除应用?" diff --git a/lib/pages/add_app.dart b/lib/pages/add_app.dart index 0208c9e..f68ae3c 100644 --- a/lib/pages/add_app.dart +++ b/lib/pages/add_app.dart @@ -71,10 +71,6 @@ class _AddAppPageState extends State { var settingsProvider = context.read(); () async { var userPickedTrackOnly = additionalSettings['trackOnly'] == true; - var userPickedNoVersionDetection = - additionalSettings['noVersionDetection'] == true; - var userPickedReleaseDateAsVersion = - additionalSettings['releaseDateAsVersion'] == true; var cont = true; if ((userPickedTrackOnly || pickedSource!.enforceTrackOnly) && // ignore: use_build_context_synchronously @@ -95,13 +91,13 @@ class _AddAppPageState extends State { null) { cont = false; } - if (userPickedReleaseDateAsVersion && // ignore: use_build_context_synchronously + if (additionalSettings['versionDetection'] == 'releaseDateAsVersion' && // ignore: use_build_context_synchronously await showDialog( context: context, builder: (BuildContext ctx) { return GeneratedFormModal( - title: tr('useReleaseDateAsVersion'), + title: tr('releaseDateAsVersion'), items: const [], message: tr('releaseDateAsVersionExplanation'), ); @@ -109,8 +105,7 @@ class _AddAppPageState extends State { null) { cont = false; } - if (!userPickedReleaseDateAsVersion && - userPickedNoVersionDetection && + if (additionalSettings['versionDetection'] == 'noVersionDetection' && // ignore: use_build_context_synchronously await showDialog( context: context, @@ -129,9 +124,7 @@ class _AddAppPageState extends State { var trackOnly = pickedSource!.enforceTrackOnly || userPickedTrackOnly; App app = await sourceProvider.getApp( pickedSource!, userInput, additionalSettings, - trackOnlyOverride: trackOnly, - noVersionDetectionOverride: userPickedNoVersionDetection, - releaseDateAsVersionOverride: userPickedReleaseDateAsVersion); + trackOnlyOverride: trackOnly); if (!trackOnly) { await settingsProvider.getInstallPermission(); } diff --git a/lib/pages/app.dart b/lib/pages/app.dart index 0cf9405..4a73b72 100644 --- a/lib/pages/app.dart +++ b/lib/pages/app.dart @@ -42,8 +42,6 @@ class _AppPageState extends State { getUpdate(app.app.id); } var trackOnly = app?.app.additionalSettings['trackOnly'] == true; - var noVersionDetection = - app?.app.additionalSettings['noVersionDetection'] == true; var infoColumn = Column( mainAxisAlignment: MainAxisAlignment.center, @@ -207,7 +205,8 @@ class _AppPageState extends State { child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - if (noVersionDetection && + if (app?.app.additionalSettings['versionDetection'] != + 'standardVersionDetection' && !trackOnly && app?.app.installedVersion != null && app?.app.installedVersion != app?.app.latestVersion) @@ -295,13 +294,11 @@ class _AppPageState extends State { context); } if (app.app.additionalSettings[ - 'releaseDateAsVersion'] == - true) { - app.app.additionalSettings[ - 'noVersionDetection'] = true; + 'versionDetection'] == + 'releaseDateAsVersion') { if (originalSettings[ - 'releaseDateAsVersion'] != - true) { + 'versionDetection'] != + 'releaseDateAsVersion') { if (app.app.releaseDate != null) { bool isUpdated = app.app.installedVersion == @@ -318,10 +315,8 @@ class _AppPageState extends State { } } } else if (originalSettings[ - 'releaseDateAsVersion'] == - true) { - app.app.additionalSettings[ - 'noVersionDetection'] = false; + 'versionDetection'] == + 'releaseDateAsVersion') { app.app.installedVersion = app .installedInfo ?.versionName ?? diff --git a/lib/pages/apps.dart b/lib/pages/apps.dart index e733439..8d4f51d 100644 --- a/lib/pages/apps.dart +++ b/lib/pages/apps.dart @@ -704,7 +704,7 @@ class AppsPageState extends State { onPressed: () { HapticFeedback.selectionClick(); appsProvider.saveApps(selectedApps.map((a) { - if (a.installedVersion != null && a.additionalSettings['noVersionDetection'] == true) { + if (a.installedVersion != null && a.additionalSettings['versionDetection'] != 'standardVersionDetection') { a.installedVersion = a.latestVersion; } return a; diff --git a/lib/providers/apps_provider.dart b/lib/providers/apps_provider.dart index f24cc98..b436358 100644 --- a/lib/providers/apps_provider.dart +++ b/lib/providers/apps_provider.dart @@ -467,8 +467,8 @@ class AppsProvider with ChangeNotifier { App? getCorrectedInstallStatusAppIfPossible(App app, AppInfo? installedInfo) { var modded = false; var trackOnly = app.additionalSettings['trackOnly'] == true; - var noVersionDetection = - app.additionalSettings['noVersionDetection'] == true; + var noVersionDetection = app.additionalSettings['versionDetection'] != + 'standardVersionDetection'; if (installedInfo == null && app.installedVersion != null && !trackOnly) { app.installedVersion = null; modded = true; diff --git a/lib/providers/source_provider.dart b/lib/providers/source_provider.dart index 2076600..8cead1e 100644 --- a/lib/providers/source_provider.dart +++ b/lib/providers/source_provider.dart @@ -100,6 +100,20 @@ class App { additionalSettings['noVersionDetection'] = json['noVersionDetection'] == 'true' || json['trackOnly'] == true; } + // Convert bool style version detection options to dropdown style + if (additionalSettings['noVersionDetection'] == true) { + additionalSettings['versionDetection'] = 'noVersionDetection'; + } + if (additionalSettings['releaseDateAsVersion'] == true) { + additionalSettings['versionDetection'] = 'releaseDateAsVersion'; + additionalSettings.remove('releaseDateAsVersion'); + } + if (additionalSettings['noVersionDetection'] != null) { + additionalSettings.remove('noVersionDetection'); + } + if (additionalSettings['releaseDateAsVersion'] != null) { + additionalSettings.remove('releaseDateAsVersion'); + } // Ensure additionalSettings are correctly typed for (var item in formItems) { if (additionalSettings[item.key] != null) { @@ -234,11 +248,16 @@ class AppSource { ) ], [ - GeneratedFormSwitch('releaseDateAsVersion', - label: tr('useReleaseDateAsVersion')) - ], - [ - GeneratedFormSwitch('noVersionDetection', label: tr('noVersionDetection')) + GeneratedFormDropdown( + 'versionDetection', + [ + MapEntry( + 'standardVersionDetection', tr('standardVersionDetection')), + MapEntry('releaseDateAsVersion', tr('releaseDateAsVersion')), + MapEntry('noVersionDetection', tr('noVersionDetection')) + ], + label: tr('versionDetection'), + defaultValue: 'standardVersionDetection') ], [ GeneratedFormTextField('apkFilterRegEx', @@ -373,26 +392,15 @@ class SourceProvider { Future getApp( AppSource source, String url, Map additionalSettings, - {App? currentApp, - bool trackOnlyOverride = false, - bool noVersionDetectionOverride = false, - bool releaseDateAsVersionOverride = false}) async { + {App? currentApp, bool trackOnlyOverride = false}) async { if (trackOnlyOverride || source.enforceTrackOnly) { additionalSettings['trackOnly'] = true; } - if (releaseDateAsVersionOverride) { - additionalSettings['releaseDateAsVersion'] = true; - noVersionDetectionOverride = - true; // Rel. date as version means no ver. det. - } - if (noVersionDetectionOverride) { - additionalSettings['noVersionDetection'] = true; - } var trackOnly = additionalSettings['trackOnly'] == true; String standardUrl = source.standardizeURL(preStandardizeUrl(url)); APKDetails apk = await source.getLatestAPKDetails(standardUrl, additionalSettings); - if (additionalSettings['releaseDateAsVersion'] == true && + if (additionalSettings['versionDetection'] == 'releaseDateAsVersion' && apk.releaseDate != null) { apk.version = apk.releaseDate!.microsecondsSinceEpoch.toString(); }