Skip to content

Commit

Permalink
Added tracking support to recovery system to skip downloading already…
Browse files Browse the repository at this point in the history
… downloaded tiles

Fixed tile counters and generators (and downloader) to respect `DownloadableRegion.start` and `.end`
Reduced memory consumption of `deleteTiles` in backend worker
Added tests for bounded tile counters and generators
Improved example application
  • Loading branch information
JaffaKetchup committed Apr 11, 2024
1 parent 9de462f commit f3f5bc7
Show file tree
Hide file tree
Showing 35 changed files with 604 additions and 375 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ class RegionInformation extends StatefulWidget {
required this.region,
required this.minZoom,
required this.maxZoom,
required this.startTile,
required this.endTile,
});

final BaseRegion region;
final int minZoom;
final int maxZoom;
final int startTile;
final int? endTile;

@override
State<RegionInformation> createState() => _RegionInformationState();
Expand Down Expand Up @@ -180,7 +184,7 @@ class _RegionInformationState extends State<RegionInformation> {
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
const Text('MIN/MAX ZOOM LEVELS'),
const Text('ZOOM LEVELS'),
Text(
'${widget.minZoom} - ${widget.maxZoom}',
style: const TextStyle(
Expand Down Expand Up @@ -218,6 +222,24 @@ class _RegionInformationState extends State<RegionInformation> {
),
),
),
const SizedBox(height: 10),
const Text('TILES RANGE'),
if (widget.startTile == 1 && widget.endTile == null)
const Text(
'*',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 24,
),
)
else
Text(
'${NumberFormat('###,###').format(widget.startTile)} - ${widget.endTile != null ? NumberFormat('###,###').format(widget.endTile) : '*'}',
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 24,
),
),
],
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ class StartDownloadButton extends StatelessWidget {
required this.region,
required this.minZoom,
required this.maxZoom,
required this.startTile,
required this.endTile,
});

final BaseRegion region;
final int minZoom;
final int maxZoom;
final int startTile;
final int? endTile;

@override
Widget build(BuildContext context) =>
Expand Down Expand Up @@ -98,6 +102,8 @@ class StartDownloadButton extends StatelessWidget {
region: region.toDownloadable(
minZoom: minZoom,
maxZoom: maxZoom,
start: startTile,
end: endTile,
options: TileLayer(
urlTemplate: metadata['sourceURL'],
userAgentPackageName:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ class ConfigureDownloadPopup extends StatelessWidget {
required this.region,
required this.minZoom,
required this.maxZoom,
required this.startTile,
required this.endTile,
});

final BaseRegion region;
final int minZoom;
final int maxZoom;
final int startTile;
final int? endTile;

@override
Widget build(BuildContext context) => Scaffold(
Expand All @@ -29,6 +33,8 @@ class ConfigureDownloadPopup extends StatelessWidget {
region: region,
minZoom: minZoom,
maxZoom: maxZoom,
startTile: startTile,
endTile: endTile,
),
body: Stack(
fit: StackFit.expand,
Expand All @@ -44,6 +50,8 @@ class ConfigureDownloadPopup extends StatelessWidget {
region: region,
minZoom: minZoom,
maxZoom: maxZoom,
startTile: startTile,
endTile: endTile,
),
const Divider(thickness: 2, height: 8),
const OptionsPane(
Expand Down
4 changes: 2 additions & 2 deletions example/lib/screens/export_import/components/path_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class PathPicker extends StatelessWidget {
);
if (picked != null) {
pathController.value = TextEditingValue(
text: picked,
text: '$picked.fmtc',
selection: TextSelection.collapsed(
offset: picked.length,
),
Expand Down Expand Up @@ -88,7 +88,7 @@ class PathPicker extends StatelessWidget {
);
if (picked != null) {
pathController.value = TextEditingValue(
text: picked,
text: '$picked.fmtc',
selection: TextSelection.collapsed(
offset: picked.length,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class RecoveryList extends StatefulWidget {

class _RecoveryListState extends State<RecoveryList> {
@override
Widget build(BuildContext context) => ListView.builder(
Widget build(BuildContext context) => ListView.separated(
itemCount: widget.all.length,
itemBuilder: (context, index) {
final result = widget.all.elementAt(index);
Expand Down Expand Up @@ -52,10 +52,10 @@ class _RecoveryListState extends State<RecoveryList> {
addressDetails: true,
),
builder: (context, response) => Text(
'Started at ${region.time} (~${DateTime.timestamp().difference(region.time).inMinutes} minutes ago)\n${response.hasData ? 'Center near ${response.data!.address!['postcode']}, ${response.data!.address!['country']}' : response.hasError ? 'Unable To Reverse Geocode Location' : 'Please Wait...'}',
'Started at ${region.time} (~${DateTime.timestamp().difference(region.time).inMinutes} minutes ago)\nCompleted ${region.start - 1} of ${region.end}\n${response.hasData ? 'Center near ${response.data!.address!['postcode']}, ${response.data!.address!['country']}' : response.hasError ? 'Unable To Reverse Geocode Location' : 'Please Wait...'}',
),
),
onTap: () {},
isThreeLine: true,
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
Expand All @@ -80,5 +80,6 @@ class _RecoveryListState extends State<RecoveryList> {
),
);
},
separatorBuilder: (context, index) => const Divider(),
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class RecoveryStartButton extends StatelessWidget {
region: regionSelectionProvider.region!,
minZoom: result.region.minZoom,
maxZoom: result.region.maxZoom,
startTile: result.region.start,
endTile: result.region.end,
),
fullscreenDialog: true,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ class _RegionSelectionPageState extends State<RegionSelectionPage> {
region: provider.region!,
minZoom: provider.minZoom,
maxZoom: provider.maxZoom,
startTile: provider.startTile,
endTile: provider.endTile,
),
fullscreenDialog: true,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ class RegionSelectionProvider extends ChangeNotifier {
notifyListeners();
}

int _startTile = 1;
int get startTile => _startTile;
set startTile(int newNum) {
_startTile = newNum;
notifyListeners();
}

int? _endTile;
int? get endTile => _endTile;
set endTile(int? newNum) {
_endTile = endTile;
notifyListeners();
}

FMTCStore? _selectedStore;
FMTCStore? get selectedStore => _selectedStore;
void setSelectedStore(FMTCStore? newStore, {bool notify = true}) {
Expand Down
1 change: 1 addition & 0 deletions lib/flutter_map_tile_caching.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'dart:collection';
import 'dart:io';
import 'dart:isolate';
import 'dart:math' as math;
import 'dart:math';

import 'package:async/async.dart';
import 'package:collection/collection.dart';
Expand Down
11 changes: 0 additions & 11 deletions lib/src/backend/impls/objectbox/backend/internal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -523,17 +523,6 @@ class _ObjectBoxBackendImpl implements FMTCObjectBoxBackendInternal {
type: _CmdType.getRecoverableRegion,
))!['recoverableRegion'];

@override
Future<void> startRecovery({
required int id,
required String storeName,
required DownloadableRegion region,
}) =>
_sendCmdOneShot(
type: _CmdType.startRecovery,
args: {'id': id, 'storeName': storeName, 'region': region},
);

@override
Future<void> cancelRecovery({
required int id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ enum _CmdType {
resetMetadata,
listRecoverableRegions,
getRecoverableRegion,
startRecovery,
cancelRecovery,
watchRecovery(hasInternalStreamSub: true),
watchStores(hasInternalStreamSub: true),
Expand Down
Loading

0 comments on commit f3f5bc7

Please sign in to comment.