mirror of
				https://github.com/ImranR98/Obtainium.git
				synced 2025-10-31 05:23:28 +01:00 
			
		
		
		
	Basic UI seems ready
This commit is contained in:
		| @@ -28,58 +28,70 @@ 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( | ||||||
|             Expanded( |               padding: | ||||||
|                 child: OutlinedButton( |                   const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0), | ||||||
|                     onPressed: (app?.installedVersion == null || |               child: Row( | ||||||
|                                 appsProvider.checkAppObjectForUpdate(app!)) && |                   mainAxisAlignment: MainAxisAlignment.spaceEvenly, | ||||||
|                             app?.currentDownloadId == null |                   children: [ | ||||||
|                         ? () { |                     Expanded( | ||||||
|                             appsProvider.backgroundDownloadAndInstallApp(app!); |                         child: OutlinedButton( | ||||||
|                           } |                             onPressed: (app?.installedVersion == null || | ||||||
|                         : null, |                                         appsProvider | ||||||
|                     child: Text( |                                             .checkAppObjectForUpdate(app!)) && | ||||||
|                         app?.installedVersion == null ? 'Install' : 'Update'))), |                                     app?.currentDownloadId == null | ||||||
|             const SizedBox(width: 16.0), |                                 ? () { | ||||||
|             OutlinedButton( |                                     appsProvider | ||||||
|               onPressed: app?.currentDownloadId != null |                                         .backgroundDownloadAndInstallApp(app!); | ||||||
|                   ? null |                                   } | ||||||
|                   : () { |                                 : null, | ||||||
|                       showDialog( |                             child: Text(app?.installedVersion == null | ||||||
|                           context: context, |                                 ? 'Install' | ||||||
|                           builder: (BuildContext ctx) { |                                 : 'Update'))), | ||||||
|                             return AlertDialog( |                     const SizedBox(width: 16.0), | ||||||
|                               title: const Text('Remove App?'), |                     OutlinedButton( | ||||||
|                               content: Text( |                       onPressed: app?.currentDownloadId != null | ||||||
|                                   'This will remove \'${app?.name}\' from Obtainium.${app?.installedVersion != null ? '\n\nNote that while Obtainium will no longer track its updates, the App will remain installed.' : ''}'), |                           ? null | ||||||
|                               actions: [ |                           : () { | ||||||
|                                 TextButton( |                               showDialog( | ||||||
|                                     onPressed: () { |                                   context: context, | ||||||
|                                       appsProvider.removeApp(app!.id).then((_) { |                                   builder: (BuildContext ctx) { | ||||||
|                                         int count = 0; |                                     return AlertDialog( | ||||||
|                                         Navigator.of(context) |                                       title: const Text('Remove App?'), | ||||||
|                                             .popUntil((_) => count++ >= 2); |                                       content: Text( | ||||||
|                                       }); |                                           'This will remove \'${app?.name}\' from Obtainium.${app?.installedVersion != null ? '\n\nNote that while Obtainium will no longer track its updates, the App will remain installed.' : ''}'), | ||||||
|                                     }, |                                       actions: [ | ||||||
|                                     child: const Text('Remove')), |                                         TextButton( | ||||||
|                                 TextButton( |                                             onPressed: () { | ||||||
|                                     onPressed: () { |                                               appsProvider | ||||||
|                                       Navigator.of(context).pop(); |                                                   .removeApp(app!.id) | ||||||
|                                     }, |                                                   .then((_) { | ||||||
|                                     child: const Text('Cancel')) |                                                 int count = 0; | ||||||
|                               ], |                                                 Navigator.of(context).popUntil( | ||||||
|                             ); |                                                     (_) => count++ >= 2); | ||||||
|                           }); |                                               }); | ||||||
|                     }, |                                             }, | ||||||
|               style: TextButton.styleFrom( |                                             child: const Text('Remove')), | ||||||
|                   foregroundColor: Theme.of(context).errorColor), |                                         TextButton( | ||||||
|               child: const Text('Remove'), |                                             onPressed: () { | ||||||
|             ) |                                               Navigator.of(context).pop(); | ||||||
|             // TODO: Add progress bar when app?.currentDownloadId != null |                                             }, | ||||||
|           ])), |                                             child: const Text('Cancel')) | ||||||
|  |                                       ], | ||||||
|  |                                     ); | ||||||
|  |                                   }); | ||||||
|  |                             }, | ||||||
|  |                       style: TextButton.styleFrom( | ||||||
|  |                           foregroundColor: Theme.of(context).errorColor), | ||||||
|  |                       child: const Text('Remove'), | ||||||
|  |                     ), | ||||||
|  |                   ])), | ||||||
|  |           if (app?.currentDownloadId != null) const LinearProgressIndicator() | ||||||
|  |         ], | ||||||
|  |       ), | ||||||
|     ); |     ); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -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()) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user