Improve release asset download UI

This commit is contained in:
Imran Remtulla
2024-04-07 01:41:35 -04:00
parent 3d1113c057
commit 00988ed04d
3 changed files with 55 additions and 67 deletions

View File

@@ -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'));
}

View File

@@ -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);
}
}
},