From bd24b78acb8105e81a855068f9002f0a71b729d9 Mon Sep 17 00:00:00 2001 From: Peter Storch Date: Wed, 31 Aug 2016 23:20:53 +0200 Subject: [PATCH] WIP: fix #4086, #4699 offline logs --- .../src/cgeo/geocaching/LogCacheActivity.java | 24 +++++++++++++------ .../cgeo/geocaching/storage/DataStore.java | 5 ++-- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/main/src/cgeo/geocaching/LogCacheActivity.java b/main/src/cgeo/geocaching/LogCacheActivity.java index 940c253bd3d..ec83e5001d2 100644 --- a/main/src/cgeo/geocaching/LogCacheActivity.java +++ b/main/src/cgeo/geocaching/LogCacheActivity.java @@ -14,6 +14,7 @@ import cgeo.geocaching.gcvote.GCVote; import cgeo.geocaching.gcvote.GCVoteRatingBarUtil; import cgeo.geocaching.gcvote.GCVoteRatingBarUtil.OnRatingChangeListener; +import cgeo.geocaching.list.StoredList; import cgeo.geocaching.models.Geocache; import cgeo.geocaching.models.Image; import cgeo.geocaching.models.LogEntry; @@ -32,11 +33,6 @@ import cgeo.geocaching.utils.LogTemplateProvider.LogContext; import cgeo.geocaching.utils.TextUtils; -import com.github.amlcurran.showcaseview.targets.ActionItemTarget; - -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; - import android.R.string; import android.app.Activity; import android.app.AlertDialog; @@ -44,6 +40,7 @@ import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.content.Intent; +import android.os.AsyncTask; import android.os.Bundle; import android.util.SparseArray; import android.view.LayoutInflater; @@ -68,6 +65,9 @@ import butterknife.BindView; import butterknife.ButterKnife; +import com.github.amlcurran.showcaseview.targets.ActionItemTarget; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import rx.Observable; import rx.android.app.AppObservable; import rx.functions.Action1; @@ -626,8 +626,18 @@ private void saveLog(final boolean force) { // without using "Clear". This may be a manipulation mistake, and erasing // again will be easy using "Clear" while retyping the text may not be. if (force || (StringUtils.isNotEmpty(log) && !StringUtils.equals(log, text))) { - cache.logOffline(this, log, date, typeSelected); - Settings.setLastCacheLog(log); + new AsyncTask() { + @Override + protected Void doInBackground(final Void... params) { + if (!cache.isOffline()) { + cache.getLists().add(StoredList.STANDARD_LIST_ID); + cache.store(); + } + cache.logOffline(LogCacheActivity.this, log, date, typeSelected); + Settings.setLastCacheLog(log); + return null; + } + }.execute(); } text = log; } diff --git a/main/src/cgeo/geocaching/storage/DataStore.java b/main/src/cgeo/geocaching/storage/DataStore.java index ccb6de6eced..1fd95c1578a 100644 --- a/main/src/cgeo/geocaching/storage/DataStore.java +++ b/main/src/cgeo/geocaching/storage/DataStore.java @@ -46,6 +46,8 @@ import android.database.sqlite.SQLiteDoneException; import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteStatement; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import java.io.File; import java.io.FilenameFilter; @@ -72,8 +74,6 @@ import org.apache.commons.collections4.MapUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; import rx.Observable; import rx.Observable.OnSubscribe; import rx.Subscriber; @@ -2667,6 +2667,7 @@ public static void clearLogsOffline(final List caches) { } database.execSQL(String.format("DELETE FROM %s where %s", dbTableLogsOffline, whereGeocodeIn(Geocache.getGeocodes(caches)))); + database.execSQL(String.format("UPDATE %s SET visiteddate = 0 where %s", dbTableCaches, whereGeocodeIn(Geocache.getGeocodes(caches)))); } public static boolean hasLogOffline(final String geocode) {