aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authormucek4 <tomaz@gorenc.org>2011-08-10 09:44:08 +0200
committermucek4 <tomaz@gorenc.org>2011-08-10 09:44:08 +0200
commit42e4da93bc86da6bbf43fe926ede0c41034b13a9 (patch)
tree86b07afb18559f49604229417f45b811fc60c238 /src
parentc0ec739bd929534b3043932f8ab622758a257bf9 (diff)
downloadcgeo-42e4da93bc86da6bbf43fe926ede0c41034b13a9.zip
cgeo-42e4da93bc86da6bbf43fe926ede0c41034b13a9.tar.gz
cgeo-42e4da93bc86da6bbf43fe926ede0c41034b13a9.tar.bz2
Personal note display
Diffstat (limited to 'src')
-rw-r--r--src/cgeo/geocaching/cgBase.java44
-rw-r--r--src/cgeo/geocaching/cgCache.java4
-rw-r--r--src/cgeo/geocaching/cgData.java19
-rw-r--r--src/cgeo/geocaching/cgeodetail.java14
4 files changed, 69 insertions, 12 deletions
diff --git a/src/cgeo/geocaching/cgBase.java b/src/cgeo/geocaching/cgBase.java
index 0d2d88e..a4c7834 100644
--- a/src/cgeo/geocaching/cgBase.java
+++ b/src/cgeo/geocaching/cgBase.java
@@ -93,10 +93,11 @@ public class cgBase {
private Resources res = null;
private HashMap<String, String> cookies = new HashMap<String, String>();
private static final String passMatch = "[/\\?&]*[Pp]ass(word)?=[^&^#^$]+";
- private final Pattern patternLoggedIn = Pattern.compile("<span class=\"Success\">You are logged in as[^<]*<strong[^>]*>([^<]+)</strong>[^<]*</span>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
- private final Pattern patternLogged2In = Pattern.compile("<strong>[^\\w]*Hello,[^<]*<a[^>]+>([^<]+)</a>[^<]*</strong>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
- private final Pattern patternViewstate = Pattern.compile("id=\"__VIEWSTATE\"[^(value)]+value=\"([^\"]+)\"[^>]+>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
- private final Pattern patternViewstate1 = Pattern.compile("id=\"__VIEWSTATE1\"[^(value)]+value=\"([^\"]+)\"[^>]+>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
+ private static final Pattern patternLoggedIn = Pattern.compile("<span class=\"Success\">You are logged in as[^<]*<strong[^>]*>([^<]+)</strong>[^<]*</span>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
+ private static final Pattern patternLogged2In = Pattern.compile("<strong>[^\\w]*Hello,[^<]*<a[^>]+>([^<]+)</a>[^<]*</strong>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
+ private static final Pattern patternViewstate = Pattern.compile("id=\"__VIEWSTATE\"[^(value)]+value=\"([^\"]+)\"[^>]+>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
+ private static final Pattern patternViewstate1 = Pattern.compile("id=\"__VIEWSTATE1\"[^(value)]+value=\"([^\"]+)\"[^>]+>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
+ private static final Pattern patternIsPremium = Pattern.compile("<span id=\"ctl00_litPMLevel\"", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
public static final double kmInMiles = 1 / 1.609344;
public static final double deg2rad = Math.PI / 180;
public static final double rad2deg = 180 / Math.PI;
@@ -471,8 +472,17 @@ public class cgBase {
return -5; // no login page
}
}
+
+ public static Boolean isPremium(String page)
+ {
+ if (checkLogin(page)) {
+ final Matcher matcherIsPremium = patternIsPremium.matcher(page);
+ return matcherIsPremium.find();
+ } else
+ return false;
+ }
- public Boolean checkLogin(String page) {
+ public static Boolean checkLogin(String page) {
if (page == null || page.length() == 0) {
Log.e(cgSettings.tag, "cgeoBase.checkLogin: No page given");
return false;
@@ -1087,6 +1097,7 @@ public class cgBase {
final Pattern patternLatLon = Pattern.compile("<span id=\"ctl00_ContentBody_LatLon\"[^>]*>(<b>)?([^<]*)(<\\/b>)?<\\/span>", Pattern.CASE_INSENSITIVE);
final Pattern patternLocation = Pattern.compile("<span id=\"ctl00_ContentBody_Location\"[^>]*>In ([^<]*)", Pattern.CASE_INSENSITIVE);
final Pattern patternHint = Pattern.compile("<p>([^<]*<strong>)?[^\\w]*Additional Hints([^<]*<\\/strong>)?[^\\(]*\\(<a[^>]+>Encrypt</a>\\)[^<]*<\\/p>[^<]*<div id=\"div_hint\"[^>]*>(.*)</div>[^<]*<div id=[\\'|\"]dk[\\'|\"]", Pattern.CASE_INSENSITIVE);
+ final Pattern patternPersonalNote = Pattern.compile("<p id=\"cache_note\"[^>]*>([^<]*)</p>", Pattern.CASE_INSENSITIVE);
final Pattern patternDescShort = Pattern.compile("<div class=\"UserSuppliedContent\">[^<]*<span id=\"ctl00_ContentBody_ShortDescription\"[^>]*>((?:(?!</span>[^\\w^<]*</div>).)*)</span>[^\\w^<]*</div>", Pattern.CASE_INSENSITIVE);
final Pattern patternDesc = Pattern.compile("<span id=\"ctl00_ContentBody_LongDescription\"[^>]*>" + "(.*)</span>[^<]*</div>[^<]*<p>[^<]*</p>[^<]*<p>[^<]*<strong>[^\\w]*Additional Hints</strong>", Pattern.CASE_INSENSITIVE);
final Pattern patternCountLogs = Pattern.compile("<span id=\"ctl00_ContentBody_lblFindCounts\"><p>(.*)<\\/p><\\/span>", Pattern.CASE_INSENSITIVE);
@@ -1437,6 +1448,19 @@ public class cgBase {
Log.d(cgSettings.tag, "hint: " + cache.hint);
*/
+ // cache personal note
+ try {
+ final Matcher matcherPersonalNote = patternPersonalNote.matcher(page);
+ if (matcherPersonalNote.find()) {
+ if (matcherPersonalNote.groupCount() > 0) {
+ cache.personalNote = getMatch(matcherPersonalNote.group(1).trim());
+ }
+ }
+ } catch (Exception e) {
+ // failed to parse cache personal note
+ Log.w(cgSettings.tag, "cgeoBase.parseCache: Failed to parse cache personal note");
+ }
+
// cache short description
try {
final Matcher matcherDescShort = patternDescShort.matcher(page);
@@ -4760,7 +4784,7 @@ public class cgBase {
public String requestJSON(String scheme, String host, String path, String method, String params) {
int httpCode = -1;
- String httpLocation = null;
+ //String httpLocation = null;
if (method == null) {
method = "GET";
@@ -4877,17 +4901,19 @@ public class cgBase {
}
String page = null;
- if (httpCode == 302 && httpLocation != null) {
+ //This is reported as beeing deadCode (httpLocation is always null)
+ //2011-08-09 - 302 is redirect so something should probably be done
+ /*if (httpCode == 302 && httpLocation != null) {
final Uri newLocation = Uri.parse(httpLocation);
if (newLocation.isRelative() == true) {
page = requestJSONgc(host, path, params);
} else {
page = requestJSONgc(newLocation.getHost(), newLocation.getPath(), params);
}
- } else {
+ } else {*/
replaceWhitespace(buffer);
page = buffer.toString();
- }
+ //}
if (page != null) {
return page;
diff --git a/src/cgeo/geocaching/cgCache.java b/src/cgeo/geocaching/cgCache.java
index df3eabc..eb2b42d 100644
--- a/src/cgeo/geocaching/cgCache.java
+++ b/src/cgeo/geocaching/cgCache.java
@@ -39,6 +39,7 @@ public class cgCache {
public Double longitude = null;
public boolean reliableLatLon = false;
public Double elevation = null;
+ public String personalNote = null;
public String shortdesc = "";
public String description = "";
public boolean disabled = false;
@@ -173,6 +174,9 @@ public class cgCache {
if (elevation == null) {
elevation = oldCache.elevation;
}
+ if (personalNote == null || personalNote.length() == 0) {
+ personalNote = oldCache.personalNote;
+ }
if (shortdesc == null || shortdesc.length() == 0) {
shortdesc = oldCache.shortdesc;
}
diff --git a/src/cgeo/geocaching/cgData.java b/src/cgeo/geocaching/cgData.java
index c8c98a0..ed7a548 100644
--- a/src/cgeo/geocaching/cgData.java
+++ b/src/cgeo/geocaching/cgData.java
@@ -12,8 +12,8 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
-import java.util.Set;
import java.util.Map.Entry;
+import java.util.Set;
import android.content.ContentValues;
import android.content.Context;
@@ -33,7 +33,7 @@ public class cgData {
private cgDbHelper dbHelper = null;
private SQLiteDatabase databaseRO = null;
private SQLiteDatabase databaseRW = null;
- private static final int dbVersion = 54;
+ private static final int dbVersion = 55;
private static final String dbName = "data";
private static final String dbTableCaches = "cg_caches";
private static final String dbTableLists = "cg_lists";
@@ -77,6 +77,7 @@ public class cgData {
+ "longitude double, "
+ "reliable_latlon integer, "
+ "elevation double, "
+ + "personal_note text, "
+ "shortdesc text, "
+ "description text, "
+ "favourite_cnt integer, "
@@ -739,6 +740,15 @@ public class cgData {
}
}
+
+ if (oldVersion < 55) { // update to 55
+ try {
+ db.execSQL("alter table " + dbTableCaches + " add column personal_note text");
+ } catch (Exception e) {
+ Log.e(cgSettings.tag, "Failed to upgrade to ver. 55: " + e.toString());
+
+ }
+ }
}
db.setTransactionSuccessful();
@@ -1139,6 +1149,7 @@ public class cgData {
}
values.put("elevation", cache.elevation);
values.put("shortdesc", cache.shortdesc);
+ values.put("personal_note", cache.personalNote);
values.put("description", cache.description);
values.put("favourite_cnt", cache.favouriteCnt);
values.put("rating", cache.rating);
@@ -1758,7 +1769,7 @@ public class cgData {
"_id", "updated", "reason", "detailed", "detailedupdate", "visiteddate", "geocode", "cacheid", "guid", "type", "name", "own", "owner", "owner_real", "hidden", "hint", "size",
"difficulty", "distance", "direction", "terrain", "latlon", "latitude_string", "longitude_string", "location", "latitude", "longitude", "elevation", "shortdesc",
"description", "favourite_cnt", "rating", "votes", "myvote", "disabled", "archived", "members", "found", "favourite", "inventorycoins", "inventorytags",
- "inventoryunknown", "onWatchlist"
+ "inventoryunknown", "onWatchlist", "personal_note"
},
where.toString(),
null,
@@ -1828,6 +1839,7 @@ public class cgData {
} else {
cache.elevation = (Double) cursor.getDouble(index);
}
+ cache.personalNote = (String) cursor.getString(cursor.getColumnIndex("personal_note"));
cache.shortdesc = (String) cursor.getString(cursor.getColumnIndex("shortdesc"));
cache.description = (String) cursor.getString(cursor.getColumnIndex("description"));
cache.favouriteCnt = (Integer) cursor.getInt(cursor.getColumnIndex("favourite_cnt"));
@@ -2495,6 +2507,7 @@ public class cgData {
cursor.close();
}
+
} catch (Exception e) {
Log.e(cgSettings.tag, "cgData.loadBatchOfStoredGeocodes: " + e.toString());
}
diff --git a/src/cgeo/geocaching/cgeodetail.java b/src/cgeo/geocaching/cgeodetail.java
index e3f646e..d929d85 100644
--- a/src/cgeo/geocaching/cgeodetail.java
+++ b/src/cgeo/geocaching/cgeodetail.java
@@ -899,6 +899,16 @@ public class cgeodetail extends AbstractActivity {
offlineStore.setOnClickListener(new storeCache());
}
+ // cache personal note
+ if (cache.personalNote != null && cache.personalNote.length() > 0) {
+ ((LinearLayout) findViewById(R.id.personalnote_box)).setVisibility(View.VISIBLE);
+
+ TextView personalNoteText = (TextView) findViewById(R.id.personalnote);
+ personalNoteText.setVisibility(View.VISIBLE);
+ personalNoteText.setText(cache.personalNote, TextView.BufferType.SPANNABLE);
+ personalNoteText.setMovementMethod(LinkMovementMethod.getInstance());
+ }
+
// cache short desc
if (cache.shortdesc != null && cache.shortdesc.length() > 0) {
((LinearLayout) findViewById(R.id.desc_box)).setVisibility(View.VISIBLE);
@@ -1470,6 +1480,10 @@ public class cgeodetail extends AbstractActivity {
description.append(Html.fromHtml(cache.shortdesc).toString());
}
+ if (cache.personalNote != null && cache.personalNote.length() > 0) {
+ description.append("\n\n"+Html.fromHtml(cache.personalNote).toString());
+ }
+
ContentValues event = new ContentValues();
event.put("calendar_id", calId);
event.put("dtstart", eventDate.getTime() + 43200000); // noon