Basic UI seems ready

This commit is contained in:
Imran Remtulla
2022-08-18 22:07:53 -04:00
parent 0e36e53b46
commit 821fd6934a
2 changed files with 93 additions and 57 deletions

View File

@@ -28,21 +28,29 @@ class _AppPageState extends State<AppPage> {
body: WebView( body: WebView(
initialUrl: app?.url, initialUrl: app?.url,
), ),
bottomSheet: Padding( bottomSheet: Column(
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0), mainAxisSize: MainAxisSize.min,
child: children: [
Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ Padding(
padding:
const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Expanded( Expanded(
child: OutlinedButton( child: OutlinedButton(
onPressed: (app?.installedVersion == null || onPressed: (app?.installedVersion == null ||
appsProvider.checkAppObjectForUpdate(app!)) && appsProvider
.checkAppObjectForUpdate(app!)) &&
app?.currentDownloadId == null app?.currentDownloadId == null
? () { ? () {
appsProvider.backgroundDownloadAndInstallApp(app!); appsProvider
.backgroundDownloadAndInstallApp(app!);
} }
: null, : null,
child: Text( child: Text(app?.installedVersion == null
app?.installedVersion == null ? 'Install' : 'Update'))), ? 'Install'
: 'Update'))),
const SizedBox(width: 16.0), const SizedBox(width: 16.0),
OutlinedButton( OutlinedButton(
onPressed: app?.currentDownloadId != null onPressed: app?.currentDownloadId != null
@@ -58,10 +66,12 @@ class _AppPageState extends State<AppPage> {
actions: [ actions: [
TextButton( TextButton(
onPressed: () { onPressed: () {
appsProvider.removeApp(app!.id).then((_) { appsProvider
.removeApp(app!.id)
.then((_) {
int count = 0; int count = 0;
Navigator.of(context) Navigator.of(context).popUntil(
.popUntil((_) => count++ >= 2); (_) => count++ >= 2);
}); });
}, },
child: const Text('Remove')), child: const Text('Remove')),
@@ -77,9 +87,11 @@ class _AppPageState extends State<AppPage> {
style: TextButton.styleFrom( style: TextButton.styleFrom(
foregroundColor: Theme.of(context).errorColor), foregroundColor: Theme.of(context).errorColor),
child: const Text('Remove'), child: const Text('Remove'),
) ),
// TODO: Add progress bar when app?.currentDownloadId != null
])), ])),
if (app?.currentDownloadId != null) const LinearProgressIndicator()
],
),
); );
} }
} }

View File

@@ -20,7 +20,9 @@ class AppsProvider with ChangeNotifier {
AppsProvider() { AppsProvider() {
initializeDownloader(); initializeDownloader();
loadApps(); loadApps().then((_) {
clearDownloadStates();
});
} }
// Notifications plugin for downloads // Notifications plugin for downloads
@@ -90,7 +92,14 @@ class AppsProvider with ChangeNotifier {
break; break;
} }
} }
// Change App status to no longer downloading // Install the App (and remove warning notification if any)
FlutterDownloader.open(taskId: id);
downloaderNotifications.cancel(1);
}
// Change App status based on result (we assume user accepts install - no way to tell programatically)
if (status == DownloadTaskStatus.complete ||
status == DownloadTaskStatus.failed ||
status == DownloadTaskStatus.canceled) {
App? foundApp; App? foundApp;
apps.forEach((appId, app) { apps.forEach((appId, app) {
if (app.currentDownloadId == id) { if (app.currentDownloadId == id) {
@@ -98,10 +107,10 @@ class AppsProvider with ChangeNotifier {
} }
}); });
foundApp!.currentDownloadId = null; foundApp!.currentDownloadId = null;
if (status == DownloadTaskStatus.complete) {
foundApp!.installedVersion = foundApp!.latestVersion;
}
saveApp(foundApp!); saveApp(foundApp!);
// Install the App (and remove warning notification if any)
FlutterDownloader.open(taskId: id);
downloaderNotifications.cancel(1);
} }
} }
@@ -158,6 +167,21 @@ class AppsProvider with ChangeNotifier {
notifyListeners(); notifyListeners();
} }
Future<void> clearDownloadStates() async {
var appList = apps.values.toList();
int count = 0;
for (int i = 0; i < appList.length; i++) {
if (appList[i].currentDownloadId != null) {
apps[appList[i].id]?.currentDownloadId = null;
await saveApp(apps[appList[i].id]!);
count++;
}
}
if (count > 0) {
notifyListeners();
}
}
Future<void> removeApp(String appId) async { Future<void> removeApp(String appId) async {
File file = File('${(await getAppsDir()).path}/$appId.json'); File file = File('${(await getAppsDir()).path}/$appId.json');
if (file.existsSync()) { if (file.existsSync()) {