diff options
Diffstat (limited to 'main/src/cgeo/geocaching/CachePopup.java')
| -rw-r--r-- | main/src/cgeo/geocaching/CachePopup.java | 76 |
1 files changed, 26 insertions, 50 deletions
diff --git a/main/src/cgeo/geocaching/CachePopup.java b/main/src/cgeo/geocaching/CachePopup.java index e01e4a0..e6d0148 100644 --- a/main/src/cgeo/geocaching/CachePopup.java +++ b/main/src/cgeo/geocaching/CachePopup.java @@ -6,6 +6,7 @@ import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.ui.CacheDetailsCreator; import cgeo.geocaching.utils.CancellableHandler; import cgeo.geocaching.utils.Log; +import cgeo.geocaching.utils.RunnableWithArgument; import org.apache.commons.lang3.StringUtils; @@ -15,7 +16,6 @@ import android.content.res.Configuration; import android.os.Handler; import android.os.Message; import android.view.View; -import android.widget.Button; import android.widget.LinearLayout; import android.widget.TextView; @@ -79,7 +79,7 @@ public class CachePopup extends AbstractPopupActivity { if (StringUtils.isNotBlank(cache.getName())) { setTitle(cache.getName()); } else { - setTitle(geocode.toUpperCase()); + setTitle(geocode); } // actionbar icon @@ -89,52 +89,11 @@ public class CachePopup extends AbstractPopupActivity { addCacheDetails(); - findViewById(R.id.offline_box).setVisibility(View.VISIBLE); - // offline use - final TextView offlineText = (TextView) findViewById(R.id.offline_text); - final Button offlineRefresh = (Button) findViewById(R.id.offline_refresh); - final Button offlineStore = (Button) findViewById(R.id.offline_store); - - if (cache.getListId() > 0) { - final long diff = (System.currentTimeMillis() / (60 * 1000)) - (cache.getDetailedUpdate() / (60 * 1000)); // minutes - - String ago; - if (diff < 15) { - ago = res.getString(R.string.cache_offline_time_mins_few); - } else if (diff < 50) { - ago = res.getString(R.string.cache_offline_time_about) + " " + diff + " " + res.getString(R.string.cache_offline_time_mins); - } else if (diff < 90) { - ago = res.getString(R.string.cache_offline_time_about) + " " + res.getString(R.string.cache_offline_time_hour); - } else if (diff < (48 * 60)) { - ago = res.getString(R.string.cache_offline_time_about) + " " + (diff / 60) + " " + res.getString(R.string.cache_offline_time_hours); - } else { - ago = res.getString(R.string.cache_offline_time_about) + " " + (diff / (24 * 60)) + " " + res.getString(R.string.cache_offline_time_days); - } - - offlineText.setText(res.getString(R.string.cache_offline_stored) + "\n" + ago); - - offlineRefresh.setVisibility(View.VISIBLE); - offlineRefresh.setEnabled(true); - offlineRefresh.setOnClickListener(new RefreshCacheClickListener()); - - offlineStore.setText(res.getString(R.string.cache_offline_drop)); - offlineStore.setEnabled(true); - offlineStore.setOnClickListener(new DropCacheClickListener()); - } else { - offlineText.setText(res.getString(R.string.cache_offline_not_ready)); + CacheDetailActivity.updateOfflineBox(findViewById(android.R.id.content), cache, res, new RefreshCacheClickListener(), new DropCacheClickListener(), new StoreCacheClickListener()); - offlineRefresh.setVisibility(View.GONE); - offlineRefresh.setEnabled(false); - offlineRefresh.setOnTouchListener(null); - offlineRefresh.setOnClickListener(null); - - offlineStore.setText(res.getString(R.string.cache_offline_store)); - offlineStore.setEnabled(true); - offlineStore.setOnClickListener(new StoreCacheClickListener()); - } } catch (Exception e) { - Log.e("cgeopopup.init: " + e.toString()); + Log.e("cgeopopup.init", e); } // cache is loaded. remove progress-popup if any there @@ -156,22 +115,39 @@ public class CachePopup extends AbstractPopupActivity { return; } + if (Settings.getChooseList()) { + // let user select list to store cache in + new StoredList.UserInterface(CachePopup.this).promptForListSelection(R.string.list_title, + new RunnableWithArgument<Integer>() { + @Override + public void run(final Integer selectedListId) { + storeCache(selectedListId); + } + }, true, StoredList.TEMPORARY_LIST_ID); + } else { + storeCache(StoredList.TEMPORARY_LIST_ID); + } + } + + protected void storeCache(final int listId) { final StoreCacheHandler storeCacheHandler = new StoreCacheHandler(); progress.show(CachePopup.this, res.getString(R.string.cache_dialog_offline_save_title), res.getString(R.string.cache_dialog_offline_save_message), true, storeCacheHandler.cancelMessage()); - new StoreCacheThread(storeCacheHandler).start(); + new StoreCacheThread(listId, storeCacheHandler).start(); } } private class StoreCacheThread extends Thread { + final private int listId; final private CancellableHandler handler; - public StoreCacheThread(final CancellableHandler handler) { + public StoreCacheThread(final int listId, final CancellableHandler handler) { + this.listId = listId; this.handler = handler; } @Override public void run() { - cache.store(handler); + cache.store(listId, handler); invalidateOptionsMenuCompatible(); } } @@ -237,7 +213,7 @@ public class CachePopup extends AbstractPopupActivity { } /** - * Tries to navigate to the {@link cgCache} of this activity. + * Tries to navigate to the {@link Geocache} of this activity. */ @Override protected void startDefaultNavigation2() { @@ -251,7 +227,7 @@ public class CachePopup extends AbstractPopupActivity { public static void startActivity(final Context context, final String geocode) { final Intent popupIntent = new Intent(context, CachePopup.class); - popupIntent.putExtra(EXTRA_GEOCODE, geocode); + popupIntent.putExtra(Intents.EXTRA_GEOCODE, geocode); context.startActivity(popupIntent); } |
