2022-09-15 00:23:03 +02:00
|
|
|
// ignore_for_file: use_build_context_synchronously
|
|
|
|
import 'package:dynamic_themes/dynamic_themes.dart';
|
2022-09-05 10:07:38 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:injectable/injectable.dart';
|
2022-09-15 00:30:02 +02:00
|
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
|
|
import 'package:revanced_manager/services/root_api.dart';
|
2022-09-05 10:07:38 +02: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-15 00:23:03 +02:00
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
2022-09-05 10:07:38 +02:00
|
|
|
import 'package:stacked/stacked.dart';
|
|
|
|
|
|
|
|
@lazySingleton
|
|
|
|
class NavigationViewModel extends IndexTrackingViewModel {
|
2022-09-15 00:23:03 +02:00
|
|
|
void initialize(BuildContext context) async {
|
|
|
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
|
|
|
if (prefs.getBool('useDarkTheme') == null) {
|
|
|
|
if (MediaQuery.of(context).platformBrightness == Brightness.light) {
|
|
|
|
await prefs.setBool('useDarkTheme', false);
|
|
|
|
DynamicTheme.of(context)!.setTheme(0);
|
|
|
|
} else {
|
|
|
|
await prefs.setBool('useDarkTheme', true);
|
|
|
|
DynamicTheme.of(context)!.setTheme(1);
|
|
|
|
}
|
|
|
|
}
|
2022-09-15 00:30:02 +02:00
|
|
|
RootAPI().hasRootPermissions();
|
|
|
|
Permission.requestInstallPackages.request();
|
2022-09-15 01:57:54 +02:00
|
|
|
Permission.ignoreBatteryOptimizations.request();
|
2022-09-15 00:23:03 +02:00
|
|
|
}
|
|
|
|
|
2022-09-05 10:07:38 +02:00
|
|
|
Widget getViewForIndex(int index) {
|
|
|
|
switch (index) {
|
|
|
|
case 0:
|
|
|
|
return const HomeView();
|
|
|
|
case 1:
|
|
|
|
return const PatcherView();
|
|
|
|
case 2:
|
2022-09-07 03:37:25 +02:00
|
|
|
return const SettingsView();
|
2022-09-05 10:07:38 +02:00
|
|
|
default:
|
|
|
|
return const HomeView();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|