aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cgeo/geocaching/LogTemplateProvider.java23
-rw-r--r--src/cgeo/geocaching/cgBase.java14
-rw-r--r--src/cgeo/geocaching/cgCache.java2
-rw-r--r--src/cgeo/geocaching/cgData.java82
-rw-r--r--src/cgeo/geocaching/cgeoadvsearch.java39
-rw-r--r--src/cgeo/geocaching/cgeoapplication.java16
-rw-r--r--src/cgeo/geocaching/cgeovisit.java6
7 files changed, 70 insertions, 112 deletions
diff --git a/src/cgeo/geocaching/LogTemplateProvider.java b/src/cgeo/geocaching/LogTemplateProvider.java
index 4cc97fc..5196aeb 100644
--- a/src/cgeo/geocaching/LogTemplateProvider.java
+++ b/src/cgeo/geocaching/LogTemplateProvider.java
@@ -24,7 +24,7 @@ public class LogTemplateProvider {
this.resourceId = resourceId;
}
- abstract String getValue(cgBase base);
+ abstract String getValue(cgBase base, boolean offline);
public int getResourceId() {
return resourceId;
@@ -38,9 +38,9 @@ public class LogTemplateProvider {
return template;
}
- protected String apply(String input, cgBase base) {
+ protected String apply(String input, cgBase base, boolean offline) {
if (input.contains("[" + template + "]")) {
- return input.replaceAll("\\[" + template + "\\]", getValue(base));
+ return input.replaceAll("\\[" + template + "\\]", getValue(base, offline));
}
return input;
}
@@ -54,21 +54,21 @@ public class LogTemplateProvider {
new LogTemplate("DATE", R.string.init_signature_template_date) {
@Override
- String getValue(final cgBase base) {
+ String getValue(final cgBase base, final boolean offline) {
return base.formatFullDate(System.currentTimeMillis());
}
},
new LogTemplate("TIME", R.string.init_signature_template_time) {
@Override
- String getValue(final cgBase base) {
+ String getValue(final cgBase base, final boolean offline) {
return base.formatTime(System.currentTimeMillis());
}
},
new LogTemplate("DATETIME", R.string.init_signature_template_datetime) {
@Override
- String getValue(final cgBase base) {
+ String getValue(final cgBase base, final boolean offline) {
final long currentTime = System.currentTimeMillis();
return base.formatFullDate(currentTime) + " " + base.formatTime(currentTime);
}
@@ -76,14 +76,17 @@ public class LogTemplateProvider {
new LogTemplate("USER", R.string.init_signature_template_user) {
@Override
- String getValue(final cgBase base) {
+ String getValue(final cgBase base, final boolean offline) {
return base.getUserName();
}
},
new LogTemplate("NUMBER", R.string.init_signature_template_number) {
@Override
- String getValue(final cgBase base) {
+ String getValue(final cgBase base, final boolean offline) {
+ if (offline) {
+ return "";
+ }
String findCount = "";
final Map<String, String> params = new HashMap<String, String>();
final String page = base.request(false, "www.geocaching.com", "/email/", "GET", params, false, false, false).getData();
@@ -109,13 +112,13 @@ public class LogTemplateProvider {
return null;
}
- public static String applyTemplates(String signature, cgBase base) {
+ public static String applyTemplates(String signature, cgBase base, boolean offline) {
if (signature == null) {
return "";
}
String result = signature;
for (LogTemplate template : getTemplates()) {
- result = template.apply(result, base);
+ result = template.apply(result, base, offline);
}
return result;
}
diff --git a/src/cgeo/geocaching/cgBase.java b/src/cgeo/geocaching/cgBase.java
index 933d9df..c3625dd 100644
--- a/src/cgeo/geocaching/cgBase.java
+++ b/src/cgeo/geocaching/cgBase.java
@@ -646,10 +646,12 @@ public class cgBase {
}
}
- int startPos = -1;
- int endPos = -1;
-
- startPos = page.indexOf("<div id=\"ctl00_ContentBody_ResultsPanel\"");
+ if (page.indexOf("SearchResultsTable") < 0) {
+ // there are no results. aborting here avoids a wrong error log in the next parsing step
+ return caches;
+ }
+
+ int startPos = page.indexOf("<div id=\"ctl00_ContentBody_ResultsPanel\"");
if (startPos == -1) {
Log.e(cgSettings.tag, "cgeoBase.parseSearch: ID \"ctl00_ContentBody_dlResults\" not found on page");
return null;
@@ -658,7 +660,7 @@ public class cgBase {
page = page.substring(startPos); // cut on <table
startPos = page.indexOf(">");
- endPos = page.indexOf("ctl00_ContentBody_UnitTxt");
+ int endPos = page.indexOf("ctl00_ContentBody_UnitTxt");
if (startPos == -1 || endPos == -1) {
Log.e(cgSettings.tag, "cgeoBase.parseSearch: ID \"ctl00_ContentBody_UnitTxt\" not found on page");
return null;
@@ -3035,7 +3037,7 @@ public class cgBase {
}
final cgCacheWrap caches = parseSearch(thread, url, page, showCaptcha);
- if (caches == null || caches.cacheList == null || caches.cacheList.isEmpty()) {
+ if (caches == null || caches.cacheList == null) {
Log.e(cgSettings.tag, "cgeoBase.searchByOwner: No cache parsed");
}
diff --git a/src/cgeo/geocaching/cgCache.java b/src/cgeo/geocaching/cgCache.java
index b51358b..21d78ce 100644
--- a/src/cgeo/geocaching/cgCache.java
+++ b/src/cgeo/geocaching/cgCache.java
@@ -280,7 +280,7 @@ public class cgCache implements ICache {
String log = "";
if (StringUtils.isNotBlank(settings.getSignature())
&& settings.signatureAutoinsert) {
- log = LogTemplateProvider.applyTemplates(settings.getSignature(), base);
+ log = LogTemplateProvider.applyTemplates(settings.getSignature(), base, true);
}
logOffline(fromActivity, log, Calendar.getInstance(), logType);
return true;
diff --git a/src/cgeo/geocaching/cgData.java b/src/cgeo/geocaching/cgData.java
index 195ce3d..6f16430 100644
--- a/src/cgeo/geocaching/cgData.java
+++ b/src/cgeo/geocaching/cgData.java
@@ -589,8 +589,9 @@ public class cgData {
if (oldVersion < 43) { // upgrade to 43
try {
+ final String dbTableCachesTemp = dbTableCaches + "_temp";
final String dbCreateCachesTemp = ""
- + "create temporary table " + dbTableCaches + "_temp ("
+ + "create temporary table " + dbTableCachesTemp + " ("
+ "_id integer primary key autoincrement, "
+ "updated long not null, "
+ "detailed integer not null default 0, "
@@ -671,11 +672,11 @@ public class cgData {
db.beginTransaction();
db.execSQL(dbCreateCachesTemp);
- db.execSQL("insert into " + dbTableCaches + "_temp select _id, updated, detailed, detailedupdate, geocode, reason, cacheid, guid, type, name, owner, hidden, hint, size, difficulty, terrain, latlon, latitude_string, longitude_string, location, distance, latitude, longitude, shortdesc, description, rating, votes, vote, disabled, archived, members, found, favourite, inventorycoins, inventorytags, inventoryunknown from " + dbTableCaches);
+ db.execSQL("insert into " + dbTableCachesTemp + " select _id, updated, detailed, detailedupdate, geocode, reason, cacheid, guid, type, name, owner, hidden, hint, size, difficulty, terrain, latlon, latitude_string, longitude_string, location, distance, latitude, longitude, shortdesc, description, rating, votes, vote, disabled, archived, members, found, favourite, inventorycoins, inventorytags, inventoryunknown from " + dbTableCaches);
db.execSQL("drop table " + dbTableCaches);
db.execSQL(dbCreateCachesNew);
- db.execSQL("insert into " + dbTableCaches + " select _id, updated, detailed, detailedupdate, geocode, reason, cacheid, guid, type, name, owner, hidden, hint, size, difficulty, terrain, latlon, latitude_string, longitude_string, location, null, distance, latitude, longitude, shortdesc, description, rating, votes, vote, disabled, archived, members, found, favourite, inventorycoins, inventorytags, inventoryunknown from " + dbTableCaches + "_temp");
- db.execSQL("drop table " + dbTableCaches + "_temp");
+ db.execSQL("insert into " + dbTableCaches + " select _id, updated, detailed, detailedupdate, geocode, reason, cacheid, guid, type, name, owner, hidden, hint, size, difficulty, terrain, latlon, latitude_string, longitude_string, location, null, distance, latitude, longitude, shortdesc, description, rating, votes, vote, disabled, archived, members, found, favourite, inventorycoins, inventorytags, inventoryunknown from " + dbTableCachesTemp);
+ db.execSQL("drop table " + dbTableCachesTemp);
db.setTransactionSuccessful();
Log.i(cgSettings.tag, "Changed direction column");
@@ -1023,63 +1024,6 @@ public class cgData {
}
}
-
- @Deprecated
- public boolean isReliableLatLon(String geocode, String guid) {
- init();
-
- Cursor cursor = null;
- int rel = 0;
-
- try {
- if (StringUtils.isNotBlank(geocode)) {
- cursor = databaseRO.query(
- dbTableCaches,
- new String[]{"reliable_latlon"},
- "geocode = \"" + geocode + "\"",
- null,
- null,
- null,
- null,
- "1");
- } else if (StringUtils.isNotBlank(guid)) {
- cursor = databaseRO.query(
- dbTableCaches,
- new String[]{"reliable_latlon"},
- "guid = \"" + guid + "\"",
- null,
- null,
- null,
- null,
- "1");
- } else {
- return false;
- }
-
- if (cursor != null) {
- final int cnt = cursor.getCount();
- int index = 0;
-
- if (cnt > 0) {
- cursor.moveToFirst();
-
- index = cursor.getColumnIndex("reliable_latlon");
- rel = (int) cursor.getInt(index);
- }
-
- cursor.close();
- }
- } catch (Exception e) {
- Log.e(cgSettings.tag, "cgData.isOffline: " + e.toString());
- }
-
- if (rel >= 1) {
- return true;
- } else {
- return false;
- }
- }
-
public String getGeocodeForGuid(String guid) {
if (StringUtils.isBlank(guid)) {
return null;
@@ -1204,18 +1148,10 @@ public class cgData {
values.put("location", cache.location);
values.put("distance", cache.distance);
values.put("direction", cache.direction);
- // save coordinates
- final boolean rel = cache.reliableLatLon;
- if (cache.reliableLatLon) { // new cache has reliable coordinates, store
- values.put("latitude", cache.coords.getLatitude());
- values.put("longitude", cache.coords.getLongitude());
- values.put("reliable_latlon", 1);
- } else if (!rel) { // new cache neither stored cache is not reliable, just update
- // FIXME: if the user is not logged in, coords may be null
- values.put("latitude", cache.coords.getLatitude());
- values.put("longitude", cache.coords.getLongitude());
- values.put("reliable_latlon", 0);
- }
+ // FIXME: if the user is not logged in, coords may be null
+ values.put("latitude", cache.coords.getLatitude());
+ values.put("longitude", cache.coords.getLongitude());
+ values.put("reliable_latlon", cache.reliableLatLon ? 1 : 0);
values.put("elevation", cache.elevation);
values.put("shortdesc", cache.shortdesc);
values.put("personal_note", cache.personalNote);
diff --git a/src/cgeo/geocaching/cgeoadvsearch.java b/src/cgeo/geocaching/cgeoadvsearch.java
index b21db0c..70db229 100644
--- a/src/cgeo/geocaching/cgeoadvsearch.java
+++ b/src/cgeo/geocaching/cgeoadvsearch.java
@@ -12,6 +12,8 @@ import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.EditorInfo;
@@ -25,6 +27,7 @@ import cgeo.geocaching.geopoint.Geopoint;
public class cgeoadvsearch extends AbstractActivity {
+ private static final int MENU_SEARCH_OWN_CACHES = 1;
private cgGeo geo = null;
private cgUpdateLoc geoUpdate = new update();
private EditText latEdit = null;
@@ -188,7 +191,13 @@ public class cgeoadvsearch extends AbstractActivity {
((EditText) findViewById(R.id.owner)).setOnEditorActionListener(new findByOwnerAction());
final Button findByOwner = (Button) findViewById(R.id.search_owner);
- findByOwner.setOnClickListener(new findByOwnerListener());
+ findByOwner.setOnClickListener(new OnClickListener() {
+
+ @Override
+ public void onClick(View arg0) {
+ findByOwnerFn();
+ }
+ });
EditText trackable = (EditText) findViewById(R.id.trackable);
trackable.setOnEditorActionListener(new findTrackableAction());
@@ -395,16 +404,13 @@ public class cgeoadvsearch extends AbstractActivity {
return false;
}
}
-
- private class findByOwnerListener implements View.OnClickListener {
-
- public void onClick(View arg0) {
- findByOwnerFn();
- }
+
+ private void findByOwnerFn() {
+ findByOwnerFn(((EditText) findViewById(R.id.owner)).getText().toString());
}
- private void findByOwnerFn() {
- final String usernameText = ((EditText) findViewById(R.id.owner)).getText().toString();
+ private void findByOwnerFn(String userName) {
+ final String usernameText = StringUtils.trimToEmpty(userName);
if (StringUtils.isBlank(usernameText)) {
helpDialog(res.getString(R.string.warn_search_help_title), res.getString(R.string.warn_search_help_user));
@@ -481,4 +487,19 @@ public class cgeoadvsearch extends AbstractActivity {
trackablesIntent.putExtra("geocode", trackableText.toUpperCase());
startActivity(trackablesIntent);
}
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ menu.add(0, MENU_SEARCH_OWN_CACHES, 0, res.getString(R.string.search_own_caches));
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() == MENU_SEARCH_OWN_CACHES) {
+ findByOwnerFn(settings.getUsername());
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
}
diff --git a/src/cgeo/geocaching/cgeoapplication.java b/src/cgeo/geocaching/cgeoapplication.java
index 68d218a..2f835a8 100644
--- a/src/cgeo/geocaching/cgeoapplication.java
+++ b/src/cgeo/geocaching/cgeoapplication.java
@@ -727,17 +727,13 @@ public class cgeoapplication extends Application {
* @return
*/
- private boolean storeWithMerge(cgCache cache, boolean forceSave) {
- boolean status;
- cgCache oldCache = null;
- if (forceSave || (oldCache = storage.loadCache(cache.geocode, cache.guid, false, true, true, true, true, true)) !=null ) { // if for offline, do not merge
- status = storage.saveCache(cache);
- } else {
- cgCache mergedCache = cache.merge(storage,oldCache);
+ private boolean storeWithMerge(final cgCache cache, final boolean forceSave) {
+ if (forceSave)
+ return storage.saveCache(cache);
- status = storage.saveCache(mergedCache);
- }
- return status;
+ final cgCache oldCache = storage.loadCache(cache.geocode, cache.guid,
+ true, true, true, true, true, true);
+ return storage.saveCache(cache.merge(storage, oldCache));
}
public void dropStored(int listId) {
diff --git a/src/cgeo/geocaching/cgeovisit.java b/src/cgeo/geocaching/cgeovisit.java
index da696ec..d7eba71 100644
--- a/src/cgeo/geocaching/cgeovisit.java
+++ b/src/cgeo/geocaching/cgeovisit.java
@@ -326,7 +326,7 @@ public class cgeovisit extends cgLogForm {
if (StringUtils.isNotBlank(content)) {
insertIntoLog("\n");
}
- insertIntoLog(LogTemplateProvider.applyTemplates(settings.getSignature(), base));
+ insertIntoLog(LogTemplateProvider.applyTemplates(settings.getSignature(), base, false));
return true;
} else if (id >= 10 && id <= 19) {
rating = (id - 9) / 2.0;
@@ -343,7 +343,7 @@ public class cgeovisit extends cgLogForm {
}
LogTemplate template = LogTemplateProvider.getTemplate(id);
if (template != null) {
- String newText = template.getValue(base);
+ String newText = template.getValue(base, false);
insertIntoLog(newText);
return true;
}
@@ -506,7 +506,7 @@ public class cgeovisit extends cgLogForm {
} else if (StringUtils.isNotBlank(settings.getSignature())
&& settings.signatureAutoinsert
&& StringUtils.isBlank(((EditText) findViewById(R.id.log)).getText())) {
- insertIntoLog(LogTemplateProvider.applyTemplates(settings.getSignature(), base));
+ insertIntoLog(LogTemplateProvider.applyTemplates(settings.getSignature(), base, false));
}
if (types.contains(typeSelected) == false) {