aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2011-11-12 14:12:07 +0100
committerBananeweizen <bananeweizen@gmx.de>2011-11-12 14:12:07 +0100
commit9b43b1ed8f21577de6b020cdf03246cc74254681 (patch)
treeecd622bc075936104222e43e5f72d799553c6fb1
parent923c694b028a0b6541eb89164275297038655b02 (diff)
downloadcgeo-9b43b1ed8f21577de6b020cdf03246cc74254681.zip
cgeo-9b43b1ed8f21577de6b020cdf03246cc74254681.tar.gz
cgeo-9b43b1ed8f21577de6b020cdf03246cc74254681.tar.bz2
ask for restore after reinstallation, fixes #777
-rw-r--r--main/res/values/strings.xml1
-rw-r--r--main/src/cgeo/geocaching/activity/AbstractActivity.java2
-rw-r--r--main/src/cgeo/geocaching/activity/ActivityMixin.java5
-rw-r--r--main/src/cgeo/geocaching/cgData.java18
-rw-r--r--main/src/cgeo/geocaching/cgeo.java37
-rw-r--r--main/src/cgeo/geocaching/cgeoapplication.java36
-rw-r--r--main/src/cgeo/geocaching/cgeoinit.java24
7 files changed, 94 insertions, 29 deletions
diff --git a/main/res/values/strings.xml b/main/res/values/strings.xml
index d0ace1a..c44df8b 100644
--- a/main/res/values/strings.xml
+++ b/main/res/values/strings.xml
@@ -401,6 +401,7 @@
<string name="init_restore_success">Restoration completed.</string>
<string name="init_restore_failed">Restoration failed.</string>
<string name="init_restore_running">Restoring cache database…</string>
+ <string name="init_restore_confirm">Database is empty. Do you want to restore the database backup?</string>
<string name="init_backup_last">Available backup from</string>
<string name="init_backup_last_no">There is no file with backup.</string>
<string name="init_mapsources">Map Sources</string>
diff --git a/main/src/cgeo/geocaching/activity/AbstractActivity.java b/main/src/cgeo/geocaching/activity/AbstractActivity.java
index 5792fbe..ba3db88 100644
--- a/main/src/cgeo/geocaching/activity/AbstractActivity.java
+++ b/main/src/cgeo/geocaching/activity/AbstractActivity.java
@@ -60,7 +60,7 @@ public abstract class AbstractActivity extends Activity implements IAbstractActi
}
public final void helpDialog(final String title, final String message) {
- ActivityMixin.helpDialog(this, title, message, null);
+ ActivityMixin.helpDialog(this, title, message);
}
public final void helpDialog(final String title, final String message, final Drawable icon) {
diff --git a/main/src/cgeo/geocaching/activity/ActivityMixin.java b/main/src/cgeo/geocaching/activity/ActivityMixin.java
index d4f9edb..5561cc7 100644
--- a/main/src/cgeo/geocaching/activity/ActivityMixin.java
+++ b/main/src/cgeo/geocaching/activity/ActivityMixin.java
@@ -122,6 +122,10 @@ public final class ActivityMixin {
alert.show();
}
+ public static void helpDialog(Activity activity, String title, String message) {
+ helpDialog(activity, title, message, null);
+ }
+
protected static void addVisitMenu(IAbstractActivity activity, Menu menu, cgCache cache) {
if (cache == null) {
return;
@@ -145,5 +149,4 @@ public final class ActivityMixin {
}
}
}
-
}
diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java
index 6cfeab9..1724fdd 100644
--- a/main/src/cgeo/geocaching/cgData.java
+++ b/main/src/cgeo/geocaching/cgData.java
@@ -221,6 +221,7 @@ public class cgData {
public boolean initialized = false;
private SQLiteStatement statementDescription;
private SQLiteStatement statementLogCount;
+ private static boolean newlyCreatedDatabase = false;
public cgData(Context contextIn) {
context = contextIn;
@@ -385,6 +386,7 @@ public class cgData {
@Override
public void onCreate(SQLiteDatabase db) {
+ newlyCreatedDatabase = true;
db.execSQL(dbCreateCaches);
db.execSQL(dbCreateLists);
db.execSQL(dbCreateAttributes);
@@ -3364,4 +3366,20 @@ public class cgData {
return null;
}
+
+ /**
+ * checks if this is a newly created database
+ *
+ * @return
+ */
+ public static boolean isNewlyCreatedDatebase() {
+ return newlyCreatedDatabase;
+ }
+
+ /**
+ * resets flag for newly created database to avoid asking the user multiple times
+ */
+ public static void resetNewlyCreatedDatabase() {
+ newlyCreatedDatabase = false;
+ }
}
diff --git a/main/src/cgeo/geocaching/cgeo.java b/main/src/cgeo/geocaching/cgeo.java
index 2a4fb13..6be2e98 100644
--- a/main/src/cgeo/geocaching/cgeo.java
+++ b/main/src/cgeo/geocaching/cgeo.java
@@ -11,7 +11,9 @@ import cgeo.geocaching.maps.CGeoMap;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
+import android.app.AlertDialog;
import android.content.Context;
+import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
@@ -446,7 +448,7 @@ public class cgeo extends AbstractActivity {
(new firstLogin()).start();
}
- (new countBubbleUpdate()).start();
+ updateCacheCounter();
(new cleanDatabase()).start();
if (Settings.getCacheType() != null && !cgBase.cacheTypesInv.containsKey(Settings.getCacheType())) {
@@ -478,7 +480,7 @@ public class cgeo extends AbstractActivity {
});
registerForContextMenu(findByOffline);
- (new countBubbleUpdate()).start();
+ updateCacheCounter();
final View advanced = findViewById(R.id.advanced_button);
advanced.setClickable(true);
@@ -506,6 +508,37 @@ public class cgeo extends AbstractActivity {
});
setFilterTitle();
+ checkRestore();
+ }
+
+ private void updateCacheCounter() {
+ (new countBubbleUpdate()).start();
+ }
+
+ private void checkRestore() {
+ if (!cgData.isNewlyCreatedDatebase() || null == cgData.isRestoreFile()) {
+ return;
+ }
+ new AlertDialog.Builder(this)
+ .setTitle(res.getString(R.string.init_backup_restore))
+ .setMessage(res.getString(R.string.init_restore_confirm))
+ .setCancelable(false)
+ .setPositiveButton(getString(android.R.string.yes), new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.dismiss();
+ cgData.resetNewlyCreatedDatabase();
+ app.restoreDatabase(cgeo.this);
+ updateCacheCounter();
+ }
+ })
+ .setNegativeButton(getString(android.R.string.no), new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.cancel();
+ cgData.resetNewlyCreatedDatabase();
+ }
+ })
+ .create()
+ .show();
}
private class update extends cgUpdateLoc {
diff --git a/main/src/cgeo/geocaching/cgeoapplication.java b/main/src/cgeo/geocaching/cgeoapplication.java
index 486665a..7ae1575 100644
--- a/main/src/cgeo/geocaching/cgeoapplication.java
+++ b/main/src/cgeo/geocaching/cgeoapplication.java
@@ -1,5 +1,6 @@
package cgeo.geocaching;
+import cgeo.geocaching.activity.ActivityMixin;
import cgeo.geocaching.enumerations.CacheType;
import cgeo.geocaching.enumerations.StatusCode;
import cgeo.geocaching.geopoint.Geopoint;
@@ -7,8 +8,13 @@ import cgeo.geocaching.geopoint.Geopoint;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
+import android.app.Activity;
import android.app.Application;
+import android.app.ProgressDialog;
import android.content.Context;
+import android.content.res.Resources;
+import android.os.Handler;
+import android.os.Message;
import android.util.Log;
import java.io.File;
@@ -17,6 +23,7 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
public class cgeoapplication extends Application {
@@ -81,8 +88,33 @@ public class cgeoapplication extends Application {
return cgData.isRestoreFile();
}
- public boolean restoreDatabase() {
- return storage.restoreDatabase();
+ /**
+ * restore the database in a new thread, showing a progress window
+ *
+ * @param fromActivity
+ * calling activity
+ */
+ public void restoreDatabase(final Activity fromActivity) {
+ final Resources res = this.getResources();
+ final ProgressDialog dialog = ProgressDialog.show(fromActivity, res.getString(R.string.init_backup_restore), res.getString(R.string.init_restore_running), true, false);
+ final AtomicBoolean atomic = new AtomicBoolean(false);
+ Thread restoreThread = new Thread() {
+ final Handler handler = new Handler() {
+ public void handleMessage(Message msg) {
+ dialog.dismiss();
+ boolean restored = atomic.get();
+ String message = restored ? res.getString(R.string.init_restore_success) : res.getString(R.string.init_restore_failed);
+ ActivityMixin.helpDialog(fromActivity, res.getString(R.string.init_backup_restore), message);
+ }
+ };
+
+ @Override
+ public void run() {
+ atomic.set(storage.restoreDatabase());
+ handler.sendMessage(handler.obtainMessage());
+ }
+ };
+ restoreThread.start();
}
public void cleanGeo() {
diff --git a/main/src/cgeo/geocaching/cgeoinit.java b/main/src/cgeo/geocaching/cgeoinit.java
index 8391f15..13a358c 100644
--- a/main/src/cgeo/geocaching/cgeoinit.java
+++ b/main/src/cgeo/geocaching/cgeoinit.java
@@ -33,7 +33,6 @@ import android.widget.Spinner;
import android.widget.TextView;
import java.io.File;
-import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
public class cgeoinit extends AbstractActivity {
@@ -603,28 +602,7 @@ public class cgeoinit extends AbstractActivity {
* unused here but needed since this method is referenced from XML layout
*/
public void restore(View view) {
- final ProgressDialog dialog = ProgressDialog.show(this, res.getString(R.string.init_backup_restore), res.getString(R.string.init_restore_running), true, false);
- final AtomicBoolean atomic = new AtomicBoolean(false);
- Thread restoreThread = new Thread() {
- final Handler handler = new Handler() {
- public void handleMessage(Message msg) {
- dialog.dismiss();
- boolean restored = atomic.get();
- if (restored) {
- helpDialog(res.getString(R.string.init_backup_restore), res.getString(R.string.init_restore_success));
- } else {
- helpDialog(res.getString(R.string.init_backup_restore), res.getString(R.string.init_restore_failed));
- }
- }
- };
-
- @Override
- public void run() {
- atomic.set(app.restoreDatabase());
- handler.sendMessage(handler.obtainMessage());
- }
- };
- restoreThread.start();
+ app.restoreDatabase(this);
}
public boolean saveValues() {