From 30075add1cfb454f4ba08a2a59d86555ea1cbcfe Mon Sep 17 00:00:00 2001 From: Imran Remtulla Date: Sat, 27 Aug 2022 19:17:29 -0400 Subject: [PATCH] Fixed APKPicker radiobutton + preferred apk index saved --- lib/main.dart | 6 ++++-- lib/providers/apps_provider.dart | 29 ++++++++++++++++++----------- lib/providers/source_provider.dart | 29 ++++++++++++++++++----------- pubspec.yaml | 2 +- 4 files changed, 41 insertions(+), 25 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index e48101b..bb6349a 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -11,7 +11,7 @@ import 'package:workmanager/workmanager.dart'; import 'package:dynamic_color/dynamic_color.dart'; const String currentReleaseTag = - 'v0.1.5-beta'; // KEEP THIS IN SYNC WITH GITHUB RELEASES + 'v0.1.6-beta'; // KEEP THIS IN SYNC WITH GITHUB RELEASES @pragma('vm:entry-point') void bgTaskCallback() { @@ -94,7 +94,9 @@ class MyApp extends StatelessWidget { 'ImranR98', 'Obtainium', currentReleaseTag, - currentReleaseTag, [])); + currentReleaseTag, + [], + 0)); } } diff --git a/lib/providers/apps_provider.dart b/lib/providers/apps_provider.dart index 209bd62..41248b4 100644 --- a/lib/providers/apps_provider.dart +++ b/lib/providers/apps_provider.dart @@ -96,7 +96,7 @@ class AppsProvider with ChangeNotifier { if (apps[id] == null) { throw 'App not found'; } - String? apkUrl = apps[id]!.app.apkUrls.last; + String? apkUrl = apps[id]!.app.apkUrls[apps[id]!.app.preferredApkIndex]; if (apps[id]!.app.apkUrls.length > 1) { apkUrl = await showDialog( context: context, @@ -105,6 +105,11 @@ class AppsProvider with ChangeNotifier { }); } if (apkUrl != null) { + int urlInd = apps[id]!.app.apkUrls.indexOf(apkUrl); + if (urlInd != apps[id]!.app.preferredApkIndex) { + apps[id]!.app.preferredApkIndex = urlInd; + await saveApp(apps[id]!.app); + } appsToInstall.putIfAbsent(id, () => apkUrl!); } } @@ -200,6 +205,9 @@ class AppsProvider with ChangeNotifier { App newApp = await SourceProvider().getApp(currentApp.url); if (newApp.latestVersion != currentApp.latestVersion) { newApp.installedVersion = currentApp.installedVersion; + if (currentApp.preferredApkIndex < newApp.apkUrls.length) { + newApp.preferredApkIndex = currentApp.preferredApkIndex; + } await saveApp(newApp); return newApp; } @@ -290,17 +298,16 @@ class _APKPickerState extends State { scrollable: true, title: const Text('Pick an APK'), content: Column(children: [ - Text('${widget.app.name} has more than one package - pick one.'), - ...widget.app.apkUrls.map((u) => ListTile( + Text('${widget.app.name} has more than one package.'), + ...widget.app.apkUrls.map((u) => RadioListTile( title: Text(Uri.parse(u).pathSegments.last), - leading: Radio( - value: u, - groupValue: apkUrl, - onChanged: (String? val) { - setState(() { - apkUrl = val; - }); - }))) + value: u, + groupValue: apkUrl, + onChanged: (String? val) { + setState(() { + apkUrl = val; + }); + })) ]), actions: [ TextButton( diff --git a/lib/providers/source_provider.dart b/lib/providers/source_provider.dart index 2cee320..3e03716 100644 --- a/lib/providers/source_provider.dart +++ b/lib/providers/source_provider.dart @@ -29,8 +29,9 @@ class App { String? installedVersion; late String latestVersion; List apkUrls = []; + late int preferredApkIndex; App(this.id, this.url, this.author, this.name, this.installedVersion, - this.latestVersion, this.apkUrls); + this.latestVersion, this.apkUrls, this.preferredApkIndex); @override String toString() { @@ -38,15 +39,19 @@ class App { } factory App.fromJson(Map json) => App( - json['id'] as String, - json['url'] as String, - json['author'] as String, - json['name'] as String, - json['installedVersion'] == null - ? null - : json['installedVersion'] as String, - json['latestVersion'] as String, - List.from(jsonDecode(json['apkUrls']))); + json['id'] as String, + json['url'] as String, + json['author'] as String, + json['name'] as String, + json['installedVersion'] == null + ? null + : json['installedVersion'] as String, + json['latestVersion'] as String, + List.from(jsonDecode(json['apkUrls'])), + json['preferredApkIndex'] == null + ? 0 + : json['preferredApkIndex'] as int, + ); Map toJson() => { 'id': id, @@ -56,6 +61,7 @@ class App { 'installedVersion': installedVersion, 'latestVersion': latestVersion, 'apkUrls': jsonEncode(apkUrls), + 'preferredApkIndex': preferredApkIndex }; } @@ -265,7 +271,8 @@ class SourceProvider { names.name[0].toUpperCase() + names.name.substring(1), null, apk.version, - apk.apkUrls); + apk.apkUrls, + apk.apkUrls.length - 1); } List getSourceHosts() => sources.map((e) => e.host).toList(); diff --git a/pubspec.yaml b/pubspec.yaml index c54c88d..b641fbb 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -17,7 +17,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 0.1.5+6 # When changing this, update the tag in main() accordingly +version: 0.1.6+7 # When changing this, update the tag in main() accordingly environment: sdk: '>=2.19.0-79.0.dev <3.0.0'