feat: Patches Selector Screen.

This commit is contained in:
Aunali321 2022-08-08 00:45:52 +05:30
parent 645589fa0e
commit cceb7e6449
10 changed files with 191 additions and 22 deletions

View File

@ -1,6 +1,8 @@
import 'package:revanced_manager/services/patcher_api.dart';
import 'package:revanced_manager/ui/views/app_selector/app_selector_view.dart'; import 'package:revanced_manager/ui/views/app_selector/app_selector_view.dart';
import 'package:revanced_manager/ui/views/home/home_view.dart'; import 'package:revanced_manager/ui/views/home/home_view.dart';
import 'package:revanced_manager/ui/views/patcher/patcher_view.dart'; import 'package:revanced_manager/ui/views/patcher/patcher_view.dart';
import 'package:revanced_manager/ui/views/patches_selector/patches_selector_view.dart';
import 'package:stacked/stacked_annotations.dart'; import 'package:stacked/stacked_annotations.dart';
import 'package:stacked_services/stacked_services.dart'; import 'package:stacked_services/stacked_services.dart';
@ -8,7 +10,9 @@ import 'package:stacked_services/stacked_services.dart';
MaterialRoute(page: HomeView), MaterialRoute(page: HomeView),
MaterialRoute(page: AppSelectorView), MaterialRoute(page: AppSelectorView),
MaterialRoute(page: PatcherView), MaterialRoute(page: PatcherView),
MaterialRoute(page: PatchesSelectorView),
], dependencies: [ ], dependencies: [
LazySingleton(classType: NavigationService), LazySingleton(classType: NavigationService),
LazySingleton(classType: PatcherService),
]) ])
class AppSetup {} class AppSetup {}

View File

@ -6,11 +6,11 @@
// ignore_for_file: public_member_api_docs // ignore_for_file: public_member_api_docs
// ignore: depend_on_referenced_packages
import 'package:stacked_core/stacked_core.dart'; import 'package:stacked_core/stacked_core.dart';
// ignore: implementation_imports
import 'package:stacked_services/src/navigation/navigation_service.dart'; import 'package:stacked_services/src/navigation/navigation_service.dart';
import '../services/patcher_api.dart';
final locator = StackedLocator.instance; final locator = StackedLocator.instance;
Future<void> setupLocator( Future<void> setupLocator(
@ -21,4 +21,5 @@ Future<void> setupLocator(
// Register dependencies // Register dependencies
locator.registerLazySingleton(() => NavigationService()); locator.registerLazySingleton(() => NavigationService());
locator.registerLazySingleton(() => PatcherService());
} }

View File

@ -7,11 +7,12 @@
// ignore_for_file: no_leading_underscores_for_library_prefixes // ignore_for_file: no_leading_underscores_for_library_prefixes
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:stacked/stacked.dart' as _i1; import 'package:stacked/stacked.dart' as _i1;
import 'package:stacked_services/stacked_services.dart' as _i5; import 'package:stacked_services/stacked_services.dart' as _i6;
import '../ui/views/app_selector/app_selector_view.dart' as _i3; import '../ui/views/app_selector/app_selector_view.dart' as _i3;
import '../ui/views/home/home_view.dart' as _i2; import '../ui/views/home/home_view.dart' as _i2;
import '../ui/views/patcher/patcher_view.dart' as _i4; import '../ui/views/patcher/patcher_view.dart' as _i4;
import '../ui/views/patches_selector/patches_selector_view.dart' as _i5;
class Routes { class Routes {
static const homeView = '/home-view'; static const homeView = '/home-view';
@ -20,14 +21,22 @@ class Routes {
static const patcherView = '/patcher-view'; static const patcherView = '/patcher-view';
static const all = <String>{homeView, appSelectorView, patcherView}; static const patchesSelectorView = '/patches-selector-view';
static const all = <String>{
homeView,
appSelectorView,
patcherView,
patchesSelectorView
};
} }
class StackedRouter extends _i1.RouterBase { class StackedRouter extends _i1.RouterBase {
final _routes = <_i1.RouteDef>[ final _routes = <_i1.RouteDef>[
_i1.RouteDef(Routes.homeView, page: _i2.HomeView), _i1.RouteDef(Routes.homeView, page: _i2.HomeView),
_i1.RouteDef(Routes.appSelectorView, page: _i3.AppSelectorView), _i1.RouteDef(Routes.appSelectorView, page: _i3.AppSelectorView),
_i1.RouteDef(Routes.patcherView, page: _i4.PatcherView) _i1.RouteDef(Routes.patcherView, page: _i4.PatcherView),
_i1.RouteDef(Routes.patchesSelectorView, page: _i5.PatchesSelectorView)
]; ];
final _pagesMap = <Type, _i1.StackedRouteFactory>{ final _pagesMap = <Type, _i1.StackedRouteFactory>{
@ -48,6 +57,12 @@ class StackedRouter extends _i1.RouterBase {
builder: (context) => const _i4.PatcherView(), builder: (context) => const _i4.PatcherView(),
settings: data, settings: data,
); );
},
_i5.PatchesSelectorView: (data) {
return MaterialPageRoute<dynamic>(
builder: (context) => const _i5.PatchesSelectorView(),
settings: data,
);
} }
}; };
@ -57,7 +72,7 @@ class StackedRouter extends _i1.RouterBase {
Map<Type, _i1.StackedRouteFactory> get pagesMap => _pagesMap; Map<Type, _i1.StackedRouteFactory> get pagesMap => _pagesMap;
} }
extension NavigatorStateExtension on _i5.NavigationService { extension NavigatorStateExtension on _i6.NavigationService {
Future<dynamic> navigateToHomeView( Future<dynamic> navigateToHomeView(
[int? routerId, [int? routerId,
bool preventDuplicates = true, bool preventDuplicates = true,
@ -99,4 +114,18 @@ extension NavigatorStateExtension on _i5.NavigationService {
parameters: parameters, parameters: parameters,
transition: transition); transition: transition);
} }
Future<dynamic> navigateToPatchesSelectorView(
[int? routerId,
bool preventDuplicates = true,
Map<String, String>? parameters,
Widget Function(
BuildContext, Animation<double>, Animation<double>, Widget)?
transition]) async {
navigateTo(Routes.patchesSelectorView,
id: routerId,
preventDuplicates: preventDuplicates,
parameters: parameters,
transition: transition);
}
} }

View File

@ -39,6 +39,7 @@ class _AppSelectorViewState extends State<AppSelectorView> {
child: Column( child: Column(
children: [ children: [
SearchBar( SearchBar(
hintText: "Search applications",
onQueryChanged: (searchQuery) { onQueryChanged: (searchQuery) {
setState(() { setState(() {
query = searchQuery; query = searchQuery;

View File

@ -43,7 +43,9 @@ class PatcherView extends StatelessWidget {
onPressed: model.navigateToAppSelector, onPressed: model.navigateToAppSelector,
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
const PatchSelectorCard(), PatchSelectorCard(
onPressed: model.navigateToPatchesSelector,
),
], ],
), ),
), ),

View File

@ -4,9 +4,13 @@ import 'package:stacked/stacked.dart';
import 'package:stacked_services/stacked_services.dart'; import 'package:stacked_services/stacked_services.dart';
class PatcherViewModel extends BaseViewModel { class PatcherViewModel extends BaseViewModel {
final _naviagtionService = locator<NavigationService>(); final _navigationService = locator<NavigationService>();
void navigateToAppSelector() { void navigateToAppSelector() {
_naviagtionService.navigateTo(Routes.appSelectorView); _navigationService.navigateTo(Routes.appSelectorView);
}
void navigateToPatchesSelector() {
_navigationService.navigateTo(Routes.patchesSelectorView);
} }
} }

View 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(),
);
}
},
),
),
],
),
),
),
);
}
}

View File

@ -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);
}
}

View File

@ -1,11 +1,11 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
class PatchItem extends StatelessWidget { class PatchItem extends StatefulWidget {
final String name; final String name;
final String description; final String description;
final String version; final String version;
final bool isSelected; bool isSelected;
PatchItem({ PatchItem({
Key? key, Key? key,
@ -15,11 +15,16 @@ class PatchItem extends StatelessWidget {
required this.isSelected, required this.isSelected,
}) : super(key: key); }) : super(key: key);
@override
State<PatchItem> createState() => _PatchItemState();
}
class _PatchItemState extends State<PatchItem> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: const Color(0xFF1A1A1A), color: const Color(0xff1B222B),
borderRadius: BorderRadius.circular(10), borderRadius: BorderRadius.circular(10),
), ),
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 12), padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 12),
@ -37,19 +42,19 @@ class PatchItem extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.end,
children: [ children: [
Text( Text(
name, widget.name,
style: GoogleFonts.inter( style: GoogleFonts.inter(
fontSize: 16, fontSize: 16,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
), ),
), ),
const SizedBox(width: 4), const SizedBox(width: 4),
Text(version) Text(widget.version)
], ],
), ),
const SizedBox(height: 4), const SizedBox(height: 4),
Text( Text(
description, widget.description,
softWrap: true, softWrap: true,
maxLines: 3, maxLines: 3,
overflow: TextOverflow.visible, overflow: TextOverflow.visible,
@ -63,8 +68,13 @@ class PatchItem extends StatelessWidget {
Transform.scale( Transform.scale(
scale: 1.2, scale: 1.2,
child: Checkbox( child: Checkbox(
value: isSelected, value: widget.isSelected,
onChanged: (newValue) {}, activeColor: Colors.blueGrey[500],
onChanged: (newValue) {
setState(() {
widget.isSelected = newValue!;
});
},
), ),
) )
], ],

View File

@ -2,7 +2,14 @@ import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
class SearchBar extends StatefulWidget { 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, Key? key,
required this.onQueryChanged, required this.onQueryChanged,
}) : super(key: key); }) : super(key: key);
@ -19,9 +26,9 @@ class _SearchBarState extends State<SearchBar> {
return Container( return Container(
decoration: BoxDecoration( decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(12),
color: const Color(0xff1B222B), color: widget.backgroundColor,
border: Border.all( border: Border.all(
color: const Color(0xff1B222B), color: widget.backgroundColor != null ? widget.backgroundColor! : Colors.white,
width: 1, width: 1,
), ),
), ),
@ -34,9 +41,9 @@ class _SearchBarState extends State<SearchBar> {
fillColor: Colors.blueGrey[700], fillColor: Colors.blueGrey[700],
filled: true, filled: true,
contentPadding: const EdgeInsets.all(12.0), contentPadding: const EdgeInsets.all(12.0),
hintText: 'Search applications', hintText: widget.hintText,
hintStyle: GoogleFonts.poppins( hintStyle: GoogleFonts.poppins(
color: Colors.white, color: widget.hintTextColor,
fontWeight: FontWeight.w400, fontWeight: FontWeight.w400,
), ),
prefixIcon: const Icon( prefixIcon: const Icon(