diff --git a/assets/i18n/en_US.json b/assets/i18n/en_US.json index 5602126754..61c1701ce0 100644 --- a/assets/i18n/en_US.json +++ b/assets/i18n/en_US.json @@ -17,6 +17,7 @@ "settingsTab": "Settings" }, "homeView": { + "refreshSuccess": "Refresh successfully", "widgetTitle": "Dashboard", "updatesSubtitle": "Updates", "patchedSubtitle": "Patched applications", diff --git a/lib/services/manager_api.dart b/lib/services/manager_api.dart index c4eaeb60f8..7991c64100 100644 --- a/lib/services/manager_api.dart +++ b/lib/services/manager_api.dart @@ -29,6 +29,10 @@ class ManagerAPI { String defaultIntegrationsRepo = 'revanced/revanced-integrations'; String defaultCliRepo = 'revanced/revanced-cli'; String defaultManagerRepo = 'revanced/revanced-manager'; + String? patchesVersion = ''; + bool isDefaultPatchesRepo() { + return getPatchesRepo() == 'revanced/revanced-patches'; + } Future initialize() async { _prefs = await SharedPreferences.getInstance(); @@ -267,6 +271,19 @@ class ManagerAPI { return packageInfo.version; } + Future getCurrentPatchesVersion() async { + if (isDefaultPatchesRepo()) { + patchesVersion = await getLatestPatchesVersion(); + // print('Patches version: $patchesVersion'); + return patchesVersion ?? '0.0.0'; + } else { + // fetch from github + patchesVersion = + await _githubAPI.getLastestReleaseVersion(getPatchesRepo()); + } + return null; + } + Future> getAppsToRemove( List patchedApps, ) async { diff --git a/lib/ui/views/home/home_view.dart b/lib/ui/views/home/home_view.dart index 4d067d5c8e..1f923390bc 100644 --- a/lib/ui/views/home/home_view.dart +++ b/lib/ui/views/home/home_view.dart @@ -50,8 +50,9 @@ class HomeView extends StatelessWidget { ), const SizedBox(height: 10), LatestCommitCard( - onPressed: () => + onPressedManager: () => model.showUpdateConfirmationDialog(context), + onPressedPatches: () => model.forceRefresh(context), ), const SizedBox(height: 23), I18nText( diff --git a/lib/ui/views/home/home_viewmodel.dart b/lib/ui/views/home/home_viewmodel.dart index ac55306146..c16d971f7c 100644 --- a/lib/ui/views/home/home_viewmodel.dart +++ b/lib/ui/views/home/home_viewmodel.dart @@ -105,6 +105,26 @@ class HomeViewModel extends BaseViewModel { return false; } + Future hasPatchesUpdates() async { + final String? latestVersion = await _managerAPI.getLatestPatchesVersion(); + final String? currentVersion = await _managerAPI.getCurrentPatchesVersion(); + if (latestVersion != null) { + try { + final int latestVersionInt = + int.parse(latestVersion.replaceAll(RegExp('[^0-9]'), '')); + final int currentVersionInt = + int.parse(currentVersion!.replaceAll(RegExp('[^0-9]'), '')); + return latestVersionInt > currentVersionInt; + } on Exception catch (e) { + if (kDebugMode) { + print(e); + } + return false; + } + } + return false; + } + Future updateManager(BuildContext context) async { try { _toast.showBottom('homeView.downloadingMessage'); @@ -180,6 +200,7 @@ class HomeViewModel extends BaseViewModel { _lastUpdate!.difference(DateTime.now()).inSeconds > 2) { _managerAPI.clearAllData(); } + _toast.showBottom('homeView.refreshSuccess'); initialize(context); } } diff --git a/lib/ui/widgets/homeView/latest_commit_card.dart b/lib/ui/widgets/homeView/latest_commit_card.dart index f23beb0796..e6830621ae 100644 --- a/lib/ui/widgets/homeView/latest_commit_card.dart +++ b/lib/ui/widgets/homeView/latest_commit_card.dart @@ -8,9 +8,11 @@ import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart'; class LatestCommitCard extends StatefulWidget { const LatestCommitCard({ Key? key, - required this.onPressed, + required this.onPressedManager, + required this.onPressedPatches, }) : super(key: key); - final Function() onPressed; + final Function() onPressedManager; + final Function() onPressedPatches; @override State createState() => _LatestCommitCardState(); @@ -21,66 +23,109 @@ class _LatestCommitCardState extends State { @override Widget build(BuildContext context) { - return CustomCard( - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.start, + return Column( + children: [ + // ReVanced Manager + CustomCard( + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Row( + Column( + crossAxisAlignment: CrossAxisAlignment.start, children: [ - I18nText('latestCommitCard.patcherLabel'), - FutureBuilder( - future: model.getLatestPatcherReleaseTime(), - builder: (context, snapshot) => Text( - snapshot.hasData && snapshot.data!.isNotEmpty - ? FlutterI18n.translate( - context, - 'latestCommitCard.timeagoLabel', - translationParams: {'time': snapshot.data!}, - ) - : FlutterI18n.translate( - context, - 'latestCommitCard.loadingLabel', - ), - ), + Row( + children: const [ + Text('ReVanced Manager'), + ], + ), + const SizedBox(height: 4), + Row( + children: [ + FutureBuilder( + future: model.getLatestManagerReleaseTime(), + builder: (context, snapshot) => + snapshot.hasData && snapshot.data!.isNotEmpty + ? I18nText( + 'latestCommitCard.timeagoLabel', + translationParams: {'time': snapshot.data!}, + ) + : I18nText('latestCommitCard.loadingLabel'), + ), + ], ), ], ), - const SizedBox(height: 4), - Row( - children: [ - I18nText('latestCommitCard.managerLabel'), - FutureBuilder( - future: model.getLatestManagerReleaseTime(), - builder: (context, snapshot) => - snapshot.hasData && snapshot.data!.isNotEmpty - ? I18nText( - 'latestCommitCard.timeagoLabel', - translationParams: {'time': snapshot.data!}, - ) - : I18nText('latestCommitCard.loadingLabel'), + FutureBuilder( + future: locator().hasManagerUpdates(), + initialData: false, + builder: (context, snapshot) => Opacity( + opacity: snapshot.hasData && snapshot.data! ? 1.0 : 0.25, + child: CustomMaterialButton( + label: I18nText('updateButton'), + onPressed: snapshot.hasData && snapshot.data! + ? widget.onPressedManager + : () => {}, ), - ], + ), ), ], ), - FutureBuilder( - future: locator().hasManagerUpdates(), - initialData: false, - builder: (context, snapshot) => Opacity( - opacity: snapshot.hasData && snapshot.data! ? 1.0 : 0.25, - child: CustomMaterialButton( - label: I18nText('latestCommitCard.updateButton'), - onPressed: snapshot.hasData && snapshot.data! - ? widget.onPressed - : () => {}, + ), + + const SizedBox(height: 16), + + // ReVanced Patches + CustomCard( + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: const [ + Text('ReVanced Patches'), + ], + ), + const SizedBox(height: 4), + Row( + children: [ + FutureBuilder( + future: model.getLatestPatcherReleaseTime(), + builder: (context, snapshot) => Text( + snapshot.hasData && snapshot.data!.isNotEmpty + ? FlutterI18n.translate( + context, + 'latestCommitCard.timeagoLabel', + translationParams: {'time': snapshot.data!}, + ) + : FlutterI18n.translate( + context, + 'latestCommitCard.loadingLabel', + ), + ), + ), + ], + ), + ], ), - ), + FutureBuilder( + future: locator().hasPatchesUpdates(), + initialData: false, + builder: (context, snapshot) => Opacity( + opacity: snapshot.hasData && snapshot.data! ? 1.0 : 0.25, + child: CustomMaterialButton( + label: I18nText('updateButton'), + onPressed: snapshot.hasData && snapshot.data! + ? widget.onPressedPatches + : () => {}, + ), + ), + ), + ], ), - ], - ), + ), + ], ); } }