mirror of
https://github.com/bspeice/itcs4180
synced 2024-11-08 16:38:14 -05:00
Added ability to check found locations
This commit is contained in:
parent
f3582b1815
commit
274048dce3
BIN
UNCCScavenger/res/drawable-mdpi/checkbox_checked.png
Normal file
BIN
UNCCScavenger/res/drawable-mdpi/checkbox_checked.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.3 KiB |
BIN
UNCCScavenger/res/drawable-mdpi/checkbox_unchecked.png
Normal file
BIN
UNCCScavenger/res/drawable-mdpi/checkbox_unchecked.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.7 KiB |
@ -32,7 +32,6 @@ public class MainActivity extends Activity {
|
||||
|
||||
ListView locationList;
|
||||
List<RestLocation> 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<RestLocation> result) {
|
||||
super.onPostExecute(result);
|
||||
// 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.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
|
||||
// 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();
|
||||
|
@ -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);
|
||||
|
@ -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<RestLocation> 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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user