Skip to content

Commit

Permalink
Implemented watching
Browse files Browse the repository at this point in the history
Fixed bugs
Enabled compilation of example app by temporary removal of import/export plugin
  • Loading branch information
JaffaKetchup committed Feb 21, 2024
1 parent 447225d commit bfde197
Show file tree
Hide file tree
Showing 17 changed files with 205 additions and 291 deletions.
20 changes: 11 additions & 9 deletions example/lib/screens/import_store/import_store.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_map_tile_caching/flutter_map_tile_caching.dart';
import 'package:fmtc_plus_sharing/fmtc_plus_sharing.dart';
//import 'package:flutter_map_tile_caching/flutter_map_tile_caching.dart';
//import 'package:fmtc_plus_sharing/fmtc_plus_sharing.dart';

class ImportStorePopup extends StatefulWidget {
const ImportStorePopup({super.key});
Expand All @@ -14,14 +14,15 @@ class ImportStorePopup extends StatefulWidget {
class _ImportStorePopupState extends State<ImportStorePopup> {
final Map<String, _ImportStore> importStores = {};

// TODO: Implement
@override
Widget build(BuildContext context) => Scaffold(
appBar: AppBar(
title: const Text('Import Stores'),
),
body: Padding(
padding: const EdgeInsets.all(12),
child: ListView.separated(
body: const Padding(
padding: EdgeInsets.all(12),
/*child: ListView.separated(
itemCount: importStores.length + 1,
itemBuilder: (context, i) {
if (i == importStores.length) {
Expand All @@ -30,7 +31,7 @@ class _ImportStorePopupState extends State<ImportStorePopup> {
title: const Text('Choose New Store(s)'),
subtitle: const Text('Select any valid store files (.fmtc)'),
onTap: () async {
importStores.addAll(
/*importStores.addAll(
(await FMTCRoot.import.withGUI(
collisionHandler: (fn, sn) {
setState(
Expand All @@ -51,7 +52,8 @@ class _ImportStorePopupState extends State<ImportStorePopup> {
_ImportStore(status, collisionInfo: null),
),
),
);
);*/
if (mounted) setState(() {});
},
);
Expand Down Expand Up @@ -131,13 +133,13 @@ class _ImportStorePopupState extends State<ImportStorePopup> {
separatorBuilder: (context, i) => i == importStores.length - 1
? const Divider()
: const SizedBox.shrink(),
),
),*/
),
);
}

class _ImportStore {
final Future<ImportResult> result;
final Future result;
List<String>? collisionInfo;
Completer<bool> collisionResolution;

Expand Down
2 changes: 1 addition & 1 deletion example/lib/screens/main/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class _MainScreenState extends State<MainScreen> {
NavigationDestination(
label: 'Recover',
icon: StreamBuilder(
stream: FMTCRoot.stats.watchChanges().asBroadcastStream(),
stream: FMTCRoot.stats.watchRecovery(),
builder: (context, _) => FutureBuilder(
future: FMTCRoot.recovery.recoverableRegions,
builder: (context, snapshot) => Badge(
Expand Down
2 changes: 1 addition & 1 deletion example/lib/screens/main/pages/recovery/recovery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class _RecoveryPageState extends State<RecoveryPage> {
_recoverableRegions = FMTCRoot.recovery.recoverableRegions;

listRecoverableRegions();
FMTCRoot.stats.watchChanges(watchRecovery: true).listen((_) {
FMTCRoot.stats.watchRecovery().listen((_) {
if (mounted) {
listRecoverableRegions();
setState(() {});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_map_tile_caching/flutter_map_tile_caching.dart';
import 'package:fmtc_plus_sharing/fmtc_plus_sharing.dart';
import 'package:provider/provider.dart';

import '../../../../../shared/misc/exts/size_formatter.dart';
Expand Down Expand Up @@ -207,7 +206,8 @@ class _StoreTileState extends State<StoreTile> {
onPressed: _exportingProgress
? null
: () async {
setState(
// TODO: Implement
/* setState(
() => _exportingProgress = true,
);
final bool result = await _store
Expand All @@ -228,7 +228,7 @@ class _StoreTileState extends State<StoreTile> {
),
),
);
}
}*/
},
),
IconButton(
Expand Down
5 changes: 3 additions & 2 deletions example/lib/screens/main/pages/stores/stores.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class _StoresPageState extends State<StoresPage> {
void listStores() => _stores = FMTCRoot.stats.storesAvailable;

listStores();
FMTCRoot.stats.watchChanges().listen((_) {
FMTCRoot.stats.watchStores().listen((_) {
if (mounted) {
listStores();
setState(() {});
Expand All @@ -48,7 +48,8 @@ class _StoresPageState extends State<StoresPage> {
child: FutureBuilder<Iterable<FMTCStore>>(
future: _stores,
builder: (context, snapshot) => snapshot.hasError
? throw snapshot.error! as FMTCDamagedStoreException
// ignore: only_throw_errors
? throw snapshot.error!
: snapshot.hasData
? snapshot.data!.isEmpty
? const EmptyIndicator()
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies:
flutter_map_animations: ^0.5.3
flutter_map_tile_caching: ^9.0.0-dev.5
flutter_speed_dial: ^7.0.0
fmtc_plus_sharing: ^8.0.0
#fmtc_plus_sharing: ^8.0.0
google_fonts: ^6.1.0
gpx: ^2.2.1
http: ^1.1.2
Expand Down
7 changes: 6 additions & 1 deletion example/windows/flutter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ include(${EPHEMERAL_DIR}/generated_config.cmake)
# https://github.com/flutter/flutter/issues/57146.
set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper")

# Set fallback configurations for older versions of the flutter tool.
if (NOT DEFINED FLUTTER_TARGET_PLATFORM)
set(FLUTTER_TARGET_PLATFORM "windows-x64")
endif()

# === Flutter Library ===
set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll")

Expand Down Expand Up @@ -92,7 +97,7 @@ add_custom_command(
COMMAND ${CMAKE_COMMAND} -E env
${FLUTTER_TOOL_ENVIRONMENT}
"${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat"
windows-x64 $<CONFIG>
${FLUTTER_TARGET_PLATFORM} $<CONFIG>
VERBATIM
)
add_custom_target(flutter_assemble DEPENDS
Expand Down
9 changes: 0 additions & 9 deletions example/windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,9 @@

#include "generated_plugin_registrant.h"

#include <isar_flutter_libs/isar_flutter_libs_plugin.h>
#include <objectbox_flutter_libs/objectbox_flutter_libs_plugin.h>
#include <share_plus/share_plus_windows_plugin_c_api.h>
#include <url_launcher_windows/url_launcher_windows.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
IsarFlutterLibsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("IsarFlutterLibsPlugin"));
ObjectboxFlutterLibsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ObjectboxFlutterLibsPlugin"));
SharePlusWindowsPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("SharePlusWindowsPluginCApi"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
}
3 changes: 0 additions & 3 deletions example/windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
#

list(APPEND FLUTTER_PLUGIN_LIST
isar_flutter_libs
objectbox_flutter_libs
share_plus
url_launcher_windows
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
Expand Down
1 change: 0 additions & 1 deletion lib/flutter_map_tile_caching.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ 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/providers/tile_provider.dart';
part 'src/regions/base_region.dart';
Expand Down
49 changes: 39 additions & 10 deletions lib/src/backend/impls/objectbox/backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import 'dart:isolate';

import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';
import 'package:path/path.dart' as path;
import 'package:path_provider/path_provider.dart';

Expand Down Expand Up @@ -103,14 +101,7 @@ class _ObjectBoxBackendImpl implements FMTCObjectBoxBackendInternal {
_sendPort!.send((id: id, type: type, args: args));
final res = await _workerRes[id]!.future;
_workerRes.remove(id);

final err = res?['error'];
if (err == null) return res;

if (err is FMTCBackendError) throw err;
debugPrint('An unexpected error in the FMTC backend occurred:');
// ignore: only_throw_errors
throw err;
return res;
}

Future<void> initialise({
Expand Down Expand Up @@ -146,6 +137,22 @@ class _ObjectBoxBackendImpl implements FMTCObjectBoxBackendInternal {
_workerHandler = receivePort.listen(
(evt) {
evt as ({int id, Map<String, dynamic>? data});

final err = evt.data?['error'];
if (err != null) {
if (err is FMTCBackendError) throw err;

debugPrint('An unexpected error in the FMTC backend occurred:');
if (err is Error) {
debugPrint(err.stackTrace.toString());
throw err;
} else {
debugPrint(
'But it was not of type `Error`, it was type ${err.runtimeType}',
);
}
}

_workerRes[evt.id]!.complete(evt.data);
},
onDone: () => _workerComplete.complete(),
Expand Down Expand Up @@ -482,4 +489,26 @@ class _ObjectBoxBackendImpl implements FMTCObjectBoxBackendInternal {
required int id,
}) =>
_sendCmd(type: _WorkerCmdType.cancelRecovery, args: {'id': id});

@override
Future<Stream<void>> watchRecovery({
required bool triggerImmediately,
}) async =>
(await _sendCmd(
type: _WorkerCmdType.watchRecovery,
args: {'triggerImmediately': triggerImmediately},
))!['stream'];

@override
Future<Stream<void>> watchStores({
required List<String> storeNames,
required bool triggerImmediately,
}) async =>
(await _sendCmd(
type: _WorkerCmdType.watchStores,
args: {
'storeNames': storeNames,
'triggerImmediately': triggerImmediately,
},
))!['stream'];
}
32 changes: 31 additions & 1 deletion lib/src/backend/impls/objectbox/models/src/recovery.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright © Luka S (JaffaKetchup) under GPL-v3
// A full license can be found at .\LICENSE

import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';
import 'package:meta/meta.dart';
import 'package:objectbox/objectbox.dart';

Expand Down Expand Up @@ -66,7 +68,7 @@ base class ObjectBoxRecovery {
required this.customPolygonLngs,
});

ObjectBoxRecovery.startFromRegion({
ObjectBoxRecovery.fromRegion({
required this.refId,
required this.storeName,
required DownloadableRegion region,
Expand Down Expand Up @@ -141,4 +143,32 @@ base class ObjectBoxRecovery {
.map((c) => c.longitude)
.toList()
: null;

RecoveredRegion toRegion() => RecoveredRegion(
id: id,
storeName: storeName,
time: creationTime,
bounds: typeId == 0
? LatLngBounds(
LatLng(rectNwLat!, rectNwLng!),
LatLng(rectSeLat!, rectSeLng!),
)
: null,
center: typeId == 1 ? LatLng(circleCenterLat!, circleCenterLng!) : null,
line: typeId == 2 || typeId == 3
? List.generate(
lineLats!.length,
(i) => LatLng(lineLats![i], lineLngs![i]),
)
: null,
radius: typeId == 1
? circleRadius!
: typeId == 2
? lineRadius!
: null,
minZoom: minZoom,
maxZoom: maxZoom,
start: startTile,
end: endTile,
);
}
Loading

0 comments on commit bfde197

Please sign in to comment.