From 384a3bf7c0102f4fd9f593d089c7d41d79331aca Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Wed, 31 Aug 2011 19:58:42 +0200 Subject: new: sort by state, fixes #324 --- res/values-de/strings.xml | 1 + res/values/strings.xml | 1 + src/cgeo/geocaching/cgeocaches.java | 12 ++++++--- src/cgeo/geocaching/sorting/StateComparator.java | 32 ++++++++++++++++++++++++ 4 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 src/cgeo/geocaching/sorting/StateComparator.java diff --git a/res/values-de/strings.xml b/res/values-de/strings.xml index 1b21a31..5cb7d31 100644 --- a/res/values-de/strings.xml +++ b/res/values-de/strings.xml @@ -287,6 +287,7 @@ Inventaranzahl Datum Funde + Status Wähle von Liste Auswahlmodus Auswahlmodus beenden diff --git a/res/values/strings.xml b/res/values/strings.xml index a246e0a..5aea870 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -288,6 +288,7 @@ count of inventory date finds + state Select from list Select mode Exit select mode diff --git a/src/cgeo/geocaching/cgeocaches.java b/src/cgeo/geocaching/cgeocaches.java index c01ae72..642336d 100644 --- a/src/cgeo/geocaching/cgeocaches.java +++ b/src/cgeo/geocaching/cgeocaches.java @@ -59,6 +59,7 @@ import cgeo.geocaching.sorting.NameComparator; import cgeo.geocaching.sorting.PopularityComparator; import cgeo.geocaching.sorting.RatingComparator; import cgeo.geocaching.sorting.SizeComparator; +import cgeo.geocaching.sorting.StateComparator; import cgeo.geocaching.sorting.TerrainComparator; import cgeo.geocaching.sorting.VoteComparator; @@ -125,6 +126,7 @@ public class cgeocaches extends AbstractListActivity { private static final int SUBMENU_MANAGE_HISTORY = 60; private static final int MENU_SORT_DATE = 61; private static final int MENU_SORT_FINDS = 62; + private static final int MENU_SORT_STATE = 63; private static final int CONTEXT_MENU_MOVE_TO_LIST = 1000; private static final int MENU_MOVE_SELECTED_OR_ALL_TO_LIST = 1200; @@ -752,6 +754,7 @@ public class cgeocaches extends AbstractListActivity { comparators.put(res.getString(R.string.caches_sort_inventory), MENU_SORT_INVENTORY); comparators.put(res.getString(R.string.caches_sort_date), MENU_SORT_DATE); comparators.put(res.getString(R.string.caches_sort_finds), MENU_SORT_FINDS); + comparators.put(res.getString(R.string.caches_sort_state), MENU_SORT_STATE); ArrayList sortedLabels = new ArrayList(comparators.keySet()); Collections.sort(sortedLabels); @@ -983,6 +986,9 @@ public class cgeocaches extends AbstractListActivity { case MENU_SORT_FINDS: setComparator(item, new FindsComparator(app)); return true; + case MENU_SORT_STATE: + setComparator(item, new StateComparator()); + return true; case SUBMENU_FILTER_TYPE: selectedFilter = res.getString(R.string.caches_filter_type); openContextMenu(getListView()); @@ -2547,7 +2553,7 @@ public class cgeocaches extends AbstractListActivity { cachesIntent.putExtra(EXTRAS_LIST_TYPE, "offline"); context.startActivity(cachesIntent); } - + public static void startActivityCachesAround(final AbstractActivity context, final Double latitude, final Double longitude) { cgeocaches cachesActivity = new cgeocaches(); @@ -2559,7 +2565,7 @@ public class cgeocaches extends AbstractListActivity { context.startActivity(cachesIntent); } - + public static void startActivityCacheOwner(final AbstractActivity context, final String userName) { final Intent cachesIntent = new Intent(context, cgeocaches.class); @@ -2569,7 +2575,7 @@ public class cgeocaches extends AbstractListActivity { context.startActivity(cachesIntent); } - + public static void startActivityCacheUser(final AbstractActivity context, final String userName) { final Intent cachesIntent = new Intent(context, cgeocaches.class); diff --git a/src/cgeo/geocaching/sorting/StateComparator.java b/src/cgeo/geocaching/sorting/StateComparator.java new file mode 100644 index 0000000..787af5a --- /dev/null +++ b/src/cgeo/geocaching/sorting/StateComparator.java @@ -0,0 +1,32 @@ +package cgeo.geocaching.sorting; + +import cgeo.geocaching.cgCache; + +/** + * sort caches by state (normal, disabled, archived) + * + */ +public class StateComparator extends AbstractCacheComparator implements + CacheComparator { + + @Override + protected boolean canCompare(final cgCache cache1, final cgCache cache2) { + return true; + } + + @Override + protected int compareCaches(final cgCache cache1, final cgCache cache2) { + return getState(cache1) - getState(cache2); + } + + private static int getState(final cgCache cache) { + if (cache.disabled) { + return 1; + } + if (cache.archived) { + return 2; + } + return 0; + } + +} -- cgit v1.1