Removed config variable

This commit is contained in:
Juan Gilsanz Polo 2024-01-25 00:47:20 +01:00
parent 9529cd6f56
commit 2fd829021c
4 changed files with 77 additions and 119 deletions

View file

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

View file

@ -3,7 +3,6 @@
import 'dart:io'; import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:adguard_home_manager/screens/home/top_items/row_item.dart'; import 'package:adguard_home_manager/screens/home/top_items/row_item.dart';
@ -13,9 +12,8 @@ import 'package:adguard_home_manager/widgets/custom_pie_chart.dart';
import 'package:adguard_home_manager/functions/number_format.dart'; import 'package:adguard_home_manager/functions/number_format.dart';
import 'package:adguard_home_manager/models/menu_option.dart'; import 'package:adguard_home_manager/models/menu_option.dart';
import 'package:adguard_home_manager/constants/enums.dart'; import 'package:adguard_home_manager/constants/enums.dart';
import 'package:adguard_home_manager/providers/app_config_provider.dart';
class TopItemsSection extends StatefulWidget { class TopItemsSection extends StatelessWidget {
final HomeTopItems type; final HomeTopItems type;
final String label; final String label;
final List<Map<String, dynamic>> data; final List<Map<String, dynamic>> data;
@ -38,12 +36,7 @@ class TopItemsSection extends StatefulWidget {
}); });
@override @override
State<TopItemsSection> createState() => _TopItemsState(); Widget build(BuildContext context) {
}
class _TopItemsState extends State<TopItemsSection> {
bool _showChart = true;
final colors = [ final colors = [
Colors.red, Colors.red,
Colors.green, Colors.green,
@ -53,29 +46,21 @@ class _TopItemsState extends State<TopItemsSection> {
Colors.grey Colors.grey
]; ];
@override
void initState() {
_showChart = Provider.of<AppConfigProvider>(context, listen: false).showTopItemsChart;
super.initState();
}
@override
Widget build(BuildContext context) {
final width = MediaQuery.of(context).size.width; final width = MediaQuery.of(context).size.width;
final withChart = widget.type != HomeTopItems.avgUpstreamResponseTime; final withChart = type != HomeTopItems.avgUpstreamResponseTime;
Map<String, double> ringData() { Map<String, double> ringData() {
Map<String, double> values = {}; Map<String, double> values = {};
widget.data.sublist(0, widget.data.length > 5 ? 5 : widget.data.length).forEach((element) { data.sublist(0, data.length > 5 ? 5 : data.length).forEach((element) {
values = { values = {
...values, ...values,
element.keys.first: element.values.first.toDouble() element.keys.first: element.values.first.toDouble()
}; };
}); });
if (widget.data.length > 5) { if (data.length > 5) {
final int rest = List<int>.from( final int rest = List<int>.from(
widget.data.sublist(5, widget.data.length).map((e) => e.values.first.toInt()) data.sublist(5, data.length).map((e) => e.values.first.toInt())
).reduce((a, b) => a + b); ).reduce((a, b) => a + b);
values = { values = {
...values, ...values,
@ -87,15 +72,15 @@ class _TopItemsState extends State<TopItemsSection> {
List<Map<String, dynamic>> lineData() { List<Map<String, dynamic>> lineData() {
List<Map<String, dynamic>> values = []; List<Map<String, dynamic>> values = [];
widget.data.sublist(0, widget.data.length > 5 ? 5 : widget.data.length).forEach((element) { data.sublist(0, data.length > 5 ? 5 : data.length).forEach((element) {
values.add({ values.add({
"label": element.keys.first, "label": element.keys.first,
"value": element.values.first.toDouble() "value": element.values.first.toDouble()
}); });
}); });
if (widget.data.length > 5) { if (data.length > 5) {
final int rest = List<int>.from( final int rest = List<int>.from(
widget.data.sublist(5, widget.data.length).map((e) => e.values.first.toInt()) data.sublist(5, data.length).map((e) => e.values.first.toInt())
).reduce((a, b) => a + b); ).reduce((a, b) => a + b);
values.add({ values.add({
"label": AppLocalizations.of(context)!.others, "label": AppLocalizations.of(context)!.others,
@ -105,8 +90,8 @@ class _TopItemsState extends State<TopItemsSection> {
return values; return values;
} }
final data = lineData(); final lineChartData = lineData();
final total = data.map((e) => e["value"]).reduce((a, b) => a + b); final total = lineChartData.map((e) => e["value"]).reduce((a, b) => a + b);
final Widget noItems = Padding( final Widget noItems = Padding(
padding: const EdgeInsets.only( padding: const EdgeInsets.only(
@ -125,8 +110,8 @@ class _TopItemsState extends State<TopItemsSection> {
return SizedBox( return SizedBox(
child: Column( child: Column(
children: [ children: [
if (widget.data.isEmpty) noItems, if (data.isEmpty) noItems,
if (widget.data.isNotEmpty && width > 700) Padding( if (data.isNotEmpty && width > 700) Padding(
padding: EdgeInsets.only(bottom: withChart == false ? 16 : 0), padding: EdgeInsets.only(bottom: withChart == false ? 16 : 0),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
@ -156,7 +141,7 @@ class _TopItemsState extends State<TopItemsSection> {
bottom: 16 bottom: 16
), ),
child: Text( child: Text(
widget.label, label,
style: const TextStyle( style: const TextStyle(
fontSize: 18, fontSize: 18,
fontWeight: FontWeight.w500 fontWeight: FontWeight.w500
@ -165,16 +150,16 @@ class _TopItemsState extends State<TopItemsSection> {
), ),
_ItemsList( _ItemsList(
colors: colors, colors: colors,
data: widget.data, data: data,
clients: widget.type == HomeTopItems.recurrentClients, clients: type == HomeTopItems.recurrentClients,
type: widget.type, type: type,
showChart: withChart == true ? _showChart : false, showChart: withChart,
buildValue: widget.buildValue, buildValue: buildValue,
menuOptions: widget.menuOptions, menuOptions: menuOptions,
onTapEntry: widget.onTapEntry, onTapEntry: onTapEntry,
), ),
if (withChart == true) OthersRowItem( if (withChart == true) OthersRowItem(
items: widget.data, items: data,
showColor: true, showColor: true,
) )
] ]
@ -183,9 +168,9 @@ class _TopItemsState extends State<TopItemsSection> {
], ],
), ),
), ),
if (widget.data.isNotEmpty && width <= 700) ...[ if (data.isNotEmpty && width <= 700) ...[
Text( Text(
widget.label, label,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
style: TextStyle( style: TextStyle(
fontSize: 18, fontSize: 18,
@ -202,7 +187,7 @@ class _TopItemsState extends State<TopItemsSection> {
height: 20, height: 20,
child: LayoutBuilder( child: LayoutBuilder(
builder: (context, constraints) => Row( builder: (context, constraints) => Row(
children: data.asMap().entries.map((e) => Tooltip( children: lineChartData.asMap().entries.map((e) => Tooltip(
message:'${e.value["label"]} (${doubleFormat((e.value["value"]/total)*100, Platform.localeName)}%)', message:'${e.value["label"]} (${doubleFormat((e.value["value"]/total)*100, Platform.localeName)}%)',
child: Container( child: Container(
width: constraints.maxWidth*(e.value["value"]/total), width: constraints.maxWidth*(e.value["value"]/total),
@ -220,22 +205,22 @@ class _TopItemsState extends State<TopItemsSection> {
padding: const EdgeInsets.only(top: 8), padding: const EdgeInsets.only(top: 8),
child: _ItemsList( child: _ItemsList(
colors: colors, colors: colors,
data: widget.data, data: data,
clients: widget.type == HomeTopItems.recurrentClients, clients: type == HomeTopItems.recurrentClients,
type: widget.type, type: type,
showChart: withChart == false ? false : _showChart, showChart: withChart,
buildValue: widget.buildValue, buildValue: buildValue,
menuOptions: widget.menuOptions, menuOptions: menuOptions,
onTapEntry: widget.onTapEntry, onTapEntry: onTapEntry,
), ),
), ),
OthersRowItem( OthersRowItem(
items: widget.data, items: data,
showColor: withChart == false ? false : _showChart, showColor: withChart,
), ),
], ],
if (widget.data.length > 5) ...[ if (data.length > 5) ...[
Padding( Padding(
padding: const EdgeInsets.only(right: 20), padding: const EdgeInsets.only(right: 20),
child: Row( child: Row(
@ -263,14 +248,14 @@ class _TopItemsState extends State<TopItemsSection> {
); );
}, },
pageBuilder: (context, animation, secondaryAnimation) => TopItemsScreen( pageBuilder: (context, animation, secondaryAnimation) => TopItemsScreen(
type: widget.type, type: type,
title: widget.label, title: label,
isClient: widget.type == HomeTopItems.recurrentClients, isClient: type == HomeTopItems.recurrentClients,
data: widget.data, data: data,
withProgressBar: widget.withProgressBar, withProgressBar: withProgressBar,
buildValue: widget.buildValue, buildValue: buildValue,
options: widget.menuOptions, options: menuOptions,
onTapEntry: widget.onTapEntry, onTapEntry: onTapEntry,
isFullscreen: !(width > 700 || !(Platform.isAndroid | Platform.isIOS)), isFullscreen: !(width > 700 || !(Platform.isAndroid | Platform.isIOS)),
) )
) )

View file

@ -206,28 +206,6 @@ class _GeneralSettingsState extends State<GeneralSettings> {
) )
) )
), ),
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), SectionLabel(label: AppLocalizations.of(context)!.logs),
CustomListTile( CustomListTile(
icon: Icons.timer_rounded, icon: Icons.timer_rounded,

View file

@ -127,9 +127,19 @@ Future<Map<String, dynamic>> loadDb(bool acceptsDynamicTheme) async {
}); });
} }
Future upgradeDbToV11(Database db) async {
await db.execute("ALTER TABLE appConfig DROP COLUMN showTopItemsChart");
await db.transaction((txn) async{
await txn.rawQuery(
'SELECT * FROM appConfig',
);
});
}
Database db = await openDatabase( Database db = await openDatabase(
'adguard_home_manager.db', 'adguard_home_manager.db',
version: 10, version: 11,
onCreate: (Database db, int version) async { onCreate: (Database db, int version) async {
await db.execute( await db.execute(
""" """
@ -165,8 +175,7 @@ Future<Map<String, dynamic>> loadDb(bool acceptsDynamicTheme) async {
combinedChart NUMERIC, combinedChart NUMERIC,
doNotRememberVersion TEXT, doNotRememberVersion TEXT,
hideServerAddress NUMERIC, hideServerAddress NUMERIC,
homeTopItemsOrder TEXT, homeTopItemsOrder TEXT
showTopItemsChart NUMERIC
) )
""" """
); );
@ -185,8 +194,7 @@ Future<Map<String, dynamic>> loadDb(bool acceptsDynamicTheme) async {
showIpLogs, showIpLogs,
combinedChart, combinedChart,
hideServerAddress, hideServerAddress,
homeTopItemsOrder, homeTopItemsOrder
showTopItemsChart
) )
VALUES ( VALUES (
0, 0,
@ -199,8 +207,7 @@ Future<Map<String, dynamic>> loadDb(bool acceptsDynamicTheme) async {
0, 0,
0, 0,
0, 0,
'$homeTopItemsDefaultOrderString', '$homeTopItemsDefaultOrderString'
1
) )
""" """
); );
@ -216,6 +223,7 @@ Future<Map<String, dynamic>> loadDb(bool acceptsDynamicTheme) async {
await upgradeDbToV8(db); await upgradeDbToV8(db);
await upgradeDbToV9(db); await upgradeDbToV9(db);
await upgradeDbToV10(db); await upgradeDbToV10(db);
await upgradeDbToV11(db);
} }
if (oldVersion == 2) { if (oldVersion == 2) {
await upgradeDbToV3(db); await upgradeDbToV3(db);
@ -226,6 +234,7 @@ Future<Map<String, dynamic>> loadDb(bool acceptsDynamicTheme) async {
await upgradeDbToV8(db); await upgradeDbToV8(db);
await upgradeDbToV9(db); await upgradeDbToV9(db);
await upgradeDbToV10(db); await upgradeDbToV10(db);
await upgradeDbToV11(db);
} }
if (oldVersion == 3) { if (oldVersion == 3) {
await upgradeDbToV4(db); await upgradeDbToV4(db);
@ -235,6 +244,7 @@ Future<Map<String, dynamic>> loadDb(bool acceptsDynamicTheme) async {
await upgradeDbToV8(db); await upgradeDbToV8(db);
await upgradeDbToV9(db); await upgradeDbToV9(db);
await upgradeDbToV10(db); await upgradeDbToV10(db);
await upgradeDbToV11(db);
} }
if (oldVersion == 4) { if (oldVersion == 4) {
await upgradeDbToV5(db); await upgradeDbToV5(db);
@ -243,6 +253,7 @@ Future<Map<String, dynamic>> loadDb(bool acceptsDynamicTheme) async {
await upgradeDbToV8(db); await upgradeDbToV8(db);
await upgradeDbToV9(db); await upgradeDbToV9(db);
await upgradeDbToV10(db); await upgradeDbToV10(db);
await upgradeDbToV11(db);
} }
if (oldVersion == 5) { if (oldVersion == 5) {
await upgradeDbToV6(db); await upgradeDbToV6(db);
@ -250,24 +261,32 @@ Future<Map<String, dynamic>> loadDb(bool acceptsDynamicTheme) async {
await upgradeDbToV8(db); await upgradeDbToV8(db);
await upgradeDbToV9(db); await upgradeDbToV9(db);
await upgradeDbToV10(db); await upgradeDbToV10(db);
await upgradeDbToV11(db);
} }
if (oldVersion == 6) { if (oldVersion == 6) {
await upgradeDbToV7(db); await upgradeDbToV7(db);
await upgradeDbToV8(db); await upgradeDbToV8(db);
await upgradeDbToV9(db); await upgradeDbToV9(db);
await upgradeDbToV10(db); await upgradeDbToV10(db);
await upgradeDbToV11(db);
} }
if (oldVersion == 7) { if (oldVersion == 7) {
await upgradeDbToV8(db); await upgradeDbToV8(db);
await upgradeDbToV9(db); await upgradeDbToV9(db);
await upgradeDbToV10(db); await upgradeDbToV10(db);
await upgradeDbToV11(db);
} }
if (oldVersion == 8) { if (oldVersion == 8) {
await upgradeDbToV9(db); await upgradeDbToV9(db);
await upgradeDbToV10(db); await upgradeDbToV10(db);
await upgradeDbToV11(db);
} }
if (oldVersion == 9) { if (oldVersion == 9) {
await upgradeDbToV10(db); await upgradeDbToV10(db);
await upgradeDbToV11(db);
}
if (oldVersion == 10) {
await upgradeDbToV11(db);
} }
}, },
onOpen: (Database db) async { onOpen: (Database db) async {