aboutsummaryrefslogtreecommitdiffstats
path: root/main/src
diff options
context:
space:
mode:
authorBananeweizen <Bananeweizen@gmx.de>2012-03-24 00:21:48 -0700
committerBananeweizen <Bananeweizen@gmx.de>2012-03-24 00:21:48 -0700
commitedccb6a2531b08450829c7e1c9a0bc2fd7353f5e (patch)
treeb91ec675132ea78d47553f7328d1cc9602c355ee /main/src
parent079575ca09919559bddc45cc7fc05aaafdf5d1bd (diff)
parent0be23a2477cf94a3c6fa5765e8eb2b3ddb2ed018 (diff)
downloadcgeo-edccb6a2531b08450829c7e1c9a0bc2fd7353f5e.zip
cgeo-edccb6a2531b08450829c7e1c9a0bc2fd7353f5e.tar.gz
cgeo-edccb6a2531b08450829c7e1c9a0bc2fd7353f5e.tar.bz2
Merge pull request #1318 from marco-jacob/issue#1309
Fix for issue 1309
Diffstat (limited to 'main/src')
-rw-r--r--main/src/cgeo/geocaching/activity/Progress.java13
-rw-r--r--main/src/cgeo/geocaching/files/GPXImporter.java22
2 files changed, 27 insertions, 8 deletions
diff --git a/main/src/cgeo/geocaching/activity/Progress.java b/main/src/cgeo/geocaching/activity/Progress.java
index 70f829d..fc64c01 100644
--- a/main/src/cgeo/geocaching/activity/Progress.java
+++ b/main/src/cgeo/geocaching/activity/Progress.java
@@ -13,6 +13,7 @@ public class Progress {
private ProgressDialog dialog;
private int progress = 0;
+ private int progressDivider = 1;
public synchronized void dismiss() {
if (dialog != null && dialog.isShowing()) {
@@ -65,16 +66,18 @@ public class Progress {
public synchronized void setMaxProgressAndReset(final int max) {
if (dialog != null && dialog.isShowing()) {
- dialog.setMax(max);
+ final int modMax = max / this.progressDivider;
+ dialog.setMax(modMax);
dialog.setProgress(0);
}
}
public synchronized void setProgress(final int progress) {
+ final int modProgress = progress / this.progressDivider;
if (dialog != null && dialog.isShowing()) {
- dialog.setProgress(progress);
+ dialog.setProgress(modProgress);
}
- this.progress = progress;
+ this.progress = modProgress;
}
public synchronized int getProgress() {
@@ -83,4 +86,8 @@ public class Progress {
}
return this.progress;
}
+
+ public synchronized void setProgressDivider(final int progressDivider) {
+ this.progressDivider = progressDivider;
+ }
}
diff --git a/main/src/cgeo/geocaching/files/GPXImporter.java b/main/src/cgeo/geocaching/files/GPXImporter.java
index 4697a62..8224437 100644
--- a/main/src/cgeo/geocaching/files/GPXImporter.java
+++ b/main/src/cgeo/geocaching/files/GPXImporter.java
@@ -34,7 +34,6 @@ import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
-import java.util.Set;
import java.util.concurrent.CancellationException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
@@ -188,10 +187,10 @@ public class GPXImporter {
private void importStaticMaps(final SearchResult importedCaches) {
final cgeoapplication app = cgeoapplication.getInstance();
- Set<cgCache> caches = importedCaches.getCachesFromSearchResult(LoadFlags.LOAD_WAYPOINTS);
int storedCacheMaps = 0;
- for (cgCache cache : caches) {
- Log.d(Settings.tag, "GPXImporter.ImportThread.importStaticMaps start downloadMaps");
+ for (String geocode : importedCaches.getGeocodes()) {
+ cgCache cache = app.loadCache(geocode, LoadFlags.LOAD_WAYPOINTS);
+ Log.d(Settings.tag, "GPXImporter.ImportThread.importStaticMaps start downloadMaps for cache " + geocode);
StaticMapsProvider.downloadMaps(cache, app);
storedCacheMaps++;
if (progressHandler.isCancelled()) {
@@ -377,6 +376,8 @@ public class GPXImporter {
};
final private Handler importStepHandler = new Handler() {
+ private boolean showProgressAfterCancel = false;
+
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
@@ -387,7 +388,14 @@ public class GPXImporter {
case IMPORT_STEP_READ_FILE:
case IMPORT_STEP_READ_WPT_FILE:
+ progress.setProgressDivider(1024);
+ progress.setMessage(res.getString(msg.arg1));
+ progress.setMaxProgressAndReset(msg.arg2);
+ break;
+
case IMPORT_STEP_STORE_CACHES:
+ showProgressAfterCancel = true;
+ progress.setProgressDivider(1);
progress.setMessage(res.getString(msg.arg1));
progress.setMaxProgressAndReset(msg.arg2);
break;
@@ -401,6 +409,7 @@ public class GPXImporter {
case IMPORT_STEP_STATIC_MAPS_SKIPPED:
progress.dismiss();
+ progressHandler.cancel();
StringBuilder bufferSkipped = new StringBuilder(20);
bufferSkipped.append(res.getString(R.string.gpx_import_static_maps_skipped)).append(", ").append(msg.arg1).append(' ').append(res.getString(R.string.gpx_import_caches_imported));
fromActivity.helpDialog(res.getString(R.string.gpx_import_title_caches_imported), bufferSkipped.toString());
@@ -426,7 +435,10 @@ public class GPXImporter {
case IMPORT_STEP_CANCELED:
StringBuilder bufferCanceled = new StringBuilder(20);
- bufferCanceled.append(res.getString(R.string.gpx_import_canceled)).append(", ").append(progress.getProgress()).append(' ').append(res.getString(R.string.gpx_import_caches_imported));
+ bufferCanceled.append(res.getString(R.string.gpx_import_canceled));
+ if (showProgressAfterCancel) {
+ bufferCanceled.append(", ").append(progress.getProgress()).append(' ').append(res.getString(R.string.gpx_import_caches_imported));
+ }
fromActivity.showShortToast(bufferCanceled.toString());
importFinished();
break;