Skip to content

Commit

Permalink
new: ignore caches
Browse files Browse the repository at this point in the history
  • Loading branch information
Bananeweizen committed Feb 22, 2015
1 parent 6730171 commit bd313c7
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 21 deletions.
6 changes: 6 additions & 0 deletions main/res/menu/cache_options.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,11 @@
android:visible="false"
app:showAsAction="ifRoom">
</item>
<item
android:id="@+id/menu_ignore"
android:title="@string/cache_menu_ignore"
android:visible="false"
app:showAsAction="ifRoom">
</item>

</menu>
1 change: 1 addition & 0 deletions main/res/values/changelog_master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
· New: Confirmation on backup/restore\n
· New: Links in personal notes can be clicked\n
· New: Menu in cache details to open geo checker\n
· New: Menu in cache details to put cache on ignore list (but not to remove)\n
· Fix: Improve detection pattern for event start time\n
· Fix: Android Beam working with trackables again\n
· Fix: Disable Android Beam when not useful\n
Expand Down
1 change: 1 addition & 0 deletions main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,7 @@
<string name="cache_menu_android_wear">Android Wear</string>
<string name="cache_menu_vote">Vote</string>
<string name="cache_menu_checker">Open geo checker</string>
<string name="cache_menu_ignore">Ignore cache</string>
<string name="cache_status">Status</string>
<string name="cache_status_offline_log">Saved Log</string>
<string name="cache_status_found">Found</string>
Expand Down
19 changes: 19 additions & 0 deletions main/src/cgeo/geocaching/CacheDetailActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import cgeo.geocaching.apps.cachelist.MapsWithMeCacheListApp;
import cgeo.geocaching.connector.ConnectorFactory;
import cgeo.geocaching.connector.IConnector;
import cgeo.geocaching.connector.capability.IgnoreCapability;
import cgeo.geocaching.connector.gc.GCConnector;
import cgeo.geocaching.connector.gc.GCConstants;
import cgeo.geocaching.enumerations.CacheAttribute;
Expand Down Expand Up @@ -494,6 +495,12 @@ public boolean onPrepareOptionsMenu(final Menu menu) {
menu.findItem(R.id.menu_refresh).setVisible(cache != null && cache.isOffline());
menu.findItem(R.id.menu_gcvote).setVisible(cache != null && GCVote.isVotingPossible(cache));
menu.findItem(R.id.menu_checker).setVisible(cache != null && StringUtils.isNotEmpty(CheckerUtils.getCheckerUrl(cache)));
if (cache != null) {
final IConnector connector = ConnectorFactory.getConnector(cache);
if (connector instanceof IgnoreCapability) {
menu.findItem(R.id.menu_ignore).setVisible(((IgnoreCapability) connector).canIgnoreCache(cache));
}
}
return super.onPrepareOptionsMenu(menu);
}

Expand Down Expand Up @@ -521,6 +528,9 @@ public boolean onOptionsItemSelected(final MenuItem item) {
case R.id.menu_checker:
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(CheckerUtils.getCheckerUrl(cache))));
return true;
case R.id.menu_ignore:
ignoreCache();
return true;
default:
if (NavigationAppFactory.onMenuItemSelected(item, this, cache)) {
return true;
Expand All @@ -534,6 +544,15 @@ public boolean onOptionsItemSelected(final MenuItem item) {
return super.onOptionsItemSelected(item);
}

private void ignoreCache() {
RxUtils.networkScheduler.createWorker().schedule(new Action0() {
@Override
public void call() {
((IgnoreCapability) ConnectorFactory.getConnector(cache)).ignoreCache(cache);
}
});
}

private void showVoteDialog() {
GCVoteDialog.show(this, cache, new Runnable() {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package cgeo.geocaching.connector.capability;

import cgeo.geocaching.Geocache;
import cgeo.geocaching.connector.IConnector;

import org.eclipse.jdt.annotation.NonNull;

/**
* Connector capability to ignore caches.
*/
public interface IgnoreCapability extends IConnector {
public boolean canIgnoreCache(final @NonNull Geocache cache);
public void ignoreCache(final @NonNull Geocache cache);
}
13 changes: 12 additions & 1 deletion main/src/cgeo/geocaching/connector/gc/GCConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import cgeo.geocaching.connector.capability.ISearchByKeyword;
import cgeo.geocaching.connector.capability.ISearchByOwner;
import cgeo.geocaching.connector.capability.ISearchByViewPort;
import cgeo.geocaching.connector.capability.IgnoreCapability;
import cgeo.geocaching.enumerations.StatusCode;
import cgeo.geocaching.loaders.RecaptchaReceiver;
import cgeo.geocaching.location.Geopoint;
Expand Down Expand Up @@ -47,7 +48,7 @@
import java.util.List;
import java.util.regex.Pattern;

public class GCConnector extends AbstractConnector implements ISearchByGeocode, ISearchByCenter, ISearchByViewPort, ISearchByKeyword, ILogin, ICredentials, ISearchByOwner, ISearchByFinder, FieldNotesCapability {
public class GCConnector extends AbstractConnector implements ISearchByGeocode, ISearchByCenter, ISearchByViewPort, ISearchByKeyword, ILogin, ICredentials, ISearchByOwner, ISearchByFinder, FieldNotesCapability, IgnoreCapability {

@NonNull
private static final String CACHE_URL_SHORT = "http://coord.info/";
Expand Down Expand Up @@ -481,4 +482,14 @@ public boolean uploadFieldNotes(@NonNull final File exportFile) {
return true;
}

@Override
public boolean canIgnoreCache(@NonNull final Geocache cache) {
return StringUtils.isNotEmpty(cache.getType().wptTypeId);
}

@Override
public void ignoreCache(@NonNull final Geocache cache) {
GCParser.ignoreCache(cache);
}

}
21 changes: 21 additions & 0 deletions main/src/cgeo/geocaching/connector/gc/GCParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -1979,4 +1979,25 @@ public static boolean uploadPersonalNote(final Geocache cache) {
return false;
}

public static boolean ignoreCache(@NonNull final Geocache cache) {
final String uri = "http://www.geocaching.com/bookmarks/ignore.aspx?guid=" + cache.getGuid() + "&WptTypeID=" + cache.getType().wptTypeId;
final String page = GCLogin.getInstance().postRequestLogged(uri, null);

if (StringUtils.isBlank(page)) {
Log.e("GCParser.ignoreCache: No data from server");
return false;
}

final String[] viewstates = GCLogin.getViewstates(page);

final Parameters params = new Parameters(
"__EVENTTARGET", "",
"__EVENTARGUMENT", "",
"ctl00$ContentBody$btnYes", "Yes. Ignore it.");

GCLogin.putViewstates(params, viewstates);
final String response = Network.getResponseData(Network.postRequest(uri, params));

return StringUtils.contains(response, "<p class=\"Success\">");
}
}
42 changes: 22 additions & 20 deletions main/src/cgeo/geocaching/enumerations/CacheType.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@
*/
public enum CacheType {

TRADITIONAL("traditional", "Traditional Cache", "32bc9333-5e52-4957-b0f6-5a2c8fc7b257", R.string.traditional, R.drawable.type_traditional),
MULTI("multi", "Multi-cache", "a5f6d0ad-d2f2-4011-8c14-940a9ebf3c74", R.string.multi, R.drawable.type_multi),
MYSTERY("mystery", "Unknown Cache", "40861821-1835-4e11-b666-8d41064d03fe", R.string.mystery, R.drawable.type_mystery),
LETTERBOX("letterbox", "Letterbox hybrid", "4bdd8fb2-d7bc-453f-a9c5-968563b15d24", R.string.letterbox, R.drawable.type_letterbox),
EVENT("event", "Event Cache", "69eb8534-b718-4b35-ae3c-a856a55b0874", R.string.event, R.drawable.type_event),
MEGA_EVENT("mega", "Mega-Event Cache", "69eb8535-b718-4b35-ae3c-a856a55b0874", R.string.mega, R.drawable.type_mega),
GIGA_EVENT("giga", "Giga-Event Cache", "51420629-5739-4945-8bdd-ccfd434c0ead", R.string.giga, R.drawable.type_giga),
EARTH("earth", "Earthcache", "c66f5cf3-9523-4549-b8dd-759cd2f18db8", R.string.earth, R.drawable.type_earth),
CITO("cito", "Cache in Trash out Event", "57150806-bc1a-42d6-9cf0-538d171a2d22", R.string.cito, R.drawable.type_cito),
WEBCAM("webcam", "Webcam Cache", "31d2ae3c-c358-4b5f-8dcd-2185bf472d3d", R.string.webcam, R.drawable.type_webcam),
VIRTUAL("virtual", "Virtual Cache", "294d4360-ac86-4c83-84dd-8113ef678d7e", R.string.virtual, R.drawable.type_virtual),
WHERIGO("wherigo", "Wherigo Cache", "0544fa55-772d-4e5c-96a9-36a51ebcf5c9", R.string.wherigo, R.drawable.type_wherigo),
LOSTANDFOUND("lostfound", "Lost and Found Event Cache", "3ea6533d-bb52-42fe-b2d2-79a3424d4728", R.string.lostfound, R.drawable.type_event), // icon missing
PROJECT_APE("ape", "Project Ape Cache", "2555690d-b2bc-4b55-b5ac-0cb704c0b768", R.string.ape, R.drawable.type_ape),
GCHQ("gchq", "Groundspeak HQ", "416f2494-dc17-4b6a-9bab-1a29dd292d8c", R.string.gchq, R.drawable.type_hq),
GPS_EXHIBIT("gps", "GPS Adventures Exhibit", "72e69af2-7986-4990-afd9-bc16cbbb4ce3", R.string.gps, R.drawable.type_event), // icon missing
BLOCK_PARTY("block", "Groundspeak Block Party", "bc2f3df2-1aab-4601-b2ff-b5091f6c02e3", R.string.block, R.drawable.type_event), // icon missing
UNKNOWN("unknown", "unknown", "", R.string.unknown, R.drawable.type_unknown),
TRADITIONAL("traditional", "Traditional Cache", "32bc9333-5e52-4957-b0f6-5a2c8fc7b257", R.string.traditional, R.drawable.type_traditional, "2"),
MULTI("multi", "Multi-cache", "a5f6d0ad-d2f2-4011-8c14-940a9ebf3c74", R.string.multi, R.drawable.type_multi, "3"),
MYSTERY("mystery", "Unknown Cache", "40861821-1835-4e11-b666-8d41064d03fe", R.string.mystery, R.drawable.type_mystery, "8"),
LETTERBOX("letterbox", "Letterbox hybrid", "4bdd8fb2-d7bc-453f-a9c5-968563b15d24", R.string.letterbox, R.drawable.type_letterbox, "5"),
EVENT("event", "Event Cache", "69eb8534-b718-4b35-ae3c-a856a55b0874", R.string.event, R.drawable.type_event, "6"),
MEGA_EVENT("mega", "Mega-Event Cache", "69eb8535-b718-4b35-ae3c-a856a55b0874", R.string.mega, R.drawable.type_mega, "453"),
GIGA_EVENT("giga", "Giga-Event Cache", "51420629-5739-4945-8bdd-ccfd434c0ead", R.string.giga, R.drawable.type_giga, "7005"),
EARTH("earth", "Earthcache", "c66f5cf3-9523-4549-b8dd-759cd2f18db8", R.string.earth, R.drawable.type_earth, "137"),
CITO("cito", "Cache in Trash out Event", "57150806-bc1a-42d6-9cf0-538d171a2d22", R.string.cito, R.drawable.type_cito, "13"),
WEBCAM("webcam", "Webcam Cache", "31d2ae3c-c358-4b5f-8dcd-2185bf472d3d", R.string.webcam, R.drawable.type_webcam, "11"),
VIRTUAL("virtual", "Virtual Cache", "294d4360-ac86-4c83-84dd-8113ef678d7e", R.string.virtual, R.drawable.type_virtual, "4"),
WHERIGO("wherigo", "Wherigo Cache", "0544fa55-772d-4e5c-96a9-36a51ebcf5c9", R.string.wherigo, R.drawable.type_wherigo, "1858"),
LOSTANDFOUND("lostfound", "Lost and Found Event Cache", "3ea6533d-bb52-42fe-b2d2-79a3424d4728", R.string.lostfound, R.drawable.type_event, "3653"), // icon missing
PROJECT_APE("ape", "Project Ape Cache", "2555690d-b2bc-4b55-b5ac-0cb704c0b768", R.string.ape, R.drawable.type_ape, "2"),
GCHQ("gchq", "Groundspeak HQ", "416f2494-dc17-4b6a-9bab-1a29dd292d8c", R.string.gchq, R.drawable.type_hq, "3773"),
GPS_EXHIBIT("gps", "GPS Adventures Exhibit", "72e69af2-7986-4990-afd9-bc16cbbb4ce3", R.string.gps, R.drawable.type_event, "1304"), // icon missing
BLOCK_PARTY("block", "Groundspeak Block Party", "bc2f3df2-1aab-4601-b2ff-b5091f6c02e3", R.string.block, R.drawable.type_event, "4738"), // icon missing
UNKNOWN("unknown", "unknown", "", R.string.unknown, R.drawable.type_unknown, ""),
/** No real cache type -> filter */
ALL("all", "display all caches", "9a79e6ce-3344-409c-bbe9-496530baf758", R.string.all_types, R.drawable.type_unknown);
ALL("all", "display all caches", "9a79e6ce-3344-409c-bbe9-496530baf758", R.string.all_types, R.drawable.type_unknown, "");

/**
* id field is used when for storing caches in the database.
Expand All @@ -48,13 +48,15 @@ public enum CacheType {
public final String guid;
private final int stringId;
public final int markerId;
@NonNull public final String wptTypeId;

CacheType(final String id, final String pattern, final String guid, final int stringId, final int markerId) {
CacheType(final String id, final String pattern, final String guid, final int stringId, final int markerId, @NonNull final String wptTypeId) {
this.id = id;
this.pattern = pattern;
this.guid = guid;
this.stringId = stringId;
this.markerId = markerId;
this.wptTypeId = wptTypeId;
}

@NonNull
Expand Down

0 comments on commit bd313c7

Please sign in to comment.