Added settings config

This commit is contained in:
Juan Gilsanz Polo 2023-10-21 21:17:28 +02:00
parent 161628a72a
commit 8c0a5bc98b
6 changed files with 86 additions and 6 deletions

View file

@ -665,5 +665,7 @@
"discardChangesDescription": "Are you sure you want to discard the changes?",
"others": "Others",
"showChart": "Show chart",
"hideChart": "Hide chart"
"hideChart": "Hide chart",
"showTopItemsChart": "Show top items chart",
"showTopItemsChartDescription": "Shows by default the ring chart on the top items sections. Only affects to the mobile view."
}

View file

@ -665,5 +665,7 @@
"discardChangesDescription": "¿Estás seguro de que deseas descartar los cambios realizados?",
"others": "Otros",
"showChart": "Mostrar gráfico",
"hideChart": "Ocultar gráfico"
"hideChart": "Ocultar gráfico",
"showTopItemsChart": "Mostrar gráfico en top de items",
"showTopItemsChartDescription": "Muestra por defecto el gráfico de anillo en las secciones de top de items. Sólo afecta a la vista móvil."
}

View file

@ -52,6 +52,8 @@ class AppConfigProvider with ChangeNotifier {
int _combinedChartHome = 0;
int _showTopItemsChart = 0;
String? _doNotRememberVersion;
GitHubRelease? _appUpdatesAvailable;
@ -168,6 +170,10 @@ class AppConfigProvider with ChangeNotifier {
return _hideServerAddress == 1 ? true : false;
}
bool get showTopItemsChart {
return _showTopItemsChart == 1 ? true : false;
}
void setDbInstance(Database db) {
_dbInstance = db;
}
@ -402,6 +408,22 @@ class AppConfigProvider with ChangeNotifier {
}
}
Future<bool> setShowTopItemsChart(bool value) async {
final updated = await updateConfigQuery(
db: _dbInstance!,
column: 'showTopItemsChart',
value: value == true ? 1 : 0
);
if (updated == true) {
_showTopItemsChart = value == true ? 1 : 0;
notifyListeners();
return true;
}
else {
return false;
}
}
Future<bool> setDoNotRememberVersion(String value) async {
final updated = await updateConfigQuery(
@ -424,6 +446,7 @@ class AppConfigProvider with ChangeNotifier {
_showIpLogs = dbData['showIpLogs'] ?? 0;
_combinedChartHome = dbData['combinedChart'] ?? 0;
_hideServerAddress = dbData['hideServerAddress'];
_showTopItemsChart = dbData['showTopItemsChart'];
if (dbData['homeTopItemsOrder'] != null) {
try {
_homeTopItemsOrder = List<HomeTopItems>.from(

View file

@ -46,6 +46,12 @@ class _TopItemsState extends State<TopItems> {
Colors.grey
];
@override
void initState() {
_showChart = Provider.of<AppConfigProvider>(context, listen: false).showTopItemsChart;
super.initState();
}
@override
Widget build(BuildContext context) {
final statusProvider = Provider.of<StatusProvider>(context);

View file

@ -191,6 +191,28 @@ class _GeneralSettingsState extends State<GeneralSettings> {
builder: (context) => const ReorderableTopItemsHome()
)),
),
CustomListTile(
icon: Icons.donut_large_rounded,
title: AppLocalizations.of(context)!.showTopItemsChart,
subtitle: AppLocalizations.of(context)!.showTopItemsChartDescription,
trailing: Switch(
value: appConfigProvider.showTopItemsChart,
onChanged: (value) => updateSettings(
newStatus: value,
function: appConfigProvider.setShowTopItemsChart
),
),
onTap: () => updateSettings(
newStatus: !appConfigProvider.showTopItemsChart,
function: appConfigProvider.setShowTopItemsChart
),
padding: const EdgeInsets.only(
top: 10,
bottom: 10,
left: 16,
right: 10
)
),
SectionLabel(label: AppLocalizations.of(context)!.logs),
CustomListTile(
icon: Icons.timer_rounded,

View file

@ -116,9 +116,20 @@ Future<Map<String, dynamic>> loadDb(bool acceptsDynamicTheme) async {
});
}
Future upgradeDbToV10(Database db) async {
await db.execute("ALTER TABLE appConfig ADD COLUMN showTopItemsChart NUMERIC");
await db.execute("UPDATE appConfig SET showTopItemsChart = 1");
await db.transaction((txn) async{
await txn.rawQuery(
'SELECT * FROM appConfig',
);
});
}
Database db = await openDatabase(
'adguard_home_manager.db',
version: 9,
version: 10,
onCreate: (Database db, int version) async {
await db.execute(
"""
@ -154,7 +165,8 @@ Future<Map<String, dynamic>> loadDb(bool acceptsDynamicTheme) async {
combinedChart NUMERIC,
doNotRememberVersion TEXT,
hideServerAddress NUMERIC,
homeTopItemsOrder TEXT
homeTopItemsOrder TEXT,
showTopItemsChart NUMERIC
)
"""
);
@ -173,7 +185,8 @@ Future<Map<String, dynamic>> loadDb(bool acceptsDynamicTheme) async {
showIpLogs,
combinedChart,
hideServerAddress,
homeTopItemsOrder
homeTopItemsOrder,
showTopItemsChart
)
VALUES (
0,
@ -186,7 +199,8 @@ Future<Map<String, dynamic>> loadDb(bool acceptsDynamicTheme) async {
0,
0,
0,
'$homeTopItemsDefaultOrderString'
'$homeTopItemsDefaultOrderString',
1
)
"""
);
@ -201,6 +215,7 @@ Future<Map<String, dynamic>> loadDb(bool acceptsDynamicTheme) async {
await upgradeDbToV7(db);
await upgradeDbToV8(db);
await upgradeDbToV9(db);
await upgradeDbToV10(db);
}
if (oldVersion == 2) {
await upgradeDbToV3(db);
@ -210,6 +225,7 @@ Future<Map<String, dynamic>> loadDb(bool acceptsDynamicTheme) async {
await upgradeDbToV7(db);
await upgradeDbToV8(db);
await upgradeDbToV9(db);
await upgradeDbToV10(db);
}
if (oldVersion == 3) {
await upgradeDbToV4(db);
@ -218,6 +234,7 @@ Future<Map<String, dynamic>> loadDb(bool acceptsDynamicTheme) async {
await upgradeDbToV7(db);
await upgradeDbToV8(db);
await upgradeDbToV9(db);
await upgradeDbToV10(db);
}
if (oldVersion == 4) {
await upgradeDbToV5(db);
@ -225,24 +242,32 @@ Future<Map<String, dynamic>> loadDb(bool acceptsDynamicTheme) async {
await upgradeDbToV7(db);
await upgradeDbToV8(db);
await upgradeDbToV9(db);
await upgradeDbToV10(db);
}
if (oldVersion == 5) {
await upgradeDbToV6(db);
await upgradeDbToV7(db);
await upgradeDbToV8(db);
await upgradeDbToV9(db);
await upgradeDbToV10(db);
}
if (oldVersion == 6) {
await upgradeDbToV7(db);
await upgradeDbToV8(db);
await upgradeDbToV9(db);
await upgradeDbToV10(db);
}
if (oldVersion == 7) {
await upgradeDbToV8(db);
await upgradeDbToV9(db);
await upgradeDbToV10(db);
}
if (oldVersion == 8) {
await upgradeDbToV9(db);
await upgradeDbToV10(db);
}
if (oldVersion == 9) {
await upgradeDbToV10(db);
}
},
onOpen: (Database db) async {