diff --git a/UNCCScavenger/res/drawable-mdpi/checkbox_checked.png b/UNCCScavenger/res/drawable-mdpi/checkbox_checked.png new file mode 100644 index 0000000..ef60283 Binary files /dev/null and b/UNCCScavenger/res/drawable-mdpi/checkbox_checked.png differ diff --git a/UNCCScavenger/res/drawable-mdpi/checkbox_unchecked.png b/UNCCScavenger/res/drawable-mdpi/checkbox_unchecked.png new file mode 100644 index 0000000..7c68419 Binary files /dev/null and b/UNCCScavenger/res/drawable-mdpi/checkbox_unchecked.png differ diff --git a/UNCCScavenger/src/edu/uncc/scavenger/MainActivity.java b/UNCCScavenger/src/edu/uncc/scavenger/MainActivity.java index 240b50b..3245c29 100644 --- a/UNCCScavenger/src/edu/uncc/scavenger/MainActivity.java +++ b/UNCCScavenger/src/edu/uncc/scavenger/MainActivity.java @@ -32,7 +32,6 @@ public class MainActivity extends Activity { ListView locationList; List locations; - static String key; @Override protected void onCreate(Bundle savedInstanceState) { @@ -76,7 +75,7 @@ public class MainActivity extends Activity { // We don't yet have any locations... ((TextView)findViewById(R.id.txtNoLocations)).setVisibility(View.VISIBLE); ((ListView)findViewById(R.id.listLocations)).setVisibility(View.GONE); - Log.d("NoLocation", "NoLocations"); + //Log.d("NoLocation", "NoLocations"); } // And kick off contacting to server to see if there are any new ones @@ -86,8 +85,22 @@ public class MainActivity extends Activity { protected void onPostExecute(List result) { super.onPostExecute(result); // And update our adapter when done - LocationAdapter mLocationAdapter = new LocationAdapter(result); + for(int x=0; x parent, View view,int position, long id) { + Intent intent = new Intent(MainActivity.this, SearchActivity.class); + intent.putExtra("restLocation", locations.get(position)); + startActivity(intent); + } + }); // Always show the ListView and hide the TextView // We're back on the main thread at this point, so it's legal. @@ -95,11 +108,10 @@ public class MainActivity extends Activity { ((ListView)findViewById(R.id.listLocations)).setVisibility(View.VISIBLE); // And we're even kind enough to update the database - LocationDatabaseHelper.getInstance(MainActivity.this).persistAll(result); - locations = LocationDatabaseHelper.getInstance(getBaseContext()).fetchAll(); + LocationDatabaseHelper.getInstance(MainActivity.this).persistAll(locations); + locations = LocationDatabaseHelper.getInstance(MainActivity.this).fetchAll(); } }.execute(); - } @Override @@ -143,6 +155,15 @@ public class MainActivity extends Activity { holder.name = (TextView)v.findViewById(R.id.txtName); holder.riddle = (TextView)v.findViewById(R.id.txtRiddle); + if(locations.get(position).getKey()!=null) + { + holder.imgFound.setImageResource(R.drawable.checkbox_checked); + } + else + { + holder.imgFound.setImageResource(R.drawable.checkbox_unchecked); + } + v.setTag(holder); } else { holder = (Holder)v.getTag(); diff --git a/UNCCScavenger/src/edu/uncc/scavenger/SearchActivity.java b/UNCCScavenger/src/edu/uncc/scavenger/SearchActivity.java index 7a3c946..3f1056f 100644 --- a/UNCCScavenger/src/edu/uncc/scavenger/SearchActivity.java +++ b/UNCCScavenger/src/edu/uncc/scavenger/SearchActivity.java @@ -181,13 +181,8 @@ public class SearchActivity extends Activity { Toast.makeText(getApplicationContext(), key, Toast.LENGTH_SHORT).show(); if(key!= null) { - //Add found to the database - /*List locations = LocationDatabaseHelper.getInstance(this).fetchAll(); - if (locations != null && locations.size() > 0) - { - locations.get(restLocation.getId()-1); - }*/ restLocation.setKey(key); + LocationDatabaseHelper.getInstance(SearchActivity.this).updateRecord(restLocation); intent = new Intent(SearchActivity.this, FoundActivity.class); intent.putExtra("restLocation", restLocation); startActivity(intent); diff --git a/UNCCScavenger/src/edu/uncc/scavenger/database/LocationDatabaseHelper.java b/UNCCScavenger/src/edu/uncc/scavenger/database/LocationDatabaseHelper.java index 2a24073..6c2f75b 100644 --- a/UNCCScavenger/src/edu/uncc/scavenger/database/LocationDatabaseHelper.java +++ b/UNCCScavenger/src/edu/uncc/scavenger/database/LocationDatabaseHelper.java @@ -113,7 +113,7 @@ public class LocationDatabaseHelper extends SQLiteOpenHelper { values.put(KEY_LOCATION_LAT, loc.getLocationLat()); 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); + helper.getWritableDatabase().insertWithOnConflict(TABLE_NAME, null, values, SQLiteDatabase.CONFLICT_IGNORE); } public void persistAll(List locs) { @@ -121,4 +121,16 @@ public class LocationDatabaseHelper extends SQLiteOpenHelper { persist(l); } } + + public void updateRecord(RestLocation loc){ + ContentValues values = new ContentValues(); + values.put(KEY_ID, loc.getId()); + values.put(KEY_NAME, loc.getName()); + values.put(KEY_RIDDLE, loc.getRiddle()); + values.put(KEY_LOCATION_LONG, loc.getLocationLong()); + values.put(KEY_LOCATION_LAT, loc.getLocationLat()); + 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); + } }