diff --git a/lib/ui/views/home/home_viewmodel.dart b/lib/ui/views/home/home_viewmodel.dart index 62a90c23a6..e28c864ff4 100644 --- a/lib/ui/views/home/home_viewmodel.dart +++ b/lib/ui/views/home/home_viewmodel.dart @@ -15,7 +15,7 @@ import 'package:revanced_manager/services/patcher_api.dart'; import 'package:revanced_manager/services/toast.dart'; import 'package:revanced_manager/ui/views/navigation/navigation_viewmodel.dart'; import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart'; -import 'package:revanced_manager/ui/widgets/installerView/custom_material_button.dart'; +import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart'; import 'package:stacked/stacked.dart'; import 'package:stacked_services/stacked_services.dart'; import 'package:timezone/timezone.dart' as tz; diff --git a/lib/ui/views/installer/installer_view.dart b/lib/ui/views/installer/installer_view.dart index 10a1f36527..e9cccb7144 100644 --- a/lib/ui/views/installer/installer_view.dart +++ b/lib/ui/views/installer/installer_view.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_i18n/flutter_i18n.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:revanced_manager/ui/views/installer/installer_viewmodel.dart'; -import 'package:revanced_manager/ui/widgets/installerView/custom_material_button.dart'; +import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart'; import 'package:revanced_manager/ui/widgets/installerView/gradient_progress_indicator.dart'; import 'package:revanced_manager/ui/widgets/shared/custom_card.dart'; import 'package:revanced_manager/ui/widgets/shared/custom_popup_menu.dart'; diff --git a/lib/ui/views/installer/installer_viewmodel.dart b/lib/ui/views/installer/installer_viewmodel.dart index 10a90a174c..70b51347e3 100644 --- a/lib/ui/views/installer/installer_viewmodel.dart +++ b/lib/ui/views/installer/installer_viewmodel.dart @@ -11,7 +11,7 @@ import 'package:revanced_manager/services/manager_api.dart'; import 'package:revanced_manager/services/patcher_api.dart'; import 'package:revanced_manager/services/toast.dart'; import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart'; -import 'package:revanced_manager/ui/widgets/installerView/custom_material_button.dart'; +import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart'; import 'package:stacked/stacked.dart'; import 'package:wakelock/wakelock.dart'; diff --git a/lib/ui/views/patcher/patcher_viewmodel.dart b/lib/ui/views/patcher/patcher_viewmodel.dart index a1a5e4a49c..9052e08430 100644 --- a/lib/ui/views/patcher/patcher_viewmodel.dart +++ b/lib/ui/views/patcher/patcher_viewmodel.dart @@ -7,7 +7,7 @@ import 'package:revanced_manager/app/app.router.dart'; import 'package:revanced_manager/models/patch.dart'; import 'package:revanced_manager/models/patched_application.dart'; import 'package:revanced_manager/services/patcher_api.dart'; -import 'package:revanced_manager/ui/widgets/installerView/custom_material_button.dart'; +import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart'; import 'package:stacked/stacked.dart'; import 'package:stacked_services/stacked_services.dart'; diff --git a/lib/ui/views/settings/settings_viewmodel.dart b/lib/ui/views/settings/settings_viewmodel.dart index be9b9c56bf..8a22036fca 100644 --- a/lib/ui/views/settings/settings_viewmodel.dart +++ b/lib/ui/views/settings/settings_viewmodel.dart @@ -10,7 +10,7 @@ import 'package:path_provider/path_provider.dart'; import 'package:revanced_manager/app/app.locator.dart'; import 'package:revanced_manager/app/app.router.dart'; import 'package:revanced_manager/services/manager_api.dart'; -import 'package:revanced_manager/ui/widgets/installerView/custom_material_button.dart'; +import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart'; import 'package:revanced_manager/ui/widgets/settingsView/custom_text_field.dart'; import 'package:share_extend/share_extend.dart'; import 'package:stacked/stacked.dart'; diff --git a/lib/ui/widgets/appInfoView/app_info_viewmodel.dart b/lib/ui/widgets/appInfoView/app_info_viewmodel.dart index a9533104b8..880acfe746 100644 --- a/lib/ui/widgets/appInfoView/app_info_viewmodel.dart +++ b/lib/ui/widgets/appInfoView/app_info_viewmodel.dart @@ -11,7 +11,7 @@ import 'package:revanced_manager/services/root_api.dart'; import 'package:revanced_manager/ui/views/home/home_viewmodel.dart'; import 'package:revanced_manager/ui/views/navigation/navigation_viewmodel.dart'; import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart'; -import 'package:revanced_manager/ui/widgets/installerView/custom_material_button.dart'; +import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart'; import 'package:revanced_manager/utils/string.dart'; import 'package:stacked/stacked.dart'; diff --git a/lib/ui/widgets/homeView/latest_commit_card.dart b/lib/ui/widgets/homeView/latest_commit_card.dart index 41a1afd934..0f95625abe 100644 --- a/lib/ui/widgets/homeView/latest_commit_card.dart +++ b/lib/ui/widgets/homeView/latest_commit_card.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_i18n/flutter_i18n.dart'; import 'package:revanced_manager/app/app.locator.dart'; import 'package:revanced_manager/ui/views/home/home_viewmodel.dart'; -import 'package:revanced_manager/ui/widgets/installerView/custom_material_button.dart'; +import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart'; import 'package:revanced_manager/ui/widgets/shared/custom_card.dart'; class LatestCommitCard extends StatefulWidget { diff --git a/lib/ui/widgets/installerView/custom_material_button.dart b/lib/ui/widgets/installerView/custom_material_button.dart deleted file mode 100644 index b8b0690e77..0000000000 --- a/lib/ui/widgets/installerView/custom_material_button.dart +++ /dev/null @@ -1,49 +0,0 @@ -import 'package:flutter/material.dart'; - -class CustomMaterialButton extends StatelessWidget { - final Widget label; - final bool isFilled; - final bool isExpanded; - final Function()? onPressed; - - const CustomMaterialButton({ - Key? key, - required this.label, - this.isFilled = true, - this.isExpanded = false, - required this.onPressed, - }) : super(key: key); - - @override - Widget build(BuildContext context) { - return TextButton( - style: ButtonStyle( - padding: MaterialStateProperty.all( - isExpanded - ? const EdgeInsets.symmetric(horizontal: 24, vertical: 12) - : const EdgeInsets.symmetric(horizontal: 20, vertical: 12), - ), - shape: MaterialStateProperty.all( - StadiumBorder( - side: isFilled - ? BorderSide.none - : BorderSide( - width: 1, - color: Theme.of(context).colorScheme.primary, - ), - ), - ), - backgroundColor: MaterialStateProperty.all( - isFilled ? Theme.of(context).colorScheme.primary : Colors.transparent, - ), - foregroundColor: MaterialStateProperty.all( - isFilled - ? Theme.of(context).colorScheme.surface - : Theme.of(context).colorScheme.primary, - ), - ), - onPressed: onPressed, - child: label, - ); - } -} diff --git a/lib/ui/widgets/patchesSelectorView/patch_item.dart b/lib/ui/widgets/patchesSelectorView/patch_item.dart index 84dd1b133d..29585090aa 100644 --- a/lib/ui/widgets/patchesSelectorView/patch_item.dart +++ b/lib/ui/widgets/patchesSelectorView/patch_item.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_i18n/flutter_i18n.dart'; -import 'package:revanced_manager/ui/widgets/installerView/custom_material_button.dart'; +import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart'; import 'package:revanced_manager/ui/widgets/shared/custom_card.dart'; // ignore: must_be_immutable diff --git a/lib/ui/widgets/shared/application_item.dart b/lib/ui/widgets/shared/application_item.dart index d59faec691..16881623ea 100644 --- a/lib/ui/widgets/shared/application_item.dart +++ b/lib/ui/widgets/shared/application_item.dart @@ -1,7 +1,7 @@ import 'dart:typed_data'; import 'package:flutter/material.dart'; import 'package:flutter_i18n/flutter_i18n.dart'; -import 'package:revanced_manager/ui/widgets/installerView/custom_material_button.dart'; +import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart'; import 'package:revanced_manager/ui/widgets/shared/custom_card.dart'; import 'package:expandable/expandable.dart'; import 'package:timeago/timeago.dart'; diff --git a/lib/ui/widgets/shared/custom_material_button.dart b/lib/ui/widgets/shared/custom_material_button.dart new file mode 100644 index 0000000000..db1a3078e6 --- /dev/null +++ b/lib/ui/widgets/shared/custom_material_button.dart @@ -0,0 +1,129 @@ +import 'package:flutter/material.dart'; + +class CustomMaterialButton extends StatelessWidget { + final Widget label; + final bool isFilled; + final bool isExpanded; + final Function()? onPressed; + + const CustomMaterialButton({ + Key? key, + required this.label, + this.isFilled = true, + this.isExpanded = false, + required this.onPressed, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + return TextButton( + style: ButtonStyle( + padding: MaterialStateProperty.all( + isExpanded + ? const EdgeInsets.symmetric(horizontal: 24, vertical: 12) + : const EdgeInsets.symmetric(horizontal: 20, vertical: 12), + ), + shape: MaterialStateProperty.all( + StadiumBorder( + side: isFilled + ? BorderSide.none + : BorderSide( + width: 1, + color: Theme.of(context).colorScheme.primary, + ), + ), + ), + backgroundColor: MaterialStateProperty.all( + isFilled ? Theme.of(context).colorScheme.primary : Colors.transparent, + ), + foregroundColor: MaterialStateProperty.all( + isFilled + ? Theme.of(context).colorScheme.surface + : Theme.of(context).colorScheme.primary, + ), + ), + onPressed: onPressed, + child: label, + ); + } +} + +class TimerButton extends StatefulWidget { + Widget label; + bool isFilled; + int seconds; + final bool isRunning; + final Function()? onTimerEnd; + + TimerButton({ + Key? key, + required this.seconds, + required this.isRunning, + required this.onTimerEnd, + this.label = const Text(''), + this.isFilled = true, + }) : super(key: key); + + @override + State createState() => _TimerButtonState(); +} + +class _TimerButtonState extends State { + void timer(int seconds) { + Future.delayed(const Duration(seconds: 1), () { + if (seconds > 0) { + setState(() { + seconds--; + }); + timer(seconds); + } else { + widget.onTimerEnd!(); + } + }); + } + + @override + void initState() { + //decrement seconds + if (widget.isRunning) { + timer(widget.seconds); + } + super.initState(); + } + + @override + Widget build(BuildContext build) { + return TextButton( + style: ButtonStyle( + shape: MaterialStateProperty.all( + StadiumBorder( + side: widget.isFilled + ? BorderSide.none + : BorderSide( + width: 1, + color: Theme.of(context).colorScheme.primary, + ), + ), + ), + backgroundColor: MaterialStateProperty.all( + widget.isFilled + ? Theme.of(context).colorScheme.primary + : Colors.transparent, + ), + foregroundColor: MaterialStateProperty.all( + widget.isFilled + ? Theme.of(context).colorScheme.surface + : Theme.of(context).colorScheme.primary, + ), + ), + onPressed: widget.isRunning ? null : widget.onTimerEnd, + child: Text( + widget.isRunning ? '${widget.seconds}' : 'Install', + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w600, + ), + ), + ); + } +}