diff --git a/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/StorageHandler.kt b/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/StorageHandler.kt index baee7c5e8..9b2893745 100644 --- a/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/StorageHandler.kt +++ b/android/app/src/main/kotlin/deckers/thibault/aves/channel/calls/StorageHandler.kt @@ -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) } @@ -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("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>("knownPaths") if (knownPaths == null) { diff --git a/lib/services/storage_service.dart b/lib/services/storage_service.dart index c97206cda..bb597a7a4 100644 --- a/lib/services/storage_service.dart +++ b/lib/services/storage_service.dart @@ -12,6 +12,8 @@ abstract class StorageService { Future> getStorageVolumes(); + Future getExternalCacheDirectory(); + Future> getUntrackedTrashPaths(Iterable knownPaths); Future> getUntrackedVaultPaths(String vaultName, Iterable knownPaths); @@ -79,6 +81,19 @@ class PlatformStorageService implements StorageService { return {}; } + @override + Future getExternalCacheDirectory() async { + try { + final result = await _platform.invokeMethod('getCacheDirectory', { + 'external': true, + }); + return result as String; + } on PlatformException catch (e, stack) { + await reportService.recordError(e, stack); + } + return ''; + } + @override Future> getUntrackedTrashPaths(Iterable knownPaths) async { try { diff --git a/lib/widgets/common/map/leaflet/tile_layers.dart b/lib/widgets/common/map/leaflet/tile_layers.dart index 417947ff8..fd7d5085c 100644 --- a/lib/widgets/common/map/leaflet/tile_layers.dart +++ b/lib/widgets/common/map/leaflet/tile_layers.dart @@ -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'; @@ -115,6 +118,10 @@ class _OsmLibertyLayerState extends State { 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')); + }, ); }, );