mirror of
https://github.com/revanced/revanced-manager.git
synced 2025-06-12 04:37:37 +02:00
fix: improve app and patches loaders
This commit is contained in:
@ -36,92 +36,59 @@ class _AppSelectorViewState extends State<AppSelectorView> {
|
||||
child: Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(vertical: 4.0, horizontal: 12.0),
|
||||
child: model.apps.isNotEmpty
|
||||
? Column(
|
||||
children: [
|
||||
SearchBar(
|
||||
showSelectIcon: false,
|
||||
fillColor:
|
||||
isDark ? const Color(0xff1B222B) : Colors.grey[200],
|
||||
hintText: FlutterI18n.translate(
|
||||
context,
|
||||
'appSelectorView.searchBarHint',
|
||||
),
|
||||
hintTextColor: Theme.of(context).colorScheme.tertiary,
|
||||
onQueryChanged: (searchQuery) {
|
||||
setState(() {
|
||||
_query = searchQuery;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_query.isEmpty || _query.length < 2
|
||||
? _getAllResults(model)
|
||||
: _getFilteredResults(model)
|
||||
],
|
||||
child: model.noApps
|
||||
? Center(
|
||||
child: I18nText('appSelectorCard.noAppsLabel'),
|
||||
)
|
||||
: _query.isEmpty || _query.length < 2
|
||||
: model.apps.isEmpty
|
||||
? Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: Theme.of(context).colorScheme.secondary,
|
||||
),
|
||||
)
|
||||
: Center(
|
||||
child: I18nText('appSelectorCard.noAppsLabel'),
|
||||
: Column(
|
||||
children: [
|
||||
SearchBar(
|
||||
showSelectIcon: false,
|
||||
fillColor: isDark
|
||||
? const Color(0xff1B222B)
|
||||
: Colors.grey[200],
|
||||
hintText: FlutterI18n.translate(
|
||||
context,
|
||||
'appSelectorView.searchBarHint',
|
||||
),
|
||||
hintTextColor:
|
||||
Theme.of(context).colorScheme.tertiary,
|
||||
onQueryChanged: (searchQuery) {
|
||||
setState(() {
|
||||
_query = searchQuery;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: model
|
||||
.getFilteredApps(_query)
|
||||
.map((app) => InkWell(
|
||||
onTap: () {
|
||||
model.selectApp(app);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: InstalledAppItem(
|
||||
name: app.appName,
|
||||
pkgName: app.packageName,
|
||||
icon: app.icon,
|
||||
),
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _getAllResults(AppSelectorViewModel model) {
|
||||
return Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: model.apps.length,
|
||||
itemBuilder: (context, index) {
|
||||
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].appName,
|
||||
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.appName.compareTo(b.appName));
|
||||
if (model.apps[index].appName.toLowerCase().contains(
|
||||
_query.toLowerCase(),
|
||||
)) {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
model.selectApp(model.apps[index]);
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: InstalledAppItem(
|
||||
name: model.apps[index].appName,
|
||||
pkgName: model.apps[index].packageName,
|
||||
icon: model.apps[index].icon,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return const SizedBox();
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -14,17 +14,20 @@ import 'package:stacked/stacked.dart';
|
||||
class AppSelectorViewModel extends BaseViewModel {
|
||||
final PatcherAPI _patcherAPI = locator<PatcherAPI>();
|
||||
final List<ApplicationWithIcon> apps = [];
|
||||
bool noApps = false;
|
||||
bool _isRooted = false;
|
||||
|
||||
Future<void> initialize() async {
|
||||
apps.addAll(await _patcherAPI.getFilteredInstalledApps());
|
||||
apps.sort((a, b) => a.appName.compareTo(b.appName));
|
||||
noApps = apps.isEmpty;
|
||||
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
_isRooted = prefs.getBool('isRooted') ?? false;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void selectApp(ApplicationWithIcon application) async {
|
||||
PatchedApplication app = PatchedApplication(
|
||||
locator<PatcherViewModel>().selectedApp = PatchedApplication(
|
||||
name: application.appName,
|
||||
packageName: application.packageName,
|
||||
version: application.versionName!,
|
||||
@ -35,7 +38,6 @@ class AppSelectorViewModel extends BaseViewModel {
|
||||
isFromStorage: false,
|
||||
appliedPatches: [],
|
||||
);
|
||||
locator<PatcherViewModel>().selectedApp = app;
|
||||
locator<PatcherViewModel>().selectedPatches.clear();
|
||||
locator<PatcherViewModel>().notifyListeners();
|
||||
}
|
||||
@ -52,7 +54,7 @@ class AppSelectorViewModel extends BaseViewModel {
|
||||
await DeviceApps.getAppFromStorage(apkFile.path, true)
|
||||
as ApplicationWithIcon?;
|
||||
if (application != null) {
|
||||
PatchedApplication app = PatchedApplication(
|
||||
locator<PatcherViewModel>().selectedApp = PatchedApplication(
|
||||
name: application.appName,
|
||||
packageName: application.packageName,
|
||||
version: application.versionName!,
|
||||
@ -63,7 +65,6 @@ class AppSelectorViewModel extends BaseViewModel {
|
||||
isFromStorage: true,
|
||||
appliedPatches: [],
|
||||
);
|
||||
locator<PatcherViewModel>().selectedApp = app;
|
||||
locator<PatcherViewModel>().selectedPatches.clear();
|
||||
locator<PatcherViewModel>().notifyListeners();
|
||||
}
|
||||
@ -79,4 +80,13 @@ class AppSelectorViewModel extends BaseViewModel {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
List<ApplicationWithIcon> getFilteredApps(String query) {
|
||||
return apps
|
||||
.where((app) =>
|
||||
query.isEmpty ||
|
||||
query.length < 2 ||
|
||||
app.appName.toLowerCase().contains(query.toLowerCase()))
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user