diff options
6 files changed, 89 insertions, 6 deletions
diff --git a/main/res/values/strings.xml b/main/res/values/strings.xml index 415a97f..9c78ffb 100644 --- a/main/res/values/strings.xml +++ b/main/res/values/strings.xml @@ -325,6 +325,9 @@ <string name="caches_filter_personal_note">With personal note</string> <string name="caches_filter_popularity">Favorites</string> <string name="caches_filter_popularity_ratio">Favorites [%]</string> + <string name="caches_filter_personal_data">With personal data</string> + <string name="caches_filter_rating">With rating</string> + <string name="caches_filter_own_rating">With own rating</string> <string name="caches_removing_from_history">Removing from History…</string> <string name="caches_clear_offlinelogs">Clear offline logs</string> <string name="caches_clear_offlinelogs_message">Do you want to clear the offline logs?</string> diff --git a/main/src/cgeo/geocaching/filter/FilterUserInterface.java b/main/src/cgeo/geocaching/filter/FilterUserInterface.java index 9f1d563..590a726 100644 --- a/main/src/cgeo/geocaching/filter/FilterUserInterface.java +++ b/main/src/cgeo/geocaching/filter/FilterUserInterface.java @@ -54,12 +54,12 @@ public final class FilterUserInterface { register(R.string.cache_attributes, AttributeFilter.Factory.class); register(R.string.cache_status, StateFilter.Factory.class); register(R.string.caches_filter_track, TrackablesFilter.class); - register(R.string.caches_filter_modified, ModifiedFilter.class); register(R.string.caches_filter_origin, OriginFilter.Factory.class); register(R.string.caches_filter_distance, DistanceFilter.Factory.class); - register(R.string.caches_filter_personal_note, PersonalNoteFilter.class); register(R.string.caches_filter_popularity, PopularityFilter.Factory.class); register(R.string.caches_filter_popularity_ratio, PopularityRatioFilter.Factory.class); + register(R.string.caches_filter_personal_data, PersonalDataFilterFactory.class); + register(R.string.caches_filter_rating, RatingFilter.class); // sort by localized names Collections.sort(registry, new Comparator<FactoryEntry>() { @@ -87,16 +87,16 @@ public final class FilterUserInterface { builder.setAdapter(adapter, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int itemIndex) { - FactoryEntry entry = adapter.getItem(itemIndex); + final FactoryEntry entry = adapter.getItem(itemIndex); // reset? if (entry.filterFactory == null) { runAfterwards.call(null); } else { try { - IFilterFactory factoryInstance = entry.filterFactory.newInstance(); + final IFilterFactory factoryInstance = entry.filterFactory.newInstance(); selectFromFactory(factoryInstance, entry.name, runAfterwards); - } catch (Exception e) { + } catch (final Exception e) { Log.e("selectFilter", e); } } diff --git a/main/src/cgeo/geocaching/filter/OwnRatingFilter.java b/main/src/cgeo/geocaching/filter/OwnRatingFilter.java new file mode 100644 index 0000000..1b5fffd --- /dev/null +++ b/main/src/cgeo/geocaching/filter/OwnRatingFilter.java @@ -0,0 +1,32 @@ +package cgeo.geocaching.filter; + +import cgeo.geocaching.CgeoApplication; +import cgeo.geocaching.Geocache; +import cgeo.geocaching.R; +import cgeo.geocaching.gcvote.GCVote; + +import java.util.Collections; +import java.util.List; + +/** + * Filter {@link Geocache}s if they have a locally stored <b>own</b> {@link GCVote} rating. This filter will not do any + * network request to find potentially missing local votes. + * + */ +public class OwnRatingFilter extends AbstractFilter implements IFilterFactory { + + protected OwnRatingFilter() { + super(CgeoApplication.getInstance().getString(R.string.caches_filter_own_rating)); + } + + @Override + public boolean accepts(final Geocache cache) { + return cache.getMyVote() > 0; + } + + @Override + public List<OwnRatingFilter> getFilters() { + return Collections.singletonList(this); + } + +} diff --git a/main/src/cgeo/geocaching/filter/PersonalDataFilterFactory.java b/main/src/cgeo/geocaching/filter/PersonalDataFilterFactory.java new file mode 100644 index 0000000..f41fbe6 --- /dev/null +++ b/main/src/cgeo/geocaching/filter/PersonalDataFilterFactory.java @@ -0,0 +1,13 @@ +package cgeo.geocaching.filter; + +import java.util.Arrays; +import java.util.List; + +public class PersonalDataFilterFactory implements IFilterFactory { + + @Override + public List<? extends IFilter> getFilters() { + return Arrays.asList(new OwnRatingFilter(), new PersonalNoteFilter(), new ModifiedFilter()); + } + +} diff --git a/main/src/cgeo/geocaching/filter/PersonalNoteFilter.java b/main/src/cgeo/geocaching/filter/PersonalNoteFilter.java index 15d262f..3f690c2 100644 --- a/main/src/cgeo/geocaching/filter/PersonalNoteFilter.java +++ b/main/src/cgeo/geocaching/filter/PersonalNoteFilter.java @@ -9,6 +9,9 @@ import org.apache.commons.lang3.StringUtils; import java.util.Collections; import java.util.List; +/** + * Filter that accepts {@link Geocache}s with a non empty personal note stored locally. + */ public class PersonalNoteFilter extends AbstractFilter implements IFilterFactory { protected PersonalNoteFilter() { @@ -16,7 +19,7 @@ public class PersonalNoteFilter extends AbstractFilter implements IFilterFactory } @Override - public boolean accepts(Geocache cache) { + public boolean accepts(final Geocache cache) { return StringUtils.isNotBlank(cache.getPersonalNote()); } diff --git a/main/src/cgeo/geocaching/filter/RatingFilter.java b/main/src/cgeo/geocaching/filter/RatingFilter.java new file mode 100644 index 0000000..c9b3bbd --- /dev/null +++ b/main/src/cgeo/geocaching/filter/RatingFilter.java @@ -0,0 +1,32 @@ +package cgeo.geocaching.filter; + +import cgeo.geocaching.CgeoApplication; +import cgeo.geocaching.Geocache; +import cgeo.geocaching.R; +import cgeo.geocaching.gcvote.GCVote; + +import java.util.Collections; +import java.util.List; + +/** + * Filter {@link Geocache}s if they have a locally stored {@link GCVote} rating. This filter will not do any network + * request to find potentially missing local votes. + * + */ +public class RatingFilter extends AbstractFilter implements IFilterFactory { + + protected RatingFilter() { + super(CgeoApplication.getInstance().getString(R.string.caches_filter_rating)); + } + + @Override + public boolean accepts(final Geocache cache) { + return cache.getRating() > 0; + } + + @Override + public List<RatingFilter> getFilters() { + return Collections.singletonList(this); + } + +} |
