3
0
Fork 0

Refresh Sites when a site is saved (closes #89) (#93)

* Refresh Sites when a site is saved (closes #89)

* Update with iOS side fix
This commit is contained in:
John Maguire 2022-11-18 16:03:52 -05:00 committed by GitHub
parent 6108bf801b
commit 974c7a4eed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 4 deletions

View File

@ -210,7 +210,6 @@ class MainActivity: FlutterActivity() {
val gson = Gson() val gson = Gson()
site = gson.fromJson(call.arguments as String, IncomingSite::class.java) site = gson.fromJson(call.arguments as String, IncomingSite::class.java)
siteDir = site.save(context) siteDir = site.save(context)
} catch (err: Exception) { } catch (err: Exception) {
//TODO: is toString the best or .message? //TODO: is toString the best or .message?
return result.error("failure", err.toString(), null) 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) return result.error("failure", "Site config was incomplete, please review and try again", null)
} }
sites?.refreshSites()
result.success(null) result.success(null)
} }

View File

@ -184,7 +184,9 @@ func MissingArgumentError(message: String, details: Any?) -> FlutterError {
return result(CallFailedError(message: "Failed to save site", details: error!.localizedDescription)) return result(CallFailedError(message: "Failed to save site", details: error!.localizedDescription))
} }
result(nil) self.sites?.loadSites { _, _ in
result(nil)
}
} }
} }

View File

@ -26,8 +26,13 @@ class Sites {
} }
sites?.values.forEach{ site in sites?.values.forEach{ site in
let updater = SiteUpdater(messenger: self.messenger!, site: site) var updater = self.containers[site.id]?.updater
self.containers[site.id] = SiteContainer(site: site, updater: 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 { let justSites = self.containers.mapValues {
@ -113,6 +118,10 @@ class SiteUpdater: NSObject, FlutterStreamHandler {
self.configObserver?.resume() self.configObserver?.resume()
} }
func setSite(site: Site) {
self.site = site
}
/// onListen is called when flutter code attaches an event listener /// onListen is called when flutter code attaches an event listener
func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink) -> FlutterError? { func onListen(withArguments arguments: Any?, eventSink events: @escaping FlutterEventSink) -> FlutterError? {
eventSink = events; eventSink = events;

View File

@ -230,6 +230,7 @@ class _SiteDetailScreenState extends State<SiteDetailScreen> {
site: widget.site, site: widget.site,
onSave: (site) async { onSave: (site) async {
changed = true; changed = true;
setState(() {});
}); });
}); });
}, },