Added CustomCursorAdapters for each PagerType

Functional -> Still update and toggle availability need to be implemented.
This commit is contained in:
Alexander Doerflinger
2017-08-17 12:28:36 +02:00
parent a9fa61bac4
commit 2b4515c284
9 changed files with 776 additions and 75 deletions

View File

@@ -7,8 +7,8 @@ android {
applicationId "com.de.aldo_apps.aldo.mariokartcircuitselector"
minSdkVersion 16
targetSdkVersion 25
versionCode 8
versionName "0.1.8"
versionCode 9
versionName "0.1.9"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
@@ -29,6 +29,7 @@ dependencies {
compile 'com.afollestad.material-dialogs:core:0.9.4.3'
compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:2.0.1'
compile 'devlight.io:navigationtabbar:1.2.5'
compile 'com.android.support:cardview-v7:25.3.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:design:25.3.1'
}

View File

@@ -110,97 +110,97 @@ public final class Constants {
/**
* The global KEY for the _id field in the database.
*/
static final String KEY_ID = "_id";
public static final String KEY_ID = "_id";
/**
* The global KEY for the name field in the database.
*/
static final String KEY_NAME = "name";
public static final String KEY_NAME = "name";
/**
* The global KEY for the game field in the database.
*/
static final String KEY_GAME = "game";
public static final String KEY_GAME = "game";
/**
* The global KEY for the available field in the database.
*/
static final String KEY_AVAILABLE = "available";
public static final String KEY_AVAILABLE = "available";
/**
* The global KEY for the weight field in the database.
*/
static final String KEY_WEIGHT = "weight";
public static final String KEY_WEIGHT = "weight";
/**
* The global KEY for the cover uri field in the database.
*/
static final String KEY_COVER_URI = "cover_uri";
public static final String KEY_COVER_URI = "cover_uri";
/**
* The global KEY for the wheels field in the database.
*/
static final String KEY_WHEELS = "wheels";
public static final String KEY_WHEELS = "wheels";
/**
* The global KEY for the accessory field in the database.
*/
static final String KEY_ACCESSORY = "accessory";
public static final String KEY_ACCESSORY = "accessory";
/**
* The global KEY for the dedicated driver field in the database.
*/
static final String KEY_DEDICATED_DRIVER = "dedicated_driver";
public static final String KEY_DEDICATED_DRIVER = "dedicated_driver";
/**
* The global KEY for the free for all field in the database.
*/
static final String KEY_FREE_FOR_ALL = "free_for_all";
public static final String KEY_FREE_FOR_ALL = "free_for_all";
/**
* The global KEY for the mirror class field in the database.
*/
private static final String KEY_MIRROR_CLASS = "mirror_class";
public static final String KEY_MIRROR_CLASS = "mirror_class";
/**
* The global KEY for the 50 ccm field in the database.
*/
private static final String KEY_50_CCM = "50_ccm";
public static final String KEY_50_CCM = "50_ccm";
/**
* The global KEY for the 100 ccm field in the database.
*/
private static final String KEY_100_CCM = "100_ccm";
public static final String KEY_100_CCM = "100_ccm";
/**
* The global KEY for the 150 ccm field in the database.
*/
private static final String KEY_150_CCM = "150_ccm";
public static final String KEY_150_CCM = "150_ccm";
/**
* The global KEY for the 200 ccm field in the database.
*/
private static final String KEY_200_CCM = "200_ccm";
public static final String KEY_200_CCM = "200_ccm";
/**
* The global KEY for the kart free for all field in the database.
*/
private static final String KEY_KART_FREE_FOR_ALL = "kart_free_for_all";
public static final String KEY_KART_FREE_FOR_ALL = "kart_free_for_all";
/**
* The global KEY for the bikes field in the database.
*/
private static final String KEY_BIKES = "bikes";
public static final String KEY_BIKES = "bikes";
/**
* The global KEY for the package field in the database.
*/
static final String KEY_PACKAGE = "package";
public static final String KEY_PACKAGE = "package";
/**
* The global KEY for the number field in the database.
*/
static final String KEY_NUMBER = "number";
public static final String KEY_NUMBER = "number";
/**
* The Projection to retrieve all Information of a game object from database.

View File

@@ -0,0 +1,122 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector.adapters;
import android.content.Context;
import android.database.Cursor;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
import com.de.aldo_apps.aldo.mariokartcircuitselector.Constants;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
/**
* Custom CursorAdapter which populates the ListView with accessory data from cursor.
*
* @author aldo7224
* @version 0.1
* @since 17.08.2017
*/
public class AccessoryCursorAdapter extends SimpleCursorAdapter {
/**
* The LayoutInflater used to inflate a new ListItem.
*/
private final LayoutInflater mInflater;
/**
* The LayoutId of the Layout to be inflated.
*/
private final int mLayout;
/**
* Default constructor.
*
* @param context The Context from which this class was called.
* @param layout The LayoutId to be inflated.
* @param cursor The cursor which holds all the data.
* @param from The Array Containing all Texts to be added to the view
* (not used in custom adapter).
* @param to The Array holding all LayoutIds where the texts need to be displayed
* (not used in custom adapter).
* @param flags Some flags (not used in custom adapter).
*/
public AccessoryCursorAdapter(final Context context,
final int layout,
final Cursor cursor,
final String[] from,
final int[] to,
final int flags) {
super(context, layout, cursor, from, to, flags);
mLayout = layout;
mInflater = LayoutInflater.from(context);
}
@Override
public View newView(final Context context, final Cursor cursor, final ViewGroup parent) {
return mInflater.inflate(mLayout, null);
}
@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
super.bindView(view, context, cursor);
final int idxId = cursor.getColumnIndex(Constants.KEY_ID);
final int idxName = cursor.getColumnIndex(Constants.KEY_NAME);
final int idxAvailable = cursor.getColumnIndex(Constants.KEY_AVAILABLE);
if (idxId > -1 && idxName > -1 && idxAvailable > -1) {
final long id = cursor.getLong(idxId);
final String name = cursor.getString(idxName);
final boolean available = cursor.getInt(idxAvailable) == Constants.TRUE;
fillViewWithData(view, id, name, available);
}
}
/**
* Helper method to fill the UI-Element with information from retrieved from cursor.
*
* @param view The view to be filled.
* @param id Id to be displayed as a backup into TextView (TextView is INVISIBLE)
* @param name Name of the accessory to be displayed.
* @param available Current AvailabilityState of the accessory.
*/
private void fillViewWithData(final View view,
final long id,
final String name,
final boolean available) {
final CheckBox availabilityCheckBox
= (CheckBox) view.findViewById(R.id.availability_checkbox);
availabilityCheckBox.setChecked(available);
final TextView idTextView = (TextView) view.findViewById(R.id.database_id_view);
idTextView.setText(String.valueOf(id));
final View multipleContainer = view.findViewById(R.id.multiple_information_container);
multipleContainer.setVisibility(View.GONE);
final TextView nameTextView = (TextView) view.findViewById(R.id.single_info_name);
nameTextView.setText(name);
nameTextView.setVisibility(View.VISIBLE);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
availabilityCheckBox.toggle();
}
});
availabilityCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton compoundButton, final boolean b) {
// TODO: Handle update method here.
}
});
}
}

View File

@@ -0,0 +1,130 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector.adapters;
import android.content.Context;
import android.database.Cursor;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
import com.de.aldo_apps.aldo.mariokartcircuitselector.Constants;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
/**
* Custom CursorAdapter which populates the ListView with character data from cursor.
*
* @author aldo7224
* @version 0.1
* @since 17.08.2017
*/
public class CharacterCursorAdapter extends SimpleCursorAdapter {
/**
* The LayoutInflater used to inflate a new ListItem.
*/
private final LayoutInflater mInflater;
/**
* The LayoutId of the Layout to be inflated.
*/
private final int mLayout;
/**
* Default constructor.
*
* @param context The Context from which this class was called.
* @param layout The LayoutId to be inflated.
* @param cursor The cursor which holds all the data.
* @param from The Array Containing all Texts to be added to the view
* (not used in custom adapter).
* @param to The Array holding all LayoutIds where the texts need to be displayed
* (not used in custom adapter).
* @param flags Some flags (not used in custom adapter).
*/
public CharacterCursorAdapter(final Context context,
final int layout,
final Cursor cursor,
final String[] from,
final int[] to,
final int flags) {
super(context, layout, cursor, from, to, flags);
mLayout = layout;
mInflater = LayoutInflater.from(context);
}
@Override
public View newView(final Context context, final Cursor cursor, final ViewGroup parent) {
return mInflater.inflate(mLayout, null);
}
@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
super.bindView(view, context, cursor);
final int idxId = cursor.getColumnIndex(Constants.KEY_ID);
final int idxName = cursor.getColumnIndex(Constants.KEY_NAME);
final int idxWeight = cursor.getColumnIndex(Constants.KEY_WEIGHT);
final int idxAvailable = cursor.getColumnIndex(Constants.KEY_AVAILABLE);
if (idxId > -1 && idxName > -1 && idxWeight > -1 && idxAvailable > -1) {
final long id = cursor.getLong(idxId);
final String name = cursor.getString(idxName);
final String weight = cursor.getString(idxWeight);
final boolean available = cursor.getInt(idxAvailable) == Constants.TRUE;
fillViewWithData(view, id, name, weight, available);
}
}
/**
* Helper method to fill the UI-Element with information from retrieved from cursor.
*
* @param view The view to be filled.
* @param id Id to be displayed as a backup into TextView (TextView is INVISIBLE)
* @param name Name of the character to be displayed.
* @param weight Weight of the character to be displayed.
* @param available Current AvailabilityState of the character.
*/
private void fillViewWithData(final View view,
final long id,
final String name,
final String weight,
final boolean available) {
final CheckBox availabilityCheckBox
= (CheckBox) view.findViewById(R.id.availability_checkbox);
availabilityCheckBox.setChecked(available);
final TextView idTextView = (TextView) view.findViewById(R.id.database_id_view);
idTextView.setText(String.valueOf(id));
final TextView nameTextView = (TextView) view.findViewById(R.id.multi_view_name);
nameTextView.setText(name);
final TextView weightTextView = (TextView) view.findViewById(R.id.additional_info_first);
weightTextView.setText(weight);
final TextView separator
= (TextView) view.findViewById(R.id.additional_information_separator);
separator.setVisibility(View.GONE);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
availabilityCheckBox.toggle();
}
});
availabilityCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
// TODO: Handle update method here.
}
});
}
}

View File

@@ -0,0 +1,134 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector.adapters;
import android.content.Context;
import android.database.Cursor;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
import com.de.aldo_apps.aldo.mariokartcircuitselector.Constants;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
/**
* Custom CursorAdapter which populates the ListView with kart data from cursor.
*
* @author aldo7224
* @version 0.1
* @since 17.08.2017
*/
public class KartCursorAdapter extends SimpleCursorAdapter {
/**
* The LayoutInflater used to inflate a new ListItem.
*/
private final LayoutInflater mInflater;
/**
* The LayoutId of the Layout to be inflated.
*/
private final int mLayout;
/**
* Default constructor.
*
* @param context The Context from which this class was called.
* @param layout The LayoutId to be inflated.
* @param cursor The cursor which holds all the data.
* @param from The Array Containing all Texts to be added to the view
* (not used in custom adapter).
* @param to The Array holding all LayoutIds where the texts need to be displayed
* (not used in custom adapter).
* @param flags Some flags (not used in custom adapter).
*/
public KartCursorAdapter(final Context context,
final int layout,
final Cursor cursor,
final String[] from,
final int[] to,
final int flags) {
super(context, layout, cursor, from, to, flags);
mLayout = layout;
mInflater = LayoutInflater.from(context);
}
@Override
public View newView(final Context context, final Cursor cursor, final ViewGroup parent) {
return mInflater.inflate(mLayout, null);
}
@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
super.bindView(view, context, cursor);
final int idxId = cursor.getColumnIndex(Constants.KEY_ID);
final int idxName = cursor.getColumnIndex(Constants.KEY_NAME);
final int idxWeight = cursor.getColumnIndex(Constants.KEY_WEIGHT);
final int idxDedicatedDriver = cursor.getColumnIndex(Constants.KEY_DEDICATED_DRIVER);
final int idxAvailable = cursor.getColumnIndex(Constants.KEY_AVAILABLE);
if (idxId > -1 && idxName > -1 && idxDedicatedDriver > -1 && idxWeight > -1
&& idxAvailable > -1) {
final long id = cursor.getLong(idxId);
final String name = cursor.getString(idxName);
final String weight = cursor.getString(idxDedicatedDriver);
final String dedicatedDriver = cursor.getString(idxWeight);
final boolean available = cursor.getInt(idxAvailable) == Constants.TRUE;
fillViewWithData(view, id, name, weight, dedicatedDriver, available);
}
}
/**
* Helper method to fill the UI-Element with information from retrieved from cursor.
*
* @param view The view to be filled.
* @param id Id to be displayed as a backup into TextView (TextView is INVISIBLE)
* @param name Name of the kart to be displayed.
* @param weight Weight of the kart to be displayed.
* @param dedicatedDriver The dedicated Driver of this Kart..
* @param available Current AvailabilityState of the kart.
*/
private void fillViewWithData(final View view,
final long id,
final String name,
final String weight,
final String dedicatedDriver,
final boolean available) {
final CheckBox availabilityCheckBox
= (CheckBox) view.findViewById(R.id.availability_checkbox);
availabilityCheckBox.setChecked(available);
final TextView idTextView = (TextView) view.findViewById(R.id.database_id_view);
idTextView.setText(String.valueOf(id));
final TextView nameTextView = (TextView) view.findViewById(R.id.multi_view_name);
nameTextView.setText(name);
final TextView weightTextView = (TextView) view.findViewById(R.id.additional_info_first);
weightTextView.setText(weight);
final TextView dedicatedDriverTextView
= (TextView) view.findViewById(R.id.additional_info_second);
dedicatedDriverTextView.setText(dedicatedDriver);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
availabilityCheckBox.toggle();
}
});
availabilityCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton compoundButton, final boolean b) {
// TODO: Handle update method here.
}
});
}
}

View File

@@ -0,0 +1,132 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector.adapters;
import android.content.Context;
import android.database.Cursor;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
import com.de.aldo_apps.aldo.mariokartcircuitselector.Constants;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
/**
* Custom CursorAdapter which populates the ListView with track data from cursor.
*
* @author aldo7224
* @version 0.1
* @since 17.08.2017
*/
public class TrackCursorAdapter extends SimpleCursorAdapter {
/**
* The LayoutInflater used to inflate a new ListItem.
*/
private final LayoutInflater mInflater;
/**
* The LayoutId of the Layout to be inflated.
*/
private final int mLayout;
/**
* Default constructor.
*
* @param context The Context from which this class was called.
* @param layout The LayoutId to be inflated.
* @param cursor The cursor which holds all the data.
* @param from The Array Containing all Texts to be added to the view
* (not used in custom adapter).
* @param to The Array holding all LayoutIds where the texts need to be displayed
* (not used in custom adapter).
* @param flags Some flags (not used in custom adapter).
*/
public TrackCursorAdapter(final Context context,
final int layout,
final Cursor cursor,
final String[] from,
final int[] to,
final int flags) {
super(context, layout, cursor, from, to, flags);
mLayout = layout;
mInflater = LayoutInflater.from(context);
}
@Override
public View newView(final Context context, final Cursor cursor, final ViewGroup parent) {
return mInflater.inflate(mLayout, null);
}
@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
super.bindView(view, context, cursor);
final int idxId = cursor.getColumnIndex(Constants.KEY_ID);
final int idxName = cursor.getColumnIndex(Constants.KEY_NAME);
final int idxPackage = cursor.getColumnIndex(Constants.KEY_PACKAGE);
final int idxNumber = cursor.getColumnIndex(Constants.KEY_NUMBER);
final int idxAvailable = cursor.getColumnIndex(Constants.KEY_AVAILABLE);
if (idxId > -1 && idxName > -1 && idxNumber > -1 && idxPackage > -1 && idxAvailable > -1) {
final long id = cursor.getLong(idxId);
final String name = cursor.getString(idxName);
final String number = cursor.getString(idxNumber);
final String packageName = cursor.getString(idxPackage);
final boolean available = cursor.getInt(idxAvailable) == Constants.TRUE;
fillViewWithData(view, id, name, packageName, number, available);
}
}
/**
* Helper method to fill the UI-Element with information from retrieved from cursor.
*
* @param view The view to be filled.
* @param id Id to be displayed as a backup into TextView (TextView is INVISIBLE)
* @param name Name of the track to be displayed.
* @param packageName Name of the package where this track is available to be displayed.
* @param number Number of the track to be displayed.
* @param available Current AvailabilityState of the track.
*/
private void fillViewWithData(final View view,
final long id,
final String name,
final String packageName,
final String number,
final boolean available) {
final CheckBox availabilityCheckBox
= (CheckBox) view.findViewById(R.id.availability_checkbox);
availabilityCheckBox.setChecked(available);
final TextView idTextView = (TextView) view.findViewById(R.id.database_id_view);
idTextView.setText(String.valueOf(id));
final TextView nameTextView = (TextView) view.findViewById(R.id.multi_view_name);
nameTextView.setText(name);
final TextView packageTextView = (TextView) view.findViewById(R.id.additional_info_first);
packageTextView.setText(packageName);
final TextView numberTextView = (TextView) view.findViewById(R.id.additional_info_second);
numberTextView.setText(number);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
availabilityCheckBox.toggle();
}
});
availabilityCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton compoundButton, final boolean b) {
// TODO: Handle update method here.
}
});
}
}

View File

@@ -0,0 +1,122 @@
package com.de.aldo_apps.aldo.mariokartcircuitselector.adapters;
import android.content.Context;
import android.database.Cursor;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
import com.de.aldo_apps.aldo.mariokartcircuitselector.Constants;
import com.de.aldo_apps.aldo.mariokartcircuitselector.R;
/**
* Custom CursorAdapter which populates the ListView with wheels data from cursor.
*
* @author aldo7224
* @version 0.1
* @since 17.08.2017
*/
public class WheelsCursorAdapter extends SimpleCursorAdapter {
/**
* The LayoutInflater used to inflate a new ListItem.
*/
private final LayoutInflater mInflater;
/**
* The LayoutId of the Layout to be inflated.
*/
private final int mLayout;
/**
* Default constructor.
*
* @param context The Context from which this class was called.
* @param layout The LayoutId to be inflated.
* @param cursor The cursor which holds all the data.
* @param from The Array Containing all Texts to be added to the view
* (not used in custom adapter).
* @param to The Array holding all LayoutIds where the texts need to be displayed
* (not used in custom adapter).
* @param flags Some flags (not used in custom adapter).
*/
public WheelsCursorAdapter(final Context context,
final int layout,
final Cursor cursor,
final String[] from,
final int[] to,
final int flags) {
super(context, layout, cursor, from, to, flags);
mLayout = layout;
mInflater = LayoutInflater.from(context);
}
@Override
public View newView(final Context context, final Cursor cursor, final ViewGroup parent) {
return mInflater.inflate(mLayout, null);
}
@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
super.bindView(view, context, cursor);
final int idxId = cursor.getColumnIndex(Constants.KEY_ID);
final int idxName = cursor.getColumnIndex(Constants.KEY_NAME);
final int idxAvailable = cursor.getColumnIndex(Constants.KEY_AVAILABLE);
if (idxId > -1 && idxName > -1 && idxAvailable > -1) {
final long id = cursor.getLong(idxId);
final String name = cursor.getString(idxName);
final boolean available = cursor.getInt(idxAvailable) == Constants.TRUE;
fillViewWithData(view, id, name, available);
}
}
/**
* Helper method to fill the UI-Element with information from retrieved from cursor.
*
* @param view The view to be filled.
* @param id Id to be displayed as a backup into TextView (TextView is INVISIBLE)
* @param name Name of the wheels to be displayed.
* @param available Current AvailabilityState of the wheels.
*/
private void fillViewWithData(final View view,
final long id,
final String name,
final boolean available) {
final CheckBox availabilityCheckBox
= (CheckBox) view.findViewById(R.id.availability_checkbox);
availabilityCheckBox.setChecked(available);
final TextView idTextView = (TextView) view.findViewById(R.id.database_id_view);
idTextView.setText(String.valueOf(id));
final View multipleContainer = view.findViewById(R.id.multiple_information_container);
multipleContainer.setVisibility(View.GONE);
final TextView nameTextView = (TextView) view.findViewById(R.id.single_info_name);
nameTextView.setText(name);
nameTextView.setVisibility(View.VISIBLE);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
availabilityCheckBox.toggle();
}
});
availabilityCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(final CompoundButton compoundButton, final boolean b) {
// TODO: Handle update method here.
}
});
}
}

View File

@@ -13,8 +13,16 @@ import com.de.aldo_apps.aldo.mariokartcircuitselector.AccessoryContentProvider;
import com.de.aldo_apps.aldo.mariokartcircuitselector.CharacterContentProvider;
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.TrackContentProvider;
import com.de.aldo_apps.aldo.mariokartcircuitselector.WheelsContentProvider;
import com.de.aldo_apps.aldo.mariokartcircuitselector.adapters.AccessoryCursorAdapter;
import com.de.aldo_apps.aldo.mariokartcircuitselector.adapters.CharacterCursorAdapter;
import com.de.aldo_apps.aldo.mariokartcircuitselector.adapters.KartCursorAdapter;
import com.de.aldo_apps.aldo.mariokartcircuitselector.adapters.TrackCursorAdapter;
import com.de.aldo_apps.aldo.mariokartcircuitselector.adapters.WheelsCursorAdapter;
import java.util.Arrays;
/**
* The ListFragment which is initialized in each PagerView and gets populated with data retrieved
@@ -34,7 +42,6 @@ public class GenericListFragment extends ListFragment
/**
* The SimpleCursorAdapter which populates the ListView.
* TODO: Needs to be replaced with Custom Adapter.
*/
private SimpleCursorAdapter mCursorAdapter;
@@ -48,14 +55,43 @@ public class GenericListFragment extends ListFragment
// Get Projection and LoaderId from arguments.
final String[] projection = arguments.getStringArray(Constants.PROJECTION_KEY);
final int loaderId = arguments.getInt(Constants.LOADER_ID_KEY);
final int[] to = new int[]{};
Log.d(TAG, "onCreate: New GenericListFragment with loaderId = [" + loaderId
+ "] and projection = [" + projection.toString() + "]");
// TODO: Replace with real ViewIds as soon as we use custom layout.
final int[] values = new int[]{android.R.id.text1};
// TODO: Replace with custom Layout and Adapter.
+ "] and projection = [" + Arrays.toString(projection) + "]");
switch (loaderId) {
case Constants.CHARACTER_LOADER_ID:
mCursorAdapter = new CharacterCursorAdapter(getContext(),
R.layout.generic_list_item,
null, projection, to, 0);
break;
case Constants.KART_LOADER_ID:
mCursorAdapter = new KartCursorAdapter(getContext(),
R.layout.generic_list_item,
null, projection, to, 0);
break;
case Constants.TRACK_LOADER_ID:
mCursorAdapter = new TrackCursorAdapter(getContext(),
R.layout.generic_list_item,
null, projection, to, 0);
break;
case Constants.ACCESSORY_LOADER_ID:
mCursorAdapter = new AccessoryCursorAdapter(getContext(),
R.layout.generic_list_item,
null, projection, to, 0);
break;
case Constants.WHEELS_LOADER_ID:
mCursorAdapter = new WheelsCursorAdapter(getContext(),
R.layout.generic_list_item,
null, projection, to, 0);
break;
default:
mCursorAdapter = new SimpleCursorAdapter(getContext(),
android.R.layout.simple_list_item_1,
null, projection, values, 0);
null, projection, to, 0);
break;
}
// Set the ListAdapter to the ListView.
setListAdapter(mCursorAdapter);

View File

@@ -1,27 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_centerHorizontal="true">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<android.support.v7.widget.CardView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
app:cardCornerRadius="5dp"
app:cardElevation="14dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:orientation="horizontal">
<TextView
android:id="@+id/database_id_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
<!-- CheckBox indicating the current availability status -->
<CheckBox
android:id="@+id/availability_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/availability_checkbox"/>
android:layout_height="wrap_content" />
<!-- LinearLayout container which holds multiple TextViews for multiple information
(e.g. name and weight) -->
<LinearLayout
android:id="@+id/multiple_information_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/multiple_information_container">
android:orientation="vertical">
<!-- The TextView containing the objects name -->
<TextView
android:id="@+id/multi_view_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/multi_view_name" />
android:textAppearance="@android:style/TextAppearance.Large" />
<!-- LinearLayout which aligns the additional information properly -->
<LinearLayout
@@ -30,34 +53,35 @@
<!-- TextView holding the first value (e.g. weight) -->
<TextView
android:id="@+id/additional_info_first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/additional_info_first" />
android:layout_height="wrap_content" />
<!-- TextView which has a function as a separator between the first and the second
value -->
<TextView
android:id="@+id/additional_information_separator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/additional_information_separator"
android:layout_marginLeft="@dimen/separator_margin"
android:layout_marginRight="@dimen/separator_margin"
android:text="@string/separator"/>
android:text="@string/separator" />
<!-- TextView holding the second value (e.g. dedicated driver) -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/additional_info_second"
/>
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<!-- TextView which simply holds a name without additional information -->
<TextView
android:id="@+id/single_info_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/single_info_name"
android:visibility="gone"/>
</LinearLayout>
android:textAppearance="@android:style/TextAppearance.Large"
android:visibility="gone" />
</LinearLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>