Skip to content

Commit

Permalink
feat(installer): redesign utility options (#1062)
Browse files Browse the repository at this point in the history
Co-authored-by: Ushie <ushiekane@gmail.com>
  • Loading branch information
validcube and Ushie committed Aug 10, 2023
1 parent 1442916 commit b77d46b
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 131 deletions.
7 changes: 4 additions & 3 deletions assets/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@
},
"installerView": {
"widgetTitle": "Installer",
"installType": "Select install type",
"installTypeDescription": "Select the installation type to proceed with.",
"installButton": "Install",
"installRootButton": "Install as Root",
"pressBackAgain": "Press back again to cancel",
Expand All @@ -149,9 +151,8 @@
"notificationTitle": "ReVanced Manager is patching",
"notificationText": "Tap to return to the installer",

"shareApkMenuOption": "Share APK",
"exportApkMenuOption": "Export APK",
"shareLogMenuOption": "Share log",
"exportApkButtonTooltip": "Export patched APK",
"exportLogButtonTooltip": "Export log",

"installErrorDialogTitle": "Error",
"installErrorDialogText1": "Root install is not possible with the current patches selection.\nRepatch your app or choose non-root install.",
Expand Down
13 changes: 9 additions & 4 deletions lib/services/patcher_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class PatcherAPI {
return newName;
}

Future<void> sharePatcherLog(String logs) async {
Future<void> exportPatcherLog(String logs) async {
final Directory appCache = await getTemporaryDirectory();
final Directory logDir = Directory('${appCache.path}/logs');
logDir.createSync();
Expand All @@ -293,10 +293,15 @@ class PatcherAPI {
.replaceAll(':', '')
.replaceAll('T', '')
.replaceAll('.', '');
final File log =
File('${logDir.path}/revanced-manager_patcher_$dateTime.log');
final String fileName = 'revanced-manager_patcher_$dateTime.log';
final File log = File('${logDir.path}/$fileName');
log.writeAsStringSync(logs);
ShareExtend.share(log.path, 'file');
CRFileSaver.saveFileWithDialog(
SaveFileDialogParams(
sourceFilePath: log.path,
destinationFileName: fileName,
),
);
}

String getSuggestedVersion(String packageName) {
Expand Down
140 changes: 34 additions & 106 deletions lib/ui/views/installer/installer_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import 'package:google_fonts/google_fonts.dart';
import 'package:revanced_manager/ui/views/installer/installer_viewmodel.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_material_button.dart';
import 'package:revanced_manager/ui/widgets/shared/custom_popup_menu.dart';
import 'package:revanced_manager/ui/widgets/shared/custom_sliver_app_bar.dart';
import 'package:stacked/stacked.dart';

Expand All @@ -22,6 +20,40 @@ class InstallerView extends StatelessWidget {
top: false,
bottom: false,
child: Scaffold(
floatingActionButton: Visibility(
visible: !model.isPatching,
child: FloatingActionButton.extended(
label: I18nText('installerView.installButton'),
icon: const Icon(Icons.file_download_outlined),
onPressed: () => model.installTypeDialog(context),
),
),
floatingActionButtonLocation:
FloatingActionButtonLocation.endContained,
bottomNavigationBar: Visibility(
visible: !model.isPatching,
child: BottomAppBar(
child: Row(
children: <Widget>[
Visibility(
visible: !model.hasErrors,
child: IconButton.filledTonal(
tooltip: FlutterI18n.translate(
context, 'installerView.exportApkButtonTooltip'),

Check warning on line 42 in lib/ui/views/installer/installer_view.dart

View workflow job for this annotation

GitHub Actions / Static analysis & format check

Missing a required trailing comma.. See https://dart.dev/tools/diagnostic-messages#require_trailing_commas

Check warning on line 42 in lib/ui/views/installer/installer_view.dart

View workflow job for this annotation

GitHub Actions / Static analysis & format check

Missing a required trailing comma.. See https://dart.dev/tools/diagnostic-messages#require_trailing_commas
icon: const Icon(Icons.save),
onPressed: () => model.onButtonPressed(0),
),
),
IconButton.filledTonal(
tooltip: FlutterI18n.translate(
context, 'installerView.exportLogButtonTooltip'),

Check warning on line 49 in lib/ui/views/installer/installer_view.dart

View workflow job for this annotation

GitHub Actions / Static analysis & format check

Missing a required trailing comma.. See https://dart.dev/tools/diagnostic-messages#require_trailing_commas

Check warning on line 49 in lib/ui/views/installer/installer_view.dart

View workflow job for this annotation

GitHub Actions / Static analysis & format check

Missing a required trailing comma.. See https://dart.dev/tools/diagnostic-messages#require_trailing_commas
icon: const Icon(Icons.post_add),
onPressed: () => model.onButtonPressed(1),
),
],
),
),
),
body: CustomScrollView(
controller: model.scrollController,
slivers: <Widget>[
Expand All @@ -35,44 +67,6 @@ class InstallerView extends StatelessWidget {
overflow: TextOverflow.ellipsis,
),
onBackButtonPressed: () => model.onWillPop(context),
actions: <Widget>[
Visibility(
visible: !model.isPatching,
child: CustomPopupMenu(
onSelected: (value) => model.onMenuSelection(value),
children: {
if (!model.hasErrors)
0: I18nText(
'installerView.shareApkMenuOption',
child: const Text(
'',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
),
1: I18nText(
'installerView.exportApkMenuOption',
child: const Text(
'',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
),
2: I18nText(
'installerView.shareLogMenuOption',
child: const Text(
'',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
),
},
),
),
],
bottom: PreferredSize(
preferredSize: const Size(double.infinity, 1.0),
child: GradientProgressIndicator(progress: model.progress),
Expand All @@ -96,72 +90,6 @@ class InstallerView extends StatelessWidget {
),
),
),
SliverFillRemaining(
hasScrollBody: false,
child: Align(
alignment: Alignment.bottomCenter,
child: Visibility(
visible: !model.isPatching && !model.hasErrors,
child: Padding(
padding: const EdgeInsets.all(20.0).copyWith(top: 0.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Visibility(
visible: model.isInstalled,
child: CustomMaterialButton(
label: I18nText('installerView.openButton'),
isExpanded: true,
onPressed: () {
model.openApp();
model.cleanPatcher();
Navigator.of(context).pop();
},
),
),
Visibility(
visible: !model.isInstalled && model.isRooted,
child: CustomMaterialButton(
isFilled: false,
label:
I18nText('installerView.installRootButton'),
isExpanded: true,
onPressed: () => model.installResult(
context,
true,
),
),
),
Visibility(
visible: !model.isInstalled,
child: const SizedBox(
width: 16,
),
),
Visibility(
visible: !model.isInstalled,
child: CustomMaterialButton(
label: I18nText('installerView.installButton'),
isExpanded: true,
onPressed: () => model.installResult(
context,
false,
),
),
),
],
),
),
),
),
),
SliverFillRemaining(
hasScrollBody: false,
child: SizedBox(
height: MediaQuery.of(context).viewPadding.bottom,
),
),
],
),
),
Expand Down
103 changes: 85 additions & 18 deletions lib/ui/views/installer/installer_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,86 @@ class InstallerViewModel extends BaseViewModel {
}
}

Future<void> installTypeDialog(BuildContext context) async {
final ValueNotifier<int> installType = ValueNotifier(0);
if (isRooted) {
await showDialog(
context: context,
barrierDismissible: false,
builder: (context) => AlertDialog(
title: I18nText(
'installerView.installType',
),
icon: const Icon(Icons.file_download_outlined),
contentPadding: const EdgeInsets.symmetric(vertical: 16),
content: ValueListenableBuilder(
valueListenable: installType,
builder: (context, value, child) {
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.symmetric(
horizontal: 20, vertical: 10),

Check warning on line 193 in lib/ui/views/installer/installer_viewmodel.dart

View workflow job for this annotation

GitHub Actions / Static analysis & format check

Missing a required trailing comma.. See https://dart.dev/tools/diagnostic-messages#require_trailing_commas

Check warning on line 193 in lib/ui/views/installer/installer_viewmodel.dart

View workflow job for this annotation

GitHub Actions / Static analysis & format check

Missing a required trailing comma.. See https://dart.dev/tools/diagnostic-messages#require_trailing_commas
child: I18nText(
'installerView.installTypeDescription',
child: Text(
'',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
color: Theme.of(context).colorScheme.secondary,
),
),
),
),
RadioListTile(
title: const Text('Non-root'),
subtitle: const Text('Recommended'),
contentPadding: const EdgeInsets.symmetric(horizontal: 10),
value: 0,
groupValue: value,
onChanged: (selected) {
installType.value = selected!;
},
),
RadioListTile(
title: const Text('Root'),
contentPadding: const EdgeInsets.symmetric(horizontal: 10),
value: 1,
groupValue: value,
onChanged: (selected) {
installType.value = selected!;
},
),
],
);
},
),
actions: [
CustomMaterialButton(
label: I18nText('cancelButton'),
isFilled: false,
onPressed: () {
Navigator.of(context).pop();
},
),
CustomMaterialButton(
label: I18nText('installerView.installButton'),
onPressed: () {
Navigator.of(context).pop();
installResult(context, installType.value == 1);
},
)
],
),
);
} else {
installResult(context, false);
}
}

Future<void> stopPatcher() async {
try {
isCanceled = true;
Expand Down Expand Up @@ -253,18 +333,8 @@ class InstallerViewModel extends BaseViewModel {
}
}

void shareResult() {
try {
_patcherAPI.sharePatchedFile(_app.name, _app.version);
} on Exception catch (e) {
if (kDebugMode) {
print(e);
}
}
}

void shareLog() {
_patcherAPI.sharePatcherLog(logs);
void exportLog() {
_patcherAPI.exportPatcherLog(logs);
}

Future<void> cleanPatcher() async {
Expand All @@ -284,16 +354,13 @@ class InstallerViewModel extends BaseViewModel {
DeviceApps.openApp(_app.packageName);
}

void onMenuSelection(int value) {
void onButtonPressed(int value) {
switch (value) {
case 0:
shareResult();
break;
case 1:
exportResult();
break;
case 2:
shareLog();
case 1:
exportLog();
break;
}
}
Expand Down

0 comments on commit b77d46b

Please sign in to comment.