mirror of
https://github.com/revanced/revanced-manager
synced 2024-05-14 13:56:57 +02:00
feat: add unsupported warning in patches selector view
This commit is contained in:
parent
533f22924a
commit
596d4f0def
@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"okButton": "OK",
|
||||||
"main": {
|
"main": {
|
||||||
"dashboardTab": "Dashboard",
|
"dashboardTab": "Dashboard",
|
||||||
"patcherTab": "Patcher",
|
"patcherTab": "Patcher",
|
||||||
@ -57,6 +58,11 @@
|
|||||||
"searchBarHint": "Search patches",
|
"searchBarHint": "Search patches",
|
||||||
"doneButton": "Done"
|
"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": {
|
"installerView": {
|
||||||
"widgetTitle": "Installer",
|
"widgetTitle": "Installer",
|
||||||
"installButton": "Install",
|
"installButton": "Install",
|
||||||
|
@ -60,6 +60,11 @@ class _PatchesSelectorViewState extends State<PatchesSelectorView> {
|
|||||||
simpleName: patch.getSimpleName(),
|
simpleName: patch.getSimpleName(),
|
||||||
version: patch.version,
|
version: patch.version,
|
||||||
description: patch.description,
|
description: patch.description,
|
||||||
|
packageVersion: model.getAppVersion(),
|
||||||
|
supportedPackageVersions:
|
||||||
|
model.getSupportedVersions(patch),
|
||||||
|
isUnsupported:
|
||||||
|
!model.isPatchSupported(patch),
|
||||||
isSelected: model.isSelected(patch),
|
isSelected: model.isSelected(patch),
|
||||||
onChanged: (value) =>
|
onChanged: (value) =>
|
||||||
model.selectPatch(patch, value),
|
model.selectPatch(patch, value),
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import 'package:revanced_manager/app/app.locator.dart';
|
import 'package:revanced_manager/app/app.locator.dart';
|
||||||
import 'package:revanced_manager/models/patch.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/services/patcher_api.dart';
|
||||||
import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart';
|
import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart';
|
||||||
import 'package:stacked/stacked.dart';
|
import 'package:stacked/stacked.dart';
|
||||||
@ -16,9 +17,9 @@ class PatchesSelectorViewModel extends BaseViewModel {
|
|||||||
));
|
));
|
||||||
patches.sort((a, b) => a.name.compareTo(b.name));
|
patches.sort((a, b) => a.name.compareTo(b.name));
|
||||||
if (selectedPatches.isEmpty) {
|
if (selectedPatches.isEmpty) {
|
||||||
for (Patch p in patches) {
|
for (Patch patch in patches) {
|
||||||
if (!p.excluded) {
|
if (!patch.excluded && isPatchSupported(patch)) {
|
||||||
selectedPatches.add(p);
|
selectedPatches.add(patch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -63,4 +64,22 @@ class PatchesSelectorViewModel extends BaseViewModel {
|
|||||||
))
|
))
|
||||||
.toList();
|
.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)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_i18n/flutter_i18n.dart';
|
||||||
import 'package:google_fonts/google_fonts.dart';
|
import 'package:google_fonts/google_fonts.dart';
|
||||||
|
import 'package:revanced_manager/theme.dart';
|
||||||
|
|
||||||
// ignore: must_be_immutable
|
// ignore: must_be_immutable
|
||||||
class PatchItem extends StatefulWidget {
|
class PatchItem extends StatefulWidget {
|
||||||
@ -7,6 +9,9 @@ class PatchItem extends StatefulWidget {
|
|||||||
final String simpleName;
|
final String simpleName;
|
||||||
final String description;
|
final String description;
|
||||||
final String version;
|
final String version;
|
||||||
|
final String packageVersion;
|
||||||
|
final List<String> supportedPackageVersions;
|
||||||
|
final bool isUnsupported;
|
||||||
bool isSelected;
|
bool isSelected;
|
||||||
final Function(bool) onChanged;
|
final Function(bool) onChanged;
|
||||||
|
|
||||||
@ -16,6 +21,9 @@ class PatchItem extends StatefulWidget {
|
|||||||
required this.simpleName,
|
required this.simpleName,
|
||||||
required this.description,
|
required this.description,
|
||||||
required this.version,
|
required this.version,
|
||||||
|
required this.packageVersion,
|
||||||
|
required this.supportedPackageVersions,
|
||||||
|
required this.isUnsupported,
|
||||||
required this.isSelected,
|
required this.isSelected,
|
||||||
required this.onChanged,
|
required this.onChanged,
|
||||||
}) : super(key: key);
|
}) : 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(),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user