Skip to content

Commit

Permalink
Added metadata support
Browse files Browse the repository at this point in the history
Added deprecations for store stats & metadata
Replaced 4 seperate statistic get methods in backend with a single unified one (and expose more efficient method to frontend)
Removed `FMTCSettings`
Integrated `FMTC.initialise`
Adjusted scope/visibility of ObjectBox backend sub-library
Loosened requirements for implementers of backend structures
Improved documentation
Other minor improvements throughout
Started syntax migration of example application
  • Loading branch information
JaffaKetchup committed Jan 4, 2024
1 parent 452e91f commit 87f7bc2
Show file tree
Hide file tree
Showing 30 changed files with 696 additions and 539 deletions.
6 changes: 1 addition & 5 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ void main() async {
);

String? damagedDatabaseDeleted;
await FlutterMapTileCaching.initialise(
errorHandler: (error) => damagedDatabaseDeleted = error.message,
settings: FMTCSettings(databaseMaxSize: 51200),
debugMode: true,
);
await FlutterMapTileCaching.initialise();

await FMTC.instance.rootDirectory.migrator.fromV6(urlTemplates: []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class StartDownloadButton extends StatelessWidget {
final navigator = Navigator.of(context);

final metadata = await regionSelectionProvider
.selectedStore!.metadata.readAsync;
.selectedStore!.metadata.read;

downloadingProvider.setDownloadProgress(
regionSelectionProvider.selectedStore!.download
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MapView extends StatelessWidget {
FutureBuilder<Map<String, String>?>(
future: currentStore == null
? Future.sync(() => {})
: FMTC.instance(currentStore).metadata.readAsync,
: FMTC.instance(currentStore).metadata.read,
builder: (context, metadata) {
if (!metadata.hasData ||
metadata.data == null ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class _RegionSelectionPageState extends State<RegionSelectionPage> {
FutureBuilder<Map<String, String>?>(
future: currentStore == null
? Future.value()
: FMTC.instance(currentStore).metadata.readAsync,
: FMTC.instance(currentStore).metadata.read,
builder: (context, metadata) {
if (currentStore != null && metadata.data == null) {
return const LoadingIndicator('Preparing Map');
Expand Down Expand Up @@ -262,7 +262,7 @@ class _RegionSelectionPageState extends State<RegionSelectionPage> {
: FMTC
.instance(currentStore)
.getTileProvider()
.checkTileCachedAsync(
.checkTileCached(
coords: tile.coordinates,
options:
TileLayer(urlTemplate: urlTemplate),
Expand Down
27 changes: 15 additions & 12 deletions example/lib/screens/main/pages/stores/components/store_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class StoreTile extends StatefulWidget {
}

class _StoreTileState extends State<StoreTile> {
Future<String>? _tiles;
Future<String>? _length;
Future<String>? _size;
Future<String>? _cacheHits;
Future<String>? _cacheMisses;
Future<String>? _hits;
Future<String>? _misses;
Future<Image?>? _image;

bool _deletingProgress = false;
Expand All @@ -36,18 +36,21 @@ class _StoreTileState extends State<StoreTile> {
late final _store = FMTC.instance(widget.storeName);

void _loadStatistics() {
_tiles = _store.stats.storeLengthAsync.then((l) => l.toString());
_size = _store.stats.storeSizeAsync.then((s) => (s * 1024).asReadableSize);
_cacheHits = _store.stats.cacheHitsAsync.then((h) => h.toString());
_cacheMisses = _store.stats.cacheMissesAsync.then((m) => m.toString());
_image = _store.manage.tileImageAsync(size: 125);
final stats = _store.stats.all;

_length = stats.then((s) => s.length.toString());
_size = stats.then((s) => (s.size * 1024).asReadableSize);
_hits = stats.then((s) => s.hits.toString());
_misses = stats.then((s) => s.misses.toString());

_image = _store.manage.tileImage(size: 125);

setState(() {});
}

List<FutureBuilder<String>> get stats => [
FutureBuilder<String>(
future: _tiles,
future: _length,
builder: (context, snapshot) => StatDisplay(
statistic: snapshot.connectionState != ConnectionState.done
? null
Expand All @@ -65,7 +68,7 @@ class _StoreTileState extends State<StoreTile> {
),
),
FutureBuilder<String>(
future: _cacheHits,
future: _hits,
builder: (context, snapshot) => StatDisplay(
statistic: snapshot.connectionState != ConnectionState.done
? null
Expand All @@ -74,7 +77,7 @@ class _StoreTileState extends State<StoreTile> {
),
),
FutureBuilder<String>(
future: _cacheMisses,
future: _misses,
builder: (context, snapshot) => StatDisplay(
statistic: snapshot.connectionState != ConnectionState.done
? null
Expand Down Expand Up @@ -177,7 +180,7 @@ class _StoreTileState extends State<StoreTile> {
setState(
() => _emptyingProgress = true,
);
await _store.manage.resetAsync();
await _store.manage.reset();
setState(
() => _emptyingProgress = false,
);
Expand Down
10 changes: 5 additions & 5 deletions example/lib/screens/store_editor/components/header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,23 @@ AppBar buildHeader({
downloadProvider.setSelectedStore(newStore);
}*/

await newStore.manage.createAsync();
await newStore.manage.create();

await newStore.metadata.addAsync(
await newStore.metadata.set(
key: 'sourceURL',
value: newValues['sourceURL']!,
);
await newStore.metadata.addAsync(
await newStore.metadata.set(
key: 'validDuration',
value: newValues['validDuration']!,
);
await newStore.metadata.addAsync(
await newStore.metadata.set(
key: 'maxLength',
value: newValues['maxLength']!,
);

if (widget.existingStoreName == null || useNewCacheModeValue) {
await newStore.metadata.addAsync(
await newStore.metadata.set(
key: 'behaviour',
value: cacheModeValue ?? 'cacheFirst',
);
Expand Down
10 changes: 3 additions & 7 deletions example/lib/screens/store_editor/store_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@ class _StoreEditorPopupState extends State<StoreEditorPopup> {

@override
Widget build(BuildContext context) => Consumer<RegionSelectionProvider>(
builder: (context, downloadProvider, _) => WillPopScope(
onWillPop: () async {
builder: (context, downloadProvider, _) => PopScope(
onPopInvoked: (_) {
scaffoldMessenger.showSnackBar(
const SnackBar(content: Text('Changes not saved')),
);
return true;
},
child: Scaffold(
appBar: buildHeader(
Expand All @@ -68,10 +67,7 @@ class _StoreEditorPopupState extends State<StoreEditorPopup> {
child: FutureBuilder<Map<String, String>?>(
future: widget.existingStoreName == null
? Future.sync(() => {})
: FMTC
.instance(widget.existingStoreName!)
.metadata
.readAsync,
: FMTC.instance(widget.existingStoreName!).metadata.read,
builder: (context, metadata) {
if (!metadata.hasData || metadata.data == null) {
return const LoadingIndicator('Retrieving Settings');
Expand Down
10 changes: 4 additions & 6 deletions lib/flutter_map_tile_caching.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,26 @@ import 'package:path_provider/path_provider.dart';
import 'package:stream_transform/stream_transform.dart';
import 'package:watcher/watcher.dart';

import 'src/backend/exports.dart';
import 'src/backend/export_internal.dart';
import 'src/bulk_download/instance.dart';
import 'src/bulk_download/rate_limited_stream.dart';
import 'src/bulk_download/tile_loops/shared.dart';
import 'src/errors/browsing.dart';
import 'src/misc/exts.dart';
import 'src/misc/int_extremes.dart';
import 'src/misc/obscure_query_params.dart';
import 'src/misc/typedefs.dart';
import 'src/providers/image_provider.dart';

export 'src/backend/exports.dart';
export 'src/backend/export_external.dart';
export 'src/errors/browsing.dart';
export 'src/errors/damaged_store.dart';
export 'src/misc/typedefs.dart';

part 'src/bulk_download/download_progress.dart';
part 'src/bulk_download/manager.dart';
part 'src/bulk_download/thread.dart';
part 'src/bulk_download/tile_event.dart';
part 'src/fmtc.dart';
part 'src/misc/deprecations.dart';
part 'src/misc/with_backend_access.dart';
part 'src/providers/tile_provider.dart';
part 'src/regions/base_region.dart';
Expand All @@ -69,8 +68,7 @@ part 'src/root/manage.dart';
part 'src/root/migrator.dart';
part 'src/root/recovery.dart';
part 'src/root/statistics.dart';
part 'src/settings/fmtc_settings.dart';
part 'src/settings/tile_provider_settings.dart';
part 'src/providers/tile_provider_settings.dart';
part 'src/store/directory.dart';
part 'src/store/download.dart';
part 'src/store/export.dart';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@

export 'impls/objectbox/backend.dart';
export 'interfaces/backend.dart';
export 'interfaces/models.dart';
export 'utils/errors.dart';
6 changes: 6 additions & 0 deletions lib/src/backend/export_internal.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright © Luka S (JaffaKetchup) under GPL-v3
// A full license can be found at .\LICENSE

export 'export_external.dart';

export 'interfaces/models.dart';
Loading

0 comments on commit 87f7bc2

Please sign in to comment.