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" applicationId "com.de.aldo_apps.aldo.mariokartcircuitselector"
minSdkVersion 16 minSdkVersion 16
targetSdkVersion 25 targetSdkVersion 25
versionCode 9 versionCode 10
versionName "0.1.9" versionName "0.1.10"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
} }
buildTypes { buildTypes {

View File

@@ -116,7 +116,27 @@ public class AccessoryContentProvider extends ContentProvider {
@Override @Override
public int update(@NonNull final Uri uri, final ContentValues values, final String selection, public int update(@NonNull final Uri uri, final ContentValues values, final String selection,
final String[] selectionArgs) { 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; return 0;
} }
} }
}

View File

@@ -115,7 +115,27 @@ public class CharacterContentProvider extends ContentProvider {
@Override @Override
public int update(@NonNull final Uri uri, final ContentValues values, final String selection, public int update(@NonNull final Uri uri, final ContentValues values, final String selection,
final String[] selectionArgs) { 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; 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. * 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. * This is the value for a false statement.
*/ */
final static Integer FALSE = 0; public final static Integer FALSE = 0;
/** /**
* The Base LoaderID. * 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. * Helper method to update the availability status of a single track.
* *
* @param track The track which should be marked as available/unavailable. * @param values The values to be put into the database.
* @param isAvailable The status of availability to be set. * @param selection The selection clause
* @param selectionArgs The Arguments for the selection clause.
* @return The result code of the update function. * @return The result code of the update function.
*/ */
public int changeTrackAvailability(final Track track, public int changeTrackAvailability(final ContentValues values,
final boolean isAvailable) { final String selection,
final String[] selectionArgs) {
final SQLiteDatabase db = this.getWritableDatabase(); final SQLiteDatabase db = this.getWritableDatabase();
return db.update(Constants.TABLE_TRACK, values, selection, selectionArgs);
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())});
} }
/** /**
* Helper method to update the availability status of a single character. * Helper method to update the availability status of a single character.
* *
* @param character The character which should be marked as available/unavailable. * @param values The values to be put into the database.
* @param isAvailable The status of availability to be set. * @param selection The selection clause
* @param selectionArgs The Arguments for the selection clause.
* @return The result code of the update function. * @return The result code of the update function.
*/ */
public int changeCharacterAvailability(final Character character, public int changeCharacterAvailability(final ContentValues values,
final boolean isAvailable) { final String selection,
final String[] selectionArgs) {
final SQLiteDatabase db = this.getWritableDatabase(); final SQLiteDatabase db = this.getWritableDatabase();
return db.update(Constants.TABLE_CHARACTER, values, selection, selectionArgs);
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())});
} }
/** /**
* Helper method to update the availability status of a single kart. * Helper method to update the availability status of a single kart.
* *
* @param kart The kart which should be marked as available/unavailable. * @param values The values to be put into the database.
* @param isAvailable The status of availability to be set. * @param selection The selection clause
* @param selectionArgs The Arguments for the selection clause.
* @return The result code of the update function. * @return The result code of the update function.
*/ */
public int changeKartAvailability(final Kart kart, public int changeKartAvailability(final ContentValues values,
final boolean isAvailable) { final String selection,
final String[] selectionArgs) {
final SQLiteDatabase db = this.getWritableDatabase(); final SQLiteDatabase db = this.getWritableDatabase();
return db.update(Constants.TABLE_KART, values, selection, selectionArgs);
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())});
} }
/** /**
* Helper method to update the availability status of a single accessory. * Helper method to update the availability status of a single accessory.
* *
* @param accessory The accessory which should be marked as available/unavailable. * @param values The values to be put into the database.
* @param isAvailable The status of availability to be set. * @param selection The selection clause
* @param selectionArgs The Arguments for the selection clause.
* @return The result code of the update function. * @return The result code of the update function.
*/ */
public int changeAccessoryAvailability(final Accessory accessory, public int changeAccessoryAvailability(final ContentValues values,
final boolean isAvailable) { final String selection,
final String[] selectionArgs) {
final SQLiteDatabase db = this.getWritableDatabase(); final SQLiteDatabase db = this.getWritableDatabase();
return db.update(Constants.TABLE_ACCESSORY, values, selection, selectionArgs);
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())});
} }
/** /**
* Helper method to update the availability status of a single wheels. * Helper method to update the availability status of a single wheels.
* *
* @param wheels The wheels which should be marked as available/unavailable. * @param values The values to be put into the database.
* @param isAvailable The status of availability to be set. * @param selection The selection clause
* @param selectionArgs The Arguments for the selection clause.
* @return The result code of the update function. * @return The result code of the update function.
*/ */
public int changeWheelsAvailability(final Wheels wheels, public int changeWheelsAvailability(final ContentValues values,
final boolean isAvailable) { final String selection,
final String[] selectionArgs) {
final SQLiteDatabase db = this.getWritableDatabase(); final SQLiteDatabase db = this.getWritableDatabase();
return db.update(Constants.TABLE_WHEELS, values, selection, selectionArgs);
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())});
} }
// ------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------

View File

@@ -115,7 +115,27 @@ public class KartContentProvider extends ContentProvider {
@Override @Override
public int update(@NonNull final Uri uri, final ContentValues values, final String selection, public int update(@NonNull final Uri uri, final ContentValues values, final String selection,
final String[] selectionArgs) { 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; return 0;
} }
} }
}

View File

@@ -115,7 +115,27 @@ public class TrackContentProvider extends ContentProvider {
@Override @Override
public int update(@NonNull final Uri uri, final ContentValues values, final String selection, public int update(@NonNull final Uri uri, final ContentValues values, final String selection,
final String[] selectionArgs) { 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; return 0;
} }
} }
}

View File

@@ -115,7 +115,27 @@ public class WheelsContentProvider extends ContentProvider {
@Override @Override
public int update(@NonNull final Uri uri, final ContentValues values, final String selection, public int update(@NonNull final Uri uri, final ContentValues values, final String selection,
final String[] selectionArgs) { 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; return 0;
} }
} }
}

View File

@@ -1,8 +1,10 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector.adapters; package com.de.aldo_apps.aldo.mariokartcircuitselector.adapters;
import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.support.v4.widget.SimpleCursorAdapter; import android.support.v4.widget.SimpleCursorAdapter;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@@ -11,6 +13,7 @@ import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView; 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.Constants;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R; 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 { 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. * The LayoutInflater used to inflate a new ListItem.
*/ */
@@ -52,6 +65,7 @@ public class AccessoryCursorAdapter extends SimpleCursorAdapter {
final int[] to, final int[] to,
final int flags) { final int flags) {
super(context, layout, cursor, from, to, flags); super(context, layout, cursor, from, to, flags);
mContext = context;
mLayout = layout; mLayout = layout;
mInflater = LayoutInflater.from(context); mInflater = LayoutInflater.from(context);
} }
@@ -113,8 +127,17 @@ public class AccessoryCursorAdapter extends SimpleCursorAdapter {
availabilityCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { availabilityCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(final CompoundButton compoundButton, final boolean b) { public void onCheckedChanged(CompoundButton compoundButton, boolean isAvailable) {
// TODO: Handle update method here. 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; package com.de.aldo_apps.aldo.mariokartcircuitselector.adapters;
import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.support.v4.widget.SimpleCursorAdapter; import android.support.v4.widget.SimpleCursorAdapter;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@@ -11,6 +13,7 @@ import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView; 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.Constants;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R; 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 { 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. * The LayoutInflater used to inflate a new ListItem.
*/ */
@@ -52,6 +65,7 @@ public class CharacterCursorAdapter extends SimpleCursorAdapter {
final int[] to, final int[] to,
final int flags) { final int flags) {
super(context, layout, cursor, from, to, flags); super(context, layout, cursor, from, to, flags);
mContext = context;
mLayout = layout; mLayout = layout;
mInflater = LayoutInflater.from(context); mInflater = LayoutInflater.from(context);
} }
@@ -121,8 +135,17 @@ public class CharacterCursorAdapter extends SimpleCursorAdapter {
availabilityCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { availabilityCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) { public void onCheckedChanged(CompoundButton compoundButton, boolean isAvailable) {
// TODO: Handle update method here. 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; package com.de.aldo_apps.aldo.mariokartcircuitselector.adapters;
import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.support.v4.widget.SimpleCursorAdapter; import android.support.v4.widget.SimpleCursorAdapter;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@@ -12,6 +14,7 @@ import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView; import android.widget.TextView;
import com.de.aldo_apps.aldo.mariokartcircuitselector.Constants; import com.de.aldo_apps.aldo.mariokartcircuitselector.Constants;
import com.de.aldo_apps.aldo.mariokartcircuitselector.KartContentProvider;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R; 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 { 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. * The LayoutInflater used to inflate a new ListItem.
*/ */
@@ -52,6 +65,7 @@ public class KartCursorAdapter extends SimpleCursorAdapter {
final int[] to, final int[] to,
final int flags) { final int flags) {
super(context, layout, cursor, from, to, flags); super(context, layout, cursor, from, to, flags);
mContext = context;
mLayout = layout; mLayout = layout;
mInflater = LayoutInflater.from(context); mInflater = LayoutInflater.from(context);
} }
@@ -125,8 +139,17 @@ public class KartCursorAdapter extends SimpleCursorAdapter {
availabilityCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { availabilityCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(final CompoundButton compoundButton, final boolean b) { public void onCheckedChanged(CompoundButton compoundButton, boolean isAvailable) {
// TODO: Handle update method here. 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; package com.de.aldo_apps.aldo.mariokartcircuitselector.adapters;
import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.support.v4.widget.SimpleCursorAdapter; import android.support.v4.widget.SimpleCursorAdapter;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; 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.Constants;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R; 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. * 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 { 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. * The LayoutInflater used to inflate a new ListItem.
*/ */
@@ -52,6 +65,7 @@ public class TrackCursorAdapter extends SimpleCursorAdapter {
final int[] to, final int[] to,
final int flags) { final int flags) {
super(context, layout, cursor, from, to, flags); super(context, layout, cursor, from, to, flags);
mContext = context;
mLayout = layout; mLayout = layout;
mInflater = LayoutInflater.from(context); mInflater = LayoutInflater.from(context);
} }
@@ -123,8 +137,17 @@ public class TrackCursorAdapter extends SimpleCursorAdapter {
availabilityCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { availabilityCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(final CompoundButton compoundButton, final boolean b) { public void onCheckedChanged(CompoundButton compoundButton, boolean isAvailable) {
// TODO: Handle update method here. 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; package com.de.aldo_apps.aldo.mariokartcircuitselector.adapters;
import android.content.ContentValues;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.support.v4.widget.SimpleCursorAdapter; import android.support.v4.widget.SimpleCursorAdapter;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; 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.Constants;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R; 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. * 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 { 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. * The LayoutInflater used to inflate a new ListItem.
*/ */
@@ -52,6 +65,7 @@ public class WheelsCursorAdapter extends SimpleCursorAdapter {
final int[] to, final int[] to,
final int flags) { final int flags) {
super(context, layout, cursor, from, to, flags); super(context, layout, cursor, from, to, flags);
mContext = context;
mLayout = layout; mLayout = layout;
mInflater = LayoutInflater.from(context); mInflater = LayoutInflater.from(context);
} }
@@ -113,8 +127,17 @@ public class WheelsCursorAdapter extends SimpleCursorAdapter {
availabilityCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() { availabilityCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(final CompoundButton compoundButton, final boolean b) { public void onCheckedChanged(CompoundButton compoundButton, boolean isAvailable) {
// TODO: Handle update method here. 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)});
} }
}); });