Added Update functionality to toggle availability

This commit is contained in:
Alexander Doerflinger
2017-08-17 13:03:44 +02:00
parent 2b4515c284
commit 7f161a7442
13 changed files with 273 additions and 111 deletions

View File

@@ -7,8 +7,8 @@ android {
applicationId "com.de.aldo_apps.aldo.mariokartcircuitselector"
minSdkVersion 16
targetSdkVersion 25
versionCode 9
versionName "0.1.9"
versionCode 10
versionName "0.1.10"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {

View File

@@ -116,7 +116,27 @@ public class AccessoryContentProvider extends ContentProvider {
@Override
public int update(@NonNull final Uri uri, final ContentValues values, final String selection,
final String[] selectionArgs) {
// TODO Add update method here?
final int resId = uriMatcher.match(uri);
switch (resId) {
case Constants.CHARACTER_LOADER_ID:
Log.d(TAG, "query: Toggling Characters availability.");
return mHandler.changeCharacterAvailability(values, selection, selectionArgs);
case Constants.KART_LOADER_ID:
Log.d(TAG, "query: Toggling Karts availability.");
return mHandler.changeKartAvailability(values, selection, selectionArgs);
case Constants.ACCESSORY_LOADER_ID:
Log.d(TAG, "query: Toggling Accessories availability.");
return mHandler.changeAccessoryAvailability(values, selection, selectionArgs);
case Constants.TRACK_LOADER_ID:
Log.d(TAG, "query: Toggling Tracks availability.");
return mHandler.changeTrackAvailability(values, selection, selectionArgs);
case Constants.WHEELS_LOADER_ID:
Log.d(TAG, "query: Toggling Wheels availability.");
return mHandler.changeWheelsAvailability(values, selection, selectionArgs);
default:
Log.d(TAG, "query: UriMatcher returned: " + uriMatcher.match(uri));
return 0;
}
}
}

View File

@@ -115,7 +115,27 @@ public class CharacterContentProvider extends ContentProvider {
@Override
public int update(@NonNull final Uri uri, final ContentValues values, final String selection,
final String[] selectionArgs) {
// TODO Add update method here?
final int resId = uriMatcher.match(uri);
switch (resId) {
case Constants.CHARACTER_LOADER_ID:
Log.d(TAG, "query: Toggling Characters availability.");
return mHandler.changeCharacterAvailability(values, selection, selectionArgs);
case Constants.KART_LOADER_ID:
Log.d(TAG, "query: Toggling Karts availability.");
return mHandler.changeKartAvailability(values, selection, selectionArgs);
case Constants.ACCESSORY_LOADER_ID:
Log.d(TAG, "query: Toggling Accessories availability.");
return mHandler.changeAccessoryAvailability(values, selection, selectionArgs);
case Constants.TRACK_LOADER_ID:
Log.d(TAG, "query: Toggling Tracks availability.");
return mHandler.changeTrackAvailability(values, selection, selectionArgs);
case Constants.WHEELS_LOADER_ID:
Log.d(TAG, "query: Toggling Wheels availability.");
return mHandler.changeWheelsAvailability(values, selection, selectionArgs);
default:
Log.d(TAG, "query: UriMatcher returned: " + uriMatcher.match(uri));
return 0;
}
}
}

View File

@@ -25,7 +25,7 @@ public final class Constants {
* As SQLite does not have a native boolean value, we use integers to represent true and false.
* This is the value for a false statement.
*/
final static Integer FALSE = 0;
public final static Integer FALSE = 0;
/**
* The Base LoaderID.

View File

@@ -54,129 +54,76 @@ public class DatabaseHandler extends SQLiteAssetHelper {
/**
* Helper method to update the availability status of a single track.
*
* @param track The track which should be marked as available/unavailable.
* @param isAvailable The status of availability to be set.
* @param values The values to be put into the database.
* @param selection The selection clause
* @param selectionArgs The Arguments for the selection clause.
* @return The result code of the update function.
*/
public int changeTrackAvailability(final Track track,
final boolean isAvailable) {
public int changeTrackAvailability(final ContentValues values,
final String selection,
final String[] selectionArgs) {
final SQLiteDatabase db = this.getWritableDatabase();
final ContentValues values = new ContentValues();
values.put(Constants.KEY_GAME, track.getGame());
values.put(Constants.KEY_NAME, track.getName());
values.put(Constants.KEY_PACKAGE, track.getPackage());
values.put(Constants.KEY_NUMBER, track.getNumber());
if (isAvailable) {
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.TRUE));
} else {
values.put(Constants.KEY_AVAILABLE, Constants.FALSE);
}
return db.update(Constants.TABLE_TRACK, values, Constants.KEY_ID + " = ?",
new String[]{String.valueOf(track.getId())});
return db.update(Constants.TABLE_TRACK, values, selection, selectionArgs);
}
/**
* Helper method to update the availability status of a single character.
*
* @param character The character which should be marked as available/unavailable.
* @param isAvailable The status of availability to be set.
* @param values The values to be put into the database.
* @param selection The selection clause
* @param selectionArgs The Arguments for the selection clause.
* @return The result code of the update function.
*/
public int changeCharacterAvailability(final Character character,
final boolean isAvailable) {
public int changeCharacterAvailability(final ContentValues values,
final String selection,
final String[] selectionArgs) {
final SQLiteDatabase db = this.getWritableDatabase();
final ContentValues values = new ContentValues();
values.put(Constants.KEY_GAME, character.getGame());
values.put(Constants.KEY_NAME, character.getName());
values.put(Constants.KEY_WEIGHT, character.getWeight());
if (isAvailable) {
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.TRUE));
} else {
values.put(Constants.KEY_AVAILABLE, Constants.FALSE);
}
return db.update(Constants.TABLE_CHARACTER, values, Constants.KEY_ID + " = ?",
new String[]{String.valueOf(character.getId())});
return db.update(Constants.TABLE_CHARACTER, values, selection, selectionArgs);
}
/**
* Helper method to update the availability status of a single kart.
*
* @param kart The kart which should be marked as available/unavailable.
* @param isAvailable The status of availability to be set.
* @param values The values to be put into the database.
* @param selection The selection clause
* @param selectionArgs The Arguments for the selection clause.
* @return The result code of the update function.
*/
public int changeKartAvailability(final Kart kart,
final boolean isAvailable) {
public int changeKartAvailability(final ContentValues values,
final String selection,
final String[] selectionArgs) {
final SQLiteDatabase db = this.getWritableDatabase();
final ContentValues values = new ContentValues();
values.put(Constants.KEY_GAME, kart.getGame());
values.put(Constants.KEY_NAME, kart.getName());
values.put(Constants.KEY_WEIGHT, kart.getWeight());
values.put(Constants.KEY_WHEELS, kart.getWheels());
values.put(Constants.KEY_ACCESSORY, kart.getAccessory());
values.put(Constants.KEY_DEDICATED_DRIVER, kart.getDedicatedDriver());
values.put(Constants.KEY_FREE_FOR_ALL, kart.getFreeForAll());
if (isAvailable) {
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.TRUE));
} else {
values.put(Constants.KEY_AVAILABLE, Constants.FALSE);
}
return db.update(Constants.TABLE_KART, values, Constants.KEY_ID + " = ?",
new String[]{String.valueOf(kart.getId())});
return db.update(Constants.TABLE_KART, values, selection, selectionArgs);
}
/**
* Helper method to update the availability status of a single accessory.
*
* @param accessory The accessory which should be marked as available/unavailable.
* @param isAvailable The status of availability to be set.
* @param values The values to be put into the database.
* @param selection The selection clause
* @param selectionArgs The Arguments for the selection clause.
* @return The result code of the update function.
*/
public int changeAccessoryAvailability(final Accessory accessory,
final boolean isAvailable) {
public int changeAccessoryAvailability(final ContentValues values,
final String selection,
final String[] selectionArgs) {
final SQLiteDatabase db = this.getWritableDatabase();
final ContentValues values = new ContentValues();
values.put(Constants.KEY_GAME, accessory.getGame());
values.put(Constants.KEY_NAME, accessory.getName());
if (isAvailable) {
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.TRUE));
} else {
values.put(Constants.KEY_AVAILABLE, Constants.FALSE);
}
return db.update(Constants.TABLE_ACCESSORY, values, Constants.KEY_ID + " = ?",
new String[]{String.valueOf(accessory.getId())});
return db.update(Constants.TABLE_ACCESSORY, values, selection, selectionArgs);
}
/**
* Helper method to update the availability status of a single wheels.
*
* @param wheels The wheels which should be marked as available/unavailable.
* @param isAvailable The status of availability to be set.
* @param values The values to be put into the database.
* @param selection The selection clause
* @param selectionArgs The Arguments for the selection clause.
* @return The result code of the update function.
*/
public int changeWheelsAvailability(final Wheels wheels,
final boolean isAvailable) {
public int changeWheelsAvailability(final ContentValues values,
final String selection,
final String[] selectionArgs) {
final SQLiteDatabase db = this.getWritableDatabase();
final ContentValues values = new ContentValues();
values.put(Constants.KEY_GAME, wheels.getGame());
values.put(Constants.KEY_NAME, wheels.getGame());
if (isAvailable) {
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.TRUE));
} else {
values.put(Constants.KEY_AVAILABLE, Constants.FALSE);
}
return db.update(Constants.TABLE_WHEELS, values, Constants.KEY_ID + " = ?",
new String[]{String.valueOf(wheels.getId())});
return db.update(Constants.TABLE_WHEELS, values, selection, selectionArgs);
}
// -------------------------------------------------------------------------------------------

View File

@@ -115,7 +115,27 @@ public class KartContentProvider extends ContentProvider {
@Override
public int update(@NonNull final Uri uri, final ContentValues values, final String selection,
final String[] selectionArgs) {
// TODO Add update method here?
final int resId = uriMatcher.match(uri);
switch (resId) {
case Constants.CHARACTER_LOADER_ID:
Log.d(TAG, "query: Toggling Characters availability.");
return mHandler.changeCharacterAvailability(values, selection, selectionArgs);
case Constants.KART_LOADER_ID:
Log.d(TAG, "query: Toggling Karts availability.");
return mHandler.changeKartAvailability(values, selection, selectionArgs);
case Constants.ACCESSORY_LOADER_ID:
Log.d(TAG, "query: Toggling Accessories availability.");
return mHandler.changeAccessoryAvailability(values, selection, selectionArgs);
case Constants.TRACK_LOADER_ID:
Log.d(TAG, "query: Toggling Tracks availability.");
return mHandler.changeTrackAvailability(values, selection, selectionArgs);
case Constants.WHEELS_LOADER_ID:
Log.d(TAG, "query: Toggling Wheels availability.");
return mHandler.changeWheelsAvailability(values, selection, selectionArgs);
default:
Log.d(TAG, "query: UriMatcher returned: " + uriMatcher.match(uri));
return 0;
}
}
}

View File

@@ -115,7 +115,27 @@ public class TrackContentProvider extends ContentProvider {
@Override
public int update(@NonNull final Uri uri, final ContentValues values, final String selection,
final String[] selectionArgs) {
// TODO Add update method here?
final int resId = uriMatcher.match(uri);
switch (resId) {
case Constants.CHARACTER_LOADER_ID:
Log.d(TAG, "query: Toggling Characters availability.");
return mHandler.changeCharacterAvailability(values, selection, selectionArgs);
case Constants.KART_LOADER_ID:
Log.d(TAG, "query: Toggling Karts availability.");
return mHandler.changeKartAvailability(values, selection, selectionArgs);
case Constants.ACCESSORY_LOADER_ID:
Log.d(TAG, "query: Toggling Accessories availability.");
return mHandler.changeAccessoryAvailability(values, selection, selectionArgs);
case Constants.TRACK_LOADER_ID:
Log.d(TAG, "query: Toggling Tracks availability.");
return mHandler.changeTrackAvailability(values, selection, selectionArgs);
case Constants.WHEELS_LOADER_ID:
Log.d(TAG, "query: Toggling Wheels availability.");
return mHandler.changeWheelsAvailability(values, selection, selectionArgs);
default:
Log.d(TAG, "query: UriMatcher returned: " + uriMatcher.match(uri));
return 0;
}
}
}

View File

@@ -115,7 +115,27 @@ public class WheelsContentProvider extends ContentProvider {
@Override
public int update(@NonNull final Uri uri, final ContentValues values, final String selection,
final String[] selectionArgs) {
// TODO Add update method here?
final int resId = uriMatcher.match(uri);
switch (resId) {
case Constants.CHARACTER_LOADER_ID:
Log.d(TAG, "query: Toggling Characters availability.");
return mHandler.changeCharacterAvailability(values, selection, selectionArgs);
case Constants.KART_LOADER_ID:
Log.d(TAG, "query: Toggling Karts availability.");
return mHandler.changeKartAvailability(values, selection, selectionArgs);
case Constants.ACCESSORY_LOADER_ID:
Log.d(TAG, "query: Toggling Accessories availability.");
return mHandler.changeAccessoryAvailability(values, selection, selectionArgs);
case Constants.TRACK_LOADER_ID:
Log.d(TAG, "query: Toggling Tracks availability.");
return mHandler.changeTrackAvailability(values, selection, selectionArgs);
case Constants.WHEELS_LOADER_ID:
Log.d(TAG, "query: Toggling Wheels availability.");
return mHandler.changeWheelsAvailability(values, selection, selectionArgs);
default:
Log.d(TAG, "query: UriMatcher returned: " + uriMatcher.match(uri));
return 0;
}
}
}

View File

@@ -1,8 +1,10 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector.adapters;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.support.v4.widget.SimpleCursorAdapter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -11,6 +13,7 @@ import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
import com.de.aldo_apps.aldo.mariokartcircuitselector.AccessoryContentProvider;
import com.de.aldo_apps.aldo.mariokartcircuitselector.Constants;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
@@ -23,6 +26,16 @@ import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
*/
public class AccessoryCursorAdapter extends SimpleCursorAdapter {
/**
* Tag for debugging purpose.
*/
private static final String TAG = "AccessoryAdapter";
/**
* The Context where this adapter was assigned.
*/
private Context mContext;
/**
* The LayoutInflater used to inflate a new ListItem.
*/
@@ -52,6 +65,7 @@ public class AccessoryCursorAdapter extends SimpleCursorAdapter {
final int[] to,
final int flags) {
super(context, layout, cursor, from, to, flags);
mContext = context;
mLayout = layout;
mInflater = LayoutInflater.from(context);
}
@@ -113,8 +127,17 @@ public class AccessoryCursorAdapter extends SimpleCursorAdapter {
availabilityCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton compoundButton, final boolean b) {
// TODO: Handle update method here.
public void onCheckedChanged(CompoundButton compoundButton, boolean isAvailable) {
final ContentValues values = new ContentValues();
Log.d(TAG, "onCheckedChanged: Toggling Availability of [" + name
+ "] to available = [" + isAvailable + "]");
if (isAvailable) {
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.TRUE));
} else {
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.FALSE));
}
mContext.getContentResolver().update(AccessoryContentProvider.CONTENT_URI, values,
Constants.KEY_ID + " = ?", new String[]{String.valueOf(id)});
}
});

View File

@@ -1,8 +1,10 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector.adapters;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.support.v4.widget.SimpleCursorAdapter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -11,6 +13,7 @@ import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
import com.de.aldo_apps.aldo.mariokartcircuitselector.CharacterContentProvider;
import com.de.aldo_apps.aldo.mariokartcircuitselector.Constants;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
@@ -23,6 +26,16 @@ import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
*/
public class CharacterCursorAdapter extends SimpleCursorAdapter {
/**
* Tag for debugging purpose.
*/
private static final String TAG = "CharacterAdapter";
/**
* The Context where this adapter was assigned.
*/
private Context mContext;
/**
* The LayoutInflater used to inflate a new ListItem.
*/
@@ -52,6 +65,7 @@ public class CharacterCursorAdapter extends SimpleCursorAdapter {
final int[] to,
final int flags) {
super(context, layout, cursor, from, to, flags);
mContext = context;
mLayout = layout;
mInflater = LayoutInflater.from(context);
}
@@ -121,8 +135,17 @@ public class CharacterCursorAdapter extends SimpleCursorAdapter {
availabilityCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
// TODO: Handle update method here.
public void onCheckedChanged(CompoundButton compoundButton, boolean isAvailable) {
final ContentValues values = new ContentValues();
Log.d(TAG, "onCheckedChanged: Toggling Availability of [" + name
+ "] to available = [" + isAvailable + "]");
if (isAvailable) {
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.TRUE));
} else {
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.FALSE));
}
mContext.getContentResolver().update(CharacterContentProvider.CONTENT_URI, values,
Constants.KEY_ID + " = ?", new String[]{String.valueOf(id)});
}
});

View File

@@ -1,8 +1,10 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector.adapters;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.support.v4.widget.SimpleCursorAdapter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -12,6 +14,7 @@ import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
import com.de.aldo_apps.aldo.mariokartcircuitselector.Constants;
import com.de.aldo_apps.aldo.mariokartcircuitselector.KartContentProvider;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
/**
@@ -23,6 +26,16 @@ import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
*/
public class KartCursorAdapter extends SimpleCursorAdapter {
/**
* Tag for debugging purpose.
*/
private static final String TAG = "KartAdapter";
/**
* The Context where this adapter was assigned.
*/
private Context mContext;
/**
* The LayoutInflater used to inflate a new ListItem.
*/
@@ -52,6 +65,7 @@ public class KartCursorAdapter extends SimpleCursorAdapter {
final int[] to,
final int flags) {
super(context, layout, cursor, from, to, flags);
mContext = context;
mLayout = layout;
mInflater = LayoutInflater.from(context);
}
@@ -125,8 +139,17 @@ public class KartCursorAdapter extends SimpleCursorAdapter {
availabilityCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton compoundButton, final boolean b) {
// TODO: Handle update method here.
public void onCheckedChanged(CompoundButton compoundButton, boolean isAvailable) {
final ContentValues values = new ContentValues();
Log.d(TAG, "onCheckedChanged: Toggling Availability of [" + name
+ "] to available = [" + isAvailable + "]");
if (isAvailable) {
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.TRUE));
} else {
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.FALSE));
}
mContext.getContentResolver().update(KartContentProvider.CONTENT_URI, values,
Constants.KEY_ID + " = ?", new String[]{String.valueOf(id)});
}
});

View File

@@ -1,8 +1,10 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector.adapters;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.support.v4.widget.SimpleCursorAdapter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -13,6 +15,7 @@ import android.widget.TextView;
import com.de.aldo_apps.aldo.mariokartcircuitselector.Constants;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
import com.de.aldo_apps.aldo.mariokartcircuitselector.TrackContentProvider;
/**
* Custom CursorAdapter which populates the ListView with track data from cursor.
@@ -23,6 +26,16 @@ import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
*/
public class TrackCursorAdapter extends SimpleCursorAdapter {
/**
* Tag for debugging purpose.
*/
private static final String TAG = "TrackAdapter";
/**
* The Context where this adapter was assigned.
*/
private Context mContext;
/**
* The LayoutInflater used to inflate a new ListItem.
*/
@@ -52,6 +65,7 @@ public class TrackCursorAdapter extends SimpleCursorAdapter {
final int[] to,
final int flags) {
super(context, layout, cursor, from, to, flags);
mContext = context;
mLayout = layout;
mInflater = LayoutInflater.from(context);
}
@@ -123,8 +137,17 @@ public class TrackCursorAdapter extends SimpleCursorAdapter {
availabilityCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton compoundButton, final boolean b) {
// TODO: Handle update method here.
public void onCheckedChanged(CompoundButton compoundButton, boolean isAvailable) {
final ContentValues values = new ContentValues();
Log.d(TAG, "onCheckedChanged: Toggling Availability of [" + name
+ "] to available = [" + isAvailable + "]");
if (isAvailable) {
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.TRUE));
} else {
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.FALSE));
}
mContext.getContentResolver().update(TrackContentProvider.CONTENT_URI, values,
Constants.KEY_ID + " = ?", new String[]{String.valueOf(id)});
}
});

View File

@@ -1,8 +1,10 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector.adapters;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.support.v4.widget.SimpleCursorAdapter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -13,6 +15,7 @@ import android.widget.TextView;
import com.de.aldo_apps.aldo.mariokartcircuitselector.Constants;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
import com.de.aldo_apps.aldo.mariokartcircuitselector.WheelsContentProvider;
/**
* Custom CursorAdapter which populates the ListView with wheels data from cursor.
@@ -23,6 +26,16 @@ import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
*/
public class WheelsCursorAdapter extends SimpleCursorAdapter {
/**
* Tag for debugging purpose.
*/
private static final String TAG = "WheelsAdapter";
/**
* The Context where this adapter was assigned.
*/
private Context mContext;
/**
* The LayoutInflater used to inflate a new ListItem.
*/
@@ -52,6 +65,7 @@ public class WheelsCursorAdapter extends SimpleCursorAdapter {
final int[] to,
final int flags) {
super(context, layout, cursor, from, to, flags);
mContext = context;
mLayout = layout;
mInflater = LayoutInflater.from(context);
}
@@ -113,8 +127,17 @@ public class WheelsCursorAdapter extends SimpleCursorAdapter {
availabilityCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton compoundButton, final boolean b) {
// TODO: Handle update method here.
public void onCheckedChanged(CompoundButton compoundButton, boolean isAvailable) {
final ContentValues values = new ContentValues();
Log.d(TAG, "onCheckedChanged: Toggling Availability of [" + name
+ "] to available = [" + isAvailable + "]");
if (isAvailable) {
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.TRUE));
} else {
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.FALSE));
}
mContext.getContentResolver().update(WheelsContentProvider.CONTENT_URI, values,
Constants.KEY_ID + " = ?", new String[]{String.valueOf(id)});
}
});