feat: add unsupported warning in patches selector view

This commit is contained in:
Alberto Ponces 2022-08-31 11:05:38 +01:00
parent 533f22924a
commit 596d4f0def
4 changed files with 101 additions and 4 deletions

View File

@ -1,4 +1,5 @@
{
"okButton": "OK",
"main": {
"dashboardTab": "Dashboard",
"patcherTab": "Patcher",
@ -57,6 +58,11 @@
"searchBarHint": "Search patches",
"doneButton": "Done"
},
"patchItem": {
"unsupportedWarningButton": "Unsupported version",
"alertDialogTitle": "Warning",
"alertDialogText": "Selecting this patch may or may not result in patching errors.\n\nApp version: {packageVersion}\nCurrent supported versions:\n{supportedVersions}"
},
"installerView": {
"widgetTitle": "Installer",
"installButton": "Install",

View File

@ -60,6 +60,11 @@ class _PatchesSelectorViewState extends State<PatchesSelectorView> {
simpleName: patch.getSimpleName(),
version: patch.version,
description: patch.description,
packageVersion: model.getAppVersion(),
supportedPackageVersions:
model.getSupportedVersions(patch),
isUnsupported:
!model.isPatchSupported(patch),
isSelected: model.isSelected(patch),
onChanged: (value) =>
model.selectPatch(patch, value),

View File

@ -1,5 +1,6 @@
import 'package:revanced_manager/app/app.locator.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/views/patcher/patcher_viewmodel.dart';
import 'package:stacked/stacked.dart';
@ -16,9 +17,9 @@ class PatchesSelectorViewModel extends BaseViewModel {
));
patches.sort((a, b) => a.name.compareTo(b.name));
if (selectedPatches.isEmpty) {
for (Patch p in patches) {
if (!p.excluded) {
selectedPatches.add(p);
for (Patch patch in patches) {
if (!patch.excluded && isPatchSupported(patch)) {
selectedPatches.add(patch);
}
}
}
@ -63,4 +64,22 @@ class PatchesSelectorViewModel extends BaseViewModel {
))
.toList();
}
String getAppVersion() {
return locator<PatcherViewModel>().selectedApp!.version;
}
List<String> getSupportedVersions(Patch patch) {
PatchedApplication app = locator<PatcherViewModel>().selectedApp!;
return patch.compatiblePackages
.firstWhere((pack) => pack.name == app.packageName)
.versions;
}
bool isPatchSupported(Patch patch) {
PatchedApplication app = locator<PatcherViewModel>().selectedApp!;
return patch.compatiblePackages.any((pack) =>
pack.name == app.packageName &&
(pack.versions.isEmpty || pack.versions.contains(app.version)));
}
}

View File

@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:revanced_manager/theme.dart';
// ignore: must_be_immutable
class PatchItem extends StatefulWidget {
@ -7,6 +9,9 @@ class PatchItem extends StatefulWidget {
final String simpleName;
final String description;
final String version;
final String packageVersion;
final List<String> supportedPackageVersions;
final bool isUnsupported;
bool isSelected;
final Function(bool) onChanged;
@ -16,6 +21,9 @@ class PatchItem extends StatefulWidget {
required this.simpleName,
required this.description,
required this.version,
required this.packageVersion,
required this.supportedPackageVersions,
required this.isUnsupported,
required this.isSelected,
required this.onChanged,
}) : super(key: key);
@ -87,10 +95,69 @@ class _PatchItemState extends State<PatchItem> {
),
)
],
),
widget.isUnsupported
? Row(
children: [
Padding(
padding: const EdgeInsets.only(top: 8),
child: TextButton.icon(
label: I18nText('patchItem.unsupportedWarningButton'),
icon: const Icon(Icons.warning),
onPressed: () => _showUnsupportedWarningDialog(),
style: ButtonStyle(
shape: MaterialStateProperty.all(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
side: BorderSide(
width: 1,
color:
Theme.of(context).colorScheme.secondary,
),
),
),
backgroundColor: MaterialStateProperty.all(
isDark
? Theme.of(context).colorScheme.background
: Colors.white,
),
foregroundColor: MaterialStateProperty.all(
Theme.of(context).colorScheme.secondary,
),
),
),
),
],
)
: Container(),
],
),
),
);
}
Future<void> _showUnsupportedWarningDialog() {
return showDialog(
context: context,
builder: (context) {
return AlertDialog(
title: I18nText('patchItem.alertDialogTitle'),
content: I18nText(
'patchItem.alertDialogText',
translationParams: {
'packageVersion': widget.packageVersion,
'supportedVersions':
'\u2022 ${widget.supportedPackageVersions.join('\n\u2022 ')}',
},
),
actions: [
TextButton(
child: I18nText('okButton'),
onPressed: () => Navigator.of(context).pop(),
)
],
);
},
);
}
}