2022-09-14 23:23:03 +01:00
|
|
|
// ignore_for_file: use_build_context_synchronously
|
2023-09-22 07:05:13 -07:00
|
|
|
import 'package:device_info_plus/device_info_plus.dart';
|
2022-09-14 23:23:03 +01:00
|
|
|
import 'package:dynamic_themes/dynamic_themes.dart';
|
2022-09-05 09:07:38 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2022-09-15 13:27:48 +01:00
|
|
|
import 'package:flutter/services.dart';
|
2022-09-05 09:07:38 +01:00
|
|
|
import 'package:injectable/injectable.dart';
|
2022-09-18 22:13:29 +01:00
|
|
|
import 'package:permission_handler/permission_handler.dart';
|
2022-09-20 00:49:31 +01:00
|
|
|
import 'package:revanced_manager/app/app.locator.dart';
|
2022-09-14 23:30:02 +01:00
|
|
|
import 'package:revanced_manager/services/root_api.dart';
|
2022-09-20 00:49:31 +01:00
|
|
|
import 'package:revanced_manager/services/toast.dart';
|
2022-09-05 09:07:38 +01:00
|
|
|
import 'package:revanced_manager/ui/views/home/home_view.dart';
|
|
|
|
import 'package:revanced_manager/ui/views/patcher/patcher_view.dart';
|
|
|
|
import 'package:revanced_manager/ui/views/settings/settings_view.dart';
|
2022-09-14 23:23:03 +01:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2022-09-05 09:07:38 +01:00
|
|
|
import 'package:stacked/stacked.dart';
|
|
|
|
|
|
|
|
@lazySingleton
|
|
|
|
class NavigationViewModel extends IndexTrackingViewModel {
|
2023-01-30 18:05:06 +05:30
|
|
|
Future<void> initialize(BuildContext context) async {
|
2022-09-20 00:49:31 +01:00
|
|
|
locator<Toast>().initialize(context);
|
2023-06-12 08:59:14 +05:30
|
|
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
2023-06-12 09:56:49 +05:30
|
|
|
|
2022-09-18 22:13:29 +01:00
|
|
|
if (prefs.getBool('permissionsRequested') == null) {
|
2023-06-12 08:59:14 +05:30
|
|
|
await Permission.storage.request();
|
2022-09-18 22:13:29 +01:00
|
|
|
await prefs.setBool('permissionsRequested', true);
|
2023-08-31 19:34:12 +05:45
|
|
|
await RootAPI().hasRootPermissions().then(
|
2022-09-18 22:13:29 +01:00
|
|
|
(value) => Permission.requestInstallPackages.request().then(
|
2023-06-12 08:59:14 +05:30
|
|
|
(value) => Permission.ignoreBatteryOptimizations.request(),
|
2022-09-18 22:13:29 +01:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2023-06-12 09:56:49 +05:30
|
|
|
|
2023-09-22 07:05:13 -07:00
|
|
|
final dynamicTheme = DynamicTheme.of(context)!;
|
2023-09-20 17:25:23 -07:00
|
|
|
if (prefs.getInt('themeMode') == null) {
|
|
|
|
await prefs.setInt('themeMode', 0);
|
2023-09-22 07:05:13 -07:00
|
|
|
await dynamicTheme.setTheme(0);
|
2022-09-14 23:23:03 +01:00
|
|
|
}
|
2023-09-22 07:05:13 -07:00
|
|
|
|
|
|
|
// Force disable Material You on Android 11 and below
|
|
|
|
if (dynamicTheme.themeId.isOdd) {
|
2023-09-29 18:39:07 +02:00
|
|
|
const int android12SdkVersion = 31;
|
2023-09-22 07:05:13 -07:00
|
|
|
final AndroidDeviceInfo info = await DeviceInfoPlugin().androidInfo;
|
2023-09-29 18:39:07 +02:00
|
|
|
if (info.version.sdkInt < android12SdkVersion) {
|
2023-09-22 07:05:13 -07:00
|
|
|
await prefs.setInt('themeMode', 0);
|
|
|
|
await prefs.setBool('useDynamicTheme', false);
|
|
|
|
await dynamicTheme.setTheme(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-24 13:49:46 +01:00
|
|
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge);
|
2022-09-15 13:27:48 +01:00
|
|
|
SystemChrome.setSystemUIOverlayStyle(
|
|
|
|
SystemUiOverlayStyle(
|
2022-09-18 23:20:08 +02:00
|
|
|
systemNavigationBarColor: Colors.transparent,
|
2022-09-15 13:27:48 +01:00
|
|
|
systemNavigationBarIconBrightness:
|
2023-06-12 08:59:14 +05:30
|
|
|
DynamicTheme.of(context)!.theme.brightness == Brightness.light
|
2022-09-15 13:27:48 +01:00
|
|
|
? Brightness.dark
|
|
|
|
: Brightness.light,
|
|
|
|
),
|
|
|
|
);
|
2022-09-14 23:23:03 +01:00
|
|
|
}
|
|
|
|
|
2022-09-05 09:07:38 +01:00
|
|
|
Widget getViewForIndex(int index) {
|
|
|
|
switch (index) {
|
|
|
|
case 0:
|
|
|
|
return const HomeView();
|
|
|
|
case 1:
|
|
|
|
return const PatcherView();
|
|
|
|
case 2:
|
2022-09-07 02:37:25 +01:00
|
|
|
return const SettingsView();
|
2022-09-05 09:07:38 +01:00
|
|
|
default:
|
|
|
|
return const HomeView();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|