1
0
mirror of https://github.com/bspeice/itcs4180 synced 2024-11-16 12:28:15 -05:00

Added ability to check found locations

This commit is contained in:
tokugawa 2014-04-26 02:07:55 -04:00
parent f3582b1815
commit 274048dce3
5 changed files with 41 additions and 13 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

@ -32,7 +32,6 @@ public class MainActivity extends Activity {
ListView locationList; ListView locationList;
List<RestLocation> locations; List<RestLocation> locations;
static String key;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -76,7 +75,7 @@ public class MainActivity extends Activity {
// We don't yet have any locations... // We don't yet have any locations...
((TextView)findViewById(R.id.txtNoLocations)).setVisibility(View.VISIBLE); ((TextView)findViewById(R.id.txtNoLocations)).setVisibility(View.VISIBLE);
((ListView)findViewById(R.id.listLocations)).setVisibility(View.GONE); ((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 // 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<RestLocation> result) { protected void onPostExecute(List<RestLocation> result) {
super.onPostExecute(result); super.onPostExecute(result);
// And update our adapter when done // And update our adapter when done
LocationAdapter mLocationAdapter = new LocationAdapter(result); for(int x=0; x<locations.size(); x++)
{
result.remove(0);
}
locations.addAll(result);
LocationAdapter mLocationAdapter = new LocationAdapter(locations);
locationList.setAdapter(mLocationAdapter); locationList.setAdapter(mLocationAdapter);
locationList.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> 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 // Always show the ListView and hide the TextView
// We're back on the main thread at this point, so it's legal. // 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); ((ListView)findViewById(R.id.listLocations)).setVisibility(View.VISIBLE);
// And we're even kind enough to update the database // And we're even kind enough to update the database
LocationDatabaseHelper.getInstance(MainActivity.this).persistAll(result); LocationDatabaseHelper.getInstance(MainActivity.this).persistAll(locations);
locations = LocationDatabaseHelper.getInstance(getBaseContext()).fetchAll(); locations = LocationDatabaseHelper.getInstance(MainActivity.this).fetchAll();
} }
}.execute(); }.execute();
} }
@Override @Override
@ -143,6 +155,15 @@ public class MainActivity extends Activity {
holder.name = (TextView)v.findViewById(R.id.txtName); holder.name = (TextView)v.findViewById(R.id.txtName);
holder.riddle = (TextView)v.findViewById(R.id.txtRiddle); 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); v.setTag(holder);
} else { } else {
holder = (Holder)v.getTag(); holder = (Holder)v.getTag();

View File

@ -181,13 +181,8 @@ public class SearchActivity extends Activity {
Toast.makeText(getApplicationContext(), key, Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), key, Toast.LENGTH_SHORT).show();
if(key!= null) 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); restLocation.setKey(key);
LocationDatabaseHelper.getInstance(SearchActivity.this).updateRecord(restLocation);
intent = new Intent(SearchActivity.this, FoundActivity.class); intent = new Intent(SearchActivity.this, FoundActivity.class);
intent.putExtra("restLocation", restLocation); intent.putExtra("restLocation", restLocation);
startActivity(intent); startActivity(intent);

View File

@ -113,7 +113,7 @@ public class LocationDatabaseHelper extends SQLiteOpenHelper {
values.put(KEY_LOCATION_LAT, loc.getLocationLat()); values.put(KEY_LOCATION_LAT, loc.getLocationLat());
values.put(KEY_VALIDATION_KEY, loc.getKey()); values.put(KEY_VALIDATION_KEY, loc.getKey());
values.put(KEY_RIDDLE_IMAGE_URL, loc.getRiddleImageUrl()); 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<RestLocation> locs) { public void persistAll(List<RestLocation> locs) {
@ -121,4 +121,16 @@ public class LocationDatabaseHelper extends SQLiteOpenHelper {
persist(l); 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);
}
} }