From 974c7a4eedb811eb23640a90cf67f3e78740438c Mon Sep 17 00:00:00 2001 From: John Maguire Date: Fri, 18 Nov 2022 16:03:52 -0500 Subject: [PATCH] Refresh Sites when a site is saved (closes #89) (#93) * Refresh Sites when a site is saved (closes #89) * Update with iOS side fix --- .../net/defined/mobile_nebula/MainActivity.kt | 3 ++- ios/Runner/AppDelegate.swift | 4 +++- ios/Runner/Sites.swift | 13 +++++++++++-- lib/screens/SiteDetailScreen.dart | 1 + 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/android/app/src/main/kotlin/net/defined/mobile_nebula/MainActivity.kt b/android/app/src/main/kotlin/net/defined/mobile_nebula/MainActivity.kt index 16dd379..9cf201a 100644 --- a/android/app/src/main/kotlin/net/defined/mobile_nebula/MainActivity.kt +++ b/android/app/src/main/kotlin/net/defined/mobile_nebula/MainActivity.kt @@ -210,7 +210,6 @@ class MainActivity: FlutterActivity() { val gson = Gson() site = gson.fromJson(call.arguments as String, IncomingSite::class.java) siteDir = site.save(context) - } catch (err: Exception) { //TODO: is toString the best or .message? return result.error("failure", err.toString(), null) @@ -220,6 +219,8 @@ class MainActivity: FlutterActivity() { return result.error("failure", "Site config was incomplete, please review and try again", null) } + sites?.refreshSites() + result.success(null) } diff --git a/ios/Runner/AppDelegate.swift b/ios/Runner/AppDelegate.swift index 2f96515..5256db2 100644 --- a/ios/Runner/AppDelegate.swift +++ b/ios/Runner/AppDelegate.swift @@ -184,7 +184,9 @@ func MissingArgumentError(message: String, details: Any?) -> FlutterError { return result(CallFailedError(message: "Failed to save site", details: error!.localizedDescription)) } - result(nil) + self.sites?.loadSites { _, _ in + result(nil) + } } } diff --git a/ios/Runner/Sites.swift b/ios/Runner/Sites.swift index 5c95b87..d0e14c3 100644 --- a/ios/Runner/Sites.swift +++ b/ios/Runner/Sites.swift @@ -26,8 +26,13 @@ class Sites { } sites?.values.forEach{ site in - let updater = SiteUpdater(messenger: self.messenger!, site: site) - self.containers[site.id] = SiteContainer(site: site, updater: updater) + var updater = self.containers[site.id]?.updater + if (updater != nil) { + updater!.setSite(site: site) + } else { + updater = SiteUpdater(messenger: self.messenger!, site: site) + } + self.containers[site.id] = SiteContainer(site: site, updater: updater!) } let justSites = self.containers.mapValues { @@ -113,6 +118,10 @@ class SiteUpdater: NSObject, FlutterStreamHandler { self.configObserver?.resume() } + func setSite(site: Site) { + self.site = site + } + /// onListen is called when flutter code attaches an event listener func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink) -> FlutterError? { eventSink = events; diff --git a/lib/screens/SiteDetailScreen.dart b/lib/screens/SiteDetailScreen.dart index 7a18ac2..0580501 100644 --- a/lib/screens/SiteDetailScreen.dart +++ b/lib/screens/SiteDetailScreen.dart @@ -230,6 +230,7 @@ class _SiteDetailScreenState extends State { site: widget.site, onSave: (site) async { changed = true; + setState(() {}); }); }); },