Added use theme color for status

This commit is contained in:
Juan Gilsanz Polo 2022-10-26 15:22:50 +02:00
parent 3875f161ca
commit 6b593dc195
7 changed files with 80 additions and 14 deletions

View file

@ -545,5 +545,7 @@
"purple": "Purple",
"pink": "Pink",
"deepOrange": "Deep orange",
"indigo": "Indigo"
"indigo": "Indigo",
"useThemeColorStatus": "Use theme color for status",
"useThemeColorStatusDescription": "Replaces green and red status colors with theme color and grey"
}

View file

@ -545,5 +545,7 @@
"purple": "Morado",
"pink": "Rosa",
"deepOrange": "Naranja oscuro",
"indigo": "Índigo"
"indigo": "Índigo",
"useThemeColorStatus": "Usar el color del tema para estados",
"useThemeColorStatusDescription": "Reemplaza el verde y rojo por el color del tema y gris"
}

View file

@ -21,6 +21,7 @@ class AppConfigProvider with ChangeNotifier {
int _selectedTheme = 0;
bool _useDynamicColor = true;
int _staticColor = 0;
bool _useThemeColorForStatus = false;
int _selectedClientsTab = 0;
int _selectedFiltersTab = 0;
@ -101,6 +102,10 @@ class AppConfigProvider with ChangeNotifier {
return _staticColor;
}
bool get useThemeColorForStatus {
return _useThemeColorForStatus;
}
void setDbInstance(Database db) {
_dbInstance = db;
}
@ -190,6 +195,18 @@ class AppConfigProvider with ChangeNotifier {
}
}
Future<bool> setUseThemeColorForStatus(bool value) async {
final updated = await _updateUseThemeColorForStatusDb(value == true ? 1 : 0);
if (updated == true) {
_useThemeColorForStatus = value;
notifyListeners();
return true;
}
else {
return false;
}
}
Future<bool> setStaticColor(int value) async {
final updated = await _updateStaticColorDb(value);
if (updated == true) {
@ -228,6 +245,19 @@ class AppConfigProvider with ChangeNotifier {
}
}
Future<bool> _updateUseThemeColorForStatusDb(int value) async {
try {
return await _dbInstance!.transaction((txn) async {
await txn.rawUpdate(
'UPDATE appConfig SET useThemeColorForStatus = $value',
);
return true;
});
} catch (e) {
return false;
}
}
Future<bool> _updateStaticColorDb(int value) async {
try {
return await _dbInstance!.transaction((txn) async {
@ -273,6 +303,7 @@ class AppConfigProvider with ChangeNotifier {
_hideZeroValues = dbData['hideZeroValues'];
_useDynamicColor = convertFromIntToBool(dbData['useDynamicColor'])!;
_staticColor = dbData['staticColor'];
_useThemeColorForStatus = convertFromIntToBool(dbData['useThemeColorForStatus'])!;
_dbInstance = dbInstance;
notifyListeners();

View file

@ -7,6 +7,7 @@ import 'package:adguard_home_manager/screens/servers/servers.dart';
import 'package:adguard_home_manager/models/server.dart';
import 'package:adguard_home_manager/providers/servers_provider.dart';
import 'package:adguard_home_manager/providers/app_config_provider.dart';
class HomeAppBar extends StatelessWidget with PreferredSizeWidget {
const HomeAppBar({Key? key}) : super(key: key);
@ -14,6 +15,7 @@ class HomeAppBar extends StatelessWidget with PreferredSizeWidget {
@override
PreferredSizeWidget build(BuildContext context) {
final serversProvider = Provider.of<ServersProvider>(context);
final appConfigProvider = Provider.of<AppConfigProvider>(context);
final Server? server = serversProvider.selectedServer;
@ -60,8 +62,12 @@ class HomeAppBar extends StatelessWidget with PreferredSizeWidget {
size: 30,
color: serversProvider.selectedServer != null && serversProvider.serverStatus.data != null
? serversProvider.serverStatus.data!.generalEnabled == true
? Colors.green
: Colors.red
? appConfigProvider.useThemeColorForStatus
? Theme.of(context).primaryColor
: Colors.green
: appConfigProvider.useThemeColorForStatus == true
? Colors.grey
: Colors.red
: Colors.grey,
),
const SizedBox(width: 20),

View file

@ -1,4 +1,7 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:adguard_home_manager/providers/app_config_provider.dart';
class StatusBox extends StatelessWidget {
final IconData icon;
@ -14,6 +17,8 @@ class StatusBox extends StatelessWidget {
@override
Widget build(BuildContext context) {
final appConfigProvider = Provider.of<AppConfigProvider>(context);
return AnimatedContainer(
padding: const EdgeInsets.all(12),
width: double.maxFinite,
@ -22,21 +27,29 @@ class StatusBox extends StatelessWidget {
curve: Curves.easeInOut,
decoration: BoxDecoration(
color: isEnabled == true
? Colors.green
: Colors.red,
? appConfigProvider.useThemeColorForStatus == true
? Theme.of(context).primaryColor
: Colors.green
: appConfigProvider.useThemeColorForStatus == true
? Colors.grey
: Colors.red,
borderRadius: BorderRadius.circular(16)
),
child: Row(
children: [
Icon(
icon,
color: Colors.white,
color: appConfigProvider.useThemeColorForStatus == true
? Theme.of(context).primaryColor.computeLuminance() > 0.5 ? Colors.black : Colors.white
: Colors.grey.computeLuminance() > 0.5 ? Colors.black : Colors.white,
),
const SizedBox(width: 12),
Text(
label,
style: const TextStyle(
color: Colors.white,
style: TextStyle(
color: appConfigProvider.useThemeColorForStatus == true
? Theme.of(context).primaryColor.computeLuminance() > 0.5 ? Colors.black : Colors.white
: Colors.grey.computeLuminance() > 0.5 ? Colors.black : Colors.white,
fontWeight: FontWeight.w500
),
)

View file

@ -41,12 +41,14 @@ class _CustomizationWidgetState extends State<CustomizationWidget> {
int selectedTheme = 0;
bool dynamicColor = true;
int selectedColor = 0;
bool useThemeColorInsteadGreenRed = false;
@override
void initState() {
selectedTheme = widget.appConfigProvider.selectedTheme == ThemeMode.light ? 1 : 2;
dynamicColor = widget.appConfigProvider.useDynamicColor;
selectedColor = widget.appConfigProvider.staticColor;
useThemeColorInsteadGreenRed = widget.appConfigProvider.useThemeColorForStatus;
super.initState();
}
@ -167,14 +169,23 @@ class _CustomizationWidgetState extends State<CustomizationWidget> {
top: 10
),
child: Text(
colorTranslation(context, selectedColor!),
colorTranslation(context, selectedColor),
style: TextStyle(
color: Theme.of(context).listTileTheme.iconColor,
fontSize: 16
),
),
)
],
CustomSwitchListTile(
value: useThemeColorInsteadGreenRed,
onChanged: (value) {
setState(() => useThemeColorInsteadGreenRed = value);
appConfigProvider.setUseThemeColorForStatus(value);
},
title: AppLocalizations.of(context)!.useThemeColorStatus,
subtitle: AppLocalizations.of(context)!.useThemeColorStatusDescription,
)
]
],
),
);

View file

@ -40,7 +40,8 @@ Future<Map<String, dynamic>> loadDb(bool acceptsDynamicTheme) async {
Future upgradeDbToV5(Database db) async {
await db.execute("ALTER TABLE appConfig ADD COLUMN useDynamicColor NUMERIC");
await db.execute("ALTER TABLE appConfig ADD COLUMN staticColor NUMERIC");
await db.execute("UPDATE appConfig SET useDynamicColor = ${acceptsDynamicTheme == true ? 1 : 0}, staticColor = 0");
await db.execute("ALTER TABLE appConfig ADD COLUMN useThemeColorForStatus NUMERIC");
await db.execute("UPDATE appConfig SET useDynamicColor = ${acceptsDynamicTheme == true ? 1 : 0}, staticColor = 0, useThemeColorForStatus = 0");
await db.transaction((txn) async{
await txn.rawQuery(
@ -54,8 +55,8 @@ Future<Map<String, dynamic>> loadDb(bool acceptsDynamicTheme) async {
version: 5,
onCreate: (Database db, int version) async {
await db.execute("CREATE TABLE servers (id TEXT PRIMARY KEY, name TEXT, connectionMethod TEXT, domain TEXT, path TEXT, port INTEGER, user TEXT, password TEXT, defaultServer INTEGER, authToken TEXT, runningOnHa INTEGER)");
await db.execute("CREATE TABLE appConfig (theme NUMERIC, overrideSslCheck NUMERIC, hideZeroValues NUMERIC, useDynamicColor NUMERIC, staticColor NUMERIC)");
await db.execute("INSERT INTO appConfig (theme, overrideSslCheck, hideZeroValues, useDynamicColor, staticColor) VALUES (0, 0, 0, ${acceptsDynamicTheme == true ? 1 : 0}, 0)");
await db.execute("CREATE TABLE appConfig (theme NUMERIC, overrideSslCheck NUMERIC, hideZeroValues NUMERIC, useDynamicColor NUMERIC, staticColor NUMERIC, useThemeColorForStatus NUMERIC)");
await db.execute("INSERT INTO appConfig (theme, overrideSslCheck, hideZeroValues, useDynamicColor, staticColor, useThemeColorForStatus) VALUES (0, 0, 0, ${acceptsDynamicTheme == true ? 1 : 0}, 0, 0)");
},
onUpgrade: (Database db, int oldVersion, int newVersion) async {
if (oldVersion == 1) {