aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo
diff options
context:
space:
mode:
authorOndřej Kunc <kunc88@gmail.com>2012-05-20 00:47:00 +0200
committerOndřej Kunc <kunc88@gmail.com>2012-05-20 00:47:00 +0200
commitfaf0a95eb3bdcf6550b88fb3c0b93b31dbbf957e (patch)
tree736c5e08ce2d5f64af1b99486ac29fed6397208e /main/src/cgeo
parentf8102fe27dc5c217a167d584ea8afd992ee518bb (diff)
downloadcgeo-faf0a95eb3bdcf6550b88fb3c0b93b31dbbf957e.zip
cgeo-faf0a95eb3bdcf6550b88fb3c0b93b31dbbf957e.tar.gz
cgeo-faf0a95eb3bdcf6550b88fb3c0b93b31dbbf957e.tar.bz2
Virtual "all caches" list
Diffstat (limited to 'main/src/cgeo')
-rw-r--r--main/src/cgeo/geocaching/StoredList.java13
-rw-r--r--main/src/cgeo/geocaching/cgData.java16
-rw-r--r--main/src/cgeo/geocaching/cgeocaches.java6
3 files changed, 29 insertions, 6 deletions
diff --git a/main/src/cgeo/geocaching/StoredList.java b/main/src/cgeo/geocaching/StoredList.java
index eaf677d..6cf018a 100644
--- a/main/src/cgeo/geocaching/StoredList.java
+++ b/main/src/cgeo/geocaching/StoredList.java
@@ -18,6 +18,7 @@ import java.util.List;
public class StoredList {
public static final int TEMPORARY_LIST_ID = 0;
public static final int STANDARD_LIST_ID = 1;
+ public static final int ALL_LIST_ID = 2;
public final int id;
public final String title;
@@ -45,6 +46,10 @@ public class StoredList {
}
public void promptForListSelection(final int titleId, final RunnableWithArgument<Integer> runAfterwards) {
+ promptForListSelection(titleId, runAfterwards, false);
+ }
+
+ public void promptForListSelection(final int titleId, final RunnableWithArgument<Integer> runAfterwards, final boolean onlyMoveTargets) {
final List<StoredList> lists = app.getLists();
if (lists == null) {
@@ -55,6 +60,9 @@ public class StoredList {
for (StoredList list : lists) {
listsTitle.add(list.getTitleAndCount());
}
+ if (!onlyMoveTargets) {
+ listsTitle.add("<" + res.getString(R.string.list_menu_all_lists) + ">");
+ }
listsTitle.add("<" + res.getString(R.string.list_menu_create) + ">");
final CharSequence[] items = new CharSequence[listsTitle.size()];
@@ -63,7 +71,10 @@ public class StoredList {
builder.setTitle(res.getString(titleId));
builder.setItems(listsTitle.toArray(items), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialogInterface, int itemId) {
- if (itemId >= lists.size()) {
+ if (itemId == lists.size() && !onlyMoveTargets) {
+ // all lists
+ runAfterwards.run(StoredList.ALL_LIST_ID);
+ } else if (itemId >= lists.size()) {
// create new list on the fly
promptForListCreation(runAfterwards);
}
diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java
index 796f1fa..16a1f35 100644
--- a/main/src/cgeo/geocaching/cgData.java
+++ b/main/src/cgeo/geocaching/cgData.java
@@ -2209,8 +2209,8 @@ public class cgData {
StringBuilder specifySql = new StringBuilder();
- specifySql.append("reason = ");
- specifySql.append(Math.max(listId, 1));
+ specifySql.append("reason ");
+ specifySql.append(listId != StoredList.ALL_LIST_ID ? "=" + Math.max(listId, 1) : ">= " + StoredList.STANDARD_LIST_ID);
if (detailedOnly) {
specifySql.append(" and detailed = 1 ");
@@ -2624,6 +2624,10 @@ public class cgData {
return getStatement("CountStandardList", "SELECT count(_id) FROM " + dbTableCaches + " WHERE reason = " + StoredList.STANDARD_LIST_ID);
}
+ private SQLiteStatement getStatementCountAllLists() {
+ return getStatement("CountAllLists", "SELECT count(_id) FROM " + dbTableCaches + " WHERE reason >= " + StoredList.STANDARD_LIST_ID);
+ }
+
public boolean hasLogOffline(final String geocode) {
if (StringUtils.isBlank(geocode)) {
return false;
@@ -2726,6 +2730,11 @@ public class cgData {
return lists.get(0);
}
}
+
+ if (id == StoredList.ALL_LIST_ID) {
+ return new StoredList(StoredList.ALL_LIST_ID, res.getString(R.string.list_all_lists), (int) getStatementCountAllLists().simpleQueryForLong());
+ }
+
// fall back to standard list in case of invalid list id
if (id == StoredList.STANDARD_LIST_ID || id >= customListIdOffset) {
return new StoredList(StoredList.STANDARD_LIST_ID, res.getString(R.string.list_inbox), (int) getStatementCountStandardList().simpleQueryForLong());
@@ -2830,6 +2839,9 @@ public class cgData {
}
public void moveToList(final List<cgCache> caches, final int listId) {
+ if (listId == StoredList.ALL_LIST_ID) {
+ return;
+ }
if (caches.isEmpty()) {
return;
}
diff --git a/main/src/cgeo/geocaching/cgeocaches.java b/main/src/cgeo/geocaching/cgeocaches.java
index b435049..a688d07 100644
--- a/main/src/cgeo/geocaching/cgeocaches.java
+++ b/main/src/cgeo/geocaching/cgeocaches.java
@@ -766,7 +766,7 @@ public class cgeocaches extends AbstractListActivity {
}
final boolean hasSelection = adapter != null && adapter.getCheckedCount() > 0;
- final boolean isNonDefaultList = listId != StoredList.STANDARD_LIST_ID;
+ final boolean isNonDefaultList = (listId != StoredList.STANDARD_LIST_ID) && (listId != StoredList.ALL_LIST_ID);
if (type == CacheListType.OFFLINE) { // only offline list
setMenuItemLabel(menu, MENU_DROP_CACHES, R.string.caches_drop_selected, R.string.caches_drop_all);
@@ -1003,7 +1003,7 @@ public class cgeocaches extends AbstractListActivity {
refreshCurrentList();
}
- });
+ }, true);
}
@Override
@@ -1065,7 +1065,7 @@ public class cgeocaches extends AbstractListActivity {
adapter.setSelectMode(false);
refreshCurrentList();
}
- });
+ }, true);
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.