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 <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2016-04-10 19:22:16 -07:00
parent 4ed369b975
commit 18b7ee3875
2 changed files with 20 additions and 9 deletions

View file

@ -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)
QList<dive *>diveAsList;
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()

View file

@ -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);