2022-11-12 16:55:33 +01:00
|
|
|
// ignore_for_file: use_build_context_synchronously
|
|
|
|
|
|
|
|
import 'package:dynamic_themes/dynamic_themes.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:flutter_i18n/widgets/I18nText.dart';
|
|
|
|
import 'package:revanced_manager/app/app.locator.dart';
|
|
|
|
import 'package:revanced_manager/services/manager_api.dart';
|
|
|
|
import 'package:revanced_manager/ui/widgets/settingsView/settings_section.dart';
|
2023-09-21 02:25:23 +02:00
|
|
|
import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart';
|
2022-11-12 16:55:33 +01:00
|
|
|
|
2023-10-25 10:37:03 +02:00
|
|
|
class SUpdateThemeUI extends StatefulWidget {
|
|
|
|
const SUpdateThemeUI({super.key});
|
2022-11-12 16:55:33 +01:00
|
|
|
|
2023-10-25 10:37:03 +02:00
|
|
|
@override
|
|
|
|
State<SUpdateThemeUI> createState() => _SUpdateThemeUIState();
|
|
|
|
}
|
2022-11-12 16:55:33 +01:00
|
|
|
|
2023-10-25 10:37:03 +02:00
|
|
|
class _SUpdateThemeUIState extends State<SUpdateThemeUI> {
|
|
|
|
final ManagerAPI managerAPI = locator<ManagerAPI>();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return SettingsSection(
|
|
|
|
title: 'settingsView.appearanceSectionTitle',
|
|
|
|
children: <Widget>[
|
|
|
|
ListTile(
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 20.0),
|
|
|
|
title: I18nText(
|
|
|
|
'settingsView.themeModeLabel',
|
|
|
|
child: const Text(
|
|
|
|
'',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 20,
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
trailing: CustomMaterialButton(
|
|
|
|
label: getThemeModeName(),
|
|
|
|
onPressed: () => {showThemeDialog(context)},
|
|
|
|
),
|
|
|
|
onTap: () => {showThemeDialog(context)},
|
|
|
|
),
|
|
|
|
if (managerAPI.isDynamicThemeAvailable)
|
|
|
|
SwitchListTile(
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 20.0),
|
|
|
|
title: I18nText(
|
|
|
|
'settingsView.dynamicThemeLabel',
|
|
|
|
child: const Text(
|
|
|
|
'',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 20,
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
subtitle: I18nText('settingsView.dynamicThemeHint'),
|
|
|
|
value: getDynamicThemeStatus(),
|
|
|
|
onChanged: (value) => {
|
|
|
|
setUseDynamicTheme(
|
|
|
|
context,
|
|
|
|
value,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
2022-11-12 16:55:33 +01:00
|
|
|
|
|
|
|
bool getDynamicThemeStatus() {
|
2023-10-25 10:37:03 +02:00
|
|
|
return managerAPI.getUseDynamicTheme();
|
2022-11-12 16:55:33 +01:00
|
|
|
}
|
|
|
|
|
2023-01-30 13:35:06 +01:00
|
|
|
Future<void> setUseDynamicTheme(BuildContext context, bool value) async {
|
2023-10-25 10:37:03 +02:00
|
|
|
await managerAPI.setUseDynamicTheme(value);
|
2023-09-21 02:25:23 +02:00
|
|
|
final int currentTheme = (DynamicTheme.of(context)!.themeId ~/ 2) * 2;
|
|
|
|
await DynamicTheme.of(context)!.setTheme(currentTheme + (value ? 1 : 0));
|
2023-10-25 10:37:03 +02:00
|
|
|
setState(() {});
|
2022-11-12 16:55:33 +01:00
|
|
|
}
|
|
|
|
|
2023-09-21 02:25:23 +02:00
|
|
|
int getThemeMode() {
|
2023-10-25 10:37:03 +02:00
|
|
|
return managerAPI.getThemeMode();
|
2022-11-12 16:55:33 +01:00
|
|
|
}
|
|
|
|
|
2023-09-21 02:25:23 +02:00
|
|
|
Future<void> setThemeMode(BuildContext context, int value) async {
|
2023-10-25 10:37:03 +02:00
|
|
|
await managerAPI.setThemeMode(value);
|
2023-09-21 02:25:23 +02:00
|
|
|
final bool isDynamicTheme = DynamicTheme.of(context)!.themeId.isEven;
|
2023-10-25 10:37:03 +02:00
|
|
|
await DynamicTheme.of(context)!
|
|
|
|
.setTheme(value * 2 + (isDynamicTheme ? 0 : 1));
|
|
|
|
final bool isLight = value != 2 &&
|
|
|
|
(value == 1 ||
|
|
|
|
DynamicTheme.of(context)!.theme.brightness == Brightness.light);
|
2022-11-12 16:55:33 +01:00
|
|
|
SystemChrome.setSystemUIOverlayStyle(
|
|
|
|
SystemUiOverlayStyle(
|
|
|
|
systemNavigationBarIconBrightness:
|
2023-10-25 10:37:03 +02:00
|
|
|
isLight ? Brightness.dark : Brightness.light,
|
2022-11-12 16:55:33 +01:00
|
|
|
),
|
|
|
|
);
|
2023-10-25 10:37:03 +02:00
|
|
|
setState(() {});
|
2022-11-12 16:55:33 +01:00
|
|
|
}
|
2023-09-21 02:25:23 +02:00
|
|
|
|
|
|
|
I18nText getThemeModeName() {
|
|
|
|
switch (getThemeMode()) {
|
|
|
|
case 0:
|
|
|
|
return I18nText('settingsView.systemThemeLabel');
|
|
|
|
case 1:
|
|
|
|
return I18nText('settingsView.lightThemeLabel');
|
|
|
|
case 2:
|
|
|
|
return I18nText('settingsView.darkThemeLabel');
|
|
|
|
default:
|
|
|
|
return I18nText('settingsView.systemThemeLabel');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> showThemeDialog(BuildContext context) async {
|
|
|
|
final ValueNotifier<int> newTheme = ValueNotifier(getThemeMode());
|
|
|
|
|
|
|
|
return showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => AlertDialog(
|
|
|
|
title: I18nText('settingsView.themeModeLabel'),
|
|
|
|
icon: const Icon(Icons.palette),
|
|
|
|
contentPadding: const EdgeInsets.symmetric(vertical: 16),
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.secondaryContainer,
|
|
|
|
content: SingleChildScrollView(
|
|
|
|
child: ValueListenableBuilder(
|
|
|
|
valueListenable: newTheme,
|
|
|
|
builder: (context, value, child) {
|
|
|
|
return Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
RadioListTile(
|
|
|
|
title: I18nText('settingsView.systemThemeLabel'),
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 16),
|
|
|
|
value: 0,
|
|
|
|
groupValue: value,
|
|
|
|
onChanged: (value) {
|
|
|
|
newTheme.value = value!;
|
|
|
|
},
|
|
|
|
),
|
|
|
|
RadioListTile(
|
|
|
|
title: I18nText('settingsView.lightThemeLabel'),
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 16),
|
|
|
|
value: 1,
|
|
|
|
groupValue: value,
|
|
|
|
onChanged: (value) {
|
|
|
|
newTheme.value = value!;
|
|
|
|
},
|
|
|
|
),
|
|
|
|
RadioListTile(
|
|
|
|
title: I18nText('settingsView.darkThemeLabel'),
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 16),
|
|
|
|
value: 2,
|
|
|
|
groupValue: value,
|
|
|
|
onChanged: (value) {
|
|
|
|
newTheme.value = value!;
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
actions: <Widget>[
|
|
|
|
CustomMaterialButton(
|
|
|
|
isFilled: false,
|
|
|
|
label: I18nText('cancelButton'),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
CustomMaterialButton(
|
|
|
|
label: I18nText('okButton'),
|
|
|
|
onPressed: () {
|
|
|
|
setThemeMode(context, newTheme.value);
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2022-11-12 16:55:33 +01:00
|
|
|
}
|