2022-08-07 20:05:44 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-08-31 12:05:38 +02:00
|
|
|
import 'package:flutter_i18n/flutter_i18n.dart';
|
2022-11-01 10:56:15 +01:00
|
|
|
import 'package:revanced_manager/app/app.locator.dart';
|
2023-10-12 02:00:39 +02:00
|
|
|
import 'package:revanced_manager/models/patch.dart';
|
2022-11-01 10:56:15 +01:00
|
|
|
import 'package:revanced_manager/services/manager_api.dart';
|
|
|
|
import 'package:revanced_manager/services/toast.dart';
|
2022-09-05 04:32:36 +02:00
|
|
|
import 'package:revanced_manager/ui/widgets/shared/custom_card.dart';
|
2024-01-14 23:29:24 +01:00
|
|
|
import 'package:revanced_manager/ui/widgets/shared/haptics/haptic_checkbox.dart';
|
|
|
|
import 'package:revanced_manager/ui/widgets/shared/haptics/haptic_custom_card.dart';
|
2022-08-07 20:05:44 +02:00
|
|
|
|
2022-08-09 01:01:06 +02:00
|
|
|
// ignore: must_be_immutable
|
2022-08-07 21:15:52 +02:00
|
|
|
class PatchItem extends StatefulWidget {
|
2023-01-30 13:35:06 +01:00
|
|
|
PatchItem({
|
2023-11-11 13:07:32 +01:00
|
|
|
super.key,
|
2023-01-30 13:35:06 +01:00
|
|
|
required this.name,
|
|
|
|
required this.simpleName,
|
|
|
|
required this.description,
|
|
|
|
required this.packageVersion,
|
|
|
|
required this.supportedPackageVersions,
|
|
|
|
required this.isUnsupported,
|
2023-10-12 02:00:39 +02:00
|
|
|
required this.hasUnsupportedPatchOption,
|
|
|
|
required this.options,
|
2023-01-30 13:35:06 +01:00
|
|
|
required this.isSelected,
|
|
|
|
required this.onChanged,
|
2023-10-12 02:00:39 +02:00
|
|
|
required this.navigateToOptions,
|
2023-08-15 11:05:27 +02:00
|
|
|
required this.isChangeEnabled,
|
2023-11-11 13:07:32 +01:00
|
|
|
});
|
2022-08-07 20:05:44 +02:00
|
|
|
final String name;
|
2022-08-09 03:30:12 +02:00
|
|
|
final String simpleName;
|
2022-08-07 20:05:44 +02:00
|
|
|
final String description;
|
2022-08-31 12:05:38 +02:00
|
|
|
final String packageVersion;
|
|
|
|
final List<String> supportedPackageVersions;
|
|
|
|
final bool isUnsupported;
|
2023-10-12 02:00:39 +02:00
|
|
|
final bool hasUnsupportedPatchOption;
|
|
|
|
final List<Option> options;
|
2022-08-07 21:15:52 +02:00
|
|
|
bool isSelected;
|
2022-08-18 16:33:33 +02:00
|
|
|
final Function(bool) onChanged;
|
2023-10-12 02:00:39 +02:00
|
|
|
final void Function(List<Option>) navigateToOptions;
|
2023-08-15 11:05:27 +02:00
|
|
|
final bool isChangeEnabled;
|
2022-11-01 10:56:15 +01:00
|
|
|
final toast = locator<Toast>();
|
|
|
|
final _managerAPI = locator<ManagerAPI>();
|
2022-08-07 20:05:44 +02:00
|
|
|
|
2022-08-07 21:15:52 +02:00
|
|
|
@override
|
|
|
|
State<PatchItem> createState() => _PatchItemState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PatchItemState extends State<PatchItem> {
|
2022-08-07 20:05:44 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-07-10 14:36:50 +02:00
|
|
|
widget.isSelected = widget.isSelected &&
|
|
|
|
(!widget.isUnsupported ||
|
2023-10-15 19:16:58 +02:00
|
|
|
!widget._managerAPI.isVersionCompatibilityCheckEnabled()) &&
|
|
|
|
!widget.hasUnsupportedPatchOption;
|
2022-09-07 12:55:37 +02:00
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 4.0),
|
2023-06-15 11:54:49 +02:00
|
|
|
child: Opacity(
|
|
|
|
opacity: widget.isUnsupported &&
|
2023-10-15 19:16:58 +02:00
|
|
|
widget._managerAPI.isVersionCompatibilityCheckEnabled() == true
|
2023-06-15 11:54:49 +02:00
|
|
|
? 0.5
|
|
|
|
: 1,
|
2024-01-14 23:29:24 +01:00
|
|
|
child: HapticCustomCard(
|
2023-10-12 02:00:39 +02:00
|
|
|
padding: EdgeInsets.only(
|
|
|
|
top: 12,
|
|
|
|
bottom: 16,
|
|
|
|
left: 8.0,
|
|
|
|
right: widget.options.isNotEmpty ? 4.0 : 8.0,
|
|
|
|
),
|
2023-06-15 11:54:49 +02:00
|
|
|
onTap: () {
|
2023-10-12 02:00:39 +02:00
|
|
|
if (widget.isUnsupported &&
|
2023-10-15 19:16:58 +02:00
|
|
|
widget._managerAPI.isVersionCompatibilityCheckEnabled()) {
|
2023-10-12 02:00:39 +02:00
|
|
|
widget.isSelected = false;
|
|
|
|
widget.toast.showBottom('patchItem.unsupportedPatchVersion');
|
|
|
|
} else if (widget.isChangeEnabled) {
|
|
|
|
if (!widget.isSelected) {
|
|
|
|
if (widget.hasUnsupportedPatchOption) {
|
|
|
|
_showUnsupportedRequiredOptionDialog();
|
|
|
|
return;
|
|
|
|
}
|
2023-06-15 11:54:49 +02:00
|
|
|
}
|
2023-10-12 02:00:39 +02:00
|
|
|
widget.isSelected = !widget.isSelected;
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
if (!widget.isUnsupported ||
|
2023-10-15 19:16:58 +02:00
|
|
|
!widget._managerAPI.isVersionCompatibilityCheckEnabled()) {
|
2023-08-15 11:05:27 +02:00
|
|
|
widget.onChanged(widget.isSelected);
|
|
|
|
}
|
2023-06-15 11:54:49 +02:00
|
|
|
},
|
2023-10-12 02:00:39 +02:00
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Transform.scale(
|
|
|
|
scale: 1.2,
|
2024-01-14 23:29:24 +01:00
|
|
|
child: HapticCheckbox(
|
2023-10-12 02:00:39 +02:00
|
|
|
value: widget.isSelected,
|
|
|
|
activeColor: Theme.of(context).colorScheme.primary,
|
|
|
|
checkColor: Theme.of(context).colorScheme.secondaryContainer,
|
|
|
|
side: BorderSide(
|
|
|
|
width: 2.0,
|
|
|
|
color: Theme.of(context).colorScheme.primary,
|
2022-09-19 18:55:44 +02:00
|
|
|
),
|
2023-10-12 02:00:39 +02:00
|
|
|
onChanged: (newValue) {
|
|
|
|
if (widget.isUnsupported &&
|
2023-10-15 19:16:58 +02:00
|
|
|
widget._managerAPI
|
|
|
|
.isVersionCompatibilityCheckEnabled()) {
|
2023-10-12 02:00:39 +02:00
|
|
|
widget.isSelected = false;
|
|
|
|
widget.toast.showBottom(
|
|
|
|
'patchItem.unsupportedPatchVersion',
|
|
|
|
);
|
|
|
|
} else if (widget.isChangeEnabled) {
|
|
|
|
if (!widget.isSelected) {
|
|
|
|
if (widget.hasUnsupportedPatchOption) {
|
|
|
|
_showUnsupportedRequiredOptionDialog();
|
|
|
|
return;
|
2023-08-15 11:05:27 +02:00
|
|
|
}
|
2023-10-12 02:00:39 +02:00
|
|
|
}
|
|
|
|
widget.isSelected = newValue!;
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
if (!widget.isUnsupported ||
|
2023-10-15 19:16:58 +02:00
|
|
|
!widget._managerAPI
|
|
|
|
.isVersionCompatibilityCheckEnabled()) {
|
2023-10-12 02:00:39 +02:00
|
|
|
widget.onChanged(widget.isSelected);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
2023-06-15 11:54:49 +02:00
|
|
|
),
|
2023-10-12 02:00:39 +02:00
|
|
|
Expanded(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 10),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
widget.simpleName,
|
|
|
|
maxLines: 2,
|
|
|
|
overflow: TextOverflow.visible,
|
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 16,
|
|
|
|
fontWeight: FontWeight.w600,
|
2023-01-30 13:35:06 +01:00
|
|
|
),
|
2022-09-19 18:55:44 +02:00
|
|
|
),
|
2023-10-12 02:00:39 +02:00
|
|
|
Text(
|
|
|
|
widget.description,
|
|
|
|
softWrap: true,
|
|
|
|
overflow: TextOverflow.visible,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 14,
|
|
|
|
color: Theme.of(context)
|
|
|
|
.colorScheme
|
|
|
|
.onSecondaryContainer,
|
2023-08-07 17:28:09 +02:00
|
|
|
),
|
|
|
|
),
|
2023-10-12 02:00:39 +02:00
|
|
|
if (widget.description.isNotEmpty)
|
|
|
|
Align(
|
|
|
|
alignment: Alignment.topLeft,
|
|
|
|
child: Wrap(
|
|
|
|
spacing: 8,
|
|
|
|
runSpacing: 4,
|
|
|
|
children: [
|
|
|
|
if (widget.isUnsupported &&
|
2023-10-15 19:16:58 +02:00
|
|
|
!widget._managerAPI
|
2023-10-15 11:56:02 +02:00
|
|
|
.isVersionCompatibilityCheckEnabled())
|
2023-10-12 02:00:39 +02:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 8),
|
|
|
|
child: TextButton.icon(
|
|
|
|
label: I18nText('warning'),
|
|
|
|
icon: const Icon(
|
|
|
|
Icons.warning_amber_outlined,
|
|
|
|
size: 20.0,
|
|
|
|
),
|
|
|
|
onPressed: () =>
|
|
|
|
_showUnsupportedWarningDialog(),
|
|
|
|
style: ButtonStyle(
|
|
|
|
shape: MaterialStateProperty.all(
|
|
|
|
RoundedRectangleBorder(
|
|
|
|
borderRadius:
|
|
|
|
BorderRadius.circular(8),
|
|
|
|
side: BorderSide(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.colorScheme
|
|
|
|
.secondary,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
backgroundColor:
|
|
|
|
MaterialStateProperty.all(
|
|
|
|
Colors.transparent,
|
|
|
|
),
|
|
|
|
foregroundColor:
|
|
|
|
MaterialStateProperty.all(
|
|
|
|
Theme.of(context).colorScheme.secondary,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2023-08-07 17:28:09 +02:00
|
|
|
),
|
2023-10-12 02:00:39 +02:00
|
|
|
if (widget.options.isNotEmpty)
|
|
|
|
IconButton(
|
|
|
|
icon: const Icon(Icons.settings_outlined),
|
|
|
|
onPressed: () => widget.navigateToOptions(widget.options),
|
|
|
|
),
|
2023-06-15 11:54:49 +02:00
|
|
|
],
|
|
|
|
),
|
2022-08-13 11:56:30 +02:00
|
|
|
),
|
2022-08-07 20:05:44 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2022-08-31 12:05:38 +02:00
|
|
|
|
|
|
|
Future<void> _showUnsupportedWarningDialog() {
|
2022-09-02 01:10:41 +02:00
|
|
|
return showDialog(
|
2022-08-31 12:05:38 +02:00
|
|
|
context: context,
|
2022-09-02 01:10:41 +02:00
|
|
|
builder: (context) => AlertDialog(
|
2022-11-12 16:55:33 +01:00
|
|
|
title: I18nText('warning'),
|
2022-09-02 01:10:41 +02:00
|
|
|
content: I18nText(
|
2022-09-07 14:03:54 +02:00
|
|
|
'patchItem.unsupportedDialogText',
|
2022-09-02 01:10:41 +02:00
|
|
|
translationParams: {
|
|
|
|
'packageVersion': widget.packageVersion,
|
|
|
|
'supportedVersions':
|
2023-10-12 02:00:39 +02:00
|
|
|
'• ${widget.supportedPackageVersions.reversed.join('\n• ')}',
|
2022-09-02 01:10:41 +02:00
|
|
|
},
|
2022-09-01 02:25:19 +02:00
|
|
|
),
|
2022-09-12 15:20:25 +02:00
|
|
|
actions: <Widget>[
|
2023-12-22 14:34:03 +01:00
|
|
|
FilledButton(
|
2022-09-02 01:10:41 +02:00
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
2023-12-22 14:34:03 +01:00
|
|
|
child: I18nText('okButton'),
|
2023-08-06 09:39:46 +02:00
|
|
|
),
|
2022-09-02 01:10:41 +02:00
|
|
|
],
|
2022-09-01 02:25:19 +02:00
|
|
|
),
|
2022-08-31 12:05:38 +02:00
|
|
|
);
|
|
|
|
}
|
2023-08-07 17:28:09 +02:00
|
|
|
|
2023-10-12 02:00:39 +02:00
|
|
|
Future<void> _showUnsupportedRequiredOptionDialog() {
|
2023-08-07 17:28:09 +02:00
|
|
|
return showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => AlertDialog(
|
2023-10-12 02:00:39 +02:00
|
|
|
title: I18nText('notice'),
|
2023-08-07 17:28:09 +02:00
|
|
|
content: I18nText(
|
2023-10-12 02:00:39 +02:00
|
|
|
'patchItem.unsupportedRequiredOption',
|
2023-08-07 17:28:09 +02:00
|
|
|
),
|
|
|
|
actions: <Widget>[
|
2023-12-22 14:34:03 +01:00
|
|
|
FilledButton(
|
2023-08-07 17:28:09 +02:00
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
2023-12-22 14:34:03 +01:00
|
|
|
child: I18nText('okButton'),
|
2023-08-07 17:28:09 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2023-02-14 11:26:37 +01:00
|
|
|
}
|