refactor: apply suggestions from analyser

Signed-off-by: validcube <pun.butrach@gmail.com>
This commit is contained in:
validcube 2023-12-23 10:47:12 +07:00
parent c56c445fb7
commit a0b673c138
No known key found for this signature in database
GPG key ID: DBA94253E1D3F267
18 changed files with 120 additions and 79 deletions

View file

@ -75,9 +75,8 @@ class Option {
if (json['valueType'] == null) {
final type = json['optionClassType'];
if (type is String) {
json['valueType'] = type
.replaceAll('PatchOption', '')
.replaceAll('List', 'Array');
json['valueType'] =
type.replaceAll('PatchOption', '').replaceAll('List', 'Array');
json['optionClassType'] = null;
}

View file

@ -19,7 +19,8 @@ class DownloadManager {
);
Future<void> initialize() async {
_userAgent = 'ReVanced-Manager/${await _managerAPI.getCurrentManagerVersion()}';
_userAgent =
'ReVanced-Manager/${await _managerAPI.getCurrentManagerVersion()}';
}
Dio initDio(String url) {

View file

@ -14,7 +14,6 @@ import 'package:revanced_manager/models/patch.dart';
import 'package:revanced_manager/models/patched_application.dart';
import 'package:revanced_manager/services/manager_api.dart';
import 'package:revanced_manager/services/root_api.dart';
import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart';
import 'package:share_plus/share_plus.dart';
@lazySingleton

View file

@ -93,7 +93,8 @@ class RootAPI {
Future<void> unmount(String packageName) async {
await Root.exec(
cmd: 'grep $packageName /proc/mounts | while read -r line; do echo \$line | cut -d " " -f 2 | sed "s/apk.*/apk/" | xargs -r umount -l; done',
cmd:
'grep $packageName /proc/mounts | while read -r line; do echo \$line | cut -d " " -f 2 | sed "s/apk.*/apk/" | xargs -r umount -l; done',
);
await Root.exec(
cmd: 'rm -rf "$_revancedDirPath/$packageName"',
@ -188,12 +189,15 @@ class RootAPI {
);
}
Future<void> mountApk(String packageName,) async {
Future<void> mountApk(
String packageName,
) async {
await Root.exec(
cmd: '''
grep $packageName /proc/mounts | while read -r line; do echo \$line | cut -d " " -f 2 | sed "s/apk.*/apk/" | xargs -r umount -l; done
.$_serviceDDirPath/$packageName.sh
'''.trim(),
'''
.trim(),
);
}

View file

@ -25,7 +25,8 @@ class DynamicThemeBuilder extends StatefulWidget {
State<DynamicThemeBuilder> createState() => _DynamicThemeBuilderState();
}
class _DynamicThemeBuilderState extends State<DynamicThemeBuilder> with WidgetsBindingObserver {
class _DynamicThemeBuilderState extends State<DynamicThemeBuilder>
with WidgetsBindingObserver {
Brightness brightness = PlatformDispatcher.instance.platformBrightness;
final ManagerAPI _managerAPI = locator<ManagerAPI>();
@ -43,8 +44,9 @@ class _DynamicThemeBuilderState extends State<DynamicThemeBuilder> with WidgetsB
if (_managerAPI.getThemeMode() < 2) {
SystemChrome.setSystemUIOverlayStyle(
SystemUiOverlayStyle(
systemNavigationBarIconBrightness:
brightness == Brightness.light ? Brightness.dark : Brightness.light,
systemNavigationBarIconBrightness: brightness == Brightness.light
? Brightness.dark
: Brightness.light,
),
);
}
@ -83,24 +85,31 @@ class _DynamicThemeBuilderState extends State<DynamicThemeBuilder> with WidgetsB
return DynamicTheme(
themeCollection: ThemeCollection(
themes: {
0: brightness == Brightness.light ? lightCustomTheme : darkCustomTheme,
1: brightness == Brightness.light ? lightDynamicTheme : darkDynamicTheme,
0: brightness == Brightness.light
? lightCustomTheme
: darkCustomTheme,
1: brightness == Brightness.light
? lightDynamicTheme
: darkDynamicTheme,
2: lightCustomTheme,
3: lightDynamicTheme,
4: darkCustomTheme,
5: darkDynamicTheme,
},
fallbackTheme: PlatformDispatcher.instance.platformBrightness == Brightness.light ? lightCustomTheme : darkCustomTheme,
fallbackTheme: PlatformDispatcher.instance.platformBrightness ==
Brightness.light
? lightCustomTheme
: darkCustomTheme,
),
builder: (context, theme) => MaterialApp(
debugShowCheckedModeBanner: false,
title: widget.title,
navigatorKey: StackedService.navigatorKey,
onGenerateRoute: StackedRouter().onGenerateRoute,
theme: theme,
home: widget.home,
localizationsDelegates: widget.localizationsDelegates,
),
debugShowCheckedModeBanner: false,
title: widget.title,
navigatorKey: StackedService.navigatorKey,
onGenerateRoute: StackedRouter().onGenerateRoute,
theme: theme,
home: widget.home,
localizationsDelegates: widget.localizationsDelegates,
),
);
},
);

View file

@ -40,8 +40,8 @@ class _AppSelectorViewState extends State<AppSelectorView> {
),
titleTextStyle: TextStyle(
fontSize: 22.0,
color: Theme.of(context).textTheme.titleLarge!.color,
),
color: Theme.of(context).textTheme.titleLarge!.color,
),
leading: IconButton(
icon: Icon(
Icons.arrow_back,
@ -94,9 +94,7 @@ class _AppSelectorViewState extends State<AppSelectorView> {
),
child: Column(
children: [
...model
.getFilteredApps(_query)
.map(
...model.getFilteredApps(_query).map(
(app) => InstalledAppItem(
name: app.appName,
pkgName: app.packageName,
@ -117,11 +115,8 @@ class _AppSelectorViewState extends State<AppSelectorView> {
packageName: app.packageName,
),
),
)
,
...model
.getFilteredAppsNames(_query)
.map(
),
...model.getFilteredAppsNames(_query).map(
(app) => NotInstalledAppItem(
name: app,
patchesCount: model.patchesCount(app),
@ -135,8 +130,7 @@ class _AppSelectorViewState extends State<AppSelectorView> {
packageName: app,
),
),
)
,
),
const SizedBox(height: 70.0),
],
),

View file

@ -83,7 +83,6 @@ class HomeViewModel extends BaseViewModel {
_managerAPI.reAssessSavedApps().then((_) => _getPatchedApps());
}
void navigateToAppInfo(PatchedApplication app) {
_navigationService.navigateTo(
Routes.appInfoView,
@ -366,7 +365,10 @@ class HomeViewModel extends BaseViewModel {
alignment: Alignment.centerRight,
child: FilledButton(
onPressed: () async {
await _patcherAPI.installApk(context, downloadedApk!.path);
await _patcherAPI.installApk(
context,
downloadedApk!.path,
);
},
child: I18nText('updateButton'),
),

View file

@ -183,7 +183,9 @@ class InstallerViewModel extends BaseViewModel {
final index = logLines.indexWhere((line) => line.endsWith(keyword));
if (newString != null && lineCount > 0) {
logLines.insert(
index, newString.replaceAll('{lineCount}', lineCount.toString()));
index,
newString.replaceAll('{lineCount}', lineCount.toString()),
);
}
logLines.removeWhere((lines) => lines.endsWith(keyword));
}
@ -203,11 +205,13 @@ class InstallerViewModel extends BaseViewModel {
return 'None';
}
return patches
.map((p) =>
p.name +
(p.options.isEmpty
? ''
: ' [${p.options.map((o) => '${o.title}: ${_getPatchOptionValue(p.name, o)}').join(", ")}]'))
.map(
(p) =>
p.name +
(p.options.isEmpty
? ''
: ' [${p.options.map((o) => '${o.title}: ${_getPatchOptionValue(p.name, o)}').join(", ")}]'),
)
.toList()
.join(', ');
}
@ -242,9 +246,11 @@ class InstallerViewModel extends BaseViewModel {
// Options changed
final patchesChanged = defaultPatches
.where((p) =>
_patches.contains(p) &&
p.options.any((o) => _getPatchOptionValue(p.name, o) != o.value))
.where(
(p) =>
_patches.contains(p) &&
p.options.any((o) => _getPatchOptionValue(p.name, o) != o.value),
)
.toList();
// Add Info
@ -453,9 +459,7 @@ class InstallerViewModel extends BaseViewModel {
update(
1.0,
'Installing...',
_app.isRooted
? 'Mounting patched app'
: 'Installing patched app',
_app.isRooted ? 'Mounting patched app' : 'Installing patched app',
);
}
final int response = await _patcherAPI.installPatchedFile(context, _app);

View file

@ -22,7 +22,7 @@ class PatcherView extends StatelessWidget {
child: FloatingActionButton.extended(
label: I18nText('patcherView.patchButton'),
icon: const Icon(Icons.build),
onPressed: () async{
onPressed: () async {
if (model.checkRequiredPatchOption(context)) {
final bool proceed = model.showRemovedPatchesDialog(context);
if (proceed && context.mounted) {

View file

@ -180,11 +180,16 @@ class _PatchesSelectorViewState extends State<PatchesSelectorView> {
),
],
),
if (model.getQueriedPatches(_query).any((patch) => model.isPatchNew(patch)))
if (model
.getQueriedPatches(_query)
.any((patch) => model.isPatchNew(patch)))
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
model.getPatchCategory(context, 'patchesSelectorView.newPatches'),
model.getPatchCategory(
context,
'patchesSelectorView.newPatches',
),
...model.getQueriedPatches(_query).map((patch) {
if (model.isPatchNew(patch)) {
return model.getPatchItem(context, patch);
@ -192,26 +197,40 @@ class _PatchesSelectorViewState extends State<PatchesSelectorView> {
return Container();
}
}),
if (model.getQueriedPatches(_query).any((patch) => !model.isPatchNew(patch) && patch.compatiblePackages.isNotEmpty))
model.getPatchCategory(context, 'patchesSelectorView.patches'),
if (model.getQueriedPatches(_query).any(
(patch) =>
!model.isPatchNew(patch) &&
patch.compatiblePackages.isNotEmpty,
))
model.getPatchCategory(
context,
'patchesSelectorView.patches',
),
],
),
...model.getQueriedPatches(_query).map(
(patch) {
if (patch.compatiblePackages.isNotEmpty && !model.isPatchNew(patch)) {
if (patch.compatiblePackages.isNotEmpty &&
!model.isPatchNew(patch)) {
return model.getPatchItem(context, patch);
} else {
return Container();
}
},
),
if (model.getQueriedPatches(_query).any((patch) => patch.compatiblePackages.isEmpty))
if (model
.getQueriedPatches(_query)
.any((patch) => patch.compatiblePackages.isEmpty))
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
model.getPatchCategory(context, 'patchesSelectorView.universalPatches'),
model.getPatchCategory(
context,
'patchesSelectorView.universalPatches',
),
...model.getQueriedPatches(_query).map((patch) {
if (patch.compatiblePackages.isEmpty && !model.isPatchNew(patch)) {
if (patch.compatiblePackages.isEmpty &&
!model.isPatchNew(patch)) {
return model.getPatchItem(context, patch);
} else {
return Container();

View file

@ -58,7 +58,8 @@ class PatchSelectorCard extends StatelessWidget {
String _getPatchesSelection() {
String text = '';
final List<Patch> selectedPatches = locator<PatcherViewModel>().selectedPatches;
final List<Patch> selectedPatches =
locator<PatcherViewModel>().selectedPatches;
selectedPatches.sort((a, b) => a.name.compareTo(b.name));
for (final Patch p in selectedPatches) {
text += '${p.getSimpleName()}\n';

View file

@ -400,7 +400,9 @@ class _TextFieldForPatchOptionState extends State<TextFieldForPatchOption> {
final bool isStringOption = widget.optionType.contains('String');
final bool isArrayOption = widget.optionType.contains('Array');
selectedKey ??= widget.selectedKey;
controller.text = !isStringOption && isArrayOption && selectedKey == '' &&
controller.text = !isStringOption &&
isArrayOption &&
selectedKey == '' &&
(widget.value != null && widget.value.toString().startsWith('['))
? ''
: widget.value ?? '';
@ -519,7 +521,8 @@ class _TextFieldForPatchOptionState extends State<TextFieldForPatchOption> {
}
break;
case 'patchOptionsView.selectFolder':
final DirectoryLocation? result = await FlutterFileDialog.pickDirectory();
final DirectoryLocation? result =
await FlutterFileDialog.pickDirectory();
if (result != null) {
controller.text = result.toString();
widget.onChanged(controller.text);

View file

@ -10,7 +10,6 @@ import 'package:revanced_manager/ui/widgets/settingsView/settings_section.dart';
import 'package:revanced_manager/ui/widgets/settingsView/settings_universal_patches.dart';
import 'package:revanced_manager/ui/widgets/settingsView/settings_version_compatibility_check.dart';
class SAdvancedSection extends StatelessWidget {
const SAdvancedSection({super.key});

View file

@ -6,7 +6,8 @@ class SEnablePatchesSelection extends StatefulWidget {
const SEnablePatchesSelection({super.key});
@override
State<SEnablePatchesSelection> createState() => _SEnablePatchesSelectionState();
State<SEnablePatchesSelection> createState() =>
_SEnablePatchesSelectionState();
}
final _settingsViewModel = SettingsViewModel();

View file

@ -6,12 +6,14 @@ class SRequireSuggestedAppVersion extends StatefulWidget {
const SRequireSuggestedAppVersion({super.key});
@override
State<SRequireSuggestedAppVersion> createState() => _SRequireSuggestedAppVersionState();
State<SRequireSuggestedAppVersion> createState() =>
_SRequireSuggestedAppVersionState();
}
final _settingsViewModel = SettingsViewModel();
class _SRequireSuggestedAppVersionState extends State<SRequireSuggestedAppVersion> {
class _SRequireSuggestedAppVersionState
extends State<SRequireSuggestedAppVersion> {
@override
Widget build(BuildContext context) {
return SwitchListTile(
@ -29,8 +31,11 @@ class _SRequireSuggestedAppVersionState extends State<SRequireSuggestedAppVersio
subtitle: I18nText('settingsView.requireSuggestedAppVersionHint'),
value: _settingsViewModel.isRequireSuggestedAppVersionEnabled(),
onChanged: (value) async {
await _settingsViewModel.showRequireSuggestedAppVersionDialog(context, value,);
setState(() {});
await _settingsViewModel.showRequireSuggestedAppVersionDialog(
context,
value,
);
setState(() {});
},
);
}

View file

@ -8,16 +8,14 @@ class SUniversalPatches extends StatefulWidget {
const SUniversalPatches({super.key});
@override
State<SUniversalPatches> createState() =>
_SUniversalPatchesState();
State<SUniversalPatches> createState() => _SUniversalPatchesState();
}
final _settingsViewModel = SettingsViewModel();
final _patchesSelectorViewModel = PatchesSelectorViewModel();
final _patcherViewModel = PatcherViewModel();
class _SUniversalPatchesState
extends State<SUniversalPatches> {
class _SUniversalPatchesState extends State<SUniversalPatches> {
@override
Widget build(BuildContext context) {
return SwitchListTile(

View file

@ -9,14 +9,16 @@ class SVersionCompatibilityCheck extends StatefulWidget {
const SVersionCompatibilityCheck({super.key});
@override
State<SVersionCompatibilityCheck> createState() => _SVersionCompatibilityCheckState();
State<SVersionCompatibilityCheck> createState() =>
_SVersionCompatibilityCheckState();
}
final _settingsViewModel = SettingsViewModel();
final _patchesSelectorViewModel = PatchesSelectorViewModel();
final _patcherViewModel = PatcherViewModel();
class _SVersionCompatibilityCheckState extends State<SVersionCompatibilityCheck> {
class _SVersionCompatibilityCheckState
extends State<SVersionCompatibilityCheck> {
@override
Widget build(BuildContext context) {
return SwitchListTile(

View file

@ -27,12 +27,12 @@ bool hasUnsupportedRequiredOption(List<Option> options, Patch patch) {
for (final Option option in options) {
if (option.required &&
option.value == null &&
locator<ManagerAPI>()
.getPatchOption(
locator<PatcherViewModel>().selectedApp!.packageName,
patch.name,
option.key,
) == null) {
locator<ManagerAPI>().getPatchOption(
locator<PatcherViewModel>().selectedApp!.packageName,
patch.name,
option.key,
) ==
null) {
requiredOptionsType.add(option.valueType);
}
}
@ -52,7 +52,8 @@ List<Option> getNullRequiredOptions(List<Patch> patches, String packageName) {
patchOption.required &&
patchOption.value == null &&
locator<ManagerAPI>()
.getPatchOption(packageName, patch.name, patchOption.key) == null) {
.getPatchOption(packageName, patch.name, patchOption.key) ==
null) {
requiredNullOptions.add(patchOption);
}
}