mirror of
https://github.com/ReVanced/revanced-manager.git
synced 2026-01-29 05:41:04 +00:00
feat: working app selector.
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_i18n/flutter_i18n.dart';
|
||||
import 'package:installed_apps/app_info.dart';
|
||||
import 'package:installed_apps/installed_apps.dart';
|
||||
import 'package:revanced_manager/app/app.locator.dart';
|
||||
import 'package:revanced_manager/services/patcher_api.dart';
|
||||
import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart';
|
||||
import 'package:revanced_manager/ui/widgets/installed_app_item.dart';
|
||||
import 'package:revanced_manager/ui/widgets/search_bar.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
@@ -15,23 +16,13 @@ class AppSelectorView extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _AppSelectorViewState extends State<AppSelectorView> {
|
||||
List<AppInfo> apps = [];
|
||||
final PatcherService patcherService = locator<PatcherService>();
|
||||
String query = '';
|
||||
|
||||
void getApps() async {
|
||||
apps = await InstalledApps.getInstalledApps(false, true);
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
getApps();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder.reactive(
|
||||
return ViewModelBuilder<AppSelectorViewModel>.reactive(
|
||||
onModelReady: (model) => model.initialise(),
|
||||
builder: (context, model, child) => Scaffold(
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
@@ -51,41 +42,53 @@ class _AppSelectorViewState extends State<AppSelectorView> {
|
||||
},
|
||||
),
|
||||
if (query.isEmpty || query.length < 2)
|
||||
apps.isEmpty
|
||||
model.apps.isEmpty
|
||||
? const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
)
|
||||
: Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: apps.length,
|
||||
itemCount: model.apps.length,
|
||||
itemBuilder: (context, index) {
|
||||
//sort alphabetically
|
||||
apps.sort((a, b) => a.name!.compareTo(b.name!));
|
||||
return InstalledAppItem(
|
||||
name: apps[index].name!,
|
||||
pkgName: apps[index].packageName!,
|
||||
icon: apps[index].icon!,
|
||||
model.apps
|
||||
.sort((a, b) => a.name!.compareTo(b.name!));
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
patcherService.setSelectedApp(
|
||||
model.apps[index].packageName!);
|
||||
Navigator.of(context).pop();
|
||||
locator<PatcherViewModel>().notifyListeners();
|
||||
},
|
||||
child: InstalledAppItem(
|
||||
name: model.apps[index].name!,
|
||||
pkgName: model.apps[index].packageName!,
|
||||
icon: model.apps[index].icon!,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
if (query.isNotEmpty)
|
||||
apps.isEmpty
|
||||
model.apps.isEmpty
|
||||
? Center(
|
||||
child: I18nText('appSelectorCard.noAppsLabel'),
|
||||
)
|
||||
: Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: apps.length,
|
||||
itemCount: model.apps.length,
|
||||
itemBuilder: (context, index) {
|
||||
apps.sort((a, b) => a.name!.compareTo(b.name!));
|
||||
if (apps[index].name!.toLowerCase().contains(
|
||||
model.apps
|
||||
.sort((a, b) => a.name!.compareTo(b.name!));
|
||||
if (model.apps[index].name!
|
||||
.toLowerCase()
|
||||
.contains(
|
||||
query.toLowerCase(),
|
||||
)) {
|
||||
return InstalledAppItem(
|
||||
name: apps[index].name!,
|
||||
pkgName: apps[index].packageName!,
|
||||
icon: apps[index].icon!,
|
||||
name: model.apps[index].name!,
|
||||
pkgName: model.apps[index].packageName!,
|
||||
icon: model.apps[index].icon!,
|
||||
);
|
||||
} else {
|
||||
return const SizedBox();
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
import 'package:installed_apps/app_info.dart';
|
||||
import 'package:installed_apps/installed_apps.dart';
|
||||
import 'package:revanced_manager/app/app.locator.dart';
|
||||
import 'package:revanced_manager/services/patcher_api.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
|
||||
class AppSelectorViewModel extends BaseViewModel {
|
||||
final PatcherService patcherService = locator<PatcherService>();
|
||||
List<AppInfo> apps = [];
|
||||
String query = '';
|
||||
|
||||
void initialization() {
|
||||
getApps();
|
||||
Future<void> initialise() async {
|
||||
await getApps();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void getApps() async {
|
||||
apps = await InstalledApps.getInstalledApps(false, true);
|
||||
Future<void> getApps() async {
|
||||
await patcherService.loadPatches();
|
||||
apps = await patcherService.getFilteredInstalledApps();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_i18n/flutter_i18n.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:revanced_manager/ui/views/home/home_viewmodel.dart';
|
||||
import 'package:revanced_manager/ui/widgets/available_updates_card.dart';
|
||||
import 'package:revanced_manager/ui/widgets/installed_apps_card.dart';
|
||||
import 'package:revanced_manager/ui/widgets/latest_commit_card.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
import 'home_viewmodel.dart';
|
||||
|
||||
class HomeView extends StatelessWidget {
|
||||
const HomeView({Key? key}) : super(key: key);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_i18n/flutter_i18n.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:revanced_manager/app/app.locator.dart';
|
||||
import 'package:revanced_manager/ui/widgets/app_selector_card.dart';
|
||||
import 'package:revanced_manager/ui/widgets/patch_selector_card.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
@@ -12,8 +13,8 @@ class PatcherView extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder.reactive(
|
||||
builder: (context, PatcherViewModel model, child) => Scaffold(
|
||||
return ViewModelBuilder<PatcherViewModel>.reactive(
|
||||
builder: (context, model, child) => Scaffold(
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () {},
|
||||
child: const Icon(
|
||||
@@ -51,7 +52,7 @@ class PatcherView extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
viewModelBuilder: () => PatcherViewModel(),
|
||||
viewModelBuilder: () => locator<PatcherViewModel>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,9 +18,9 @@ class _PatchesSelectorViewState extends State<PatchesSelectorView> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder.reactive(
|
||||
return ViewModelBuilder<PatchesSelectorViewModel>.reactive(
|
||||
viewModelBuilder: () => PatchesSelectorViewModel(),
|
||||
builder: (context, PatchesSelectorViewModel model, child) => Scaffold(
|
||||
builder: (context, model, child) => Scaffold(
|
||||
body: Container(
|
||||
margin: const EdgeInsets.fromLTRB(6.0, 26.0, 6.0, 0),
|
||||
child: Column(
|
||||
|
||||
@@ -1,23 +1,21 @@
|
||||
import 'package:installed_apps/app_info.dart';
|
||||
import 'package:installed_apps/installed_apps.dart';
|
||||
import 'package:revanced_manager/app/app.locator.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 = [];
|
||||
final PatcherService patcherService = locator<PatcherService>();
|
||||
AppInfo? appInfo;
|
||||
|
||||
Future<void> getApp() async {
|
||||
AppInfo app = await InstalledApps.getAppInfo("com.google.android.youtube");
|
||||
appInfo = app;
|
||||
}
|
||||
Future<List<Patch>?>? getPatches() async {
|
||||
|
||||
Future<List<Patch>?> getPatches() async {
|
||||
getApp();
|
||||
PatcherService patcherService = PatcherService();
|
||||
patcherService.loadPatches();
|
||||
return patcherService.getFilteredPatches(appInfo);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user