From cc268aeeda7c7351d27a0d94c434b9df31b915d4 Mon Sep 17 00:00:00 2001 From: Imran Remtulla Date: Sat, 6 May 2023 14:25:17 -0400 Subject: [PATCH] "Check updates on start" toggle --- assets/translations/de.json | 3 +- assets/translations/en.json | 3 +- assets/translations/es.json | 1 + assets/translations/fa.json | 1 + assets/translations/fr.json | 3 +- assets/translations/hu.json | 1 + assets/translations/it.json | 3 +- assets/translations/ja.json | 1 + assets/translations/zh.json | 1 + lib/pages/apps.dart | 41 ++++++++++++++++++---------- lib/pages/settings.dart | 12 ++++++++ lib/providers/settings_provider.dart | 18 ++++++++++++ 12 files changed, 70 insertions(+), 18 deletions(-) diff --git a/assets/translations/de.json b/assets/translations/de.json index fb3135a..5f53337 100644 --- a/assets/translations/de.json +++ b/assets/translations/de.json @@ -121,7 +121,7 @@ "followSystem": "System folgen", "obtainium": "Obtainium", "materialYou": "Material You", - "useBlackTheme": "Use pure black dark theme", + "useBlackTheme": "Use Pure Black Dark Theme", "appSortBy": "App sortieren nach", "authorName": "Autor/Name", "nameAuthor": "Name/Autor", @@ -231,6 +231,7 @@ "gitlabPATLabel": "GitLab Personal Access Token (Enables Search)", "about": "About", "requiresCredentialsInSettings": "This needs additional credentials (in Settings)", + "checkOnStart": "Check Once on Start", "removeAppQuestion": { "one": "App entfernen?", "other": "Apps entfernen?" diff --git a/assets/translations/en.json b/assets/translations/en.json index dd027a9..eb59399 100644 --- a/assets/translations/en.json +++ b/assets/translations/en.json @@ -121,7 +121,7 @@ "followSystem": "Follow System", "obtainium": "Obtainium", "materialYou": "Material You", - "useBlackTheme": "Use pure black dark theme", + "useBlackTheme": "Use Pure Black Dark Theme", "appSortBy": "App Sort By", "authorName": "Author/Name", "nameAuthor": "Name/Author", @@ -231,6 +231,7 @@ "gitlabPATLabel": "GitLab Personal Access Token (Enables Search)", "about": "About", "requiresCredentialsInSettings": "This needs additional credentials (in Settings)", + "checkOnStart": "Check Once on Start", "removeAppQuestion": { "one": "Remove App?", "other": "Remove Apps?" diff --git a/assets/translations/es.json b/assets/translations/es.json index d3fae41..c013d01 100644 --- a/assets/translations/es.json +++ b/assets/translations/es.json @@ -231,6 +231,7 @@ "gitlabPATLabel": "GitLab Personal Access Token (Enables Search)", "about": "About", "requiresCredentialsInSettings": "This needs additional credentials (in Settings)", + "checkOnStart": "Check Once on Start", "removeAppQuestion": { "one": "¿Eliminar Aplicación?", "other": "¿Eliminar Aplicaciones?" diff --git a/assets/translations/fa.json b/assets/translations/fa.json index 36e25d4..5685c1e 100644 --- a/assets/translations/fa.json +++ b/assets/translations/fa.json @@ -231,6 +231,7 @@ "gitlabPATLabel": "GitLab Personal Access Token (Enables Search)", "about": "About", "requiresCredentialsInSettings": "This needs additional credentials (in Settings)", + "checkOnStart": "Check Once on Start", "removeAppQuestion": { "one": "برنامه حذف شود؟", "other": "برنامه ها حذف شوند؟" diff --git a/assets/translations/fr.json b/assets/translations/fr.json index 4e29966..90c060f 100644 --- a/assets/translations/fr.json +++ b/assets/translations/fr.json @@ -121,7 +121,7 @@ "followSystem": "Suivre le système", "obtainium": "Obtainium", "materialYou": "Material You", - "useBlackTheme": "Use pure black dark theme", + "useBlackTheme": "Use Pure Black Dark Theme", "appSortBy": "Applications triées par", "authorName": "Auteur/Nom", "nameAuthor": "Nom/Auteur", @@ -231,6 +231,7 @@ "gitlabPATLabel": "GitLab Personal Access Token (Enables Search)", "about": "About", "requiresCredentialsInSettings": "This needs additional credentials (in Settings)", + "checkOnStart": "Check Once on Start", "removeAppQuestion": { "one": "Supprimer l'application ?", "other": "Supprimer les applications ?" diff --git a/assets/translations/hu.json b/assets/translations/hu.json index 85134f0..c73ef70 100644 --- a/assets/translations/hu.json +++ b/assets/translations/hu.json @@ -230,6 +230,7 @@ "gitlabPATLabel": "GitLab Personal Access Token (Enables Search)", "about": "About", "requiresCredentialsInSettings": "This needs additional credentials (in Settings)", + "checkOnStart": "Check Once on Start", "removeAppQuestion": { "one": "Eltávolítja az alkalmazást?", "other": "Eltávolítja az alkalmazást?" diff --git a/assets/translations/it.json b/assets/translations/it.json index 728bce8..0cff11d 100644 --- a/assets/translations/it.json +++ b/assets/translations/it.json @@ -121,7 +121,7 @@ "followSystem": "Segui sistema", "obtainium": "Obtainium", "materialYou": "Material You", - "useBlackTheme": "Use pure black dark theme", + "useBlackTheme": "Use Pure Black Dark Theme", "appSortBy": "App ordinate per", "authorName": "Autore/Nome", "nameAuthor": "Nome/Autore", @@ -231,6 +231,7 @@ "gitlabPATLabel": "GitLab Personal Access Token (Enables Search)", "about": "About", "requiresCredentialsInSettings": "This needs additional credentials (in Settings)", + "checkOnStart": "Check Once on Start", "removeAppQuestion": { "one": "Rimuovere l'App?", "other": "Rimuovere le App?" diff --git a/assets/translations/ja.json b/assets/translations/ja.json index 02ee143..621b831 100644 --- a/assets/translations/ja.json +++ b/assets/translations/ja.json @@ -231,6 +231,7 @@ "gitlabPATLabel": "GitLab Personal Access Token (Enables Search)", "about": "About", "requiresCredentialsInSettings": "This needs additional credentials (in Settings)", + "checkOnStart": "Check Once on Start", "removeAppQuestion": { "one": "アプリを削除しますか?", "other": "アプリを削除しますか?" diff --git a/assets/translations/zh.json b/assets/translations/zh.json index 1cf5267..cd6f101 100644 --- a/assets/translations/zh.json +++ b/assets/translations/zh.json @@ -231,6 +231,7 @@ "gitlabPATLabel": "GitLab Personal Access Token (Enables Search)", "about": "About", "requiresCredentialsInSettings": "This needs additional credentials (in Settings)", + "checkOnStart": "Check Once on Start", "removeAppQuestion": { "one": "是否删除应用?", "other": "是否删除应用?" diff --git a/lib/pages/apps.dart b/lib/pages/apps.dart index f7a8159..5fcee6a 100644 --- a/lib/pages/apps.dart +++ b/lib/pages/apps.dart @@ -52,6 +52,9 @@ class AppsPageState extends State { } } + final GlobalKey _refreshIndicatorKey = + GlobalKey(); + @override Widget build(BuildContext context) { var appsProvider = context.watch(); @@ -61,6 +64,27 @@ class AppsPageState extends State { var currentFilterIsUpdatesOnly = filter.isIdenticalTo(updatesOnlyFilter, settingsProvider); + refresh() { + HapticFeedback.lightImpact(); + setState(() { + refreshingSince = DateTime.now(); + }); + return appsProvider.checkUpdates().catchError((e) { + showError(e, context); + }).whenComplete(() { + setState(() { + refreshingSince = null; + }); + }); + } + + if (!appsProvider.loadingApps && + appsProvider.apps.isNotEmpty && + settingsProvider.checkJustStarted() && + settingsProvider.checkOnStart) { + _refreshIndicatorKey.currentState?.show(); + } + selectedAppIds = selectedAppIds .where((element) => listedApps.map((e) => e.app.id).contains(element)) .toSet(); @@ -315,7 +339,7 @@ class AppsPageState extends State { ?.isBefore(refreshingSince!) ?? true)) .length / - appsProvider.apps.length, + (appsProvider.apps.isNotEmpty ? appsProvider.apps.length : 1), ), ) ]; @@ -1019,19 +1043,8 @@ class AppsPageState extends State { return Scaffold( backgroundColor: Theme.of(context).colorScheme.surface, body: RefreshIndicator( - onRefresh: () { - HapticFeedback.lightImpact(); - setState(() { - refreshingSince = DateTime.now(); - }); - return appsProvider.checkUpdates().catchError((e) { - showError(e, context); - }).whenComplete(() { - setState(() { - refreshingSince = null; - }); - }); - }, + key: _refreshIndicatorKey, + onRefresh: refresh, child: CustomScrollView(slivers: [ CustomAppBar(title: tr('appsString')), ...getLoadingWidgets(), diff --git a/lib/pages/settings.dart b/lib/pages/settings.dart index 65684cf..7827111 100644 --- a/lib/pages/settings.dart +++ b/lib/pages/settings.dart @@ -228,6 +228,18 @@ class _SettingsPageState extends State { color: Theme.of(context).colorScheme.primary), ), intervalDropdown, + height16, + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Flexible(child: Text(tr('checkOnStart'))), + Switch( + value: settingsProvider.checkOnStart, + onChanged: (value) { + settingsProvider.checkOnStart = value; + }) + ], + ), height32, Text( tr('sourceSpecific'), diff --git a/lib/providers/settings_provider.dart b/lib/providers/settings_provider.dart index 162d7f9..8ddfdf2 100644 --- a/lib/providers/settings_provider.dart +++ b/lib/providers/settings_provider.dart @@ -35,6 +35,7 @@ List updateIntervals = [15, 30, 60, 120, 180, 360, 720, 1440, 4320, 0] class SettingsProvider with ChangeNotifier { SharedPreferences? prefs; + bool justStarted = true; String sourceUrl = 'https://github.com/ImranR98/Obtainium'; @@ -92,6 +93,15 @@ class SettingsProvider with ChangeNotifier { notifyListeners(); } + bool get checkOnStart { + return prefs?.getBool('checkOnStart') ?? false; + } + + set checkOnStart(bool checkOnStart) { + prefs?.setBool('checkOnStart', checkOnStart); + notifyListeners(); + } + SortColumnSettings get sortColumn { return SortColumnSettings.values[ prefs?.getInt('sortColumn') ?? SortColumnSettings.nameAuthor.index]; @@ -120,6 +130,14 @@ class SettingsProvider with ChangeNotifier { return result; } + bool checkJustStarted() { + if (justStarted) { + justStarted = false; + return true; + } + return false; + } + Future getInstallPermission({bool enforce = false}) async { while (!(await Permission.requestInstallPackages.isGranted)) { // Explicit request as InstallPlugin request sometimes bugged