clear catalog metadata to get correct date/times when moving to a different time zone
This commit is contained in:
parent
7a068b226b
commit
af7f5536ac
5 changed files with 39 additions and 6 deletions
|
@ -10,6 +10,7 @@ import 'package:aves/widgets/common/fake_app_bar.dart';
|
||||||
import 'package:aves/widgets/common/icons.dart';
|
import 'package:aves/widgets/common/icons.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:flutter_native_timezone/flutter_native_timezone.dart';
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
|
@ -58,19 +59,26 @@ class _HomePageState extends State<HomePage> {
|
||||||
}
|
}
|
||||||
|
|
||||||
setup() async {
|
setup() async {
|
||||||
await androidFileUtils.init();
|
|
||||||
await IconUtils.init();
|
|
||||||
await settings.init();
|
|
||||||
localMediaCollection.groupFactor = settings.collectionGroupFactor;
|
|
||||||
localMediaCollection.sortFactor = settings.collectionSortFactor;
|
|
||||||
|
|
||||||
final permissions = await PermissionHandler().requestPermissions([PermissionGroup.storage]);
|
final permissions = await PermissionHandler().requestPermissions([PermissionGroup.storage]);
|
||||||
if (permissions[PermissionGroup.storage] != PermissionStatus.granted) {
|
if (permissions[PermissionGroup.storage] != PermissionStatus.granted) {
|
||||||
SystemNavigator.pop();
|
SystemNavigator.pop();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await androidFileUtils.init();
|
||||||
|
await IconUtils.init();
|
||||||
|
await settings.init();
|
||||||
|
localMediaCollection.groupFactor = settings.collectionGroupFactor;
|
||||||
|
localMediaCollection.sortFactor = settings.collectionSortFactor;
|
||||||
|
|
||||||
await metadataDb.init();
|
await metadataDb.init();
|
||||||
|
final currentTimeZone = await FlutterNativeTimezone.getLocalTimezone();
|
||||||
|
final catalogTimeZone = settings.catalogTimeZone;
|
||||||
|
if (currentTimeZone != catalogTimeZone) {
|
||||||
|
// clear catalog metadata to get correct date/times when moving to a different time zone
|
||||||
|
await metadataDb.clearMetadataEntries();
|
||||||
|
settings.catalogTimeZone = currentTimeZone;
|
||||||
|
}
|
||||||
|
|
||||||
eventChannel.receiveBroadcastStream().cast<Map>().listen(
|
eventChannel.receiveBroadcastStream().cast<Map>().listen(
|
||||||
(entryMap) => localMediaCollection.add(ImageEntry.fromMap(entryMap)),
|
(entryMap) => localMediaCollection.add(ImageEntry.fromMap(entryMap)),
|
||||||
|
|
|
@ -34,6 +34,12 @@ class MetadataDb {
|
||||||
await init();
|
await init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clearMetadataEntries() async {
|
||||||
|
final db = await _database;
|
||||||
|
final count = await db.delete(metadataTable, where: '1');
|
||||||
|
debugPrint('$runtimeType clearMetadataEntries deleted $count entries');
|
||||||
|
}
|
||||||
|
|
||||||
Future<List<CatalogMetadata>> loadMetadataEntries() async {
|
Future<List<CatalogMetadata>> loadMetadataEntries() async {
|
||||||
final start = DateTime.now();
|
final start = DateTime.now();
|
||||||
final db = await _database;
|
final db = await _database;
|
||||||
|
@ -57,6 +63,12 @@ class MetadataDb {
|
||||||
debugPrint('$runtimeType saveMetadata complete in ${DateTime.now().difference(start).inMilliseconds}ms with ${metadataEntries.length} entries');
|
debugPrint('$runtimeType saveMetadata complete in ${DateTime.now().difference(start).inMilliseconds}ms with ${metadataEntries.length} entries');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clearAddresses() async {
|
||||||
|
final db = await _database;
|
||||||
|
final count = await db.delete(addressTable, where: '1');
|
||||||
|
debugPrint('$runtimeType clearAddresses deleted $count entries');
|
||||||
|
}
|
||||||
|
|
||||||
Future<List<AddressDetails>> loadAddresses() async {
|
Future<List<AddressDetails>> loadAddresses() async {
|
||||||
final start = DateTime.now();
|
final start = DateTime.now();
|
||||||
final db = await _database;
|
final db = await _database;
|
||||||
|
|
|
@ -17,6 +17,7 @@ class Settings {
|
||||||
static const collectionGroupFactorKey = 'collection_group_factor';
|
static const collectionGroupFactorKey = 'collection_group_factor';
|
||||||
static const collectionSortFactorKey = 'collection_sort_factor';
|
static const collectionSortFactorKey = 'collection_sort_factor';
|
||||||
static const infoMapZoomKey = 'info_map_zoom';
|
static const infoMapZoomKey = 'info_map_zoom';
|
||||||
|
static const catalogTimeZoneKey = 'catalog_time_zone';
|
||||||
|
|
||||||
init() async {
|
init() async {
|
||||||
prefs = await SharedPreferences.getInstance();
|
prefs = await SharedPreferences.getInstance();
|
||||||
|
@ -46,6 +47,10 @@ class Settings {
|
||||||
|
|
||||||
set infoMapZoom(double newValue) => setAndNotify(infoMapZoomKey, newValue);
|
set infoMapZoom(double newValue) => setAndNotify(infoMapZoomKey, newValue);
|
||||||
|
|
||||||
|
String get catalogTimeZone => prefs.getString(catalogTimeZoneKey) ?? '';
|
||||||
|
|
||||||
|
set catalogTimeZone(String newValue) => setAndNotify(catalogTimeZoneKey, newValue);
|
||||||
|
|
||||||
GroupFactor get collectionGroupFactor => getEnumOrDefault(collectionGroupFactorKey, GroupFactor.date, GroupFactor.values);
|
GroupFactor get collectionGroupFactor => getEnumOrDefault(collectionGroupFactorKey, GroupFactor.date, GroupFactor.values);
|
||||||
|
|
||||||
set collectionGroupFactor(GroupFactor newValue) => setAndNotify(collectionGroupFactorKey, newValue.toString());
|
set collectionGroupFactor(GroupFactor newValue) => setAndNotify(collectionGroupFactorKey, newValue.toString());
|
||||||
|
|
|
@ -76,6 +76,13 @@ packages:
|
||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
|
flutter_native_timezone:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: flutter_native_timezone
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "1.0.4"
|
||||||
flutter_sticky_header:
|
flutter_sticky_header:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|
|
@ -19,6 +19,7 @@ dependencies:
|
||||||
chewie: 0.9.7
|
chewie: 0.9.7
|
||||||
collection:
|
collection:
|
||||||
flushbar:
|
flushbar:
|
||||||
|
flutter_native_timezone:
|
||||||
flutter_sticky_header:
|
flutter_sticky_header:
|
||||||
git:
|
git:
|
||||||
url: git://github.com/deckerst/flutter_sticky_header.git
|
url: git://github.com/deckerst/flutter_sticky_header.git
|
||||||
|
|
Loading…
Reference in a new issue