Skip to content

Commit

Permalink
feat: dialogs correctly follows Material 3 specifications (ReVanced#1560
Browse files Browse the repository at this point in the history
)

Signed-off-by: validcube <pun.butrach@gmail.com>
  • Loading branch information
validcube authored Dec 22, 2023
1 parent c06d15d commit f8d086a
Show file tree
Hide file tree
Showing 21 changed files with 135 additions and 333 deletions.
9 changes: 4 additions & 5 deletions lib/services/manager_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import 'package:revanced_manager/services/github_api.dart';
import 'package:revanced_manager/services/patcher_api.dart';
import 'package:revanced_manager/services/revanced_api.dart';
import 'package:revanced_manager/services/root_api.dart';
import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart';
import 'package:revanced_manager/utils/check_for_supported_patch.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:timeago/timeago.dart';
Expand Down Expand Up @@ -62,7 +61,8 @@ class ManagerAPI {
Future<void> initialize() async {
_prefs = await SharedPreferences.getInstance();
isRooted = await _rootAPI.isRooted();
isDynamicThemeAvailable = (await getSdkVersion()) >= 31; // ANDROID_12_SDK_VERSION = 31
isDynamicThemeAvailable =
(await getSdkVersion()) >= 31; // ANDROID_12_SDK_VERSION = 31
storedPatchesFile =
(await getApplicationDocumentsDirectory()).path + storedPatchesFile;
}
Expand Down Expand Up @@ -585,7 +585,6 @@ class ManagerAPI {
builder: (context) => WillPopScope(
onWillPop: () async => false,
child: AlertDialog(
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
title: I18nText('warning'),
content: ValueListenableBuilder(
valueListenable: noShow,
Expand Down Expand Up @@ -620,12 +619,12 @@ class ManagerAPI {
},
),
actions: [
CustomMaterialButton(
label: I18nText('okButton'),
FilledButton(
onPressed: () {
setPatchesChangeWarning(noShow.value);
Navigator.of(context).pop();
},
child: I18nText('okButton'),
),
],
),
Expand Down
18 changes: 8 additions & 10 deletions lib/ui/views/app_selector/app_selector_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ 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/shared/custom_material_button.dart';
import 'package:revanced_manager/utils/check_for_supported_patch.dart';
import 'package:stacked/stacked.dart';

Expand Down Expand Up @@ -105,7 +104,8 @@ class AppSelectorViewModel extends BaseViewModel {
]) async {
final String suggestedVersion =
getSuggestedVersion(application.packageName);
if (application.versionName != suggestedVersion && suggestedVersion.isNotEmpty) {
if (application.versionName != suggestedVersion &&
suggestedVersion.isNotEmpty) {
_managerAPI.suggestedAppVersionSelected = false;
if (_managerAPI.isRequireSuggestedAppVersionEnabled() &&
context.mounted) {
Expand Down Expand Up @@ -168,7 +168,6 @@ class AppSelectorViewModel extends BaseViewModel {
return showDialog(
context: context,
builder: (context) => AlertDialog(
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
title: I18nText('warning'),
content: I18nText(
'appSelectorView.requireSuggestedAppVersionDialogText',
Expand All @@ -185,9 +184,9 @@ class AppSelectorViewModel extends BaseViewModel {
),
),
actions: [
CustomMaterialButton(
label: I18nText('okButton'),
FilledButton(
onPressed: () => Navigator.of(context).pop(),
child: I18nText('okButton'),
),
],
),
Expand Down Expand Up @@ -232,12 +231,12 @@ class AppSelectorViewModel extends BaseViewModel {
),
),
const SizedBox(height: 30),
CustomMaterialButton(
FilledButton(
onPressed: () async {
Navigator.pop(innerContext);
await selectAppFromStorage(context);
},
label: Row(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.sd_card),
Expand All @@ -247,12 +246,11 @@ class AppSelectorViewModel extends BaseViewModel {
),
),
const SizedBox(height: 10),
CustomMaterialButton(
isFilled: false,
TextButton(
onPressed: () {
Navigator.pop(innerContext);
},
label: Row(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(width: 10),
Expand Down
27 changes: 12 additions & 15 deletions lib/ui/views/home/home_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ 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/homeView/update_confirmation_dialog.dart';
import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart';
import 'package:stacked/stacked.dart';
import 'package:stacked_services/stacked_services.dart';

Expand Down Expand Up @@ -65,8 +64,8 @@ class HomeViewModel extends BaseViewModel {
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.requestNotificationsPermission();
final bool isConnected = await Connectivity().checkConnectivity() !=
ConnectivityResult.none;
final bool isConnected =
await Connectivity().checkConnectivity() != ConnectivityResult.none;
if (!isConnected) {
_toast.showBottom('homeView.noConnection');
}
Expand Down Expand Up @@ -223,21 +222,20 @@ class HomeViewModel extends BaseViewModel {
},
),
actions: [
CustomMaterialButton(
isFilled: false,
TextButton(
onPressed: () async {
await _managerAPI.setPatchesConsent(false);
SystemNavigator.pop();
},
label: I18nText('quitButton'),
child: I18nText('quitButton'),
),
CustomMaterialButton(
FilledButton(
onPressed: () async {
await _managerAPI.setPatchesConsent(true);
await _managerAPI.setPatchesAutoUpdate(autoUpdate.value);
Navigator.of(context).pop();
},
label: I18nText('okButton'),
child: I18nText('okButton'),
),
],
),
Expand Down Expand Up @@ -324,12 +322,12 @@ class HomeViewModel extends BaseViewModel {
const SizedBox(height: 16.0),
Align(
alignment: Alignment.centerRight,
child: CustomMaterialButton(
label: I18nText('cancelButton'),
child: FilledButton(
onPressed: () {
_revancedAPI.disposeManagerUpdateProgress();
Navigator.of(context).pop();
},
child: I18nText('cancelButton'),
),
),
],
Expand All @@ -355,24 +353,23 @@ class HomeViewModel extends BaseViewModel {
children: [
Align(
alignment: Alignment.centerRight,
child: CustomMaterialButton(
isFilled: false,
label: I18nText('cancelButton'),
child: TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: I18nText('cancelButton'),
),
),
const SizedBox(width: 8.0),
Align(
alignment: Alignment.centerRight,
child: CustomMaterialButton(
label: I18nText('updateButton'),
child: FilledButton(
onPressed: () async {
await InstallPlugin.installApk(
downloadedApk!.path,
);
},
child: I18nText('updateButton'),
),
),
],
Expand Down
21 changes: 8 additions & 13 deletions lib/ui/views/installer/installer_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import 'package:revanced_manager/services/patcher_api.dart';
import 'package:revanced_manager/services/root_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/shared/custom_material_button.dart';
import 'package:revanced_manager/utils/about_info.dart';
import 'package:screenshot_callback/screenshot_callback.dart';
import 'package:stacked/stacked.dart';
Expand Down Expand Up @@ -287,26 +286,24 @@ class InstallerViewModel extends BaseViewModel {
title: I18nText(
'warning',
),
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
icon: const Icon(Icons.warning),
content: SingleChildScrollView(
child: I18nText('installerView.screenshotDetected'),
),
actions: <Widget>[
CustomMaterialButton(
isFilled: false,
label: I18nText('noButton'),
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: I18nText('noButton'),
),
CustomMaterialButton(
label: I18nText('yesButton'),
FilledButton(
onPressed: () {
copyLogs();
showPopupScreenshotWarning = true;
Navigator.of(context).pop();
},
child: I18nText('yesButton'),
),
],
),
Expand All @@ -323,7 +320,6 @@ class InstallerViewModel extends BaseViewModel {
title: I18nText(
'installerView.installType',
),
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
icon: const Icon(Icons.file_download_outlined),
contentPadding: const EdgeInsets.symmetric(vertical: 16),
content: SingleChildScrollView(
Expand Down Expand Up @@ -377,19 +373,18 @@ class InstallerViewModel extends BaseViewModel {
),
),
actions: [
CustomMaterialButton(
label: I18nText('cancelButton'),
isFilled: false,
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: I18nText('cancelButton'),
),
CustomMaterialButton(
label: I18nText('installerView.installButton'),
FilledButton(
onPressed: () {
Navigator.of(context).pop();
installResult(context, installType.value == 1);
},
child: I18nText('installerView.installButton'),
),
],
),
Expand Down
8 changes: 3 additions & 5 deletions lib/ui/views/patch_options/patch_options_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:google_fonts/google_fonts.dart';
import 'package:revanced_manager/models/patch.dart';
import 'package:revanced_manager/ui/views/patch_options/patch_options_viewmodel.dart';
import 'package:revanced_manager/ui/widgets/patchesSelectorView/patch_options_fields.dart';
import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart';
import 'package:stacked/stacked.dart';

class PatchOptionsView extends StatelessWidget {
Expand Down Expand Up @@ -82,8 +81,7 @@ class PatchOptionsView extends StatelessWidget {
model.modifyOptions(value, option);
},
)
else if (option.valueType ==
'StringArray' ||
else if (option.valueType == 'StringArray' ||
option.valueType == 'IntArray' ||
option.valueType == 'LongArray')
IntStringLongListPatchOption(
Expand All @@ -104,11 +102,11 @@ class PatchOptionsView extends StatelessWidget {
const SizedBox(
height: 8,
),
CustomMaterialButton(
FilledButton(
onPressed: () {
model.showAddOptionDialog(context);
},
label: Row(
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(Icons.add),
Expand Down
30 changes: 11 additions & 19 deletions lib/ui/views/patch_options/patch_options_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:revanced_manager/services/manager_api.dart';
import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart';
import 'package:revanced_manager/ui/views/patches_selector/patches_selector_viewmodel.dart';
import 'package:revanced_manager/ui/widgets/shared/custom_card.dart';
import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart';
import 'package:stacked/stacked.dart';

class PatchOptionsViewModel extends BaseViewModel {
Expand All @@ -32,13 +31,11 @@ class PatchOptionsViewModel extends BaseViewModel {
if (savedOptions.isNotEmpty) {
visibleOptions = [
...savedOptions,
...options
.where(
(option) =>
option.required &&
!savedOptions.any((sOption) => sOption.key == option.key),
)
,
...options.where(
(option) =>
option.required &&
!savedOptions.any((sOption) => sOption.key == option.key),
),
];
} else {
visibleOptions = [
Expand Down Expand Up @@ -136,7 +133,6 @@ class PatchOptionsViewModel extends BaseViewModel {
await showDialog(
context: context,
builder: (context) => AlertDialog(
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
title: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
Expand All @@ -154,11 +150,11 @@ class PatchOptionsViewModel extends BaseViewModel {
],
),
actions: [
CustomMaterialButton(
label: I18nText('cancelButton'),
FilledButton(
onPressed: () {
Navigator.of(context).pop();
},
child: I18nText('cancelButton'),
),
],
contentPadding: const EdgeInsets.all(8),
Expand Down Expand Up @@ -227,14 +223,9 @@ Future<void> showRequiredOptionNullDialog(
await showDialog(
context: context,
builder: (context) => AlertDialog(
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
title: I18nText('notice'),
actions: [
CustomMaterialButton(
isFilled: false,
label: I18nText(
'patchOptionsView.deselectPatch',
),
TextButton(
onPressed: () async {
if (managerAPI.isPatchesChangeEnabled()) {
locator<PatcherViewModel>()
Expand All @@ -256,12 +247,13 @@ Future<void> showRequiredOptionNullDialog(
PatchesSelectorViewModel().showPatchesChangeDialog(context);
}
},
child: I18nText('patchOptionsView.deselectPatch'),
),
CustomMaterialButton(
label: I18nText('okButton'),
FilledButton(
onPressed: () {
Navigator.of(context).pop();
},
child: I18nText('okButton'),
),
],
content: I18nText(
Expand Down
Loading

0 comments on commit f8d086a

Please sign in to comment.