mirror of
https://github.com/revanced/revanced-manager.git
synced 2025-06-12 04:37:37 +02:00
feat: add installer and enable app selection from storage (#2)
This commit is contained in:
@ -21,9 +21,19 @@ class _AppSelectorViewState extends State<AppSelectorView> {
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<AppSelectorViewModel>.reactive(
|
||||
disposeViewModel: false,
|
||||
onModelReady: (model) => model.initialise(),
|
||||
onModelReady: (model) => model.initialize(),
|
||||
viewModelBuilder: () => locator<AppSelectorViewModel>(),
|
||||
builder: (context, model, child) => Scaffold(
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () {
|
||||
model.selectAppFromStorage(context);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
label: I18nText('appSelectorView.fabButton'),
|
||||
icon: const Icon(Icons.sd_storage),
|
||||
backgroundColor: Theme.of(context).colorScheme.secondary,
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding:
|
||||
@ -71,16 +81,16 @@ class _AppSelectorViewState extends State<AppSelectorView> {
|
||||
child: ListView.builder(
|
||||
itemCount: model.apps.length,
|
||||
itemBuilder: (context, index) {
|
||||
model.apps.sort((a, b) => a.name!.compareTo(b.name!));
|
||||
model.apps.sort((a, b) => a.appName.compareTo(b.appName));
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
model.selectApp(model.apps[index]);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: InstalledAppItem(
|
||||
name: model.apps[index].name!,
|
||||
pkgName: model.apps[index].packageName!,
|
||||
icon: model.apps[index].icon!,
|
||||
name: model.apps[index].appName,
|
||||
pkgName: model.apps[index].packageName,
|
||||
icon: model.apps[index].icon,
|
||||
),
|
||||
);
|
||||
},
|
||||
@ -93,8 +103,8 @@ class _AppSelectorViewState extends State<AppSelectorView> {
|
||||
child: ListView.builder(
|
||||
itemCount: model.apps.length,
|
||||
itemBuilder: (context, index) {
|
||||
model.apps.sort((a, b) => a.name!.compareTo(b.name!));
|
||||
if (model.apps[index].name!.toLowerCase().contains(
|
||||
model.apps.sort((a, b) => a.appName.compareTo(b.appName));
|
||||
if (model.apps[index].appName.toLowerCase().contains(
|
||||
query.toLowerCase(),
|
||||
)) {
|
||||
return InkWell(
|
||||
@ -103,9 +113,9 @@ class _AppSelectorViewState extends State<AppSelectorView> {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: InstalledAppItem(
|
||||
name: model.apps[index].name!,
|
||||
pkgName: model.apps[index].packageName!,
|
||||
icon: model.apps[index].icon!,
|
||||
name: model.apps[index].appName,
|
||||
pkgName: model.apps[index].packageName,
|
||||
icon: model.apps[index].icon,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
|
@ -1,15 +1,22 @@
|
||||
import 'package:installed_apps/app_info.dart';
|
||||
import 'dart:io';
|
||||
import 'package:device_apps/device_apps.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_i18n/flutter_i18n.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import 'package:package_archive_info/package_archive_info.dart';
|
||||
import 'package:revanced_manager/app/app.locator.dart';
|
||||
import 'package:revanced_manager/models/application_info.dart';
|
||||
import 'package:revanced_manager/services/patcher_api.dart';
|
||||
import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
|
||||
class AppSelectorViewModel extends BaseViewModel {
|
||||
final PatcherAPI patcherAPI = locator<PatcherAPI>();
|
||||
List<AppInfo> apps = [];
|
||||
AppInfo? selectedApp;
|
||||
List<ApplicationWithIcon> apps = [];
|
||||
ApplicationInfo? selectedApp;
|
||||
|
||||
Future<void> initialise() async {
|
||||
Future<void> initialize() async {
|
||||
await getApps();
|
||||
notifyListeners();
|
||||
}
|
||||
@ -19,9 +26,47 @@ class AppSelectorViewModel extends BaseViewModel {
|
||||
apps = await patcherAPI.getFilteredInstalledApps();
|
||||
}
|
||||
|
||||
void selectApp(AppInfo appInfo) {
|
||||
locator<AppSelectorViewModel>().selectedApp = appInfo;
|
||||
void selectApp(ApplicationWithIcon application) {
|
||||
ApplicationInfo app = ApplicationInfo(
|
||||
name: application.appName,
|
||||
packageName: application.packageName,
|
||||
version: application.versionName!,
|
||||
apkFilePath: application.apkFilePath,
|
||||
);
|
||||
locator<AppSelectorViewModel>().selectedApp = app;
|
||||
locator<PatcherViewModel>().dimPatchCard = false;
|
||||
locator<PatcherViewModel>().notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> selectAppFromStorage(BuildContext context) async {
|
||||
try {
|
||||
FilePickerResult? result = await FilePicker.platform.pickFiles(
|
||||
type: FileType.custom,
|
||||
allowedExtensions: ['apk'],
|
||||
);
|
||||
if (result != null && result.files.single.path != null) {
|
||||
File apkFile = File(result.files.single.path!);
|
||||
PackageArchiveInfo? packageArchiveInfo =
|
||||
await PackageArchiveInfo.fromPath(apkFile.path);
|
||||
ApplicationInfo app = ApplicationInfo(
|
||||
name: packageArchiveInfo.appName,
|
||||
packageName: packageArchiveInfo.packageName,
|
||||
version: packageArchiveInfo.version,
|
||||
apkFilePath: result.files.single.path!,
|
||||
);
|
||||
locator<AppSelectorViewModel>().selectedApp = app;
|
||||
locator<PatcherViewModel>().dimPatchCard = false;
|
||||
locator<PatcherViewModel>().notifyListeners();
|
||||
}
|
||||
} on Exception {
|
||||
Fluttertoast.showToast(
|
||||
msg: FlutterI18n.translate(
|
||||
context,
|
||||
'appSelectorView.errorMessage',
|
||||
),
|
||||
toastLength: Toast.LENGTH_LONG,
|
||||
gravity: ToastGravity.CENTER,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user