mirror of
https://github.com/ImranR98/Obtainium.git
synced 2025-08-11 17:40:15 +02:00
Improve release asset download UI
This commit is contained in:
@@ -155,7 +155,8 @@ class AddAppPageState extends State<AddAppPage> {
|
||||
// Only download the APK here if you need to for the package ID
|
||||
if (isTempId(app) && app.additionalSettings['trackOnly'] != true) {
|
||||
// ignore: use_build_context_synchronously
|
||||
var apkUrl = await appsProvider.confirmApkUrl(app, context);
|
||||
var apkUrl =
|
||||
await appsProvider.confirmAppFileUrl(app, context, false);
|
||||
if (apkUrl == null) {
|
||||
throw ObtainiumError(tr('cancelled'));
|
||||
}
|
||||
|
@@ -1,8 +1,6 @@
|
||||
import 'package:animations/animations.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:obtainium/components/generated_form.dart';
|
||||
import 'package:obtainium/components/generated_form_modal.dart';
|
||||
import 'package:obtainium/custom_errors.dart';
|
||||
import 'package:obtainium/main.dart';
|
||||
@@ -167,46 +165,19 @@ class _AppPageState extends State<AppPage> {
|
||||
onTap: app?.app == null || updating
|
||||
? null
|
||||
: () async {
|
||||
var allAssetUrls = [
|
||||
...app!.app.apkUrls,
|
||||
...app.app.otherAssetUrls
|
||||
].map((e) => MapEntry(e.value, e.key)).toList();
|
||||
var values = await showModal(
|
||||
context: globalNavigatorKey.currentContext ?? context,
|
||||
builder: (BuildContext ctx) {
|
||||
return GeneratedFormModal(
|
||||
title:
|
||||
tr('downloadX', args: [tr('releaseAsset')]),
|
||||
initValid: true,
|
||||
items: [
|
||||
[
|
||||
GeneratedFormDropdown(
|
||||
'assetToDownload', allAssetUrls,
|
||||
defaultValue: allAssetUrls[0].key,
|
||||
label: tr('selectX', args: [
|
||||
tr('releaseAsset').toLowerCase()
|
||||
]))
|
||||
]
|
||||
]);
|
||||
},
|
||||
);
|
||||
|
||||
if (values != null) {
|
||||
var downloadUrl = values['assetToDownload'] as String;
|
||||
var fileName = allAssetUrls
|
||||
.where((e) => e.key == downloadUrl)
|
||||
.first
|
||||
.value;
|
||||
var fileUrl = await appsProvider.confirmAppFileUrl(
|
||||
app!.app, context, true);
|
||||
if (fileUrl != null) {
|
||||
NotificationsProvider notificationsProvider =
|
||||
(globalNavigatorKey.currentContext ?? context)
|
||||
.read<NotificationsProvider>();
|
||||
try {
|
||||
showMessage(
|
||||
'${tr('downloadingX', args: [fileName])}...',
|
||||
'${tr('downloadingX', args: [fileUrl.key])}...',
|
||||
globalNavigatorKey.currentContext ?? context);
|
||||
await downloadFile(
|
||||
downloadUrl,
|
||||
fileName
|
||||
fileUrl.value,
|
||||
fileUrl.key
|
||||
.split('.')
|
||||
.reversed
|
||||
.toList()
|
||||
@@ -214,21 +185,21 @@ class _AppPageState extends State<AppPage> {
|
||||
.reversed
|
||||
.join('.'), (double? progress) {
|
||||
notificationsProvider.notify(DownloadNotification(
|
||||
fileName, progress?.ceil() ?? 0));
|
||||
fileUrl.key, progress?.ceil() ?? 0));
|
||||
}, '/storage/emulated/0/Download',
|
||||
headers: await source?.getRequestHeaders(
|
||||
app.app.additionalSettings,
|
||||
forAPKDownload: fileName.endsWith('.apk')
|
||||
forAPKDownload: fileUrl.key.endsWith('.apk')
|
||||
? true
|
||||
: false));
|
||||
notificationsProvider.notify(
|
||||
DownloadedNotification(fileName, downloadUrl));
|
||||
notificationsProvider.notify(DownloadedNotification(
|
||||
fileUrl.key, fileUrl.value));
|
||||
} catch (e) {
|
||||
showError(
|
||||
e, globalNavigatorKey.currentContext ?? context);
|
||||
} finally {
|
||||
notificationsProvider
|
||||
.cancel(DownloadNotification(fileName, 0).id);
|
||||
.cancel(DownloadNotification(fileUrl.key, 0).id);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@@ -705,23 +705,28 @@ class AppsProvider with ChangeNotifier {
|
||||
await intent.launch();
|
||||
}
|
||||
|
||||
Future<MapEntry<String, String>?> confirmApkUrl(
|
||||
App app, BuildContext? context) async {
|
||||
Future<MapEntry<String, String>?> confirmAppFileUrl(
|
||||
App app, BuildContext? context, bool pickAnyAsset) async {
|
||||
var urlsToSelectFrom = app.apkUrls;
|
||||
if (pickAnyAsset) {
|
||||
urlsToSelectFrom = [...urlsToSelectFrom, ...app.otherAssetUrls];
|
||||
}
|
||||
// If the App has more than one APK, the user should pick one (if context provided)
|
||||
MapEntry<String, String>? apkUrl =
|
||||
app.apkUrls[app.preferredApkIndex >= 0 ? app.preferredApkIndex : 0];
|
||||
MapEntry<String, String>? appFileUrl = urlsToSelectFrom[
|
||||
app.preferredApkIndex >= 0 ? app.preferredApkIndex : 0];
|
||||
// get device supported architecture
|
||||
List<String> archs = (await DeviceInfoPlugin().androidInfo).supportedAbis;
|
||||
|
||||
if (app.apkUrls.length > 1 && context != null) {
|
||||
if (urlsToSelectFrom.length > 1 && context != null) {
|
||||
// ignore: use_build_context_synchronously
|
||||
apkUrl = await showDialog(
|
||||
appFileUrl = await showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext ctx) {
|
||||
return APKPicker(
|
||||
return AppFilePicker(
|
||||
app: app,
|
||||
initVal: apkUrl,
|
||||
initVal: appFileUrl,
|
||||
archs: archs,
|
||||
pickAnyAsset: pickAnyAsset,
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -731,8 +736,8 @@ class AppsProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
// If the picked APK comes from an origin different from the source, get user confirmation (if context provided)
|
||||
if (apkUrl != null &&
|
||||
getHost(apkUrl.value) != getHost(app.url) &&
|
||||
if (appFileUrl != null &&
|
||||
getHost(appFileUrl.value) != getHost(app.url) &&
|
||||
context != null) {
|
||||
// ignore: use_build_context_synchronously
|
||||
if (!(settingsProvider.hideAPKOriginWarning) &&
|
||||
@@ -741,13 +746,13 @@ class AppsProvider with ChangeNotifier {
|
||||
context: context,
|
||||
builder: (BuildContext ctx) {
|
||||
return APKOriginWarningDialog(
|
||||
sourceUrl: app.url, apkUrl: apkUrl!.value);
|
||||
sourceUrl: app.url, apkUrl: appFileUrl!.value);
|
||||
}) !=
|
||||
true) {
|
||||
apkUrl = null;
|
||||
appFileUrl = null;
|
||||
}
|
||||
}
|
||||
return apkUrl;
|
||||
return appFileUrl;
|
||||
}
|
||||
|
||||
// Given a list of AppIds, uses stored info about the apps to download APKs and install them
|
||||
@@ -774,7 +779,7 @@ class AppsProvider with ChangeNotifier {
|
||||
var trackOnly = apps[id]!.app.additionalSettings['trackOnly'] == true;
|
||||
if (!trackOnly) {
|
||||
// ignore: use_build_context_synchronously
|
||||
apkUrl = await confirmApkUrl(apps[id]!.app, context);
|
||||
apkUrl = await confirmAppFileUrl(apps[id]!.app, context, false);
|
||||
}
|
||||
if (apkUrl != null) {
|
||||
int urlInd = apps[id]!
|
||||
@@ -1482,38 +1487,49 @@ class AppsProvider with ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
class APKPicker extends StatefulWidget {
|
||||
const APKPicker({super.key, required this.app, this.initVal, this.archs});
|
||||
class AppFilePicker extends StatefulWidget {
|
||||
const AppFilePicker(
|
||||
{super.key,
|
||||
required this.app,
|
||||
this.initVal,
|
||||
this.archs,
|
||||
this.pickAnyAsset = false});
|
||||
|
||||
final App app;
|
||||
final MapEntry<String, String>? initVal;
|
||||
final List<String>? archs;
|
||||
final bool pickAnyAsset;
|
||||
|
||||
@override
|
||||
State<APKPicker> createState() => _APKPickerState();
|
||||
State<AppFilePicker> createState() => _AppFilePickerState();
|
||||
}
|
||||
|
||||
class _APKPickerState extends State<APKPicker> {
|
||||
MapEntry<String, String>? apkUrl;
|
||||
class _AppFilePickerState extends State<AppFilePicker> {
|
||||
MapEntry<String, String>? fileUrl;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
apkUrl ??= widget.initVal;
|
||||
fileUrl ??= widget.initVal;
|
||||
var urlsToSelectFrom = widget.app.apkUrls;
|
||||
if (widget.pickAnyAsset) {
|
||||
urlsToSelectFrom = [...urlsToSelectFrom, ...widget.app.otherAssetUrls];
|
||||
}
|
||||
return AlertDialog(
|
||||
scrollable: true,
|
||||
title: Text(tr('pickAnAPK')),
|
||||
title: Text(widget.pickAnyAsset
|
||||
? tr('selectX', args: [tr('releaseAsset').toLowerCase()])
|
||||
: tr('pickAnAPK')),
|
||||
content: Column(children: [
|
||||
Text(tr('appHasMoreThanOnePackage', args: [widget.app.finalName])),
|
||||
const SizedBox(height: 16),
|
||||
...widget.app.apkUrls.map(
|
||||
...urlsToSelectFrom.map(
|
||||
(u) => RadioListTile<String>(
|
||||
title: Text(u.key),
|
||||
value: u.value,
|
||||
groupValue: apkUrl!.value,
|
||||
groupValue: fileUrl!.value,
|
||||
onChanged: (String? val) {
|
||||
setState(() {
|
||||
apkUrl =
|
||||
widget.app.apkUrls.where((e) => e.value == val).first;
|
||||
fileUrl = urlsToSelectFrom.where((e) => e.value == val).first;
|
||||
});
|
||||
}),
|
||||
),
|
||||
@@ -1540,7 +1556,7 @@ class _APKPickerState extends State<APKPicker> {
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
HapticFeedback.selectionClick();
|
||||
Navigator.of(context).pop(apkUrl);
|
||||
Navigator.of(context).pop(fileUrl);
|
||||
},
|
||||
child: Text(tr('continue')))
|
||||
],
|
||||
|
Reference in New Issue
Block a user