Fixed APKPicker radiobutton + preferred apk index saved

This commit is contained in:
Imran Remtulla
2022-08-27 19:17:29 -04:00
parent 52b4e1fb96
commit 30075add1c
4 changed files with 41 additions and 25 deletions

View File

@@ -11,7 +11,7 @@ import 'package:workmanager/workmanager.dart';
import 'package:dynamic_color/dynamic_color.dart'; import 'package:dynamic_color/dynamic_color.dart';
const String currentReleaseTag = 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') @pragma('vm:entry-point')
void bgTaskCallback() { void bgTaskCallback() {
@@ -94,7 +94,9 @@ class MyApp extends StatelessWidget {
'ImranR98', 'ImranR98',
'Obtainium', 'Obtainium',
currentReleaseTag, currentReleaseTag,
currentReleaseTag, [])); currentReleaseTag,
[],
0));
} }
} }

View File

@@ -96,7 +96,7 @@ class AppsProvider with ChangeNotifier {
if (apps[id] == null) { if (apps[id] == null) {
throw 'App not found'; 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) { if (apps[id]!.app.apkUrls.length > 1) {
apkUrl = await showDialog( apkUrl = await showDialog(
context: context, context: context,
@@ -105,6 +105,11 @@ class AppsProvider with ChangeNotifier {
}); });
} }
if (apkUrl != null) { 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!); appsToInstall.putIfAbsent(id, () => apkUrl!);
} }
} }
@@ -200,6 +205,9 @@ class AppsProvider with ChangeNotifier {
App newApp = await SourceProvider().getApp(currentApp.url); App newApp = await SourceProvider().getApp(currentApp.url);
if (newApp.latestVersion != currentApp.latestVersion) { if (newApp.latestVersion != currentApp.latestVersion) {
newApp.installedVersion = currentApp.installedVersion; newApp.installedVersion = currentApp.installedVersion;
if (currentApp.preferredApkIndex < newApp.apkUrls.length) {
newApp.preferredApkIndex = currentApp.preferredApkIndex;
}
await saveApp(newApp); await saveApp(newApp);
return newApp; return newApp;
} }
@@ -290,17 +298,16 @@ class _APKPickerState extends State<APKPicker> {
scrollable: true, scrollable: true,
title: const Text('Pick an APK'), title: const Text('Pick an APK'),
content: Column(children: [ content: Column(children: [
Text('${widget.app.name} has more than one package - pick one.'), Text('${widget.app.name} has more than one package.'),
...widget.app.apkUrls.map((u) => ListTile( ...widget.app.apkUrls.map((u) => RadioListTile<String>(
title: Text(Uri.parse(u).pathSegments.last), title: Text(Uri.parse(u).pathSegments.last),
leading: Radio<String>( value: u,
value: u, groupValue: apkUrl,
groupValue: apkUrl, onChanged: (String? val) {
onChanged: (String? val) { setState(() {
setState(() { apkUrl = val;
apkUrl = val; });
}); }))
})))
]), ]),
actions: [ actions: [
TextButton( TextButton(

View File

@@ -29,8 +29,9 @@ class App {
String? installedVersion; String? installedVersion;
late String latestVersion; late String latestVersion;
List<String> apkUrls = []; List<String> apkUrls = [];
late int preferredApkIndex;
App(this.id, this.url, this.author, this.name, this.installedVersion, App(this.id, this.url, this.author, this.name, this.installedVersion,
this.latestVersion, this.apkUrls); this.latestVersion, this.apkUrls, this.preferredApkIndex);
@override @override
String toString() { String toString() {
@@ -38,15 +39,19 @@ class App {
} }
factory App.fromJson(Map<String, dynamic> json) => App( factory App.fromJson(Map<String, dynamic> json) => 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,
json['name'] as String, json['name'] as String,
json['installedVersion'] == null json['installedVersion'] == null
? null ? null
: json['installedVersion'] as String, : json['installedVersion'] as String,
json['latestVersion'] as String, json['latestVersion'] as String,
List<String>.from(jsonDecode(json['apkUrls']))); List<String>.from(jsonDecode(json['apkUrls'])),
json['preferredApkIndex'] == null
? 0
: json['preferredApkIndex'] as int,
);
Map<String, dynamic> toJson() => { Map<String, dynamic> toJson() => {
'id': id, 'id': id,
@@ -56,6 +61,7 @@ class App {
'installedVersion': installedVersion, 'installedVersion': installedVersion,
'latestVersion': latestVersion, 'latestVersion': latestVersion,
'apkUrls': jsonEncode(apkUrls), 'apkUrls': jsonEncode(apkUrls),
'preferredApkIndex': preferredApkIndex
}; };
} }
@@ -265,7 +271,8 @@ class SourceProvider {
names.name[0].toUpperCase() + names.name.substring(1), names.name[0].toUpperCase() + names.name.substring(1),
null, null,
apk.version, apk.version,
apk.apkUrls); apk.apkUrls,
apk.apkUrls.length - 1);
} }
List<String> getSourceHosts() => sources.map((e) => e.host).toList(); List<String> getSourceHosts() => sources.map((e) => e.host).toList();

View File

@@ -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 # 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 # 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. # 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: environment:
sdk: '>=2.19.0-79.0.dev <3.0.0' sdk: '>=2.19.0-79.0.dev <3.0.0'