2022-08-07 21:15:52 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-08-08 01:31:55 +02:00
|
|
|
import 'package:flutter_i18n/flutter_i18n.dart';
|
2022-08-07 21:15:52 +02:00
|
|
|
import 'package:revanced_manager/ui/views/patches_selector/patches_selector_viewmodel.dart';
|
2022-08-21 12:47:44 +02:00
|
|
|
import 'package:revanced_manager/ui/widgets/patchesSelectorView/patch_item.dart';
|
|
|
|
import 'package:revanced_manager/ui/widgets/shared/search_bar.dart';
|
2022-08-07 21:15:52 +02:00
|
|
|
import 'package:stacked/stacked.dart';
|
|
|
|
|
|
|
|
class PatchesSelectorView extends StatefulWidget {
|
|
|
|
const PatchesSelectorView({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<PatchesSelectorView> createState() => _PatchesSelectorViewState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _PatchesSelectorViewState extends State<PatchesSelectorView> {
|
2022-08-24 17:07:40 +02:00
|
|
|
String _query = '';
|
2022-08-07 21:15:52 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-08-09 01:01:06 +02:00
|
|
|
return ViewModelBuilder<PatchesSelectorViewModel>.reactive(
|
2022-08-13 11:56:30 +02:00
|
|
|
onModelReady: (model) => model.initialize(),
|
2022-08-18 16:33:33 +02:00
|
|
|
viewModelBuilder: () => PatchesSelectorViewModel(),
|
2022-08-09 01:01:06 +02:00
|
|
|
builder: (context, model, child) => Scaffold(
|
2022-09-08 13:57:51 +02:00
|
|
|
resizeToAvoidBottomInset: false,
|
2022-09-01 02:25:19 +02:00
|
|
|
floatingActionButton: Visibility(
|
|
|
|
visible: model.patches.isNotEmpty,
|
|
|
|
child: FloatingActionButton.extended(
|
|
|
|
label: I18nText('patchesSelectorView.doneButton'),
|
|
|
|
icon: const Icon(Icons.check),
|
|
|
|
onPressed: () {
|
|
|
|
model.selectPatches();
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
2022-09-19 13:57:40 +02:00
|
|
|
body: CustomScrollView(
|
|
|
|
slivers: [
|
|
|
|
SliverAppBar(
|
|
|
|
pinned: true,
|
|
|
|
floating: true,
|
|
|
|
snap: false,
|
2022-09-19 17:24:31 +02:00
|
|
|
title: I18nText(
|
|
|
|
'patchesSelectorView.viewTitle',
|
|
|
|
child: Text(
|
|
|
|
'',
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).textTheme.headline6!.color,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
leading: IconButton(
|
|
|
|
icon: Icon(
|
|
|
|
Icons.arrow_back,
|
|
|
|
color: Theme.of(context).textTheme.headline6!.color,
|
|
|
|
),
|
|
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
|
|
),
|
2022-10-16 22:10:16 +02:00
|
|
|
actions: [
|
|
|
|
Container(
|
|
|
|
height: 2,
|
|
|
|
margin: const EdgeInsets.only(right: 16, top: 12, bottom: 12),
|
|
|
|
padding:
|
|
|
|
const EdgeInsets.symmetric(horizontal: 6, vertical: 6),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color:
|
|
|
|
Theme.of(context).colorScheme.tertiary.withOpacity(0.5),
|
|
|
|
borderRadius: BorderRadius.circular(6),
|
|
|
|
),
|
|
|
|
child: Text(
|
|
|
|
model.patchesVersion!,
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).textTheme.headline6!.color,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2022-09-19 13:57:40 +02:00
|
|
|
bottom: PreferredSize(
|
|
|
|
preferredSize: const Size.fromHeight(64.0),
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(
|
2022-09-19 17:24:31 +02:00
|
|
|
vertical: 8.0,
|
|
|
|
horizontal: 12.0,
|
|
|
|
),
|
2022-09-19 13:57:40 +02:00
|
|
|
child: SearchBar(
|
|
|
|
showSelectIcon: true,
|
|
|
|
hintText: FlutterI18n.translate(
|
|
|
|
context,
|
|
|
|
'patchesSelectorView.searchBarHint',
|
|
|
|
),
|
|
|
|
onQueryChanged: (searchQuery) {
|
|
|
|
setState(() {
|
|
|
|
_query = searchQuery;
|
|
|
|
});
|
|
|
|
},
|
2022-09-23 11:23:21 +02:00
|
|
|
onSelectAll: (value) {
|
|
|
|
if (value) {
|
|
|
|
model.selectAllPatcherWarning(context);
|
|
|
|
}
|
|
|
|
model.selectAllPatches(value);
|
|
|
|
},
|
2022-09-12 01:36:18 +02:00
|
|
|
),
|
|
|
|
),
|
2022-09-19 13:57:40 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
SliverToBoxAdapter(
|
|
|
|
child: model.patches.isEmpty
|
|
|
|
? Padding(
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
child: Center(
|
|
|
|
child: I18nText(
|
|
|
|
'patchesSelectorView.noPatchesFound',
|
|
|
|
child: Text(
|
|
|
|
'',
|
|
|
|
style: Theme.of(context).textTheme.bodyMedium,
|
2022-09-12 01:36:18 +02:00
|
|
|
),
|
2022-09-19 13:57:40 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: Padding(
|
2022-09-19 17:24:31 +02:00
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 12.0)
|
|
|
|
.copyWith(bottom: 80),
|
2022-09-19 13:57:40 +02:00
|
|
|
child: Column(
|
|
|
|
children: model
|
|
|
|
.getQueriedPatches(_query)
|
|
|
|
.map(
|
|
|
|
(patch) => PatchItem(
|
|
|
|
name: patch.name,
|
|
|
|
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),
|
|
|
|
),
|
|
|
|
/* TODO: Enable this and make use of new Patch Options implementation
|
|
|
|
patch.hasOptions ? ExpandablePanel(
|
|
|
|
controller: expController,
|
|
|
|
theme: const ExpandableThemeData(
|
|
|
|
hasIcon: false,
|
|
|
|
tapBodyToExpand: true,
|
|
|
|
tapBodyToCollapse: true,
|
|
|
|
tapHeaderToExpand: true,
|
|
|
|
),
|
|
|
|
header: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
GestureDetector(
|
|
|
|
onLongPress: () =>
|
|
|
|
expController.toggle(),
|
|
|
|
child: PatchItem(
|
|
|
|
name: patch.name,
|
|
|
|
simpleName: patch.getSimpleName(),
|
|
|
|
description: patch.description,
|
|
|
|
version: patch.version,
|
|
|
|
packageVersion:
|
|
|
|
model.getAppVersion(),
|
|
|
|
supportedPackageVersions: model
|
|
|
|
.getSupportedVersions(patch),
|
|
|
|
isUnsupported: !model
|
|
|
|
.isPatchSupported(patch),
|
|
|
|
isSelected:
|
|
|
|
model.isSelected(patch),
|
|
|
|
onChanged: (value) => model
|
|
|
|
.selectPatch(patch, value),
|
|
|
|
child: const Padding(
|
|
|
|
padding: EdgeInsets.symmetric(
|
|
|
|
vertical: 8.0,
|
|
|
|
),
|
|
|
|
child: Text(
|
|
|
|
'Long press for additional options.',
|
2022-09-04 19:54:21 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2022-09-19 13:57:40 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
expanded: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
vertical: 10.0,
|
|
|
|
horizontal: 10,
|
2022-09-04 19:54:21 +02:00
|
|
|
),
|
2022-09-19 13:57:40 +02:00
|
|
|
child: Container(
|
2022-09-04 19:54:21 +02:00
|
|
|
padding: const EdgeInsets.symmetric(
|
2022-09-19 13:57:40 +02:00
|
|
|
vertical: 8,
|
|
|
|
horizontal: 8,
|
2022-09-04 19:54:21 +02:00
|
|
|
),
|
2022-09-19 13:57:40 +02:00
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Theme.of(context)
|
|
|
|
.colorScheme
|
|
|
|
.tertiary
|
|
|
|
.withOpacity(0.1),
|
|
|
|
borderRadius:
|
|
|
|
BorderRadius.circular(12),
|
|
|
|
),
|
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
Text(
|
|
|
|
'Patch options',
|
|
|
|
style: GoogleFonts.inter(
|
|
|
|
fontSize: 18,
|
|
|
|
fontWeight: FontWeight.w600,
|
2022-09-04 19:54:21 +02:00
|
|
|
),
|
2022-09-19 13:57:40 +02:00
|
|
|
),
|
|
|
|
const OptionsTextField(
|
|
|
|
hint: 'App name'),
|
|
|
|
const OptionsFilePicker(
|
|
|
|
optionName: 'Choose a logo',
|
|
|
|
),
|
|
|
|
],
|
2022-09-04 19:54:21 +02:00
|
|
|
),
|
|
|
|
),
|
2022-09-19 13:57:40 +02:00
|
|
|
),
|
|
|
|
collapsed: Container(),
|
|
|
|
) */
|
|
|
|
)
|
|
|
|
.toList(),
|
|
|
|
),
|
|
|
|
),
|
2022-09-12 01:36:18 +02:00
|
|
|
),
|
2022-09-19 13:57:40 +02:00
|
|
|
],
|
2022-08-07 21:15:52 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|