mirror of
https://github.com/revanced/revanced-manager.git
synced 2025-06-12 04:37:37 +02:00
feat: working patches selector and improve app selector.
This commit is contained in:
@ -1,8 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_i18n/flutter_i18n.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';
|
||||
@ -16,92 +14,101 @@ class AppSelectorView extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _AppSelectorViewState extends State<AppSelectorView> {
|
||||
final PatcherService patcherService = locator<PatcherService>();
|
||||
String query = '';
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<AppSelectorViewModel>.reactive(
|
||||
disposeViewModel: false,
|
||||
onModelReady: (model) => model.initialise(),
|
||||
viewModelBuilder: () => locator<AppSelectorViewModel>(),
|
||||
builder: (context, model, child) => Scaffold(
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(vertical: 4.0, horizontal: 12.0),
|
||||
child: Column(
|
||||
children: [
|
||||
SearchBar(
|
||||
hintText: FlutterI18n.translate(
|
||||
context,
|
||||
'appSelectorView.searchBarHint',
|
||||
),
|
||||
onQueryChanged: (searchQuery) {
|
||||
setState(() {
|
||||
query = searchQuery;
|
||||
});
|
||||
},
|
||||
),
|
||||
if (query.isEmpty || query.length < 2)
|
||||
model.apps.isEmpty
|
||||
? const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
)
|
||||
: Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: model.apps.length,
|
||||
itemBuilder: (context, index) {
|
||||
//sort alphabetically
|
||||
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!,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
child: model.apps.isNotEmpty
|
||||
? Column(
|
||||
children: [
|
||||
SearchBar(
|
||||
hintText: FlutterI18n.translate(
|
||||
context,
|
||||
'appSelectorView.searchBarHint',
|
||||
),
|
||||
if (query.isNotEmpty)
|
||||
model.apps.isEmpty
|
||||
? Center(
|
||||
child: I18nText('appSelectorCard.noAppsLabel'),
|
||||
)
|
||||
: Expanded(
|
||||
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(
|
||||
query.toLowerCase(),
|
||||
)) {
|
||||
return InstalledAppItem(
|
||||
name: model.apps[index].name!,
|
||||
pkgName: model.apps[index].packageName!,
|
||||
icon: model.apps[index].icon!,
|
||||
);
|
||||
} else {
|
||||
return const SizedBox();
|
||||
}
|
||||
},
|
||||
),
|
||||
onQueryChanged: (searchQuery) {
|
||||
setState(() {
|
||||
query = searchQuery;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
query.isEmpty || query.length < 2
|
||||
? _getAllResults(model)
|
||||
: _getFilteredResults(model)
|
||||
],
|
||||
)
|
||||
: query.isEmpty || query.length < 2
|
||||
? const Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: Color(0xff7792BA),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: Center(
|
||||
child: I18nText('appSelectorCard.noAppsLabel'),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
viewModelBuilder: () => AppSelectorViewModel(),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _getAllResults(AppSelectorViewModel model) {
|
||||
return Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: model.apps.length,
|
||||
itemBuilder: (context, index) {
|
||||
model.apps.sort((a, b) => a.name!.compareTo(b.name!));
|
||||
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!,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _getFilteredResults(AppSelectorViewModel model) {
|
||||
return Expanded(
|
||||
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(
|
||||
query.toLowerCase(),
|
||||
)) {
|
||||
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!,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return const SizedBox();
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
import 'package:installed_apps/app_info.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:stacked/stacked.dart';
|
||||
|
||||
class AppSelectorViewModel extends BaseViewModel {
|
||||
final PatcherService patcherService = locator<PatcherService>();
|
||||
List<AppInfo> apps = [];
|
||||
String query = '';
|
||||
AppInfo? selectedApp;
|
||||
|
||||
Future<void> initialise() async {
|
||||
await getApps();
|
||||
@ -17,4 +18,9 @@ class AppSelectorViewModel extends BaseViewModel {
|
||||
await patcherService.loadPatches();
|
||||
apps = await patcherService.getFilteredInstalledApps();
|
||||
}
|
||||
|
||||
void selectApp(AppInfo appInfo) {
|
||||
locator<AppSelectorViewModel>().selectedApp = appInfo;
|
||||
locator<PatcherViewModel>().notifyListeners();
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ class HomeView extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder.reactive(
|
||||
viewModelBuilder: () => HomeViewModel(),
|
||||
builder: (context, model, child) => Scaffold(
|
||||
body: SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
@ -24,7 +25,7 @@ class HomeView extends StatelessWidget {
|
||||
Align(
|
||||
alignment: Alignment.topRight,
|
||||
child: IconButton(
|
||||
onPressed: () {},
|
||||
onPressed: () => {},
|
||||
icon: const Icon(
|
||||
Icons.more_vert,
|
||||
),
|
||||
@ -72,7 +73,6 @@ class HomeView extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
viewModelBuilder: () => HomeViewModel(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -14,13 +14,15 @@ class PatcherView extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<PatcherViewModel>.reactive(
|
||||
disposeViewModel: false,
|
||||
viewModelBuilder: () => locator<PatcherViewModel>(),
|
||||
builder: (context, model, child) => Scaffold(
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () {},
|
||||
child: const Icon(
|
||||
Icons.build,
|
||||
color: Colors.white,
|
||||
),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () => {},
|
||||
label: I18nText('patcherView.fabButton'),
|
||||
icon: const Icon(Icons.build),
|
||||
backgroundColor: const Color(0xff7792BA),
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
@ -52,7 +54,6 @@ class PatcherView extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
viewModelBuilder: () => locator<PatcherViewModel>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_i18n/flutter_i18n.dart';
|
||||
import 'package:revanced_manager/models/patch.dart';
|
||||
import 'package:revanced_manager/app/app.locator.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';
|
||||
@ -19,74 +19,89 @@ class _PatchesSelectorViewState extends State<PatchesSelectorView> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ViewModelBuilder<PatchesSelectorViewModel>.reactive(
|
||||
viewModelBuilder: () => PatchesSelectorViewModel(),
|
||||
disposeViewModel: false,
|
||||
onModelReady: (model) => model.initialise(),
|
||||
viewModelBuilder: () => locator<PatchesSelectorViewModel>(),
|
||||
builder: (context, 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: FlutterI18n.translate(
|
||||
context,
|
||||
'patchesSelectorView.searchBarHint',
|
||||
),
|
||||
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();
|
||||
}
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () => {},
|
||||
label: I18nText('patchesSelectorView.fabButton'),
|
||||
icon: const Icon(Icons.check),
|
||||
backgroundColor: const Color(0xff7792BA),
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(vertical: 4.0, horizontal: 12.0),
|
||||
child: model.patches != null && model.patches!.isNotEmpty
|
||||
? Column(
|
||||
children: [
|
||||
SearchBar(
|
||||
hintText: FlutterI18n.translate(
|
||||
context,
|
||||
'patchesSelectorView.searchBarHint',
|
||||
),
|
||||
onQueryChanged: (searchQuery) {
|
||||
setState(() {
|
||||
query = searchQuery;
|
||||
});
|
||||
},
|
||||
);
|
||||
} else if (snapshot.hasError) {
|
||||
return Text("${snapshot.error}");
|
||||
} else {
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
query.isEmpty || query.length < 2
|
||||
? _getAllResults(model)
|
||||
: _getFilteredResults(model)
|
||||
],
|
||||
)
|
||||
: const Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: Color(0xff7792BA),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _getAllResults(PatchesSelectorViewModel model) {
|
||||
return Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: model.patches!.length,
|
||||
itemBuilder: (context, index) {
|
||||
model.patches!.sort((a, b) => a.simpleName.compareTo(b.simpleName));
|
||||
return PatchItem(
|
||||
name: model.patches![index].simpleName,
|
||||
version: model.patches![index].version,
|
||||
description: model.patches![index].description,
|
||||
isSelected: false,
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _getFilteredResults(PatchesSelectorViewModel model) {
|
||||
return Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: model.patches!.length,
|
||||
itemBuilder: (context, index) {
|
||||
model.patches!.sort((a, b) => a.simpleName.compareTo(b.simpleName));
|
||||
if (model.patches![index].simpleName.toLowerCase().contains(
|
||||
query.toLowerCase(),
|
||||
)) {
|
||||
return PatchItem(
|
||||
name: model.patches![index].simpleName,
|
||||
version: model.patches![index].version,
|
||||
description: model.patches![index].description,
|
||||
isSelected: false,
|
||||
);
|
||||
} else {
|
||||
return const SizedBox();
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +1,24 @@
|
||||
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:revanced_manager/ui/views/app_selector/app_selector_viewmodel.dart';
|
||||
import 'package:stacked/stacked.dart';
|
||||
|
||||
class PatchesSelectorViewModel extends BaseViewModel {
|
||||
final PatcherService patcherService = locator<PatcherService>();
|
||||
AppInfo? appInfo;
|
||||
List<Patch>? patches = [];
|
||||
List<Patch> selectedPatches = [];
|
||||
|
||||
Future<void> getApp() async {
|
||||
AppInfo app = await InstalledApps.getAppInfo("com.google.android.youtube");
|
||||
appInfo = app;
|
||||
Future<void> initialise() async {
|
||||
await getPatches();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<List<Patch>?> getPatches() async {
|
||||
getApp();
|
||||
return patcherService.getFilteredPatches(appInfo);
|
||||
Future<void> getPatches() async {
|
||||
AppInfo? appInfo = locator<AppSelectorViewModel>().selectedApp;
|
||||
patches = await patcherService.getFilteredPatches(appInfo);
|
||||
}
|
||||
|
||||
void selectPatches(List<Patch> patches) {}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import 'package:google_fonts/google_fonts.dart';
|
||||
import 'package:revanced_manager/app/app.locator.dart';
|
||||
import 'package:revanced_manager/constants.dart';
|
||||
import 'package:revanced_manager/services/patcher_api.dart';
|
||||
import 'package:revanced_manager/ui/views/app_selector/app_selector_viewmodel.dart';
|
||||
|
||||
class AppSelectorCard extends StatelessWidget {
|
||||
final Function()? onPressed;
|
||||
@ -39,9 +40,9 @@ class AppSelectorCard extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
patcherService.getSelectedApp().isNotEmpty
|
||||
locator<AppSelectorViewModel>().selectedApp != null
|
||||
? Text(
|
||||
patcherService.getSelectedApp(),
|
||||
locator<AppSelectorViewModel>().selectedApp!.packageName!,
|
||||
style: robotoTextStyle,
|
||||
)
|
||||
: I18nText(
|
||||
|
@ -38,7 +38,7 @@ class AvailableUpdatesCard extends StatelessWidget {
|
||||
context,
|
||||
'availableUpdatesCard.patchButton',
|
||||
),
|
||||
onPressed: () {},
|
||||
onPressed: () => {},
|
||||
backgroundColor: const Color(0xff7792BA),
|
||||
),
|
||||
],
|
||||
@ -47,13 +47,13 @@ class AvailableUpdatesCard extends StatelessWidget {
|
||||
asset: 'assets/images/revanced.svg',
|
||||
name: 'ReVanced',
|
||||
releaseDate: '2 days ago',
|
||||
onPressed: () {},
|
||||
onPressed: () => {},
|
||||
),
|
||||
ApplicationItem(
|
||||
asset: 'assets/images/reddit.png',
|
||||
name: 'ReReddit',
|
||||
releaseDate: 'Released 1 month ago',
|
||||
onPressed: () {},
|
||||
onPressed: () => {},
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
I18nText(
|
||||
|
@ -33,7 +33,7 @@ class InstalledAppsCard extends StatelessWidget {
|
||||
asset: 'assets/images/revanced.svg',
|
||||
name: 'ReVanced',
|
||||
releaseDate: '2 days ago',
|
||||
onPressed: () {},
|
||||
onPressed: () => {},
|
||||
),
|
||||
I18nText(
|
||||
'installedAppsCard.changelogLabel',
|
||||
|
@ -90,7 +90,7 @@ class _LatestCommitCardState extends State<LatestCommitCard> {
|
||||
context,
|
||||
'latestCommitCard.updateButton',
|
||||
),
|
||||
onPressed: () {},
|
||||
onPressed: () => {},
|
||||
backgroundColor: const Color(0xff7792BA),
|
||||
),
|
||||
],
|
||||
|
Reference in New Issue
Block a user