2023-07-15 03:11:51 +02:00
|
|
|
import 'package:device_apps/device_apps.dart';
|
2022-07-31 21:46:27 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-08-16 15:06:56 +02:00
|
|
|
import 'package:revanced_manager/app/app.locator.dart';
|
2024-02-12 00:22:25 +01:00
|
|
|
import 'package:revanced_manager/gen/strings.g.dart';
|
2022-08-30 03:07:28 +02:00
|
|
|
import 'package:revanced_manager/models/patched_application.dart';
|
2023-07-15 03:11:51 +02:00
|
|
|
import 'package:revanced_manager/services/manager_api.dart';
|
2022-08-16 15:06:56 +02:00
|
|
|
import 'package:revanced_manager/ui/views/home/home_viewmodel.dart';
|
2022-08-21 12:47:44 +02:00
|
|
|
import 'package:revanced_manager/ui/widgets/shared/application_item.dart';
|
2022-09-05 04:32:36 +02:00
|
|
|
import 'package:revanced_manager/ui/widgets/shared/custom_card.dart';
|
2022-07-31 21:46:27 +02:00
|
|
|
|
2023-07-16 07:46:01 +02:00
|
|
|
//ignore: must_be_immutable
|
|
|
|
class InstalledAppsCard extends StatelessWidget {
|
2023-11-11 13:07:32 +01:00
|
|
|
InstalledAppsCard({super.key});
|
2022-07-31 21:46:27 +02:00
|
|
|
|
2023-07-15 03:11:51 +02:00
|
|
|
List<PatchedApplication> apps = locator<HomeViewModel>().patchedInstalledApps;
|
|
|
|
final ManagerAPI _managerAPI = locator<ManagerAPI>();
|
|
|
|
List<PatchedApplication> patchedApps = [];
|
|
|
|
|
|
|
|
Future _getApps() async {
|
|
|
|
if (apps.isNotEmpty) {
|
|
|
|
patchedApps = [...apps];
|
|
|
|
for (final element in apps) {
|
|
|
|
await DeviceApps.getApp(element.packageName).then((value) {
|
|
|
|
if (element.version != value?.versionName) {
|
|
|
|
patchedApps.remove(element);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (apps.length != patchedApps.length) {
|
|
|
|
await _managerAPI.setPatchedApps(patchedApps);
|
|
|
|
apps.clear();
|
|
|
|
apps = [...patchedApps];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-30 03:07:28 +02:00
|
|
|
|
2022-07-31 21:46:27 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-07-16 07:46:01 +02:00
|
|
|
return FutureBuilder(
|
|
|
|
future: _getApps(),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.connectionState == ConnectionState.done) {
|
|
|
|
return apps.isEmpty
|
|
|
|
? CustomCard(
|
|
|
|
child: Center(
|
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
Icon(
|
|
|
|
size: 40,
|
|
|
|
Icons.file_download_off,
|
|
|
|
color: Theme.of(context).colorScheme.secondary,
|
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
2024-02-12 00:22:25 +01:00
|
|
|
Text(
|
|
|
|
t.homeView.noInstallations,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.titleMedium!
|
|
|
|
.copyWith(
|
|
|
|
color: Theme.of(context).colorScheme.secondary,
|
|
|
|
),
|
2023-08-06 09:39:46 +02:00
|
|
|
),
|
2023-07-16 07:46:01 +02:00
|
|
|
],
|
2022-09-02 01:10:10 +02:00
|
|
|
),
|
2022-09-05 14:43:13 +02:00
|
|
|
),
|
|
|
|
)
|
2023-07-16 07:46:01 +02:00
|
|
|
: ListView(
|
|
|
|
shrinkWrap: true,
|
|
|
|
padding: EdgeInsets.zero,
|
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
|
|
children: apps
|
|
|
|
.map(
|
|
|
|
(app) => ApplicationItem(
|
|
|
|
icon: app.icon,
|
|
|
|
name: app.name,
|
|
|
|
patchDate: app.patchDate,
|
|
|
|
onPressed: () =>
|
2024-06-29 14:38:00 +02:00
|
|
|
locator<HomeViewModel>().navigateToAppInfo(app, false),
|
2023-07-16 07:46:01 +02:00
|
|
|
),
|
|
|
|
)
|
|
|
|
.toList(),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return const Center(child: CircularProgressIndicator());
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
2022-07-31 21:46:27 +02:00
|
|
|
}
|
|
|
|
}
|