From 18b7ee3875f8e469a456b61f78fa3ab85b7f5041 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sun, 10 Apr 2016 19:22:16 -0700 Subject: QML UI: try to do the right thing for changes on all platforms On Android we can save locally right away, but we don't want to make the user wait for a network sync. Sadly, on Android currently the saving in the background doesn't work and the save will run when the user comes back. Definitely not ideal. On iOS the situation is different - a save to the local git cache takes surprisingly long. Must be the shitty file system they use or something. Because of that we only mark the dive list changed and instead save the next time the app is not in the foreground (which works on iOS but not on Android - go figure). On all the other OSs (I guess that would be desktop builds of Subsurface-mobile? But there may be other mobile OSs that people might want to build it on) we save both locally and to the cloud right away. Signed-off-by: Dirk Hohndel --- mobile-widgets/qmlmanager.cpp | 28 +++++++++++++++++++--------- mobile-widgets/qmlmanager.h | 1 + 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index 67b8d993b..d16ef1eab 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -737,10 +737,24 @@ parsed: DiveListModel::instance()->updateDive(oldModelIdx, d); } if (diveChanged || needResort) - // we no longer save right away, but only the next time the app is not - // in the foreground (or when explicitly requested) - mark_divelist_changed(true); + changesNeedSaving(); +} +void QMLManager::changesNeedSaving() +{ + // we no longer save right away on iOS because file access is so slow; on the other hand, + // on Android the save as the user switches away doesn't seem to work... drat. + // as a compromise for now we save just to local storage on Android right away (that appears + // to be reasonably fast), but don't save at all (and only remember that we need to save things + // on iOS + // on all other platforms we just save the changes and be done with it +#if defined(Q_OS_IOS) + mark_divelist_changed(true); +#elif defined(Q_OS_ANDROID) + saveChangesLocal(); +#else + saveChanges(); +#endif } void QMLManager::saveChangesLocal() { @@ -823,9 +837,7 @@ void QMLManager::undoDelete(int id) QListdiveAsList; diveAsList << deletedDive; DiveListModel::instance()->addDive(diveAsList); - // make sure the changes get saved if the app is no longer in the foreground - // or if the user requests a save - mark_divelist_changed(true); + changesNeedSaving(); deletedDive = NULL; deletedTrip = NULL; } @@ -860,9 +872,7 @@ void QMLManager::deleteDive(int id) } DiveListModel::instance()->removeDiveById(id); delete_single_dive(get_idx_by_uniq_id(id)); - // make sure the changes get saved if the app is no longer in the foreground - // or if the user requests a save - mark_divelist_changed(true); + changesNeedSaving(); } QString QMLManager::addDive() diff --git a/mobile-widgets/qmlmanager.h b/mobile-widgets/qmlmanager.h index bb9db791f..9609baddf 100644 --- a/mobile-widgets/qmlmanager.h +++ b/mobile-widgets/qmlmanager.h @@ -99,6 +99,7 @@ public slots: QString airtemp, QString watertemp, QString suit, QString buddy, QString diveMaster, QString weight, QString notes, QString startpressure, QString endpressure, QString gasmix); + void changesNeedSaving(); void saveChangesLocal(); void saveChangesCloud(bool forceRemoteSync); void deleteDive(int id); -- cgit v1.2.3-70-g09d2