Skip to content

Commit

Permalink
map: vector tile cache on external storage
Browse files Browse the repository at this point in the history
  • Loading branch information
deckerst committed Oct 20, 2024
1 parent 5f80fab commit a3b6136
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class StorageHandler(private val context: Context) : MethodCallHandler {
when (call.method) {
"getDataUsage" -> ioScope.launch { safe(call, result, ::getDataUsage) }
"getStorageVolumes" -> ioScope.launch { safe(call, result, ::getStorageVolumes) }
"getCacheDirectory" -> ioScope.launch { safe(call, result, ::getCacheDirectory) }
"getUntrackedTrashPaths" -> ioScope.launch { safe(call, result, ::getUntrackedTrashPaths) }
"getUntrackedVaultPaths" -> ioScope.launch { safe(call, result, ::getUntrackedVaultPaths) }
"getVaultRoot" -> ioScope.launch { safe(call, result, ::getVaultRoot) }
Expand Down Expand Up @@ -122,6 +123,18 @@ class StorageHandler(private val context: Context) : MethodCallHandler {
result.success(volumes)
}

private fun getCacheDirectory(call: MethodCall, result: MethodChannel.Result) {
val external = call.argument<Boolean>("external")
if (external == null) {
result.error("getCacheDirectory-args", "missing arguments", null)
return
}

val dir = (if (external) context.externalCacheDir else context.cacheDir)
result.success(dir!!.path)
}


private fun getUntrackedTrashPaths(call: MethodCall, result: MethodChannel.Result) {
val knownPaths = call.argument<List<String>>("knownPaths")
if (knownPaths == null) {
Expand Down
15 changes: 15 additions & 0 deletions lib/services/storage_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ abstract class StorageService {

Future<Set<StorageVolume>> getStorageVolumes();

Future<String> getExternalCacheDirectory();

Future<Set<String>> getUntrackedTrashPaths(Iterable<String> knownPaths);

Future<Set<String>> getUntrackedVaultPaths(String vaultName, Iterable<String> knownPaths);
Expand Down Expand Up @@ -79,6 +81,19 @@ class PlatformStorageService implements StorageService {
return {};
}

@override
Future<String> getExternalCacheDirectory() async {
try {
final result = await _platform.invokeMethod('getCacheDirectory', <String, dynamic>{
'external': true,
});
return result as String;
} on PlatformException catch (e, stack) {
await reportService.recordError(e, stack);
}
return '';
}

@override
Future<Set<String>> getUntrackedTrashPaths(Iterable<String> knownPaths) async {
try {
Expand Down
7 changes: 7 additions & 0 deletions lib/widgets/common/map/leaflet/tile_layers.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import 'dart:io';

import 'package:aves/model/device.dart';
import 'package:aves/services/common/services.dart';
import 'package:aves/widgets/common/map/leaflet/vector_style_reader_extra.dart';
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
Expand Down Expand Up @@ -115,6 +118,10 @@ class _OsmLibertyLayerState extends State<OsmLibertyLayer> {
sprites: style.sprites,
// `vector` is higher quality and follows map orientation, but it is slower
layerMode: VectorTileLayerMode.raster,
cacheFolder: () async {
final cacheRoot = await storageService.getExternalCacheDirectory();
return Directory(pContext.join(cacheRoot, 'map_vector_tiles'));
},
);
},
);
Expand Down

0 comments on commit a3b6136

Please sign in to comment.