mirror of
https://github.com/revanced/revanced-manager.git
synced 2025-06-12 04:37:37 +02:00
feat: Patches Selector Screen.
This commit is contained in:
@ -39,6 +39,7 @@ class _AppSelectorViewState extends State<AppSelectorView> {
|
||||
child: Column(
|
||||
children: [
|
||||
SearchBar(
|
||||
hintText: "Search applications",
|
||||
onQueryChanged: (searchQuery) {
|
||||
setState(() {
|
||||
query = searchQuery;
|
||||
|
@ -43,7 +43,9 @@ class PatcherView extends StatelessWidget {
|
||||
onPressed: model.navigateToAppSelector,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const PatchSelectorCard(),
|
||||
PatchSelectorCard(
|
||||
onPressed: model.navigateToPatchesSelector,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -4,9 +4,13 @@ import 'package:stacked/stacked.dart';
|
||||
import 'package:stacked_services/stacked_services.dart';
|
||||
|
||||
class PatcherViewModel extends BaseViewModel {
|
||||
final _naviagtionService = locator<NavigationService>();
|
||||
final _navigationService = locator<NavigationService>();
|
||||
|
||||
void navigateToAppSelector() {
|
||||
_naviagtionService.navigateTo(Routes.appSelectorView);
|
||||
_navigationService.navigateTo(Routes.appSelectorView);
|
||||
}
|
||||
|
||||
void navigateToPatchesSelector() {
|
||||
_navigationService.navigateTo(Routes.patchesSelectorView);
|
||||
}
|
||||
}
|
||||
|
88
lib/ui/views/patches_selector/patches_selector_view.dart
Normal file
88
lib/ui/views/patches_selector/patches_selector_view.dart
Normal file
@ -0,0 +1,88 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:revanced_manager/models/patch.dart';
|
||||
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> {
|
||||
String query = '';
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder.reactive(
|
||||
viewModelBuilder: () => PatchesSelectorViewModel(),
|
||||
builder: (context, PatchesSelectorViewModel model, child) => Scaffold(
|
||||
body: Container(
|
||||
margin: const EdgeInsets.fromLTRB(6.0, 26.0, 6.0, 0),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8.0, left: 8.0, right: 8.0),
|
||||
child: SearchBar(
|
||||
hintText: "Search patches",
|
||||
onQueryChanged: (searchQuery) {
|
||||
setState(
|
||||
() {
|
||||
query = searchQuery;
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: FutureBuilder<List<Patch>?>(
|
||||
future: model.getPatches(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
return ListView.builder(
|
||||
itemCount: snapshot.data!.length,
|
||||
itemBuilder: (context, index) {
|
||||
if (query.isEmpty ||
|
||||
query.length < 2) {
|
||||
return PatchItem(
|
||||
name: snapshot.data![index].simpleName,
|
||||
version: snapshot.data![index].version,
|
||||
description: snapshot.data![index].description,
|
||||
isSelected: false,
|
||||
);
|
||||
}
|
||||
else if(query.isNotEmpty &&
|
||||
query.length >= 2 &&
|
||||
snapshot.data![index].simpleName.toLowerCase().contains(query.toLowerCase())) {
|
||||
return PatchItem(
|
||||
name: snapshot.data![index].simpleName,
|
||||
version: snapshot.data![index].version,
|
||||
description: snapshot.data![index].description,
|
||||
isSelected: false,
|
||||
);
|
||||
}
|
||||
else {return Container();}
|
||||
|
||||
},
|
||||
);
|
||||
} else if (snapshot.hasError) {
|
||||
return Text("${snapshot.error}");
|
||||
} else {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
import 'package:installed_apps/app_info.dart';
|
||||
import 'package:installed_apps/installed_apps.dart';
|
||||
import 'package:revanced_manager/models/patch.dart';
|
||||
import 'package:revanced_manager/services/patcher_api.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
|
||||
class PatchesSelectorViewModel extends BaseViewModel {
|
||||
PatcherService patcherService = PatcherService();
|
||||
List<Patch>? patches = [];
|
||||
AppInfo? appInfo;
|
||||
|
||||
Future<void> getApp() async {
|
||||
AppInfo app = await InstalledApps.getAppInfo("com.google.android.youtube");
|
||||
appInfo = app;
|
||||
}
|
||||
Future<List<Patch>?>? getPatches() async {
|
||||
getApp();
|
||||
PatcherService patcherService = PatcherService();
|
||||
patcherService.loadPatches();
|
||||
return patcherService.getFilteredPatches(appInfo);
|
||||
}
|
||||
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
|
||||
class PatchItem extends StatelessWidget {
|
||||
class PatchItem extends StatefulWidget {
|
||||
final String name;
|
||||
final String description;
|
||||
final String version;
|
||||
final bool isSelected;
|
||||
bool isSelected;
|
||||
|
||||
PatchItem({
|
||||
Key? key,
|
||||
@ -15,11 +15,16 @@ class PatchItem extends StatelessWidget {
|
||||
required this.isSelected,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<PatchItem> createState() => _PatchItemState();
|
||||
}
|
||||
|
||||
class _PatchItemState extends State<PatchItem> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF1A1A1A),
|
||||
color: const Color(0xff1B222B),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 12),
|
||||
@ -37,19 +42,19 @@ class PatchItem extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
name,
|
||||
widget.name,
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(version)
|
||||
Text(widget.version)
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
description,
|
||||
widget.description,
|
||||
softWrap: true,
|
||||
maxLines: 3,
|
||||
overflow: TextOverflow.visible,
|
||||
@ -63,8 +68,13 @@ class PatchItem extends StatelessWidget {
|
||||
Transform.scale(
|
||||
scale: 1.2,
|
||||
child: Checkbox(
|
||||
value: isSelected,
|
||||
onChanged: (newValue) {},
|
||||
value: widget.isSelected,
|
||||
activeColor: Colors.blueGrey[500],
|
||||
onChanged: (newValue) {
|
||||
setState(() {
|
||||
widget.isSelected = newValue!;
|
||||
});
|
||||
},
|
||||
),
|
||||
)
|
||||
],
|
||||
|
@ -2,7 +2,14 @@ import 'package:flutter/material.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
|
||||
class SearchBar extends StatefulWidget {
|
||||
const SearchBar({
|
||||
String? hintText = "Search";
|
||||
Color? backgroundColor;
|
||||
Color? hintTextColor;
|
||||
|
||||
SearchBar({
|
||||
required this.hintText,
|
||||
this.backgroundColor = const Color(0xff1B222B),
|
||||
this.hintTextColor = Colors.white,
|
||||
Key? key,
|
||||
required this.onQueryChanged,
|
||||
}) : super(key: key);
|
||||
@ -19,9 +26,9 @@ class _SearchBarState extends State<SearchBar> {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
color: const Color(0xff1B222B),
|
||||
color: widget.backgroundColor,
|
||||
border: Border.all(
|
||||
color: const Color(0xff1B222B),
|
||||
color: widget.backgroundColor != null ? widget.backgroundColor! : Colors.white,
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
@ -34,9 +41,9 @@ class _SearchBarState extends State<SearchBar> {
|
||||
fillColor: Colors.blueGrey[700],
|
||||
filled: true,
|
||||
contentPadding: const EdgeInsets.all(12.0),
|
||||
hintText: 'Search applications',
|
||||
hintText: widget.hintText,
|
||||
hintStyle: GoogleFonts.poppins(
|
||||
color: Colors.white,
|
||||
color: widget.hintTextColor,
|
||||
fontWeight: FontWeight.w400,
|
||||
),
|
||||
prefixIcon: const Icon(
|
||||
|
Reference in New Issue
Block a user