mirror of
				https://github.com/ImranR98/Obtainium.git
				synced 2025-10-22 18:33:45 +02:00 
			
		
		
		
	More version filtering options for F-Droid (#885)
This commit is contained in:
		| @@ -256,6 +256,8 @@ | ||||
|     "highlightTouchTargets": "Highlight less obvious touch targets", | ||||
|     "pickExportDir": "Pick Export Directory", | ||||
|     "autoExportOnChanges": "Auto-export on changes", | ||||
|     "filterVersionsByRegEx": "Filter Versions by Regular Expression", | ||||
|     "trySelectingSuggestedVersionCode": "Try selecting suggested versionCode APK", | ||||
|     "removeAppQuestion": { | ||||
|         "one": "Remover App?", | ||||
|         "other": "Remover Apps?" | ||||
|   | ||||
| @@ -253,6 +253,8 @@ | ||||
|    "highlightTouchTargets": "Highlight less obvious touch targets", | ||||
|    "pickExportDir": "Pick Export Directory", | ||||
|    "autoExportOnChanges": "Auto-export on changes", | ||||
|    "filterVersionsByRegEx": "Filter Versions by Regular Expression", | ||||
|    "trySelectingSuggestedVersionCode": "Try selecting suggested versionCode APK", | ||||
|      "removeAppQuestion": { | ||||
|       "one": "Želite li ukloniti aplikaciju?", | ||||
|       "other": "Želite li ukloniti aplikacije?" | ||||
|   | ||||
| @@ -253,6 +253,8 @@ | ||||
|     "highlightTouchTargets": "Highlight less obvious touch targets", | ||||
|     "pickExportDir": "Pick Export Directory", | ||||
|     "autoExportOnChanges": "Auto-export on changes", | ||||
|     "filterVersionsByRegEx": "Filter Versions by Regular Expression", | ||||
|     "trySelectingSuggestedVersionCode": "Try selecting suggested versionCode APK", | ||||
|     "removeAppQuestion": { | ||||
|         "one": "App entfernen?", | ||||
|         "other": "Apps entfernen?" | ||||
|   | ||||
| @@ -256,6 +256,8 @@ | ||||
|     "highlightTouchTargets": "Highlight less obvious touch targets", | ||||
|     "pickExportDir": "Pick Export Directory", | ||||
|     "autoExportOnChanges": "Auto-export on changes", | ||||
|     "filterVersionsByRegEx": "Filter Versions by Regular Expression", | ||||
|     "trySelectingSuggestedVersionCode": "Try selecting suggested versionCode APK", | ||||
|     "removeAppQuestion": { | ||||
|         "one": "Remove App?", | ||||
|         "other": "Remove Apps?" | ||||
|   | ||||
| @@ -253,6 +253,8 @@ | ||||
|     "highlightTouchTargets": "Highlight less obvious touch targets", | ||||
|     "pickExportDir": "Pick Export Directory", | ||||
|     "autoExportOnChanges": "Auto-export on changes", | ||||
|     "filterVersionsByRegEx": "Filter Versions by Regular Expression", | ||||
|     "trySelectingSuggestedVersionCode": "Try selecting suggested versionCode APK", | ||||
|     "removeAppQuestion": { | ||||
|         "one": "¿Eliminar Aplicación?", | ||||
|         "other": "¿Eliminar Aplicaciones?" | ||||
|   | ||||
| @@ -253,6 +253,8 @@ | ||||
|     "highlightTouchTargets": "Highlight less obvious touch targets", | ||||
|     "pickExportDir": "Pick Export Directory", | ||||
|     "autoExportOnChanges": "Auto-export on changes", | ||||
|     "filterVersionsByRegEx": "Filter Versions by Regular Expression", | ||||
|     "trySelectingSuggestedVersionCode": "Try selecting suggested versionCode APK", | ||||
|     "removeAppQuestion": { | ||||
|         "one": "برنامه حذف شود؟", | ||||
|         "other": "برنامه ها حذف شوند؟" | ||||
|   | ||||
| @@ -253,6 +253,8 @@ | ||||
|     "highlightTouchTargets": "Highlight less obvious touch targets", | ||||
|     "pickExportDir": "Pick Export Directory", | ||||
|     "autoExportOnChanges": "Auto-export on changes", | ||||
|     "filterVersionsByRegEx": "Filter Versions by Regular Expression", | ||||
|     "trySelectingSuggestedVersionCode": "Try selecting suggested versionCode APK", | ||||
|     "removeAppQuestion": { | ||||
|         "one": "Supprimer l'application ?", | ||||
|         "other": "Supprimer les applications ?" | ||||
|   | ||||
| @@ -252,6 +252,8 @@ | ||||
|     "highlightTouchTargets": "Highlight less obvious touch targets", | ||||
|     "pickExportDir": "Pick Export Directory", | ||||
|     "autoExportOnChanges": "Auto-export on changes", | ||||
|     "filterVersionsByRegEx": "Filter Versions by Regular Expression", | ||||
|     "trySelectingSuggestedVersionCode": "Try selecting suggested versionCode APK", | ||||
|     "removeAppQuestion": { | ||||
|         "one": "Eltávolítja az alkalmazást?", | ||||
|         "other": "Eltávolítja az alkalmazást?" | ||||
|   | ||||
| @@ -253,6 +253,8 @@ | ||||
|     "highlightTouchTargets": "Highlight less obvious touch targets", | ||||
|     "pickExportDir": "Pick Export Directory", | ||||
|     "autoExportOnChanges": "Auto-export on changes", | ||||
|     "filterVersionsByRegEx": "Filter Versions by Regular Expression", | ||||
|     "trySelectingSuggestedVersionCode": "Try selecting suggested versionCode APK", | ||||
|     "removeAppQuestion": { | ||||
|         "one": "Rimuovere l'app?", | ||||
|         "other": "Rimuovere le app?" | ||||
|   | ||||
| @@ -254,6 +254,8 @@ | ||||
|     "highlightTouchTargets": "Highlight less obvious touch targets", | ||||
|     "pickExportDir": "Pick Export Directory", | ||||
|     "autoExportOnChanges": "Auto-export on changes", | ||||
|     "filterVersionsByRegEx": "Filter Versions by Regular Expression", | ||||
|     "trySelectingSuggestedVersionCode": "Try selecting suggested versionCode APK", | ||||
|     "removeAppQuestion": { | ||||
|         "one": "アプリを削除しますか?", | ||||
|         "other": "アプリを削除しますか?" | ||||
|   | ||||
| @@ -259,6 +259,8 @@ | ||||
|     "highlightTouchTargets": "Highlight less obvious touch targets", | ||||
|     "pickExportDir": "Pick Export Directory", | ||||
|     "autoExportOnChanges": "Auto-export on changes", | ||||
|     "filterVersionsByRegEx": "Filter Versions by Regular Expression", | ||||
|     "trySelectingSuggestedVersionCode": "Try selecting suggested versionCode APK", | ||||
|     "removeAppQuestion": { | ||||
|         "one": "Usunąć aplikację?", | ||||
|         "few": "Usunąć aplikacje?", | ||||
|   | ||||
| @@ -253,6 +253,8 @@ | ||||
|     "highlightTouchTargets": "Highlight less obvious touch targets", | ||||
|     "pickExportDir": "Pick Export Directory", | ||||
|     "autoExportOnChanges": "Auto-export on changes", | ||||
|     "filterVersionsByRegEx": "Filter Versions by Regular Expression", | ||||
|     "trySelectingSuggestedVersionCode": "Try selecting suggested versionCode APK", | ||||
|     "removeAppQuestion": { | ||||
|         "one": "Удалить приложение?", | ||||
|         "other": "Удалить приложения?" | ||||
|   | ||||
| @@ -254,6 +254,8 @@ | ||||
|     "highlightTouchTargets": "Highlight less obvious touch targets", | ||||
|     "pickExportDir": "Pick Export Directory", | ||||
|     "autoExportOnChanges": "Auto-export on changes", | ||||
|     "filterVersionsByRegEx": "Filter Versions by Regular Expression", | ||||
|     "trySelectingSuggestedVersionCode": "Try selecting suggested versionCode APK", | ||||
|     "removeAppQuestion": { | ||||
|         "one": "是否删除应用?", | ||||
|         "other": "是否删除应用?" | ||||
|   | ||||
| @@ -13,10 +13,24 @@ class FDroid extends AppSource { | ||||
|     name = tr('fdroid'); | ||||
|     canSearch = true; | ||||
|     additionalSourceAppSpecificSettingFormItems = [ | ||||
|       [ | ||||
|         GeneratedFormTextField('filterVersionsByRegEx', | ||||
|             label: tr('filterVersionsByRegEx'), | ||||
|             required: false, | ||||
|             additionalValidators: [ | ||||
|               (value) { | ||||
|                 return regExValidator(value); | ||||
|               } | ||||
|             ]) | ||||
|       ], | ||||
|       [ | ||||
|         GeneratedFormSwitch('trySelectingSuggestedVersionCode', | ||||
|             label: tr('trySelectingSuggestedVersionCode'), defaultValue: true) | ||||
|       ], | ||||
|       [ | ||||
|         GeneratedFormSwitch('autoSelectHighestVersionCode', | ||||
|             label: tr('autoSelectHighestVersionCode')) | ||||
|       ] | ||||
|       ], | ||||
|     ]; | ||||
|   } | ||||
|  | ||||
| @@ -45,25 +59,73 @@ class FDroid extends AppSource { | ||||
|  | ||||
|   APKDetails getAPKUrlsFromFDroidPackagesAPIResponse( | ||||
|       Response res, String apkUrlPrefix, String standardUrl, | ||||
|       {bool autoSelectHighestVersionCode = false}) { | ||||
|       {bool autoSelectHighestVersionCode = false, | ||||
|       bool trySelectingSuggestedVersionCode = false, | ||||
|       String? filterVersionsByRegEx}) { | ||||
|     if (res.statusCode == 200) { | ||||
|       List<dynamic> releases = jsonDecode(res.body)['packages'] ?? []; | ||||
|       var response = jsonDecode(res.body); | ||||
|       List<dynamic> releases = response['packages'] ?? []; | ||||
|       if (releases.isEmpty) { | ||||
|         throw NoReleasesError(); | ||||
|       } | ||||
|       String? latestVersion = releases[0]['versionName']; | ||||
|       if (latestVersion == null) { | ||||
|       String? version; | ||||
|       Iterable<dynamic> releaseChoices = []; | ||||
|       // Grab the versionCode suggested if the user chose to do that | ||||
|       // Only do so at this stage if the user has no release filter | ||||
|       if (trySelectingSuggestedVersionCode && | ||||
|           response['suggestedVersionCode'] != null && | ||||
|           filterVersionsByRegEx == null) { | ||||
|         var suggestedReleases = releases.where((element) => | ||||
|             element['versionCode'] == response['suggestedVersionCode']); | ||||
|         if (suggestedReleases.isNotEmpty) { | ||||
|           releaseChoices = suggestedReleases; | ||||
|           version = suggestedReleases.first['versionName']; | ||||
|         } | ||||
|       } | ||||
|       // Apply the release filter if any | ||||
|       if (filterVersionsByRegEx != null) { | ||||
|         version = null; | ||||
|         releaseChoices = []; | ||||
|         for (var i = 0; i < releases.length; i++) { | ||||
|           if (RegExp(filterVersionsByRegEx) | ||||
|               .hasMatch(releases[i]['versionName'])) { | ||||
|             version = releases[i]['versionName']; | ||||
|           } | ||||
|         } | ||||
|         if (version == null) { | ||||
|           throw NoVersionError(); | ||||
|         } | ||||
|       } | ||||
|       // Default to the highest version | ||||
|       version ??= releases[0]['versionName']; | ||||
|       if (version == null) { | ||||
|         throw NoVersionError(); | ||||
|       } | ||||
|       Iterable<dynamic> latestReleases = | ||||
|           releases.where((element) => element['versionName'] == latestVersion); | ||||
|       if (latestReleases.length > 1 && autoSelectHighestVersionCode) { | ||||
|         latestReleases = [latestReleases.first]; | ||||
|       // If a suggested release was not already picked, pick all those with the selected version | ||||
|       if (releaseChoices.isEmpty) { | ||||
|         releaseChoices = | ||||
|             releases.where((element) => element['versionName'] == version); | ||||
|       } | ||||
|       List<String> apkUrls = latestReleases | ||||
|       // For the remaining releases, use the toggles to auto-select one if possible | ||||
|       if (releaseChoices.length > 1) { | ||||
|         if (autoSelectHighestVersionCode) { | ||||
|           releaseChoices = [releaseChoices.first]; | ||||
|         } else if (trySelectingSuggestedVersionCode && | ||||
|             response['suggestedVersionCode'] != null) { | ||||
|           var suggestedReleases = releaseChoices.where((element) => | ||||
|               element['versionCode'] == response['suggestedVersionCode']); | ||||
|           if (suggestedReleases.isNotEmpty) { | ||||
|             releaseChoices = suggestedReleases; | ||||
|           } | ||||
|         } | ||||
|       } | ||||
|       if (releaseChoices.isEmpty) { | ||||
|         throw NoReleasesError(); | ||||
|       } | ||||
|       List<String> apkUrls = releaseChoices | ||||
|           .map((e) => '${apkUrlPrefix}_${e['versionCode']}.apk') | ||||
|           .toList(); | ||||
|       return APKDetails(latestVersion, getApkUrlsFromUrls(apkUrls), | ||||
|       return APKDetails(version, getApkUrlsFromUrls(apkUrls), | ||||
|           AppNames(name, Uri.parse(standardUrl).pathSegments.last)); | ||||
|     } else { | ||||
|       throw getObtainiumHttpError(res); | ||||
| @@ -82,7 +144,15 @@ class FDroid extends AppSource { | ||||
|         'https://$host/repo/$appId', | ||||
|         standardUrl, | ||||
|         autoSelectHighestVersionCode: | ||||
|             additionalSettings['autoSelectHighestVersionCode'] == true); | ||||
|             additionalSettings['autoSelectHighestVersionCode'] == true, | ||||
|         trySelectingSuggestedVersionCode: | ||||
|             additionalSettings['trySelectingSuggestedVersionCode'] == true, | ||||
|         filterVersionsByRegEx: | ||||
|             (additionalSettings['filterVersionsByRegEx'] as String?) | ||||
|                         ?.isNotEmpty == | ||||
|                     true | ||||
|                 ? additionalSettings['filterVersionsByRegEx'] | ||||
|                 : null); | ||||
|   } | ||||
|  | ||||
|   @override | ||||
|   | ||||
| @@ -40,6 +40,9 @@ class IzzyOnDroid extends AppSource { | ||||
|         'https://android.izzysoft.de/frepo/$appId', | ||||
|         standardUrl, | ||||
|         autoSelectHighestVersionCode: | ||||
|             additionalSettings['autoSelectHighestVersionCode'] == true); | ||||
|             additionalSettings['autoSelectHighestVersionCode'] == true, | ||||
|         trySelectingSuggestedVersionCode: | ||||
|             additionalSettings['trySelectingSuggestedVersionCode'] == true, | ||||
|         filterVersionsByRegEx: additionalSettings['filterVersionsByRegEx']); | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user