2022-09-05 03:32:36 +01:00
|
|
|
// ignore_for_file: use_build_context_synchronously
|
|
|
|
|
|
|
|
import 'package:dynamic_themes/dynamic_themes.dart';
|
2022-09-02 14:35:25 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_i18n/flutter_i18n.dart';
|
2022-08-12 23:37:16 +05:30
|
|
|
import 'package:revanced_manager/app/app.locator.dart';
|
|
|
|
import 'package:revanced_manager/app/app.router.dart';
|
2022-09-05 03:32:36 +01:00
|
|
|
import 'package:revanced_manager/services/manager_api.dart';
|
2022-08-10 18:00:28 +05:30
|
|
|
import 'package:stacked/stacked.dart';
|
2022-08-12 23:37:16 +05:30
|
|
|
import 'package:stacked_services/stacked_services.dart';
|
2022-09-02 14:35:25 +01:00
|
|
|
import 'package:timeago/timeago.dart';
|
2022-08-10 18:00:28 +05:30
|
|
|
|
|
|
|
class SettingsViewModel extends BaseViewModel {
|
2022-08-18 15:33:33 +01:00
|
|
|
final NavigationService _navigationService = locator<NavigationService>();
|
2022-09-05 03:32:36 +01:00
|
|
|
final ManagerAPI _managerAPI = locator<ManagerAPI>();
|
2022-08-12 23:37:16 +05:30
|
|
|
|
2022-08-10 18:00:28 +05:30
|
|
|
void setLanguage(String language) {
|
|
|
|
notifyListeners();
|
|
|
|
}
|
2022-08-12 23:37:16 +05:30
|
|
|
|
2022-08-20 17:47:00 +05:30
|
|
|
void navigateToRootChecker() {
|
|
|
|
_navigationService.navigateTo(Routes.rootCheckerView);
|
|
|
|
}
|
2022-09-02 14:35:25 +01:00
|
|
|
|
|
|
|
Future<void> updateLanguage(BuildContext context, String? value) async {
|
|
|
|
if (value != null) {
|
|
|
|
await FlutterI18n.refresh(context, Locale(value));
|
|
|
|
setLocaleMessages(value, EnMessages());
|
|
|
|
}
|
|
|
|
}
|
2022-09-05 03:32:36 +01:00
|
|
|
|
|
|
|
bool getDynamicThemeStatus() {
|
|
|
|
return _managerAPI.getUseDynamicTheme();
|
|
|
|
}
|
|
|
|
|
|
|
|
void setUseDynamicTheme(BuildContext context, bool value) async {
|
|
|
|
await _managerAPI.setUseDynamicTheme(value);
|
|
|
|
int currentTheme = DynamicTheme.of(context)!.themeId;
|
|
|
|
if (currentTheme.isEven) {
|
|
|
|
DynamicTheme.of(context)!.setTheme(value ? 2 : 0);
|
|
|
|
} else {
|
|
|
|
DynamicTheme.of(context)!.setTheme(value ? 3 : 1);
|
|
|
|
}
|
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool getDarkThemeStatus() {
|
|
|
|
return _managerAPI.getUseDarkTheme();
|
|
|
|
}
|
|
|
|
|
|
|
|
void setUseDarkTheme(BuildContext context, bool value) async {
|
|
|
|
await _managerAPI.setUseDarkTheme(value);
|
|
|
|
int currentTheme = DynamicTheme.of(context)!.themeId;
|
|
|
|
if (currentTheme < 2) {
|
|
|
|
DynamicTheme.of(context)!.setTheme(value ? 1 : 0);
|
|
|
|
} else {
|
|
|
|
DynamicTheme.of(context)!.setTheme(value ? 3 : 2);
|
|
|
|
}
|
|
|
|
notifyListeners();
|
|
|
|
}
|
2022-08-10 18:00:28 +05:30
|
|
|
}
|