Skip to content

Commit

Permalink
Updated Locus Data API to version 9. Started in implementation of sen…
Browse files Browse the repository at this point in the history
…ding Field notes and better checking of logged user.
  • Loading branch information
arcao committed Dec 12, 2011
1 parent 5e19776 commit 826b7a4
Show file tree
Hide file tree
Showing 18 changed files with 306 additions and 105 deletions.
Binary file modified lib/locusaddonpubliclib.jar
Binary file not shown.
Binary file modified lib/locusaddonpubliclib_src.jar
Binary file not shown.
5 changes: 2 additions & 3 deletions src/com/arcao/geocaching4locus/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import menion.android.locus.addon.publiclib.LocusIntents;
import menion.android.locus.addon.publiclib.LocusIntents.OnIntentMainFunction;
import menion.android.locus.addon.publiclib.LocusIntentsPatch;
import menion.android.locus.addon.publiclib.LocusUtils;
import menion.android.locus.addon.publiclib.geoData.Point;

Expand Down Expand Up @@ -89,7 +88,7 @@ public void onClick(DialogInterface dialog, int which) {

setContentView(R.layout.main_activity);

if (LocusIntentsPatch.isIntentOnPointAction(getIntent())) {
if (LocusIntents.isIntentOnPointAction(getIntent())) {
Point p = LocusIntents.handleIntentOnPointAction(getIntent());
if (p == null) {
Toast.makeText(this, "Wrong INTENT - no point!", Toast.LENGTH_SHORT).show();
Expand All @@ -101,7 +100,7 @@ public void onClick(DialogInterface dialog, int which) {
hasCoordinates = true;
}
}
if (LocusIntentsPatch.isIntentMainFunction(getIntent())) {
if (LocusIntents.isIntentMainFunction(getIntent())) {
LocusIntents.handleIntentMainFunction(getIntent(), this);
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/geocaching/api/AbstractGeocachingApiV2.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package geocaching.api;

import geocaching.api.data.CacheLog;
import geocaching.api.data.FieldNote;
import geocaching.api.data.Geocache;
import geocaching.api.data.ImageData;
import geocaching.api.data.SimpleGeocache;
import geocaching.api.data.UserProfile;
import geocaching.api.data.WayPoint;
import geocaching.api.data.type.CacheType;
import geocaching.api.data.type.LogType;
import geocaching.api.exception.GeocachingApiException;
import geocaching.api.impl.live_geocaching_api.filter.CacheCodeFilter;
import geocaching.api.impl.live_geocaching_api.filter.CacheFilter;
import geocaching.api.impl.live_geocaching_api.filter.GeocacheTypeFilter;
import geocaching.api.impl.live_geocaching_api.filter.PointRadiusFilter;

import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -54,6 +60,13 @@ public List<WayPoint> getWayPointsByCache(String cacheCode) throws GeocachingApi

public abstract List<SimpleGeocache> searchForGeocachesJSON(boolean isLite, int startIndex, int maxPerPage, int geocacheLogCount, int trackableLogCount, CacheFilter[] filters) throws GeocachingApiException;

public abstract UserProfile getYourUserProfile(boolean favoritePointData, boolean geocacheData, boolean publicProfileData, boolean souvenirData, boolean trackableData) throws GeocachingApiException;
public abstract CacheLog createFieldNoteAndPublish(String cacheCode, LogType logType, Date dateLogged, String note, boolean publish, ImageData imageData, boolean favoriteThisCache) throws GeocachingApiException;

public CacheLog createFieldNoteAndPublish(FieldNote fieldNote, boolean publish, ImageData imageData, boolean favoriteThisCache) throws GeocachingApiException {
return createFieldNoteAndPublish(fieldNote.getCacheCode(), fieldNote.getLogType(), fieldNote.getDateLogged(), fieldNote.getNote(), publish, imageData, favoriteThisCache);
}

protected void fireProgressListener(int progress) {
synchronized(listeners) {
for (GeocachingApiProgressListener listener : listeners) {
Expand Down
68 changes: 68 additions & 0 deletions src/geocaching/api/data/FieldNote.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package geocaching.api.data;

import geocaching.api.data.type.LogType;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class FieldNote {
public static final SimpleDateFormat DATE_FORMAT;

static {
DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
}

protected String cacheCode;
protected LogType logType;
protected Date dateLogged;
protected String note;

public FieldNote(String cacheCode, Date dateLogged, LogType logType, String note) {
this.cacheCode = cacheCode;
this.dateLogged = dateLogged;
this.logType = logType;
this.note = note;
}

public String getCacheCode() {
return cacheCode;
}

public Date getDateLogged() {
return dateLogged;
}

public LogType getLogType() {
return logType;
}

public String getNote() {
return note;
}

@Override
public String toString() {
return String.format("%s,%s,%s,\"%s\"", cacheCode, DATE_FORMAT.format(dateLogged), logType.getFriendlyName(), safeNote(note));
}

public static FieldNote parseLine(String line) {
String[] items = line.split(",", 4);

String note = items[3];
if (note.length() >= 2 && note.startsWith("\"") && note.endsWith("\""))
note = note.substring(1, note.length() - 1);

try {
return new FieldNote(items[0], DATE_FORMAT.parse(items[1]), LogType.parseLogType(items[2]), note);
} catch (ParseException e) {
return null;
}
}

protected static String safeNote(String note) {
return note.replace('"', '\'').replaceAll("[\r\n\t]+", "");
}
}
5 changes: 5 additions & 0 deletions src/geocaching/api/data/ImageData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package geocaching.api.data;

public class ImageData {

}
4 changes: 4 additions & 0 deletions src/geocaching/api/data/SimpleGeocache.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

import menion.android.locus.addon.publiclib.geoData.Point;
import menion.android.locus.addon.publiclib.geoData.PointGeocachingData;
Expand Down Expand Up @@ -37,6 +38,9 @@ public class SimpleGeocache {
private final boolean found;

private static final DateFormat GPX_TIME_FMT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
static {
GPX_TIME_FMT.setTimeZone(TimeZone.getTimeZone("GMT+00:00"));
}

public SimpleGeocache(String geoCode, String name, double longitude,
double latitude, CacheType cacheType, float difficultyRating,
Expand Down
64 changes: 64 additions & 0 deletions src/geocaching/api/data/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package geocaching.api.data;

import geocaching.api.data.type.MemberType;

public class User {
protected String avatarUrl;
protected int findCount;
protected int hideCount;
protected float[] homeCoordinates;
protected long id;
protected boolean admin;
protected MemberType memberType;
protected String publicGuid;
protected String userName;

public User(String avatarUrl, int findCount, int hideCount, float[] homeCoordinates, long id, boolean admin, MemberType memberType, String publicGuid,
String userName) {
this.avatarUrl = avatarUrl;
this.findCount = findCount;
this.hideCount = hideCount;
this.homeCoordinates = homeCoordinates;
this.id = id;
this.admin = admin;
this.memberType = memberType;
this.publicGuid = publicGuid;
this.userName = userName;
}

public String getAvatarUrl() {
return avatarUrl;
}

public int getFindCount() {
return findCount;
}

public int getHideCount() {
return hideCount;
}

public float[] getHomeCoordinates() {
return homeCoordinates;
}

public long getId() {
return id;
}

public boolean isAdmin() {
return admin;
}

public MemberType getMemberType() {
return memberType;
}

public String getPublicGuid() {
return publicGuid;
}

public String getUserName() {
return userName;
}
}
25 changes: 25 additions & 0 deletions src/geocaching/api/data/UserProfile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package geocaching.api.data;


public class UserProfile {
//protected List<FavoritePoint> favoritePoints;
//protected GeocacheFindStats findStats;
//protected PublicProfile publicProfile;
//protected List<Souvenir> souvenirs;
//protected GlobalStats globalStats;
//protected TrackableStats trackableStats;
protected User user;

public UserProfile(/*List<FavoritePoint> favoritePoints, GeocacheFindStats findStats, PublicProfile publicProfile, List<Souvenir> souvenirs,
GlobalStats globalStats, TrackableStats trackableStats,*/ User user) {
/* this.favoritePoints = favoritePoints;
this.findStats = findStats;
this.publicProfile = publicProfile;
this.souvenirs = souvenirs;
this.globalStats = globalStats;
this.trackableStats = trackableStats;*/
this.user = user;
}


}
33 changes: 33 additions & 0 deletions src/geocaching/api/data/type/MemberType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package geocaching.api.data.type;

public enum MemberType {
Guest("Guest", 0),
Basic("Basic", 1),
Charter("Charter", 2),
Premium("Premium", 3);

protected String friendlyName;
protected int groundSpeakId;

private MemberType(String friendlyName, int groundSpeakId) {
this.friendlyName = friendlyName;
this.groundSpeakId = groundSpeakId;
}

public String getFriendlyName() {
return friendlyName;
}

public int getGroundSpeakId() {
return groundSpeakId;
}

public static MemberType parseMemeberTypeByGroundSpeakId(int groundSpeakId) {
for (MemberType memberType : values()) {
if (memberType.groundSpeakId == groundSpeakId)
return memberType;
}

return Guest;
}
}
15 changes: 15 additions & 0 deletions src/geocaching/api/impl/LiveGeocachingApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import geocaching.api.AbstractGeocachingApiV2;
import geocaching.api.GeocachingApiProgressListener;
import geocaching.api.data.CacheLog;
import geocaching.api.data.ImageData;
import geocaching.api.data.SimpleGeocache;
import geocaching.api.data.TravelBug;
import geocaching.api.data.UserProfile;
import geocaching.api.data.type.LogType;
import geocaching.api.exception.GeocachingApiException;
import geocaching.api.exception.InvalidCredentialsException;
import geocaching.api.exception.InvalidSessionException;
Expand All @@ -25,6 +28,7 @@
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.zip.GZIPInputStream;
import java.util.zip.Inflater;
Expand Down Expand Up @@ -165,6 +169,17 @@ public List<CacheLog> getCacheLogs(String cacheCode, int startPosition, int endP
throw new GeocachingApiException("Not implemented.");
}

@Override
public CacheLog createFieldNoteAndPublish(String cacheCode, LogType logType, Date dateLogged, String note, boolean publish, ImageData imageData,
boolean favoriteThisCache) throws GeocachingApiException {
throw new GeocachingApiException("Not implemented.");
}

@Override
public UserProfile getYourUserProfile(boolean favoritePointData, boolean geocacheData, boolean publicProfileData, boolean souvenirData, boolean trackableData) throws GeocachingApiException {
throw new GeocachingApiException("Not implemented.");
}

// -------------------- Helper methods ----------------------------------------

protected void checkError(JsonReader r) throws GeocachingApiException, IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static CacheLog parse(JsonReader r) throws IOException {
} else if ("LogType".equals(name)) {
logType = parseLogType(r);
} else if ("Finder".equals(name)) {
author = parseUser(r).name;
author = parseUser(r).getUserName();
} else if ("LogText".equals(name)) {
text = r.nextString();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import geocaching.api.data.Geocache;
import geocaching.api.data.SimpleGeocache;
import geocaching.api.data.TravelBug;
import geocaching.api.data.User;
import geocaching.api.data.WayPoint;
import geocaching.api.data.type.AttributeType;
import geocaching.api.data.type.CacheType;
Expand Down Expand Up @@ -86,8 +87,8 @@ public static Geocache parse(JsonReader r) throws IOException {
terrainRating = (float) r.nextDouble();
} else if ("Owner".equals(name)) {
User u = parseUser(r);
authorGuid = u.name;
authorName = u.guid;
authorGuid = u.getPublicGuid();
authorName = u.getUserName();
} else if ("Available".equals(name)) {
available = r.nextBoolean();
} else if ("Archived".equals(name)) {
Expand Down
Loading

0 comments on commit 826b7a4

Please sign in to comment.