From 60062298bc2f419b17085cac695d6ebd8db7747b Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Mon, 21 Apr 2014 09:40:24 -0400 Subject: [PATCH 1/2] RestLocations created correctly from the server. --- UNCCScavenger/src/edu/uncc/scavenger/MainActivity.java | 1 + .../src/edu/uncc/scavenger/SearchActivity.java | 2 +- .../src/edu/uncc/scavenger/rest/LocationClient.java | 8 ++++++++ .../src/edu/uncc/scavenger/rest/RestLocation.java | 10 +++++----- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/UNCCScavenger/src/edu/uncc/scavenger/MainActivity.java b/UNCCScavenger/src/edu/uncc/scavenger/MainActivity.java index 71527f4..d30a8d1 100644 --- a/UNCCScavenger/src/edu/uncc/scavenger/MainActivity.java +++ b/UNCCScavenger/src/edu/uncc/scavenger/MainActivity.java @@ -53,6 +53,7 @@ public class MainActivity extends Activity { /*End Test Code*/ // And kick off contacting to server to see if there are any new ones + locationList = (ListView)findViewById(R.id.listLocations); new LocationClient.LocationsDownloader(this) { @Override protected void onPostExecute(List result) { diff --git a/UNCCScavenger/src/edu/uncc/scavenger/SearchActivity.java b/UNCCScavenger/src/edu/uncc/scavenger/SearchActivity.java index 7796e99..c154019 100644 --- a/UNCCScavenger/src/edu/uncc/scavenger/SearchActivity.java +++ b/UNCCScavenger/src/edu/uncc/scavenger/SearchActivity.java @@ -138,7 +138,7 @@ public class SearchActivity extends Activity { } else { - new ImageDownloader().execute(restLocation.getRiddleImageURL()); + new ImageDownloader().execute(restLocation.getRiddleImageUrl()); } } diff --git a/UNCCScavenger/src/edu/uncc/scavenger/rest/LocationClient.java b/UNCCScavenger/src/edu/uncc/scavenger/rest/LocationClient.java index 30823bf..39e85e4 100644 --- a/UNCCScavenger/src/edu/uncc/scavenger/rest/LocationClient.java +++ b/UNCCScavenger/src/edu/uncc/scavenger/rest/LocationClient.java @@ -11,7 +11,12 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import com.google.gson.FieldNamingPolicy; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; + import retrofit.RestAdapter; +import retrofit.converter.GsonConverter; import android.content.Context; import android.os.AsyncTask; import edu.uncc.scavenger.R; @@ -20,7 +25,10 @@ public class LocationClient { private static LocationService getAdapter(Context ctx) { String endpoint = ctx.getString(R.string.endpoint); + Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES) + .create(); RestAdapter ra = new RestAdapter.Builder().setEndpoint(endpoint) + .setConverter(new GsonConverter(gson)) .build(); return ra.create(LocationService.class); } diff --git a/UNCCScavenger/src/edu/uncc/scavenger/rest/RestLocation.java b/UNCCScavenger/src/edu/uncc/scavenger/rest/RestLocation.java index cea4050..86c60f5 100644 --- a/UNCCScavenger/src/edu/uncc/scavenger/rest/RestLocation.java +++ b/UNCCScavenger/src/edu/uncc/scavenger/rest/RestLocation.java @@ -18,7 +18,7 @@ public class RestLocation implements Serializable{ private String riddle; private double locationLong; private double locationLat; - private String riddleImageURL; + private String riddleImageUrl; private String key; public int getId() { @@ -57,11 +57,11 @@ public class RestLocation implements Serializable{ public void setKey(String key) { this.key = key; } - public String getRiddleImageURL() { - return riddleImageURL; + public String getRiddleImageUrl() { + return riddleImageUrl; } - public void setRiddleImageURL(String riddleImageURL) { - this.riddleImageURL = riddleImageURL; + public void setRiddleImageUrl(String riddleImageUrl) { + this.riddleImageUrl = riddleImageUrl; } public Location getLocation() { From 02c9482d555cd9d6dffae3231ff2607e10d78cab Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Mon, 21 Apr 2014 09:40:37 -0400 Subject: [PATCH 2/2] On insert conflict, update the row. --- .../scavenger/database/LocationDatabaseHelper.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/UNCCScavenger/src/edu/uncc/scavenger/database/LocationDatabaseHelper.java b/UNCCScavenger/src/edu/uncc/scavenger/database/LocationDatabaseHelper.java index 82d028f..3ea11f2 100644 --- a/UNCCScavenger/src/edu/uncc/scavenger/database/LocationDatabaseHelper.java +++ b/UNCCScavenger/src/edu/uncc/scavenger/database/LocationDatabaseHelper.java @@ -34,7 +34,8 @@ public class LocationDatabaseHelper extends SQLiteOpenHelper { private static final String KEY_RIDDLE = "RIDDLE"; private static final String KEY_LOCATION_LONG = "LOCATION_LONG"; private static final String KEY_LOCATION_LAT = "LOCATION_LAT"; - private static final String KEY_KEY = "KEYs"; + private static final String KEY_VALIDATION_KEY = "VALIDATION_KEY"; + private static final String KEY_RIDDLE_IMAGE_URL = "RIDDLE_IMAGE_URL"; private LocationDatabaseHelper(Context ctx) { super(ctx, DATABASE_NAME, null, DATABASE_VERSION); @@ -54,7 +55,8 @@ public class LocationDatabaseHelper extends SQLiteOpenHelper { KEY_RIDDLE + " VARCHAR(1024)," + KEY_LOCATION_LONG + " REAL," + KEY_LOCATION_LAT + " REAL," + - KEY_KEY + " VARCHAR(255)" + + KEY_VALIDATION_KEY + " VARCHAR(255)," + + KEY_RIDDLE_IMAGE_URL + " VARCHAR(255)" + ");"; @Override public void onCreate(SQLiteDatabase db) { @@ -85,7 +87,7 @@ public class LocationDatabaseHelper extends SQLiteOpenHelper { ArrayList results = new ArrayList(); SQLiteDatabase db = helper.getReadableDatabase(); Cursor c = db.query(TABLE_NAME, new String[]{KEY_ID, KEY_NAME, KEY_RIDDLE, KEY_LOCATION_LONG, - KEY_LOCATION_LAT, KEY_KEY}, + KEY_LOCATION_LAT, KEY_VALIDATION_KEY, KEY_RIDDLE_IMAGE_URL}, null, null, null, null, null); if (c != null && c.getCount() > 0) { @@ -108,8 +110,9 @@ public class LocationDatabaseHelper extends SQLiteOpenHelper { values.put(KEY_RIDDLE, loc.getRiddle()); values.put(KEY_LOCATION_LONG, loc.getLocationLong()); values.put(KEY_LOCATION_LAT, loc.getLocationLat()); - values.put(KEY_KEY, loc.getKey()); - helper.getWritableDatabase().insert(TABLE_NAME, null, values); + values.put(KEY_VALIDATION_KEY, loc.getKey()); + values.put(KEY_RIDDLE_IMAGE_URL, loc.getRiddleImageUrl()); + helper.getWritableDatabase().insertWithOnConflict(TABLE_NAME, null, values, SQLiteDatabase.CONFLICT_REPLACE); } public void persistAll(List locs) {