DB compressing + prepairing for custmization
This commit is contained in:
parent
eca63a5288
commit
533d38042e
|
@ -4,6 +4,7 @@ import 'package:flutter/gestures.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:package_info_plus/package_info_plus.dart';
|
import 'package:package_info_plus/package_info_plus.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
import 'package:tetra_stats/views/customization_view.dart';
|
||||||
import 'package:window_manager/window_manager.dart';
|
import 'package:window_manager/window_manager.dart';
|
||||||
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
|
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
|
||||||
import 'package:sqflite_common_ffi_web/sqflite_ffi_web.dart';
|
import 'package:sqflite_common_ffi_web/sqflite_ffi_web.dart';
|
||||||
|
@ -58,7 +59,7 @@ class MyApp extends StatelessWidget {
|
||||||
locale: TranslationProvider.of(context).flutterLocale,
|
locale: TranslationProvider.of(context).flutterLocale,
|
||||||
supportedLocales: AppLocaleUtils.supportedLocales,
|
supportedLocales: AppLocaleUtils.supportedLocales,
|
||||||
localizationsDelegates: GlobalMaterialLocalizations.delegates,
|
localizationsDelegates: GlobalMaterialLocalizations.delegates,
|
||||||
routes: {"/settings": (context) => const SettingsView(), "/states": (context) => const TrackedPlayersView(), "/calc": (context) => const CalcView()},
|
routes: {"/settings": (context) => const SettingsView(), "/states": (context) => const TrackedPlayersView(), "/calc": (context) => const CalcView(), "/customization": (context) => const CustomizationView()},
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
fontFamily: 'Eurostile Round',
|
fontFamily: 'Eurostile Round',
|
||||||
colorScheme: const ColorScheme.dark(primary: Colors.cyanAccent, secondary: Colors.white),
|
colorScheme: const ColorScheme.dark(primary: Colors.cyanAccent, secondary: Colors.white),
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:io';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:sqflite/sqflite.dart';
|
import 'package:sqflite/sqflite.dart';
|
||||||
import 'package:path_provider/path_provider.dart' show MissingPlatformDirectoryException, getApplicationDocumentsDirectory;
|
import 'package:path_provider/path_provider.dart' show MissingPlatformDirectoryException, getApplicationDocumentsDirectory;
|
||||||
|
@ -58,4 +59,21 @@ class DB {
|
||||||
// empty
|
// empty
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<int> compressDB() async{
|
||||||
|
await ensureDbIsOpen();
|
||||||
|
final db = getDatabaseOrThrow();
|
||||||
|
String dbPath;
|
||||||
|
if (kIsWeb) {
|
||||||
|
dbPath = dbName;
|
||||||
|
} else {
|
||||||
|
final docsPath = await getApplicationDocumentsDirectory();
|
||||||
|
dbPath = join(docsPath.path, dbName);
|
||||||
|
}
|
||||||
|
var dbFile = File(dbPath);
|
||||||
|
var dbStats = await dbFile.stat();
|
||||||
|
await db.execute("VACUUM");
|
||||||
|
var newDBStats = await dbFile.stat();
|
||||||
|
return dbStats.size - newDBStats.size;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
import 'dart:math';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
|
String bytesToSize(int num){
|
||||||
|
if (num.toString().length<= 4) return "$num B";
|
||||||
|
List<String> postfixs = ["K", "M", "G", "T", "P", "E"];
|
||||||
|
int nl = num.toString().length-1;
|
||||||
|
int scale = min((nl / 3).truncate(), postfixs.length);
|
||||||
|
double newNum = num / pow(1024, scale);
|
||||||
|
int decimalLength = nl / 3 <= postfixs.length ? 2 - nl % 3 : 0;
|
||||||
|
return "${NumberFormat.decimalPatternDigits(decimalDigits: decimalLength).format(newNum)} ${postfixs[scale-1]}iB";
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
import 'dart:io';
|
||||||
|
import 'package:tetra_stats/main.dart' show packageInfo;
|
||||||
|
import 'package:file_selector/file_selector.dart';
|
||||||
|
import 'package:file_picker/file_picker.dart';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
import 'package:tetra_stats/gen/strings.g.dart';
|
||||||
|
import 'package:tetra_stats/services/crud_exceptions.dart';
|
||||||
|
import 'package:tetra_stats/services/tetrio_crud.dart';
|
||||||
|
import 'package:tetra_stats/utils/open_in_browser.dart';
|
||||||
|
import 'package:window_manager/window_manager.dart';
|
||||||
|
|
||||||
|
late String oldWindowTitle;
|
||||||
|
|
||||||
|
class CustomizationView extends StatefulWidget {
|
||||||
|
const CustomizationView({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<StatefulWidget> createState() => CustomizationState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class CustomizationState extends State<CustomizationView> {
|
||||||
|
late SharedPreferences prefs;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
if (!kIsWeb && !Platform.isAndroid && !Platform.isIOS){
|
||||||
|
windowManager.getTitle().then((value) => oldWindowTitle = value);
|
||||||
|
windowManager.setTitle("Tetra Stats: ${t.settings}");
|
||||||
|
}
|
||||||
|
_getPreferences();
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose(){
|
||||||
|
if (!kIsWeb && !Platform.isAndroid && !Platform.isIOS) windowManager.setTitle(oldWindowTitle);
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _getPreferences() async {
|
||||||
|
prefs = await SharedPreferences.getInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final t = Translations.of(context);
|
||||||
|
List<DropdownMenuItem<AppLocale>>? locales = <DropdownMenuItem<AppLocale>>[];
|
||||||
|
for (var v in AppLocale.values){
|
||||||
|
locales.add(DropdownMenuItem<AppLocale>(
|
||||||
|
value: v, child: Text(t.locales[v.languageTag]!)));
|
||||||
|
}
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: Text(t.settings),
|
||||||
|
),
|
||||||
|
backgroundColor: Colors.black,
|
||||||
|
body: SafeArea(
|
||||||
|
child: ListView(
|
||||||
|
children: [
|
||||||
|
ListTile(title: Text("Accent Color"),),
|
||||||
|
ListTile(title: Text("Font"),),
|
||||||
|
ListTile(title: Text("Stats Table in TL mathes list"),),
|
||||||
|
],
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -236,6 +236,11 @@ class SettingsState extends State<SettingsView> {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
ListTile(title: Text("Customization"),
|
||||||
|
trailing: Icon(Icons.arrow_right),
|
||||||
|
onTap: () {
|
||||||
|
Navigator.pushNamed(context, "/customization");
|
||||||
|
},),
|
||||||
const Divider(),
|
const Divider(),
|
||||||
ListTile(
|
ListTile(
|
||||||
onTap: (){
|
onTap: (){
|
||||||
|
|
|
@ -5,6 +5,7 @@ import 'package:intl/intl.dart';
|
||||||
import 'package:tetra_stats/data_objects/tetrio.dart';
|
import 'package:tetra_stats/data_objects/tetrio.dart';
|
||||||
import 'package:tetra_stats/gen/strings.g.dart';
|
import 'package:tetra_stats/gen/strings.g.dart';
|
||||||
import 'package:tetra_stats/services/tetrio_crud.dart';
|
import 'package:tetra_stats/services/tetrio_crud.dart';
|
||||||
|
import 'package:tetra_stats/utils/filesizes_converter.dart';
|
||||||
import 'package:tetra_stats/views/states_view.dart';
|
import 'package:tetra_stats/views/states_view.dart';
|
||||||
import 'package:window_manager/window_manager.dart';
|
import 'package:window_manager/window_manager.dart';
|
||||||
|
|
||||||
|
@ -49,11 +50,21 @@ class TrackedPlayersState extends State<TrackedPlayersView> {
|
||||||
value: 1,
|
value: 1,
|
||||||
child: Text("Remove duplicated TL mathces"),
|
child: Text("Remove duplicated TL mathces"),
|
||||||
),
|
),
|
||||||
|
PopupMenuItem(
|
||||||
|
value: 2,
|
||||||
|
child: Text("Compress DB"),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
onSelected: (value) {
|
onSelected: (value) {
|
||||||
if (value == 1) {teto.removeDuplicatesFromTLMatches();
|
switch (value) {
|
||||||
return;}
|
case 1:
|
||||||
Navigator.pushNamed(context, value);
|
teto.removeDuplicatesFromTLMatches();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
teto.compressDB().then((value) => ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text("Space saved: ${bytesToSize(value)}"))));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
|
@ -270,6 +270,14 @@ packages:
|
||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
|
flutter_colorpicker:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: flutter_colorpicker
|
||||||
|
sha256: "458a6ed8ea480eb16ff892aedb4b7092b2804affd7e046591fb03127e8d8ef8b"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.0.3"
|
||||||
flutter_launcher_icons:
|
flutter_launcher_icons:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description:
|
description:
|
||||||
|
|
|
@ -41,6 +41,7 @@ dependencies:
|
||||||
flutter_svg: any
|
flutter_svg: any
|
||||||
window_manager: ^0.3.7
|
window_manager: ^0.3.7
|
||||||
flutter_markdown: ^0.6.18
|
flutter_markdown: ^0.6.18
|
||||||
|
flutter_colorpicker: ^1.0.3
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|
Loading…
Reference in New Issue