Skip to content

Commit 63c6704

Browse files
committed
Implemented initial tile loading debug system
Deprecated `obscuredQueryParams` Added `urlTransformer` & `urlTransformerOmitKeyValues` [as replacement for above Refactored `_FMTCImageProvider` internals
1 parent 0e89c6e commit 63c6704

File tree

14 files changed

+491
-346
lines changed

14 files changed

+491
-346
lines changed

example/lib/src/screens/home/config_view/panels/behaviour/behaviour.dart

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'package:flutter_map_tile_caching/flutter_map_tile_caching.dart';
23
import 'package:provider/provider.dart';
34

45
import '../../../../../shared/state/general_provider.dart';
@@ -9,42 +10,43 @@ class ConfigPanelBehaviour extends StatelessWidget {
910
});
1011

1112
@override
12-
Widget build(BuildContext context) => Selector<GeneralProvider, bool?>(
13-
selector: (context, provider) => provider.behaviourPrimary,
14-
builder: (context, behaviourPrimary, _) => Column(
13+
Widget build(BuildContext context) =>
14+
Selector<GeneralProvider, CacheBehavior>(
15+
selector: (context, provider) => provider.cacheBehavior,
16+
builder: (context, cacheBehavior, _) => Column(
1517
mainAxisSize: MainAxisSize.min,
1618
children: [
1719
SizedBox(
1820
width: double.infinity,
1921
child: SegmentedButton(
2022
segments: const [
2123
ButtonSegment(
22-
value: null,
24+
value: CacheBehavior.cacheOnly,
2325
icon: Icon(Icons.download_for_offline_outlined),
2426
label: Text('Cache Only'),
2527
),
2628
ButtonSegment(
27-
value: false,
29+
value: CacheBehavior.cacheFirst,
2830
icon: Icon(Icons.storage_rounded),
2931
label: Text('Cache'),
3032
),
3133
ButtonSegment(
32-
value: true,
34+
value: CacheBehavior.onlineFirst,
3335
icon: Icon(Icons.public_rounded),
3436
label: Text('Network'),
3537
),
3638
],
37-
selected: {behaviourPrimary},
39+
selected: {cacheBehavior},
3840
onSelectionChanged: (value) => context
3941
.read<GeneralProvider>()
40-
.behaviourPrimary = value.single,
42+
.cacheBehavior = value.single,
4143
style: const ButtonStyle(
4244
visualDensity: VisualDensity.comfortable,
4345
),
4446
),
4547
),
4648
const SizedBox(height: 6),
47-
Selector<GeneralProvider, bool>(
49+
/*Selector<GeneralProvider, bool>(
4850
selector: (context, provider) =>
4951
provider.behaviourUpdateFromNetwork,
5052
builder: (context, behaviourUpdateFromNetwork, _) => Row(
@@ -53,9 +55,8 @@ class ConfigPanelBehaviour extends StatelessWidget {
5355
const Text('Update cache when network used'),
5456
const Spacer(),
5557
Switch.adaptive(
56-
value:
57-
behaviourPrimary != null && behaviourUpdateFromNetwork,
58-
onChanged: behaviourPrimary == null
58+
value: cacheBehavior != null && behaviourUpdateFromNetwork,
59+
onChanged: cacheBehavior == null
5960
? null
6061
: (value) => context
6162
.read<GeneralProvider>()
@@ -69,7 +70,7 @@ class ConfigPanelBehaviour extends StatelessWidget {
6970
const SizedBox(width: 8),
7071
],
7172
),
72-
),
73+
),*/
7374
],
7475
),
7576
);

example/lib/src/shared/state/general_provider.dart

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,19 @@ class GeneralProvider extends ChangeNotifier {
2828
notifyListeners();
2929
}
3030

31-
CacheBehavior get behaviour =>
32-
switch ((_behaviourPrimary, _behaviourUpdateFromNetwork)) {
33-
(null, _) => CacheBehavior.cacheOnly,
34-
(false, false) => CacheBehavior.cacheFirstNoUpdate,
35-
(false, true) => CacheBehavior.cacheFirst,
36-
(true, false) => CacheBehavior.onlineFirstNoUpdate,
37-
(true, true) => CacheBehavior.onlineFirst,
38-
};
39-
40-
bool? _behaviourPrimary = false;
41-
bool? get behaviourPrimary => _behaviourPrimary;
42-
set behaviourPrimary(bool? newBehaviourPrimary) {
43-
_behaviourPrimary = newBehaviourPrimary;
31+
CacheBehavior _cacheBehavior = CacheBehavior.onlineFirst;
32+
CacheBehavior get cacheBehavior => _cacheBehavior;
33+
set cacheBehavior(CacheBehavior newCacheBehavior) {
34+
_cacheBehavior = newCacheBehavior;
4435
notifyListeners();
4536
}
4637

47-
bool _behaviourUpdateFromNetwork = true;
38+
/*bool _behaviourUpdateFromNetwork = true;
4839
bool get behaviourUpdateFromNetwork => _behaviourUpdateFromNetwork;
4940
set behaviourUpdateFromNetwork(bool newBehaviourUpdateFromNetwork) {
5041
_behaviourUpdateFromNetwork = newBehaviourUpdateFromNetwork;
5142
notifyListeners();
52-
}
43+
}*/
5344

5445
bool _displayDebugOverlay = true;
5546
bool get displayDebugOverlay => _displayDebugOverlay;

lib/flutter_map_tile_caching.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import 'src/bulk_download/instance.dart';
3535
import 'src/bulk_download/rate_limited_stream.dart';
3636
import 'src/bulk_download/tile_loops/shared.dart';
3737
import 'src/misc/int_extremes.dart';
38-
import 'src/misc/obscure_query_params.dart';
3938
import 'src/providers/browsing_errors.dart';
4039

4140
export 'src/backend/export_external.dart';
@@ -46,7 +45,9 @@ part 'src/bulk_download/download_progress.dart';
4645
part 'src/bulk_download/manager.dart';
4746
part 'src/bulk_download/thread.dart';
4847
part 'src/bulk_download/tile_event.dart';
48+
part 'src/providers/allowed_notify_value_notifier.dart';
4949
part 'src/providers/image_provider.dart';
50+
part 'src/providers/internal_get_bytes.dart';
5051
part 'src/providers/tile_provider.dart';
5152
part 'src/providers/tile_provider_settings.dart';
5253
part 'src/regions/base_region.dart';

lib/src/backend/interfaces/models.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@ import 'dart:typed_data';
55

66
import 'package:meta/meta.dart';
77

8-
import '../../misc/obscure_query_params.dart';
8+
import '../../../flutter_map_tile_caching.dart';
99

1010
/// Represents a tile (which is never directly exposed to the user)
1111
///
1212
/// Note that the relationship between stores and tiles is many-to-many, and
1313
/// backend implementations should fully support this.
1414
abstract base class BackendTile {
15-
/// The representative URL of the tile
15+
/// The storage-suitable UID of the tile
1616
///
17-
/// This is passed through [obscureQueryParams] before storage here, and so
18-
/// may not be the same as the network URL.
17+
/// This is the result of [FMTCTileProviderSettings.urlTransformer].
1918
String get url;
2019

2120
/// The time at which the [bytes] of this tile were last changed

lib/src/bulk_download/manager.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Future<void> _downloadManager(
1414
bool skipSeaTiles,
1515
Duration? maxReportInterval,
1616
int? rateLimit,
17-
List<RegExp> obscuredQueryParams,
17+
String Function(String) urlTransformer,
1818
int? recoveryId,
1919
FMTCBackendInternalThreadSafe backend,
2020
}) input,
@@ -223,7 +223,7 @@ Future<void> _downloadManager(
223223
maxBufferLength: threadBufferLength,
224224
skipExistingTiles: input.skipExistingTiles,
225225
seaTileBytes: seaTileBytes,
226-
obscuredQueryParams: input.obscuredQueryParams,
226+
urlTransformer: input.urlTransformer,
227227
headers: headers,
228228
backend: threadBackend,
229229
),

lib/src/bulk_download/thread.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Future<void> _singleDownloadThread(
1111
int maxBufferLength,
1212
bool skipExistingTiles,
1313
Uint8List? seaTileBytes,
14-
Iterable<RegExp> obscuredQueryParams,
14+
String Function(String) urlTransformer,
1515
Map<String, String> headers,
1616
FMTCBackendInternalThreadSafe backend,
1717
}) input,
@@ -65,10 +65,7 @@ Future<void> _singleDownloadThread(
6565
// Get new tile URL & any existing tile
6666
final networkUrl =
6767
input.options.tileProvider.getTileUrl(coordinates, input.options);
68-
final matcherUrl = obscureQueryParams(
69-
url: networkUrl,
70-
obscuredQueryParams: input.obscuredQueryParams,
71-
);
68+
final matcherUrl = input.urlTransformer(networkUrl);
7269

7370
final existingTile = await input.backend.readTile(
7471
url: matcherUrl,

lib/src/misc/obscure_query_params.dart

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright © Luka S (JaffaKetchup) under GPL-v3
2+
// A full license can be found at .\LICENSE
3+
4+
part of '../../flutter_map_tile_caching.dart';
5+
6+
class _AllowedNotifyValueNotifier<T> extends ValueNotifier<T> {
7+
_AllowedNotifyValueNotifier(super._value);
8+
9+
// Removes the `@protected` annotation, as we want to perform this operation
10+
// ourselves
11+
@override
12+
void notifyListeners() => super.notifyListeners();
13+
}

0 commit comments

Comments
 (0)