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-12 11:42:43 +02:00
|
|
|
import 'package:revanced_manager/theme.dart';
|
2022-08-07 21:15:52 +02:00
|
|
|
import 'package:revanced_manager/ui/views/patches_selector/patches_selector_viewmodel.dart';
|
|
|
|
import 'package:revanced_manager/ui/widgets/patch_item.dart';
|
|
|
|
import 'package:revanced_manager/ui/widgets/search_bar.dart';
|
|
|
|
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-18 16:33:33 +02:00
|
|
|
final List<PatchItem> _items = [];
|
2022-08-07 21:15:52 +02:00
|
|
|
String query = '';
|
|
|
|
|
|
|
|
@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-08-09 02:16:33 +02:00
|
|
|
body: SafeArea(
|
|
|
|
child: Padding(
|
|
|
|
padding:
|
|
|
|
const EdgeInsets.symmetric(vertical: 4.0, horizontal: 12.0),
|
2022-08-17 19:44:27 +02:00
|
|
|
child: model.patches.isNotEmpty
|
2022-08-09 02:16:33 +02:00
|
|
|
? Column(
|
|
|
|
children: [
|
|
|
|
SearchBar(
|
2022-08-21 03:03:36 +02:00
|
|
|
showSelectIcon: true,
|
2022-08-11 22:17:10 +02:00
|
|
|
fillColor:
|
2022-08-12 11:42:43 +02:00
|
|
|
isDark ? const Color(0xff1B222B) : Colors.grey[200],
|
2022-08-09 02:16:33 +02:00
|
|
|
hintText: FlutterI18n.translate(
|
|
|
|
context,
|
|
|
|
'patchesSelectorView.searchBarHint',
|
|
|
|
),
|
2022-08-12 11:42:43 +02:00
|
|
|
hintTextColor: Theme.of(context).colorScheme.tertiary,
|
2022-08-09 02:16:33 +02:00
|
|
|
onQueryChanged: (searchQuery) {
|
|
|
|
setState(() {
|
|
|
|
query = searchQuery;
|
|
|
|
});
|
2022-08-07 21:15:52 +02:00
|
|
|
},
|
2022-08-21 03:03:36 +02:00
|
|
|
onSelectAll: (value) => model.selectAllPatches(value),
|
2022-08-09 02:16:33 +02:00
|
|
|
),
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
query.isEmpty || query.length < 2
|
|
|
|
? _getAllResults(model)
|
2022-08-10 10:42:24 +02:00
|
|
|
: _getFilteredResults(model),
|
|
|
|
MaterialButton(
|
|
|
|
textColor: Colors.white,
|
2022-08-13 11:56:30 +02:00
|
|
|
color: Theme.of(context).colorScheme.secondary,
|
2022-08-10 10:42:24 +02:00
|
|
|
minWidth: double.infinity,
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
vertical: 12,
|
|
|
|
horizontal: 8,
|
|
|
|
),
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.circular(12),
|
|
|
|
),
|
2022-08-18 16:33:33 +02:00
|
|
|
onPressed: () {
|
|
|
|
model.selectPatches();
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
2022-08-10 10:42:24 +02:00
|
|
|
child: I18nText('patchesSelectorView.fabButton'),
|
|
|
|
),
|
2022-08-09 02:16:33 +02:00
|
|
|
],
|
|
|
|
)
|
2022-08-12 11:42:43 +02:00
|
|
|
: Center(
|
2022-08-09 02:16:33 +02:00
|
|
|
child: CircularProgressIndicator(
|
2022-08-12 11:42:43 +02:00
|
|
|
color: Theme.of(context).colorScheme.secondary,
|
2022-08-09 02:16:33 +02:00
|
|
|
),
|
|
|
|
),
|
2022-08-07 21:15:52 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2022-08-09 02:16:33 +02:00
|
|
|
|
|
|
|
Widget _getAllResults(PatchesSelectorViewModel model) {
|
2022-08-18 16:33:33 +02:00
|
|
|
_items.clear();
|
2022-08-09 02:16:33 +02:00
|
|
|
return Expanded(
|
|
|
|
child: ListView.builder(
|
2022-08-17 19:44:27 +02:00
|
|
|
itemCount: model.patches.length,
|
2022-08-09 02:16:33 +02:00
|
|
|
itemBuilder: (context, index) {
|
2022-08-17 19:44:27 +02:00
|
|
|
model.patches.sort((a, b) => a.simpleName.compareTo(b.simpleName));
|
2022-08-09 03:30:12 +02:00
|
|
|
PatchItem item = PatchItem(
|
2022-08-17 19:44:27 +02:00
|
|
|
name: model.patches[index].name,
|
|
|
|
simpleName: model.patches[index].simpleName,
|
|
|
|
version: model.patches[index].version,
|
|
|
|
description: model.patches[index].description,
|
2022-08-21 03:03:36 +02:00
|
|
|
isSelected: model.isSelected(index),
|
|
|
|
onChanged: (value) => model.selectPatch(index, value),
|
2022-08-09 02:16:33 +02:00
|
|
|
);
|
2022-08-18 16:33:33 +02:00
|
|
|
_items.add(item);
|
2022-08-09 03:30:12 +02:00
|
|
|
return item;
|
2022-08-09 02:16:33 +02:00
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _getFilteredResults(PatchesSelectorViewModel model) {
|
2022-08-18 16:33:33 +02:00
|
|
|
_items.clear();
|
2022-08-09 02:16:33 +02:00
|
|
|
return Expanded(
|
|
|
|
child: ListView.builder(
|
2022-08-17 19:44:27 +02:00
|
|
|
itemCount: model.patches.length,
|
2022-08-09 02:16:33 +02:00
|
|
|
itemBuilder: (context, index) {
|
2022-08-17 19:44:27 +02:00
|
|
|
model.patches.sort((a, b) => a.simpleName.compareTo(b.simpleName));
|
|
|
|
if (model.patches[index].simpleName.toLowerCase().contains(
|
2022-08-09 02:16:33 +02:00
|
|
|
query.toLowerCase(),
|
|
|
|
)) {
|
2022-08-09 03:30:12 +02:00
|
|
|
PatchItem item = PatchItem(
|
2022-08-17 19:44:27 +02:00
|
|
|
name: model.patches[index].name,
|
|
|
|
simpleName: model.patches[index].simpleName,
|
|
|
|
version: model.patches[index].version,
|
|
|
|
description: model.patches[index].description,
|
2022-08-21 03:03:36 +02:00
|
|
|
isSelected: model.isSelected(index),
|
|
|
|
onChanged: (value) => model.selectPatch(index, value),
|
2022-08-09 02:16:33 +02:00
|
|
|
);
|
2022-08-18 16:33:33 +02:00
|
|
|
_items.add(item);
|
2022-08-09 03:30:12 +02:00
|
|
|
return item;
|
2022-08-09 02:16:33 +02:00
|
|
|
} else {
|
|
|
|
return const SizedBox();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2022-08-07 21:15:52 +02:00
|
|
|
}
|