aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/cgeocaches.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/cgeocaches.java')
-rw-r--r--main/src/cgeo/geocaching/cgeocaches.java412
1 files changed, 206 insertions, 206 deletions
diff --git a/main/src/cgeo/geocaching/cgeocaches.java b/main/src/cgeo/geocaching/cgeocaches.java
index 688af99..fa83a60 100644
--- a/main/src/cgeo/geocaching/cgeocaches.java
+++ b/main/src/cgeo/geocaching/cgeocaches.java
@@ -3,9 +3,12 @@ package cgeo.geocaching;
import cgeo.geocaching.activity.AbstractActivity;
import cgeo.geocaching.activity.AbstractListActivity;
import cgeo.geocaching.activity.ActivityMixin;
+import cgeo.geocaching.activity.FilteredActivity;
import cgeo.geocaching.activity.Progress;
import cgeo.geocaching.apps.cache.navi.NavigationAppFactory;
import cgeo.geocaching.apps.cachelist.CacheListAppFactory;
+import cgeo.geocaching.connector.ConnectorFactory;
+import cgeo.geocaching.connector.capability.ISearchByCenter;
import cgeo.geocaching.connector.gc.AbstractSearchThread;
import cgeo.geocaching.connector.gc.GCParser;
import cgeo.geocaching.connector.gc.SearchHandler;
@@ -28,6 +31,8 @@ import cgeo.geocaching.sorting.EventDateComparator;
import cgeo.geocaching.sorting.VisitComparator;
import cgeo.geocaching.ui.CacheListAdapter;
import cgeo.geocaching.ui.LoggingUI;
+import cgeo.geocaching.ui.WeakReferenceHandler;
+import cgeo.geocaching.utils.DateUtils;
import cgeo.geocaching.utils.GeoDirHandler;
import cgeo.geocaching.utils.Log;
import cgeo.geocaching.utils.RunnableWithArgument;
@@ -60,11 +65,12 @@ import android.widget.TextView;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
-public class cgeocaches extends AbstractListActivity {
+public class cgeocaches extends AbstractListActivity implements FilteredActivity {
private static final String EXTRAS_USERNAME = "username";
private static final String EXTRAS_ADDRESS = "address";
@@ -98,6 +104,7 @@ public class cgeocaches extends AbstractListActivity {
private static final int MENU_NAVIGATION = 69;
private static final int MENU_STORE_CACHE = 73;
private static final int MENU_FILTER = 74;
+ private static final int MENU_DELETE_EVENTS = 75;
private static final int MSG_DONE = -1;
private static final int MSG_RESTART_GEO_AND_DIR = -2;
@@ -124,11 +131,7 @@ public class cgeocaches extends AbstractListActivity {
@Override
public void updateGeoData(final IGeoData geo) {
- if (adapter == null) {
- return;
- }
-
- if (geo.getCoords() != null) {
+ if (geo.getCoords() != null) {
adapter.setActualCoordinates(geo.getCoords());
}
if (!Settings.isUseCompass() || geo.getSpeed() > 5) { // use GPS when speed is higher than 18 km/h
@@ -138,7 +141,7 @@ public class cgeocaches extends AbstractListActivity {
@Override
public void updateDirection(final float direction) {
- if (adapter == null || !Settings.isLiveList()) {
+ if (!Settings.isLiveList()) {
return;
}
@@ -156,57 +159,42 @@ public class cgeocaches extends AbstractListActivity {
*/
private MenuItem navigationMenu;
- private Handler loadCachesHandler = new Handler() {
-
- @Override
- public void handleMessage(Message msg) {
- try {
- setAdapter();
-
- updateTitle();
-
- setDateComparatorForEventList();
+ public void handleCachesLoaded() {
+ try {
+ setAdapter();
- showFooterMoreCaches();
+ updateTitle();
- if (search != null && search.getError() == StatusCode.UNAPPROVED_LICENSE) {
- AlertDialog.Builder dialog = new AlertDialog.Builder(cgeocaches.this);
- dialog.setTitle(res.getString(R.string.license));
- dialog.setMessage(res.getString(R.string.err_license));
- dialog.setCancelable(true);
- dialog.setNegativeButton(res.getString(R.string.license_dismiss), new DialogInterface.OnClickListener() {
-
- @Override
- public void onClick(DialogInterface dialog, int id) {
- Cookies.clearCookies();
- dialog.cancel();
- }
- });
- dialog.setPositiveButton(res.getString(R.string.license_show), new DialogInterface.OnClickListener() {
+ setDateComparatorForEventList();
- @Override
- public void onClick(DialogInterface dialog, int id) {
- Cookies.clearCookies();
- startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.geocaching.com/software/agreement.aspx?ID=0")));
- }
- });
+ showFooterMoreCaches();
- AlertDialog alert = dialog.create();
- alert.show();
- } else if (search != null && search.getError() != null) {
- showToast(res.getString(R.string.err_download_fail) + ' ' + search.getError().getErrorString(res) + '.');
+ if (search != null && search.getError() == StatusCode.UNAPPROVED_LICENSE) {
+ AlertDialog.Builder dialog = new AlertDialog.Builder(this);
+ dialog.setTitle(res.getString(R.string.license));
+ dialog.setMessage(res.getString(R.string.err_license));
+ dialog.setCancelable(true);
+ dialog.setNegativeButton(res.getString(R.string.license_dismiss), new DialogInterface.OnClickListener() {
- hideLoading();
- showProgress(false);
+ @Override
+ public void onClick(DialogInterface dialog, int id) {
+ Cookies.clearCookies();
+ dialog.cancel();
+ }
+ });
+ dialog.setPositiveButton(res.getString(R.string.license_show), new DialogInterface.OnClickListener() {
- finish();
- return;
- }
+ @Override
+ public void onClick(DialogInterface dialog, int id) {
+ Cookies.clearCookies();
+ startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.geocaching.com/software/agreement.aspx?ID=0")));
+ }
+ });
- setAdapterCurrentCoordinates(false);
- } catch (Exception e) {
- showToast(res.getString(R.string.err_detail_cache_find_any));
- Log.e("cgeocaches.loadCachesHandler: " + e.toString());
+ AlertDialog alert = dialog.create();
+ alert.show();
+ } else if (search != null && search.getError() != null) {
+ showToast(res.getString(R.string.err_download_fail) + ' ' + search.getError().getErrorString(res) + '.');
hideLoading();
showProgress(false);
@@ -215,29 +203,52 @@ public class cgeocaches extends AbstractListActivity {
return;
}
- try {
- hideLoading();
- showProgress(false);
- } catch (Exception e2) {
- Log.e("cgeocaches.loadCachesHandler.2: " + e2.toString());
- }
+ setAdapterCurrentCoordinates(false);
+ } catch (Exception e) {
+ showToast(res.getString(R.string.err_detail_cache_find_any));
+ Log.e("cgeocaches.loadCachesHandler", e);
- if (adapter != null) {
- adapter.setSelectMode(false);
+ hideLoading();
+ showProgress(false);
+
+ finish();
+ return;
+ }
+
+ try {
+ hideLoading();
+ showProgress(false);
+ } catch (Exception e2) {
+ Log.e("cgeocaches.loadCachesHandler.2", e2);
+ }
+
+ adapter.setSelectMode(false);
+ }
+
+ private Handler loadCachesHandler = new LoadCachesHandler(this);
+
+ private static class LoadCachesHandler extends WeakReferenceHandler<cgeocaches> {
+
+ protected LoadCachesHandler(cgeocaches activity) {
+ super(activity);
+ }
+
+ @Override
+ public void handleMessage(Message msg) {
+ final cgeocaches activity = getActivity();
+ if (activity == null) {
+ return;
}
+ activity.handleCachesLoaded();
}
- };
+ }
+
private Handler loadNextPageHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
try {
- if (search != null) {
- replaceCacheListFromSearch();
- if (adapter != null) {
- adapter.reFilter();
- }
- }
+ replaceCacheListFromSearch();
setAdapter();
updateTitle();
@@ -258,33 +269,41 @@ public class cgeocaches extends AbstractListActivity {
setAdapterCurrentCoordinates(false);
} catch (Exception e) {
showToast(res.getString(R.string.err_detail_cache_find_next));
- Log.e("cgeocaches.loadNextPageHandler: " + e.toString());
+ Log.e("cgeocaches.loadNextPageHandler", e);
}
hideLoading();
showProgress(false);
- if (adapter != null) {
- adapter.setSelectMode(false);
- }
+ adapter.setSelectMode(false);
}
};
- private Set<cgCache> cachesFromSearchResult;
/**
- * Loads the caches and fills the cachelist
+ * Loads the caches and fills the {@link #cacheList} according to {@link #search} content.
+ *
+ * If {@link #search} is <code>null</code>, this does nothing.
*/
private void replaceCacheListFromSearch() {
- if (search!=null) {
- cachesFromSearchResult = search.getCachesFromSearchResult(LoadFlags.LOAD_CACHE_OR_DB);
+ if (search != null) {
+ final Set<cgCache> cachesFromSearchResult = search.getCachesFromSearchResult(LoadFlags.LOAD_CACHE_OR_DB);
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ cacheList.clear();
+ cacheList.addAll(cachesFromSearchResult);
+ adapter.reFilter();
+ updateTitle();
+ showFooterMoreCaches();
+ }
+ });
}
- refreshCacheListHandler.sendEmptyMessage(0);
}
protected void updateTitle() {
ArrayList<Integer> numbers = new ArrayList<Integer>();
- if (adapter != null && adapter.isFiltered()) {
+ if (adapter.isFiltered()) {
numbers.add(adapter.getCount());
}
if (search != null) {
@@ -307,9 +326,7 @@ public class cgeocaches extends AbstractListActivity {
if (msg.what > -1) {
cacheList.get(msg.what).setStatusChecked(false);
- if (adapter != null) {
- adapter.notifyDataSetChanged();
- }
+ adapter.notifyDataSetChanged();
int secondsElapsed = (int) ((System.currentTimeMillis() - detailProgressTime) / 1000);
int minutesRemaining = ((detailTotal - detailProgress) * secondsElapsed / ((detailProgress > 0) ? detailProgress : 1) / 60);
@@ -353,9 +370,7 @@ public class cgeocaches extends AbstractListActivity {
public void handleMessage(Message msg) {
setAdapter();
- if (adapter != null) {
- adapter.notifyDataSetChanged();
- }
+ adapter.notifyDataSetChanged();
if (msg.what == 0) { //no caches
progress.setMessage(res.getString(R.string.web_import_waiting));
@@ -377,9 +392,7 @@ public class cgeocaches extends AbstractListActivity {
threadWeb.kill();
}
} else {
- if (adapter != null) {
- adapter.setSelectMode(false);
- }
+ adapter.setSelectMode(false);
replaceCacheListFromSearch();
@@ -392,9 +405,7 @@ public class cgeocaches extends AbstractListActivity {
@Override
public void handleMessage(Message msg) {
if (msg.what != MSG_CANCEL) {
- if (adapter != null) {
- adapter.setSelectMode(false);
- }
+ adapter.setSelectMode(false);
refreshCurrentList();
@@ -413,9 +424,7 @@ public class cgeocaches extends AbstractListActivity {
if (msg.what > -1) {
progress.setProgress(detailProgress);
} else {
- if (adapter != null) {
- adapter.setSelectMode(false);
- }
+ adapter.setSelectMode(false);
// reload history list
(new LoadByHistoryThread()).start();
@@ -479,7 +488,7 @@ public class cgeocaches extends AbstractListActivity {
listId = StoredList.STANDARD_LIST_ID;
title = res.getString(R.string.stored_caches_button);
} else {
- final StoredList list = app.getList(listId);
+ final StoredList list = cgData.getList(listId);
// list.id may be different if listId was not valid
listId = list.id;
title = list.title;
@@ -630,10 +639,8 @@ public class cgeocaches extends AbstractListActivity {
startGeoAndDir();
- if (adapter != null) {
- adapter.setSelectMode(false);
- setAdapterCurrentCoordinates(true);
- }
+ adapter.setSelectMode(false);
+ setAdapterCurrentCoordinates(true);
if (loadCachesHandler != null && search != null) {
replaceCacheListFromSearch();
@@ -642,7 +649,7 @@ public class cgeocaches extends AbstractListActivity {
// refresh standard list if it has changed (new caches downloaded)
if (type == CacheListType.OFFLINE && listId >= StoredList.STANDARD_LIST_ID && search != null) {
- SearchResult newSearch = cgeoapplication.getInstance().getBatchOfStoredCaches(true, coords, Settings.getCacheType(), listId);
+ SearchResult newSearch = cgData.getBatchOfStoredCaches(coords, Settings.getCacheType(), listId);
if (newSearch != null && newSearch.getTotal() != search.getTotal()) {
refreshCurrentList();
}
@@ -660,15 +667,6 @@ public class cgeocaches extends AbstractListActivity {
}
@Override
- public void onDestroy() {
- if (adapter != null) {
- adapter = null;
- }
-
- super.onDestroy();
- }
-
- @Override
public void onPause() {
removeGeoAndDir();
@@ -691,6 +689,7 @@ public class cgeocaches extends AbstractListActivity {
subMenu.add(0, MENU_DROP_CACHES_AND_LIST, 0, res.getString(R.string.caches_drop_all_and_list));
subMenu.add(0, MENU_REFRESH_STORED, 0, res.getString(R.string.cache_offline_refresh)); // download details for all caches
subMenu.add(0, MENU_MOVE_TO_LIST, 0, res.getString(R.string.cache_menu_move_list));
+ subMenu.add(0, MENU_DELETE_EVENTS, 0, res.getString(R.string.caches_delete_events));
//TODO: add submenu/AlertDialog and use R.string.gpx_import_title
subMenu.add(0, MENU_IMPORT_GPX, 0, res.getString(R.string.gpx_import_title));
@@ -733,7 +732,7 @@ public class cgeocaches extends AbstractListActivity {
super.onPrepareOptionsMenu(menu);
try {
- if (adapter != null && adapter.isSelectMode()) {
+ if (adapter.isSelectMode()) {
menu.findItem(MENU_SWITCH_SELECT_MODE).setTitle(res.getString(R.string.caches_select_mode_exit))
.setIcon(R.drawable.ic_menu_clear_playlist);
menu.findItem(MENU_INVERT_SELECTION).setVisible(true);
@@ -753,6 +752,7 @@ public class cgeocaches extends AbstractListActivity {
setVisible(menu, MENU_REFRESH_STORED, !isEmpty && (isConcrete || type != CacheListType.OFFLINE));
setVisible(menu, MENU_DROP_CACHES, !isEmpty);
setVisible(menu, MENU_DROP_CACHES_AND_LIST, isConcrete && !isEmpty);
+ setVisible(menu, MENU_DELETE_EVENTS, isConcrete && !isEmpty && containsEvents());
setVisible(menu, MENU_MOVE_TO_LIST, !isEmpty);
setVisible(menu, MENU_EXPORT, !isEmpty);
setVisible(menu, MENU_REMOVE_FROM_HISTORY, !isEmpty);
@@ -784,14 +784,14 @@ public class cgeocaches extends AbstractListActivity {
item.setVisible(isNonDefaultList);
}
- final boolean multipleLists = app.getLists().size() >= 2;
+ final boolean multipleLists = cgData.getLists().size() >= 2;
item = menu.findItem(MENU_SWITCH_LIST);
if (item != null) {
item.setVisible(multipleLists);
}
item = menu.findItem(MENU_MOVE_TO_LIST);
if (item != null) {
- item.setVisible(multipleLists && !isEmpty);
+ item.setVisible(!isEmpty);
}
setMenuItemLabel(menu, MENU_REMOVE_FROM_HISTORY, R.string.cache_remove_from_history, R.string.cache_clear_history);
@@ -803,6 +803,15 @@ public class cgeocaches extends AbstractListActivity {
return true;
}
+ private boolean containsEvents() {
+ for (cgCache cache : adapter.getCheckedOrAllCaches()) {
+ if (cache.isEventCache()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
private void setMenuItemLabel(final Menu menu, final int menuId, final int resIdSelection, final int resId) {
final MenuItem menuItem = menu.findItem(menuId);
if (menuItem == null) {
@@ -821,9 +830,7 @@ public class cgeocaches extends AbstractListActivity {
int itemId = item.getItemId();
switch (itemId) {
case MENU_SWITCH_SELECT_MODE:
- if (adapter != null) {
- adapter.switchSelectMode();
- }
+ adapter.switchSelectMode();
invalidateOptionsMenuCompatible();
return true;
case MENU_REFRESH_STORED:
@@ -854,9 +861,7 @@ public class cgeocaches extends AbstractListActivity {
renameList();
return false;
case MENU_INVERT_SELECTION:
- if (adapter != null) {
- adapter.invertSelection();
- }
+ adapter.invertSelection();
invalidateOptionsMenuCompatible();
return false;
case MENU_SWITCH_LIST:
@@ -864,20 +869,7 @@ public class cgeocaches extends AbstractListActivity {
invalidateOptionsMenuCompatible();
return false;
case MENU_FILTER:
- new FilterUserInterface(this).selectFilter(new RunnableWithArgument<IFilter>() {
- @Override
- public void run(IFilter selectedFilter) {
- if (selectedFilter != null) {
- setFilter(selectedFilter);
- }
- else {
- // clear filter
- if (adapter != null) {
- setFilter(null);
- }
- }
- }
- });
+ showFilterMenu(null);
return true;
case MENU_SORT:
new ComparatorUserInterface(this).selectComparator(adapter.getCacheComparator(), new RunnableWithArgument<CacheComparator>() {
@@ -901,30 +893,61 @@ public class cgeocaches extends AbstractListActivity {
moveCachesToOtherList();
invalidateOptionsMenuCompatible();
return true;
+ case MENU_DELETE_EVENTS:
+ deletePastEvents();
+ invalidateOptionsMenuCompatible();
+ return true;
+ default:
+ return CacheListAppFactory.onMenuItemSelected(item, cacheList, this, search);
}
+ }
- return CacheListAppFactory.onMenuItemSelected(item, cacheList, this, search);
+ public void deletePastEvents() {
+ progress.show(this, null, res.getString(R.string.caches_drop_progress), true, dropDetailsHandler.obtainMessage(MSG_CANCEL));
+ final List<cgCache> deletion = new ArrayList<cgCache>();
+ for (cgCache cache : adapter.getCheckedOrAllCaches()) {
+ if (cache.isEventCache()) {
+ final Date eventDate = cache.getHiddenDate();
+ if (DateUtils.daysSince(eventDate.getTime()) > 0) {
+ deletion.add(cache);
+ }
+ }
+ }
+ new DropDetailsThread(dropDetailsHandler, deletion).start();
+ }
+
+ /**
+ * called from the filter bar view
+ */
+ @Override
+ public void showFilterMenu(final View view) {
+ new FilterUserInterface(this).selectFilter(new RunnableWithArgument<IFilter>() {
+ @Override
+ public void run(IFilter selectedFilter) {
+ if (selectedFilter != null) {
+ setFilter(selectedFilter);
+ }
+ else {
+ // clear filter
+ setFilter(null);
+ }
+ }
+ });
}
private void setComparator(final CacheComparator comparator) {
- if (adapter != null) {
- adapter.setComparator(comparator);
- }
+ adapter.setComparator(comparator);
}
@Override
public void onCreateContextMenu(final ContextMenu menu, final View view, final ContextMenu.ContextMenuInfo info) {
super.onCreateContextMenu(menu, view, info);
- if (adapter == null) {
- return;
- }
-
AdapterContextMenuInfo adapterInfo = null;
try {
adapterInfo = (AdapterContextMenuInfo) info;
} catch (Exception e) {
- Log.w("cgeocaches.onCreateContextMenu: " + e.toString());
+ Log.w("cgeocaches.onCreateContextMenu", e);
}
if (adapterInfo == null || adapterInfo.position >= adapter.getCount()) {
@@ -944,10 +967,7 @@ public class cgeocaches extends AbstractListActivity {
}
if (cache.isOffline()) {
menu.add(0, MENU_DROP_CACHE, 0, res.getString(R.string.cache_offline_drop));
- final List<StoredList> cacheLists = app.getLists();
- if (cacheLists.size() > 1) {
- menu.add(0, MENU_MOVE_TO_LIST, 0, res.getString(R.string.cache_menu_move_list));
- }
+ menu.add(0, MENU_MOVE_TO_LIST, 0, res.getString(R.string.cache_menu_move_list));
menu.add(0, MENU_EXPORT, 0, res.getString(R.string.export));
}
else {
@@ -960,12 +980,12 @@ public class cgeocaches extends AbstractListActivity {
@Override
public void run(Integer newListId) {
- app.moveToList(adapter.getCheckedOrAllCaches(), newListId);
+ cgData.moveToList(adapter.getCheckedOrAllCaches(), newListId);
adapter.setSelectMode(false);
refreshCurrentList();
}
- }, true);
+ }, true, listId);
}
@Override
@@ -983,7 +1003,7 @@ public class cgeocaches extends AbstractListActivity {
try {
adapterInfo = (AdapterContextMenuInfo) info;
} catch (Exception e) {
- Log.w("cgeocaches.onContextItemSelected: " + e.toString());
+ Log.w("cgeocaches.onContextItemSelected", e);
}
final cgCache cache = adapterInfo != null ? getCacheFromAdapter(adapterInfo) : null;
@@ -1003,7 +1023,7 @@ public class cgeocaches extends AbstractListActivity {
break;
case MENU_CACHE_DETAILS:
final Intent cachesIntent = new Intent(this, CacheDetailActivity.class);
- cachesIntent.putExtra("geocode", cache.getGeocode().toUpperCase());
+ cachesIntent.putExtra("geocode", cache.getGeocode());
cachesIntent.putExtra("name", cache.getName());
startActivity(cachesIntent);
break;
@@ -1021,11 +1041,11 @@ public class cgeocaches extends AbstractListActivity {
@Override
public void run(Integer newListId) {
- app.moveToList(Collections.singletonList(cache), newListId);
+ cgData.moveToList(Collections.singletonList(cache), newListId);
adapter.setSelectMode(false);
refreshCurrentList();
}
- }, true);
+ }, true, listId);
break;
case MENU_STORE_CACHE:
//FIXME: this must use the same handler like in the CacheDetailActivity. Will be done by moving the handler into the store method.
@@ -1062,24 +1082,19 @@ public class cgeocaches extends AbstractListActivity {
}
private boolean setFilter(IFilter filter) {
- if (adapter != null) {
- adapter.setFilter(filter);
- prepareFilterBar();
- updateTitle();
- invalidateOptionsMenuCompatible();
- return true;
- }
- return false;
+ adapter.setFilter(filter);
+ prepareFilterBar();
+ updateTitle();
+ invalidateOptionsMenuCompatible();
+ return true;
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
- if (adapter != null) {
- if (adapter.isSelectMode()) {
- adapter.setSelectMode(false);
- return true;
- }
+ if (adapter.isSelectMode()) {
+ adapter.setSelectMode(false);
+ return true;
}
}
return super.onKeyDown(keyCode, event);
@@ -1239,7 +1254,7 @@ public class cgeocaches extends AbstractListActivity {
dialog.setCancelable(true);
dialog.setTitle(res.getString(R.string.caches_drop_stored));
- if (adapter != null && adapter.getCheckedCount() > 0) {
+ if (adapter.getCheckedCount() > 0) {
dialog.setMessage(res.getString(R.string.caches_drop_selected_ask));
} else {
dialog.setMessage(res.getString(R.string.caches_drop_all_ask));
@@ -1269,7 +1284,7 @@ public class cgeocaches extends AbstractListActivity {
public void dropSelected() {
progress.show(this, null, res.getString(R.string.caches_drop_progress), true, dropDetailsHandler.obtainMessage(MSG_CANCEL));
- new DropDetailsThread(dropDetailsHandler).start();
+ new DropDetailsThread(dropDetailsHandler, adapter.getCheckedOrAllCaches()).start();
}
private class LoadByOfflineThread extends Thread {
@@ -1283,7 +1298,7 @@ public class cgeocaches extends AbstractListActivity {
@Override
public void run() {
- search = cgeoapplication.getInstance().getBatchOfStoredCaches(true, coords, Settings.getCacheType(), listId);
+ search = cgData.getBatchOfStoredCaches(coords, Settings.getCacheType(), listId);
replaceCacheListFromSearch();
loadCachesHandler.sendMessage(Message.obtain());
}
@@ -1292,7 +1307,7 @@ public class cgeocaches extends AbstractListActivity {
private class LoadByHistoryThread extends Thread {
@Override
public void run() {
- search = cgeoapplication.getInstance().getHistoryOfCaches(true, coords != null ? Settings.getCacheType() : CacheType.ALL);
+ search = cgData.getHistoryOfCaches(true, coords != null ? Settings.getCacheType() : CacheType.ALL);
replaceCacheListFromSearch();
loadCachesHandler.sendMessage(Message.obtain());
}
@@ -1319,7 +1334,17 @@ public class cgeocaches extends AbstractListActivity {
@Override
public void runSearch() {
+
search = GCParser.searchByCoords(coords, Settings.getCacheType(), Settings.isShowCaptcha());
+
+ for (ISearchByCenter centerConn : ConnectorFactory.getSearchByCenterConnectors()) {
+ if (centerConn.isActivated()) {
+ SearchResult temp = centerConn.searchByCenter(coords);
+ if (temp != null) {
+ search.addGeocodes(temp.getGeocodes());
+ }
+ }
+ }
replaceCacheListFromSearch();
}
}
@@ -1458,7 +1483,7 @@ public class cgeocaches extends AbstractListActivity {
Log.i("Waiting for next cache " + delay + " ms");
} catch (Exception e) {
- Log.e("cgeocaches.LoadDetailsThread.sleep: " + e.toString());
+ Log.e("cgeocaches.LoadDetailsThread.sleep", e);
}
}
@@ -1476,7 +1501,7 @@ public class cgeocaches extends AbstractListActivity {
Log.i(e.getMessage());
return false;
} catch (Exception e) {
- Log.e("cgeocaches.LoadDetailsThread: " + e.toString());
+ Log.e("cgeocaches.LoadDetailsThread", e);
}
last = System.currentTimeMillis();
@@ -1501,13 +1526,13 @@ public class cgeocaches extends AbstractListActivity {
@Override
public void run() {
- int ret = MSG_DONE;
removeGeoAndDir();
int delay = -1;
int times = 0;
+ int ret = MSG_DONE;
while (!needToStop && times < 3 * 60 / 5) // maximum: 3 minutes, every 5 seconds
{
//download new code
@@ -1558,7 +1583,7 @@ public class cgeocaches extends AbstractListActivity {
times = 0;
}
} catch (InterruptedException e) {
- Log.e("cgeocaches.LoadFromWebThread.sleep: " + e.toString());
+ Log.e("cgeocaches.LoadFromWebThread.sleep", e);
}
}
@@ -1573,15 +1598,15 @@ public class cgeocaches extends AbstractListActivity {
final private Handler handler;
final private List<cgCache> selected;
- public DropDetailsThread(Handler handlerIn) {
+ public DropDetailsThread(Handler handlerIn, List<cgCache> selectedIn) {
handler = handlerIn;
- selected = adapter.getCheckedOrAllCaches();
+ selected = selectedIn;
}
@Override
public void run() {
removeGeoAndDir();
- app.markDropped(selected);
+ cgData.markDropped(selected);
handler.sendEmptyMessage(MSG_DONE);
startGeoAndDir();
@@ -1600,7 +1625,7 @@ public class cgeocaches extends AbstractListActivity {
@Override
public void run() {
- app.clearVisitDate(selected);
+ cgData.clearVisitDate(selected);
handler.sendEmptyMessage(MSG_DONE);
}
}
@@ -1650,7 +1675,7 @@ public class cgeocaches extends AbstractListActivity {
return;
}
- StoredList list = app.getList(id);
+ StoredList list = cgData.getList(id);
if (list == null) {
return;
}
@@ -1693,32 +1718,11 @@ public class cgeocaches extends AbstractListActivity {
@Override
public void run() {
final List<cgCache> caches = adapter.getCheckedCaches();
- app.moveToList(caches, listId);
+ cgData.moveToList(caches, listId);
handler.sendEmptyMessage(listId);
}
}
- /**
- * Handler to refresh the current list of caches. This list is shared with the Adapter and therefore must be updated
- * in the UI-Thread
- */
-
- private Handler refreshCacheListHandler = new Handler() {
- @Override
- public void handleMessage(Message msg) {
- cacheList.clear();
- if (cachesFromSearchResult != null) {
- cacheList.addAll(cachesFromSearchResult);
- }
- if (adapter != null) {
- adapter.reFilter();
- }
- updateTitle();
- showFooterMoreCaches();
- }
- };
-
-
private void renameList() {
new StoredList.UserInterface(this).promptForListRename(listId, new Runnable() {
@@ -1730,7 +1734,7 @@ public class cgeocaches extends AbstractListActivity {
}
private void removeListInternal() {
- if (app.removeList(listId)) {
+ if (cgData.removeList(listId)) {
showToast(res.getString(R.string.list_dialog_remove_ok));
switchListById(StoredList.STANDARD_LIST_ID);
} else {
@@ -1783,18 +1787,14 @@ public class cgeocaches extends AbstractListActivity {
return;
}
- SearchResult searchToUse = search;
-
// apply filter settings (if there's a filter)
- if (adapter != null) {
- Set<String> geocodes = new HashSet<String>();
- for (cgCache cache : adapter.getFilteredList()) {
- geocodes.add(cache.getGeocode());
- }
- searchToUse = new SearchResult(geocodes);
+ Set<String> geocodes = new HashSet<String>();
+ for (cgCache cache : adapter.getFilteredList()) {
+ geocodes.add(cache.getGeocode());
}
- int count = searchToUse.getCount();
+ final SearchResult searchToUse = new SearchResult(geocodes);
+ final int count = searchToUse.getCount();
String mapTitle = title;
if (count > 0) {
mapTitle = title + " [" + count + "]";