From 2ffb854927521b07d4303672314fd26fa637d1ea Mon Sep 17 00:00:00 2001 From: Alexander Doerflinger Date: Wed, 16 Aug 2017 16:20:05 +0200 Subject: [PATCH] Fully Functional Database loading Adapter needs to be replaced with custom adapter. Click needs to be implemented as well. --- .idea/misc.xml | 2 +- app/src/main/AndroidManifest.xml | 26 + .../AccessoryContentProvider.java | 112 ++++ .../CharacterContentProvider.java | 108 +++ .../mariokartcircuitselector/Constants.java | 103 +-- .../DatabaseHandler.java | 626 ++---------------- .../GameSelection.java | 71 +- .../KartContentProvider.java | 111 ++++ .../mariokartcircuitselector/PagerType.java | 13 + .../TrackContentProvider.java | 110 +++ .../WheelsContentProvider.java | 111 ++++ .../adapter/CharacterListAdapter.java | 59 -- .../adapters/CursorPagerAdapter.java | 70 ++ .../fragments/GenericListFragment.java | 93 +++ .../fragments/PagerItem.java | 99 --- .../fragments/SingleAccessoryFragment.java | 133 ---- .../fragments/SingleCharacterFragment.java | 155 ----- .../fragments/SingleKartFragment.java | 161 ----- .../fragments/SingleTrackFragment.java | 160 ----- .../fragments/SingleWheelsFragment.java | 134 ---- .../res/layout/activity_game_selection.xml | 15 +- 21 files changed, 871 insertions(+), 1601 deletions(-) create mode 100644 app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/AccessoryContentProvider.java create mode 100644 app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/CharacterContentProvider.java create mode 100644 app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/KartContentProvider.java create mode 100644 app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/PagerType.java create mode 100644 app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/TrackContentProvider.java create mode 100644 app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/WheelsContentProvider.java delete mode 100644 app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/adapter/CharacterListAdapter.java create mode 100644 app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/adapters/CursorPagerAdapter.java create mode 100644 app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/fragments/GenericListFragment.java delete mode 100644 app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/fragments/PagerItem.java delete mode 100644 app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/fragments/SingleAccessoryFragment.java delete mode 100644 app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/fragments/SingleCharacterFragment.java delete mode 100644 app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/fragments/SingleKartFragment.java delete mode 100644 app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/fragments/SingleTrackFragment.java delete mode 100644 app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/fragments/SingleWheelsFragment.java diff --git a/.idea/misc.xml b/.idea/misc.xml index 406ac20..738edfe 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -56,7 +56,7 @@ - + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4fc3268..07c54c0 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -16,6 +16,32 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/AccessoryContentProvider.java b/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/AccessoryContentProvider.java new file mode 100644 index 0000000..d2e909a --- /dev/null +++ b/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/AccessoryContentProvider.java @@ -0,0 +1,112 @@ +package com.de.aldo_apps.aldo.mariokartcircuitselector; + +import android.content.ContentProvider; +import android.content.ContentValues; +import android.content.UriMatcher; +import android.database.Cursor; +import android.net.Uri; +import android.util.Log; + +import com.de.aldo_apps.aldo.mariokartcircuitselector.Constants; +import com.de.aldo_apps.aldo.mariokartcircuitselector.DatabaseHandler; + +/** + * Created by aldo7224 on 16.08.17. + */ + +public class AccessoryContentProvider extends ContentProvider { + + private static final String TAG = "AccessoryProvider"; + public static final String PROVIDER_NAME + = "com.de.aldo_apps.aldo.mariokartcircuitselector"; + + /** + * A uri to do operations on cust_master table. A content provider is identified by its uri + */ + public static final Uri CONTENT_URI = Uri.parse("content://" + PROVIDER_NAME + "/accessories"); + + private static final UriMatcher uriMatcher; + + static { + uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); + uriMatcher.addURI(PROVIDER_NAME, "characters", Constants.CHARACTER_LOADER_ID); + uriMatcher.addURI(PROVIDER_NAME, "tracks", Constants.TRACK_LOADER_ID); + uriMatcher.addURI(PROVIDER_NAME, "karts", Constants.KART_LOADER_ID); + uriMatcher.addURI(PROVIDER_NAME, "wheels", Constants.WHEELS_LOADER_ID); + uriMatcher.addURI(PROVIDER_NAME, "accessories", Constants.ACCESSORY_LOADER_ID); + + } + + /** + * This content provider does the database operations by this object + */ + DatabaseHandler mHandler; + + /** + * A callback method which is invoked when the content provider is starting up + */ + @Override + public boolean onCreate() { + mHandler = new DatabaseHandler(getContext()); + return true; + } + + @Override + public String getType(final Uri uri) { + return null; + } + + /** + * A callback method which is by the default content uri + */ + @Override + public Cursor query(final Uri uri, + final String[] projection, + final String selection, + final String[] selectionArgs, + final String sortOrder) { + Log.d(TAG, "query: Perform Query for [" + uri + "]"); + + final int resId = uriMatcher.match(uri); + + switch (resId) { + case Constants.CHARACTER_LOADER_ID: + Log.d(TAG, "query: Getting all Characters."); + return mHandler.getAllCharacters(Constants.PROJECTION_CHARACTER, null, null); + case Constants.KART_LOADER_ID: + Log.d(TAG, "query: Getting all Karts."); + return mHandler.getAllKarts(Constants.PROJECTION_KART, null, null); + case Constants.ACCESSORY_LOADER_ID: + Log.d(TAG, "query: Getting all Acessories."); + return mHandler.getAllAccessories(Constants.PROJECTION_ACCESSORY, null, null); + case Constants.TRACK_LOADER_ID: + Log.d(TAG, "query: Getting all Tracks."); + return mHandler.getAllTracks(Constants.PROJECTION_TRACK, null, null); + case Constants.WHEELS_LOADER_ID: + Log.d(TAG, "query: Getting all Wheels."); + return mHandler.getAllWheels(Constants.PROJECTION_WHEELS, null, null); + default: + Log.d(TAG, "query: UriMatcher returned: " + uriMatcher.match(uri)); + return null; + } + } + + @Override + public int delete(final Uri uri, final String selection, final String[] selectionArgs) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public Uri insert(final Uri uri, final ContentValues values) { + // TODO Auto-generated method stub + return null; + } + + @Override + public int update(final Uri uri, final ContentValues values, final String selection, + final String[] selectionArgs) { + // TODO Auto-generated method stub + return 0; + } +} diff --git a/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/CharacterContentProvider.java b/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/CharacterContentProvider.java new file mode 100644 index 0000000..69b111c --- /dev/null +++ b/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/CharacterContentProvider.java @@ -0,0 +1,108 @@ +package com.de.aldo_apps.aldo.mariokartcircuitselector; + +import android.content.ContentProvider; +import android.content.ContentValues; +import android.content.UriMatcher; +import android.database.Cursor; +import android.net.Uri; +import android.util.Log; + +/** + * Created by aldo7224 on 16.08.17. + */ + +public class CharacterContentProvider extends ContentProvider { + + private static final String TAG = "CharacterProvider"; + public static final String PROVIDER_NAME + = "com.de.aldo_apps.aldo.mariokartcircuitselector"; + + /** + * A uri to do operations on cust_master table. A content provider is identified by its uri + */ + public static final Uri CONTENT_URI = Uri.parse("content://" + PROVIDER_NAME + "/characters"); + + private static final UriMatcher uriMatcher; + + static { + uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); + uriMatcher.addURI(PROVIDER_NAME, "characters", Constants.CHARACTER_LOADER_ID); + uriMatcher.addURI(PROVIDER_NAME, "tracks", Constants.TRACK_LOADER_ID); + uriMatcher.addURI(PROVIDER_NAME, "karts", Constants.KART_LOADER_ID); + uriMatcher.addURI(PROVIDER_NAME, "wheels", Constants.WHEELS_LOADER_ID); + uriMatcher.addURI(PROVIDER_NAME, "accessories", Constants.ACCESSORY_LOADER_ID); + } + + /** + * This content provider does the database operations by this object + */ + DatabaseHandler mHandler; + + /** + * A callback method which is invoked when the content provider is starting up + */ + @Override + public boolean onCreate() { + mHandler = new DatabaseHandler(getContext()); + return true; + } + + @Override + public String getType(final Uri uri) { + return null; + } + + /** + * A callback method which is by the default content uri + */ + @Override + public Cursor query(final Uri uri, + final String[] projection, + final String selection, + final String[] selectionArgs, + final String sortOrder) { + Log.d(TAG, "query: Perform Query for [" + uri + "]"); + + final int resId = uriMatcher.match(uri); + + switch (resId) { + case Constants.CHARACTER_LOADER_ID: + Log.d(TAG, "query: Getting all Characters."); + return mHandler.getAllCharacters(Constants.PROJECTION_CHARACTER, null, null); + case Constants.KART_LOADER_ID: + Log.d(TAG, "query: Getting all Karts."); + return mHandler.getAllKarts(Constants.PROJECTION_KART, null, null); + case Constants.ACCESSORY_LOADER_ID: + Log.d(TAG, "query: Getting all Acessories."); + return mHandler.getAllAccessories(Constants.PROJECTION_ACCESSORY, null, null); + case Constants.TRACK_LOADER_ID: + Log.d(TAG, "query: Getting all Tracks."); + return mHandler.getAllTracks(Constants.PROJECTION_TRACK, null, null); + case Constants.WHEELS_LOADER_ID: + Log.d(TAG, "query: Getting all Wheels."); + return mHandler.getAllWheels(Constants.PROJECTION_WHEELS, null, null); + default: + Log.d(TAG, "query: UriMatcher returned: " + uriMatcher.match(uri)); + return null; + } + } + + @Override + public int delete(final Uri uri, final String selection, final String[] selectionArgs) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public Uri insert(final Uri uri, final ContentValues values) { + // TODO Auto-generated method stub + return null; + } + + @Override + public int update(final Uri uri, final ContentValues values, final String selection, + final String[] selectionArgs) { + // TODO Auto-generated method stub + return 0; + } +} diff --git a/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/Constants.java b/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/Constants.java index b78a0f4..a645264 100644 --- a/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/Constants.java +++ b/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/Constants.java @@ -8,164 +8,177 @@ package com.de.aldo_apps.aldo.mariokartcircuitselector; * @version 0.1 * @since 07.08.2017 */ -public class Constants { +public final class Constants { /** * The Version Code of the Database. */ - static final Integer DATABASE_VERSION = 1; + public static final Integer DATABASE_VERSION = 1; /** * As SQLite does not have a native boolean value, we use integers to represent true and false. * This is the value for a true statement. */ - public final static Integer TRUE = 1; + public static final Integer TRUE = 1; /** * 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; + + public static final int BASE_LOADER_ID = 0; + + public static final int CHARACTER_LOADER_ID = BASE_LOADER_ID; + + public static final int KART_LOADER_ID = BASE_LOADER_ID + 1; + + public static final int TRACK_LOADER_ID = BASE_LOADER_ID + 2; + + public static final int ACCESSORY_LOADER_ID = BASE_LOADER_ID + 3; + + public static final int WHEELS_LOADER_ID = BASE_LOADER_ID + 4; + /** * The Name of the complete database. */ - static final String DATABASE_NAME = "mario_kart_circuit_selector"; + public static final String DATABASE_NAME = "mario_kart_circuit_selector"; /** * The name of the table containing all information according accessories. */ - static final String TABLE_ACCESSORY = "accessory"; + public static final String TABLE_ACCESSORY = "accessory"; /** * The name of the table containing all information according characters. */ - static final String TABLE_CHARACTER = "character"; + public static final String TABLE_CHARACTER = "character"; /** * The name of the table containing all information according games. */ - static final String TABLE_GAME = "game"; + public static final String TABLE_GAME = "game"; /** * The name of the table containing all information according karts. */ - static final String TABLE_KART = "kart"; + public static final String TABLE_KART = "kart"; /** * The name of the table containing all information according rulesets. */ - static final String TABLE_RULESET = "ruleset"; + public static final String TABLE_RULESET = "ruleset"; /** * The name of the table containing all information according tracks. */ - static final String TABLE_TRACK = "track"; + public static final String TABLE_TRACK = "track"; /** * The name of the table containing all information according wheels. */ - static final String TABLE_WHEELS = "wheels"; + public static final String TABLE_WHEELS = "wheels"; /** * 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. */ - 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. */ - 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. */ - 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. */ - 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. */ - 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. */ - 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. */ - 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. */ - static final String[] PROJECTION_GAME = { + public static final String[] PROJECTION_GAME = { KEY_ID, KEY_NAME, KEY_COVER_URI @@ -174,7 +187,7 @@ public class Constants { /** * The Projection to retrieve all Information of a track object from database. */ - static final String[] PROJECTION_TRACK = { + public static final String[] PROJECTION_TRACK = { KEY_ID, KEY_NAME, KEY_GAME, @@ -186,7 +199,7 @@ public class Constants { /** * The Projection to retrieve all Information of a character object from database. */ - static final String[] PROJECTION_CHARACTER = { + public static final String[] PROJECTION_CHARACTER = { KEY_ID, KEY_NAME, KEY_GAME, @@ -194,10 +207,14 @@ public class Constants { KEY_AVAILABLE }; + public static final String[] PROJECTION_TEST = { + KEY_NAME + }; + /** * The Projection to retrieve all Information of a kart object from database. */ - static final String[] PROJECTION_KART = { + public static final String[] PROJECTION_KART = { KEY_ID, KEY_NAME, KEY_GAME, @@ -212,7 +229,7 @@ public class Constants { /** * The Projection to retrieve all Information of a ruleset object from database. */ - static final String[] PROJECTION_RULESET = { + public static final String[] PROJECTION_RULESET = { KEY_ID, KEY_GAME, KEY_MIRROR_CLASS, @@ -227,7 +244,7 @@ public class Constants { /** * The Projection to retrieve all Information of a accessory object from database. */ - static final String[] PROJECTION_ACCESSORY = { + public static final String[] PROJECTION_ACCESSORY = { KEY_ID, KEY_NAME, KEY_GAME, @@ -237,7 +254,7 @@ public class Constants { /** * The Projection to retrieve all Information of a wheels object from database. */ - static final String[] PROJECTION_WHEELS = { + public static final String[] PROJECTION_WHEELS = { KEY_ID, KEY_NAME, KEY_GAME, @@ -248,25 +265,25 @@ public class Constants { /** * Enum Value defining the position of the Character Tab. */ - static final int CHARACTER = 0; + public static final int CHARACTER = 0; /** * Enum Value defining the position of the Kart Tab. */ - static final int KART = 1; + public static final int KART = 1; /** * Enum Value defining the position of the Track Tab. */ - static final int TRACK = 2; + public static final int TRACK = 2; /** * Enum Value defining the position of the Accessory Tab. */ - static final int ACCESSORY = 3; + public static final int ACCESSORY = 3; /** * Enum Value defining the position of the Wheels Tab. */ - static final int WHEELS = 4; + public static final int WHEELS = 4; } diff --git a/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/DatabaseHandler.java b/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/DatabaseHandler.java index 4e9d368..054776a 100644 --- a/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/DatabaseHandler.java +++ b/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/DatabaseHandler.java @@ -5,6 +5,7 @@ import android.content.Context; import android.database.Cursor; import android.database.DatabaseUtils; import android.database.sqlite.SQLiteDatabase; +import android.net.Uri; import android.support.annotation.Nullable; import android.util.Log; @@ -194,651 +195,110 @@ public class DatabaseHandler extends SQLiteAssetHelper { /** * Retrieves all Tracks from Database. If a Game is provided, all tracks of this specific * game will be retrieved. - * - * @param game The game of which all tracks should be retrieved. - * @param onlyAvailable If true, only available objects will be returned, otherwise all * * @return List containing all Track Objects retrieved from Database. */ - public ArrayList getAllTracks(@Nullable final Game game, - final boolean onlyAvailable) { + public Cursor getAllTracks(final String[] projection, + final String selection, + final String[] selectionArgs) { final SQLiteDatabase database = this.getReadableDatabase(); - final String selectionClause; - final String[] selectionArgs; - if (game != null && onlyAvailable) { - selectionClause = Constants.KEY_GAME + "=? AND " + Constants.KEY_AVAILABLE + "=?"; - selectionArgs = new String[]{game.getName(), String.valueOf(Constants.TRUE)}; - } else if (game != null) { - selectionClause = Constants.KEY_GAME + "=?"; - selectionArgs = new String[]{game.getName()}; - } else if (onlyAvailable) { - selectionClause = Constants.KEY_AVAILABLE + "=?"; - selectionArgs = new String[]{String.valueOf(Constants.TRUE)}; - } else { - selectionClause = null; - selectionArgs = null; - } - - final Cursor cursor = database.query(Constants.TABLE_TRACK, Constants.PROJECTION_TRACK, - selectionClause, selectionArgs, null, null, null, null); - if (cursor != null && cursor.moveToFirst()) { - Log.d(TAG, "getAllTracks: Moving cursor to first."); - } else { - Log.d(TAG, "getAllTracks: cursor is null or cannot be moved to first."); - return null; - } - - final ArrayList allAvailableTrack = new ArrayList<>(); - - do { - final int idIdx = cursor.getColumnIndex(Constants.KEY_ID); - final int nameIdx = cursor.getColumnIndex(Constants.KEY_NAME); - final int gameIdx = cursor.getColumnIndex(Constants.KEY_GAME); - final int packageIdx = cursor.getColumnIndex(Constants.KEY_PACKAGE); - final int numberIdx = cursor.getColumnIndex(Constants.KEY_NUMBER); - final int availableIdx = cursor.getColumnIndex(Constants.KEY_AVAILABLE); - - final Track track = new Track(); - boolean isValid = true; - if (idIdx >= 0) { - track.setId(cursor.getInt(idIdx)); - } else { - Log.d(TAG, "getAllTracks: No such column [" + Constants.KEY_ID + "]"); - isValid = false; - } - - if (nameIdx >= 0) { - track.setName(cursor.getString(nameIdx)); - } else { - Log.d(TAG, "getAllTracks: No such column [" + Constants.KEY_NAME + "]"); - isValid = false; - } - - if (gameIdx >= 0) { - track.setGame(cursor.getString(gameIdx)); - } else { - Log.d(TAG, "getAllTracks: No such column [" + Constants.KEY_GAME + "]"); - isValid = false; - } - - if (packageIdx >= 0) { - track.setPackage(cursor.getString(packageIdx)); - } else { - Log.d(TAG, "getAllTracks: No such column [" + Constants.KEY_PACKAGE + "]"); - isValid = false; - } - - if (numberIdx >= 0) { - track.setPackage(cursor.getString(numberIdx)); - } else { - Log.d(TAG, "getAllTracks: No such column [" + Constants.KEY_NUMBER + "]"); - isValid = false; - } - - if (availableIdx >= 0) { - track.setAvailable(cursor.getInt(availableIdx)); - } else { - Log.d(TAG, "getAllTracks: No such column [" + Constants.KEY_AVAILABLE + "]"); - isValid = false; - } - - if (isValid) { - allAvailableTrack.add(track); - } else { - Log.d(TAG, "getAllTracks: Do not add Track as one or more arguments are invalid."); - } - - } while (cursor.moveToNext()); - - cursor.close(); - database.close(); - - // return contact - return allAvailableTrack; + Log.d(TAG, "getAllTracks: Creating Cursor for Tracks."); + final Cursor cursor = database.query(Constants.TABLE_TRACK, projection, + selection, selectionArgs, null, null, null, null); + return cursor; } /** * Retrieves all Karts from Database. If a Game is provided, all karts of this specific * game will be retrieved. * - * @param game The game of which all tracks should be retrieved. - * @param onlyAvailable If true, only available objects will be returned, otherwise all - * * @return List containing all Kart Objects retrieved from Database. */ - public ArrayList getAllKarts(@Nullable final Game game, - final boolean onlyAvailable) { + public Cursor getAllKarts(final String[] projection, + final String selection, + final String[] selectionArgs) { final SQLiteDatabase database = this.getReadableDatabase(); - final String selectionClause; - final String[] selectionArgs; - if (game != null && onlyAvailable) { - selectionClause = Constants.KEY_GAME + "=? AND " + Constants.KEY_AVAILABLE + "=?"; - selectionArgs = new String[]{game.getName(), String.valueOf(Constants.TRUE)}; - } else if (game != null) { - selectionClause = Constants.KEY_GAME + "=?"; - selectionArgs = new String[]{game.getName()}; - } else if (onlyAvailable) { - selectionClause = Constants.KEY_AVAILABLE + "=?"; - selectionArgs = new String[]{String.valueOf(Constants.TRUE)}; - } else { - selectionClause = null; - selectionArgs = null; - } - - final Cursor cursor = database.query(Constants.TABLE_KART, Constants.PROJECTION_KART, - selectionClause, selectionArgs, null, null, null, null); - if (cursor != null && cursor.moveToFirst()) { - Log.d(TAG, "getAllKarts: Moving cursor to first."); - } else { - Log.d(TAG, "getAllKarts: cursor is null or cannot be moved to first."); - return null; - } - - final ArrayList allAvailableKarts = new ArrayList<>(); - - do { - final int idIdx = cursor.getColumnIndex(Constants.KEY_ID); - final int nameIdx = cursor.getColumnIndex(Constants.KEY_NAME); - final int gameIdx = cursor.getColumnIndex(Constants.KEY_GAME); - final int weightIdx = cursor.getColumnIndex(Constants.KEY_WEIGHT); - final int accessoryIdx = cursor.getColumnIndex(Constants.KEY_ACCESSORY); - final int wheelsIdx = cursor.getColumnIndex(Constants.KEY_WHEELS); - final int freeForAllIdx = cursor.getColumnIndex(Constants.KEY_FREE_FOR_ALL); - final int availableIdx = cursor.getColumnIndex(Constants.KEY_AVAILABLE); - - final Kart kart = new Kart(); - boolean isValid = true; - if (idIdx >= 0) { - kart.setId(cursor.getInt(idIdx)); - } else { - Log.d(TAG, "getAllKarts: No such column [" + Constants.KEY_ID + "]"); - isValid = false; - } - - if (nameIdx >= 0) { - kart.setName(cursor.getString(nameIdx)); - } else { - Log.d(TAG, "getAllKarts: No such column [" + Constants.KEY_NAME + "]"); - isValid = false; - } - - if (gameIdx >= 0) { - kart.setGame(cursor.getString(gameIdx)); - } else { - Log.d(TAG, "getAllKarts: No such column [" + Constants.KEY_GAME + "]"); - isValid = false; - } - - if (weightIdx >= 0) { - kart.setWeight(cursor.getString(weightIdx)); - } else { - Log.d(TAG, "getAllKarts: No such column [" + Constants.KEY_WEIGHT + "]"); - isValid = false; - } - - if (accessoryIdx >= 0) { - kart.setAccessory(cursor.getInt(accessoryIdx)); - } else { - Log.d(TAG, "getAllKarts: No such column [" + Constants.KEY_ACCESSORY + "]"); - isValid = false; - } - - if (wheelsIdx >= 0) { - kart.setWheels(cursor.getInt(wheelsIdx)); - } else { - Log.d(TAG, "getAllKarts: No such column [" + Constants.KEY_WHEELS + "]"); - isValid = false; - } - - if (freeForAllIdx >= 0) { - kart.setFreeForAll(cursor.getInt(freeForAllIdx)); - } else { - Log.d(TAG, "getAllKarts: No such column [" + Constants.KEY_FREE_FOR_ALL + "]"); - isValid = false; - } - - if (availableIdx >= 0) { - kart.setAvailable(cursor.getInt(availableIdx)); - } else { - Log.d(TAG, "getAllKarts: No such column [" + Constants.KEY_AVAILABLE + "]"); - isValid = false; - } - - if (isValid) { - allAvailableKarts.add(kart); - } else { - Log.d(TAG, "getAllKarts: Do not add Kart as one or more arguments are invalid."); - } - - } while (cursor.moveToNext()); - - cursor.close(); - database.close(); - - // return contact - return allAvailableKarts; + Log.d(TAG, "getAllKarts: Creating Cursor for Karts."); + final Cursor cursor = database.query(Constants.TABLE_KART, projection, selection, + selectionArgs, null, null, null, null); + return cursor; } /** * Retrieves all Characters from Database. If a Game is provided, all characters of this * specific game will be retrieved. * - * @param game The game of which all tracks should be retrieved. - * @param onlyAvailable If true, only available objects will be returned, otherwise all + * @param projection The character projection. + * @param selection The selection clause. + * @param selectionArgs The selection arguments. * - * @return List containing all Character Objects retrieved from Database. + * @return Cursor containing all Character Objects retrieved from Database. */ - public ArrayList getAllCharacters(@Nullable final Game game, - final boolean onlyAvailable) { + public Cursor getAllCharacters(final String[] projection, + final String selection, + final String[] selectionArgs) { final SQLiteDatabase database = this.getReadableDatabase(); - final String selectionClause; - final String[] selectionArgs; - if (game != null && onlyAvailable) { - selectionClause = Constants.KEY_GAME + "=? AND " + Constants.KEY_AVAILABLE + "=?"; - selectionArgs = new String[]{game.getName(), String.valueOf(Constants.TRUE)}; - } else if (game != null) { - selectionClause = Constants.KEY_GAME + "=?"; - selectionArgs = new String[]{game.getName()}; - } else if (onlyAvailable) { - selectionClause = Constants.KEY_AVAILABLE + "=?"; - selectionArgs = new String[]{String.valueOf(Constants.TRUE)}; - } else { - selectionClause = null; - selectionArgs = null; - } - + Log.d(TAG, "getAllCharacters: Creating Cursor for Characters."); final Cursor cursor = database.query(Constants.TABLE_CHARACTER, - Constants.PROJECTION_CHARACTER, selectionClause, selectionArgs, null, null, null, + projection, selection, selectionArgs, null, null, null, null); - if (cursor != null && cursor.moveToFirst()) { - Log.d(TAG, "getAllCharacters: Moving cursor to first."); - } else { - Log.d(TAG, "getAllCharacters: cursor is null or cannot be moved to first."); - return null; - } - - final ArrayList allAvailableCharacters = new ArrayList<>(); - - do { - final int idIdx = cursor.getColumnIndex(Constants.KEY_ID); - final int nameIdx = cursor.getColumnIndex(Constants.KEY_NAME); - final int gameIdx = cursor.getColumnIndex(Constants.KEY_GAME); - final int weightIdx = cursor.getColumnIndex(Constants.KEY_WEIGHT); - final int availableIdx = cursor.getColumnIndex(Constants.KEY_AVAILABLE); - - final Character character = new Character(); - boolean isValid = true; - - if (idIdx >= 0) { - character.setId(cursor.getInt(idIdx)); - } else { - Log.d(TAG, "getAllCharacters: No such column [" + Constants.KEY_ID + "]"); - isValid = false; - } - - if (nameIdx >= 0) { - character.setName(cursor.getString(nameIdx)); - } else { - Log.d(TAG, "getAllCharacters: No such column [" + Constants.KEY_NAME + "]"); - isValid = false; - } - - if (gameIdx >= 0) { - character.setGame(cursor.getString(gameIdx)); - } else { - Log.d(TAG, "getAllCharacters: No such column [" + Constants.KEY_GAME + "]"); - isValid = false; - } - - if (weightIdx >= 0) { - character.setWeight(cursor.getString(weightIdx)); - } else { - Log.d(TAG, "getAllCharacters: No such column [" + Constants.KEY_WEIGHT + "]"); - isValid = false; - } - - if (availableIdx >= 0) { - character.setAvailable(cursor.getInt(availableIdx)); - } else { - Log.d(TAG, "getAllCharacters: No such column [" + Constants.KEY_AVAILABLE + "]"); - isValid = false; - } - - if (isValid) { - allAvailableCharacters.add(character); - } else { - Log.d(TAG, "getAllCharacters: Do not add Character as one or more arguments " + - "are invalid."); - } - - } while (cursor.moveToNext()); - - cursor.close(); - database.close(); - - // return contact - return allAvailableCharacters; + return cursor; } /** * Retrieves all Rulesets from Database. If a Game is provided, the ruleset of this specific * game will be retrieved. * - * @param game The game of which all tracks should be retrieved. - * @param onlyAvailable If true, only available objects will be returned, otherwise all - * * @return List containing all Ruleset Objects retrieved from Database. */ - public ArrayList getAllRulesets(@Nullable final Game game, - final boolean onlyAvailable) { + public Cursor getAllRulesets(final String[] projection, + final String selection, + final String[] selectionArgs) { final SQLiteDatabase database = this.getReadableDatabase(); - final String selectionClause; - final String[] selectionArgs; - if (game != null && onlyAvailable) { - selectionClause = Constants.KEY_GAME + "=? AND " + Constants.KEY_AVAILABLE + "=?"; - selectionArgs = new String[]{game.getName(), String.valueOf(Constants.TRUE)}; - } else if (game != null) { - selectionClause = Constants.KEY_GAME + "=?"; - selectionArgs = new String[]{game.getName()}; - } else if (onlyAvailable) { - selectionClause = Constants.KEY_AVAILABLE + "=?"; - selectionArgs = new String[]{String.valueOf(Constants.TRUE)}; - } else { - selectionClause = null; - selectionArgs = null; - } - - final Cursor cursor = database.query(Constants.TABLE_RULESET, Constants.PROJECTION_RULESET, - selectionClause, selectionArgs, null, null, null, null); - if (cursor != null && cursor.moveToFirst()) { - Log.d(TAG, "getAllRulesets: Moving cursor to first."); - } else { - Log.d(TAG, "getAllRulesets: cursor is null or cannot be moved to first."); - return null; - } - final ArrayList allAvailableRulesets = new ArrayList<>(); - do { - final int idIdx = cursor.getColumnIndex(Constants.KEY_ID); - final int gameIdx = cursor.getColumnIndex(Constants.KEY_GAME); - final int mirrorIdx = cursor.getColumnIndex(Constants.KEY_MIRROR_CLASS); - final int ccm50Idx = cursor.getColumnIndex(Constants.KEY_50_CCM); - final int ccm100Idx = cursor.getColumnIndex(Constants.KEY_100_CCM); - final int ccm150Idx = cursor.getColumnIndex(Constants.KEY_150_CCM); - final int ccm200Idx = cursor.getColumnIndex(Constants.KEY_200_CCM); - final int freeForAllIdx = cursor.getColumnIndex(Constants.KEY_KART_FREE_FOR_ALL); - final int bikesIdx = cursor.getColumnIndex(Constants.KEY_BIKES); - - final Ruleset ruleset = new Ruleset(); - boolean isValid = true; - - if (idIdx >= 0) { - ruleset.setId(cursor.getInt(idIdx)); - } else { - Log.d(TAG, "getAllRulesets: No such column [" + Constants.KEY_ID + "]"); - isValid = false; - } - - if (gameIdx >= 0) { - ruleset.setGame(cursor.getString(gameIdx)); - } else { - Log.d(TAG, "getAllRulesets: No such column [" + Constants.KEY_GAME + "]"); - isValid = false; - } - - if (mirrorIdx >= 0) { - ruleset.setGame(cursor.getString(gameIdx)); - } else { - Log.d(TAG, "getAllRulesets: No such column [" + Constants.KEY_GAME + "]"); - isValid = false; - } - - if (ccm50Idx >= 0) { - ruleset.set50CcmAvailable(cursor.getInt(ccm50Idx)); - } else { - Log.d(TAG, "getAllRulesets: No such column [" + Constants.KEY_50_CCM + "]"); - isValid = false; - } - - if (ccm100Idx >= 0) { - ruleset.set100CcmAvailable(cursor.getInt(ccm100Idx)); - } else { - Log.d(TAG, "getAllRulesets: No such column [" + Constants.KEY_100_CCM + "]"); - isValid = false; - } - - if (ccm150Idx >= 0) { - ruleset.set150CcmAvailable(cursor.getInt(ccm150Idx)); - } else { - Log.d(TAG, "getAllRulesets: No such column [" + Constants.KEY_150_CCM + "]"); - isValid = false; - } - - if (ccm200Idx >= 0) { - ruleset.set200CcmAvailable(cursor.getInt(ccm200Idx)); - } else { - Log.d(TAG, "getAllRulesets: No such column [" + Constants.KEY_200_CCM + "]"); - isValid = false; - } - - if (freeForAllIdx >= 0) { - ruleset.setKartsFreeForAll(cursor.getInt(freeForAllIdx)); - } else { - Log.d(TAG, "getAllRulesets: No such column [" + Constants.KEY_KART_FREE_FOR_ALL - + "]"); - isValid = false; - } - - if (bikesIdx >= 0) { - ruleset.setBikesAvailable(cursor.getInt(bikesIdx)); - } else { - Log.d(TAG, "getAllRulesets: No such column [" + Constants.KEY_BIKES + "]"); - isValid = false; - } - - if (isValid) { - allAvailableRulesets.add(ruleset); - } else { - Log.d(TAG, "getAllRulesets: Do not add Ruleset as one or more arguments " + - "are invalid."); - } - - } while (cursor.moveToNext()); - - cursor.close(); - database.close(); - - // return contact - return allAvailableRulesets; + Log.d(TAG, "getAllRulesets: Creating Cursor for Rulesets."); + final Cursor cursor = database.query(Constants.TABLE_RULESET, projection, selection, + selectionArgs, null, null, null, null); + return cursor; } /** * Retrieves all Accessories from Database. If a Game is provided, all accessories of this * specific game will be retrieved. * - * @param game The game of which all tracks should be retrieved. - * @param onlyAvailable If true, only available objects will be returned, otherwise all - * * @return List containing all Accessory Objects retrieved from Database. */ - public ArrayList getAllAccessories(@Nullable final Game game, - final boolean onlyAvailable) { + public Cursor getAllAccessories(final String[] projection, + final String selection, + final String[] selectionArgs) { final SQLiteDatabase database = this.getReadableDatabase(); - final String selectionClause; - final String[] selectionArgs; - if (game != null && onlyAvailable) { - selectionClause = Constants.KEY_GAME + "=? AND " + Constants.KEY_AVAILABLE + "=?"; - selectionArgs = new String[]{game.getName(), String.valueOf(Constants.TRUE)}; - } else if (game != null) { - selectionClause = Constants.KEY_GAME + "=?"; - selectionArgs = new String[]{game.getName()}; - } else if (onlyAvailable) { - selectionClause = Constants.KEY_AVAILABLE + "=?"; - selectionArgs = new String[]{String.valueOf(Constants.TRUE)}; - } else { - selectionClause = null; - selectionArgs = null; - } - final Cursor cursor = database.query(Constants.TABLE_ACCESSORY, - Constants.PROJECTION_ACCESSORY, selectionClause, selectionArgs, null, null, null, + projection, selection, selectionArgs, null, null, null, null); - if (cursor != null && cursor.moveToFirst()) { - Log.d(TAG, "getAllAccessories: Moving cursor to first."); - } else { - Log.d(TAG, "getAllAccessories: cursor is null or cannot be moved to first."); - return null; - } - - - final ArrayList allAvailableAccessories = new ArrayList<>(); - - do { - final int idIdx = cursor.getColumnIndex(Constants.KEY_ID); - final int nameIdx = cursor.getColumnIndex(Constants.KEY_NAME); - final int gameIdx = cursor.getColumnIndex(Constants.KEY_GAME); - final int availableIdx = cursor.getColumnIndex(Constants.KEY_AVAILABLE); - - final Accessory accessory = new Accessory(); - boolean isValid = true; - if (idIdx >= 0) { - accessory.setId(cursor.getInt(idIdx)); - } else { - Log.d(TAG, "getAllAccessories: No such column [" + Constants.KEY_ID + "]"); - isValid = false; - } - - if (nameIdx >= 0) { - accessory.setName(cursor.getString(nameIdx)); - } else { - Log.d(TAG, "getAllAccessories: No such column [" + Constants.KEY_NAME + "]"); - isValid = false; - } - - if (gameIdx >= 0) { - accessory.setGame(cursor.getString(gameIdx)); - } else { - Log.d(TAG, "getAllAccessories: No such column [" + Constants.KEY_GAME + "]"); - isValid = false; - } - - if (availableIdx >= 0) { - accessory.setAvailable(cursor.getInt(availableIdx)); - } else { - Log.d(TAG, "getAllAccessories: No such column [" + Constants.KEY_AVAILABLE + "]"); - isValid = false; - } - - if (isValid) { - allAvailableAccessories.add(accessory); - } else { - Log.d(TAG, "getAllAccessories: Do not add Accessory as one or more arguments " + - "are invalid."); - } - - } while (cursor.moveToNext()); - - cursor.close(); - database.close(); - - // return contact - return allAvailableAccessories; + return cursor; } /** * Retrieves all Wheels from Database. If a Game is provided, all wheels of this specific * game will be retrieved. * - * @param game The game of which all tracks should be retrieved. - * @param onlyAvailable If true, only available objects will be returned, otherwise all - * * @return List containing all Wheels Objects retrieved from Database. */ - public ArrayList getAllWheels(@Nullable final Game game, - final boolean onlyAvailable) { + public Cursor getAllWheels(final String[] projection, + final String selection, + final String[] selectionArgs) { final SQLiteDatabase database = this.getReadableDatabase(); - final String selectionClause; - final String[] selectionArgs; - if (game != null && onlyAvailable) { - selectionClause = Constants.KEY_GAME + "=? AND " + Constants.KEY_AVAILABLE + "=?"; - selectionArgs = new String[]{game.getName(), String.valueOf(Constants.TRUE)}; - } else if (game != null) { - selectionClause = Constants.KEY_GAME + "=?"; - selectionArgs = new String[]{game.getName()}; - } else if (onlyAvailable) { - selectionClause = Constants.KEY_AVAILABLE + "=?"; - selectionArgs = new String[]{String.valueOf(Constants.TRUE)}; - } else { - selectionClause = null; - selectionArgs = null; - } - - final Cursor cursor = database.query(Constants.TABLE_WHEELS, Constants.PROJECTION_WHEELS, - selectionClause, selectionArgs, null, null, null, null); - if (cursor != null && cursor.moveToFirst()) { - Log.d(TAG, "getAllWheels: Moving cursor to first."); - } else { - Log.d(TAG, "getAllWheels: cursor is null or cannot be moved to first."); - return null; - } - - final ArrayList allAvailableWheels = new ArrayList<>(); - - do { - final int idIdx = cursor.getColumnIndex(Constants.KEY_ID); - final int nameIdx = cursor.getColumnIndex(Constants.KEY_NAME); - final int gameIdx = cursor.getColumnIndex(Constants.KEY_GAME); - final int availableIdx = cursor.getColumnIndex(Constants.KEY_AVAILABLE); - - final Wheels wheels = new Wheels(); - boolean isValid = true; - if (idIdx >= 0) { - wheels.setId(cursor.getInt(idIdx)); - } else { - Log.d(TAG, "getAllWheels: No such column [" + Constants.KEY_ID + "]"); - isValid = false; - } - - if (nameIdx >= 0) { - wheels.setName(cursor.getString(nameIdx)); - } else { - Log.d(TAG, "getAllWheels: No such column [" + Constants.KEY_NAME + "]"); - isValid = false; - } - - if (gameIdx >= 0) { - wheels.setGame(cursor.getString(gameIdx)); - } else { - Log.d(TAG, "getAllWheels: No such column [" + Constants.KEY_GAME + "]"); - isValid = false; - } - - if (availableIdx >= 0) { - wheels.setAvailable(cursor.getInt(availableIdx)); - } else { - Log.d(TAG, "getAllWheels: No such column [" + Constants.KEY_AVAILABLE + "]"); - isValid = false; - } - - if (isValid) { - allAvailableWheels.add(wheels); - } else { - Log.d(TAG, "getAllWheels: Do not add Wheels as one or more arguments are invalid."); - } - - } while (cursor.moveToNext()); - - cursor.close(); - database.close(); + final Cursor cursor = database.query(Constants.TABLE_WHEELS, projection, selection, + selectionArgs, null, null, null, null); // return contact - return allAvailableWheels; + return cursor; } /** diff --git a/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/GameSelection.java b/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/GameSelection.java index 248cc24..2febea7 100644 --- a/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/GameSelection.java +++ b/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/GameSelection.java @@ -1,19 +1,12 @@ package com.de.aldo_apps.aldo.mariokartcircuitselector; import android.graphics.Color; -import android.os.AsyncTask; import android.support.v4.view.ViewPager; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; -import com.afollestad.materialdialogs.MaterialDialog; -import com.de.aldo_apps.aldo.mariokartcircuitselector.adapter.PagerItemAdapter; -import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Accessory; -import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Character; -import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Kart; -import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Track; -import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Wheels; +import com.de.aldo_apps.aldo.mariokartcircuitselector.adapters.CursorPagerAdapter; import java.util.ArrayList; @@ -23,19 +16,9 @@ public class GameSelection extends AppCompatActivity { private static final String TAG = "GameSelection"; - private ArrayList mAllKarts = new ArrayList<>(); - private ArrayList mAllCharacters = new ArrayList<>(); - private ArrayList mAllTracks = new ArrayList<>(); - private ArrayList mAllWheels = new ArrayList<>(); - private ArrayList mAllAccessories = new ArrayList<>(); - private final ArrayList> mListOfObjects = new ArrayList<>(); - private DatabaseHandler mDbHandler; - /** - * Progress Bar to show during initial loading of the list. - */ - private MaterialDialog mProgressBar; + private CursorPagerAdapter mAdapter; @Override protected void onCreate(final Bundle savedInstanceState) { @@ -43,32 +26,16 @@ public class GameSelection extends AppCompatActivity { setContentView(R.layout.activity_game_selection); mDbHandler = new DatabaseHandler(this); - showLoading(); - new GetFramDatabaseTask().execute(""); - } - - private void showLoading() { - // Show Loading Bar until all items are loaded. - mProgressBar = new MaterialDialog.Builder(this) - .content("Lade...") - .progress(true, 0) - .show(); - } - - public void hideLoading() { - if (mProgressBar != null) { - mProgressBar.dismiss(); - } + mAdapter = new CursorPagerAdapter(getSupportFragmentManager()); + updateUI(); } public void updateUI() { final String[] colors = getResources().getStringArray(R.array.vertical_ntb); final ViewPager viewPager = (ViewPager) findViewById(R.id.vp_horizontal_ntb); - viewPager.setAdapter(new PagerItemAdapter(getLayoutInflater(), mDbHandler, - this, getSupportFragmentManager(), mListOfObjects)); - + viewPager.setAdapter(mAdapter); final NavigationTabBar navigationTabBar = (NavigationTabBar) findViewById(R.id.ntb_vertical); @@ -153,32 +120,4 @@ public class GameSelection extends AppCompatActivity { } }, 500); } - - - private class GetFramDatabaseTask extends AsyncTask { - - @Override - protected String doInBackground(String... strings) { - mAllKarts = mDbHandler.getAllKarts(null, false); - mAllCharacters = mDbHandler.getAllCharacters(null, false); - mAllTracks = mDbHandler.getAllTracks(null, false); - mAllWheels = mDbHandler.getAllWheels(null, false); - mAllAccessories = mDbHandler.getAllAccessories(null, false); - - return null; - } - - @Override - protected void onPostExecute(String result) { - mListOfObjects.add(mAllKarts); - mListOfObjects.add(mAllCharacters); - mListOfObjects.add(mAllTracks); - mListOfObjects.add(mAllWheels); - mListOfObjects.add(mAllAccessories); - - - updateUI(); - hideLoading(); - } - } } diff --git a/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/KartContentProvider.java b/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/KartContentProvider.java new file mode 100644 index 0000000..12fa659 --- /dev/null +++ b/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/KartContentProvider.java @@ -0,0 +1,111 @@ +package com.de.aldo_apps.aldo.mariokartcircuitselector; + +import android.content.ContentProvider; +import android.content.ContentValues; +import android.content.UriMatcher; +import android.database.Cursor; +import android.net.Uri; +import android.util.Log; + +import com.de.aldo_apps.aldo.mariokartcircuitselector.Constants; +import com.de.aldo_apps.aldo.mariokartcircuitselector.DatabaseHandler; + +/** + * Created by aldo7224 on 16.08.17. + */ + +public class KartContentProvider extends ContentProvider { + + private static final String TAG = "KartProvider"; + public static final String PROVIDER_NAME + = "com.de.aldo_apps.aldo.mariokartcircuitselector"; + + /** + * A uri to do operations on cust_master table. A content provider is identified by its uri + */ + public static final Uri CONTENT_URI = Uri.parse("content://" + PROVIDER_NAME + "/karts"); + + private static final UriMatcher uriMatcher; + + static { + uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); + uriMatcher.addURI(PROVIDER_NAME, "characters", Constants.CHARACTER_LOADER_ID); + uriMatcher.addURI(PROVIDER_NAME, "tracks", Constants.TRACK_LOADER_ID); + uriMatcher.addURI(PROVIDER_NAME, "karts", Constants.KART_LOADER_ID); + uriMatcher.addURI(PROVIDER_NAME, "wheels", Constants.WHEELS_LOADER_ID); + uriMatcher.addURI(PROVIDER_NAME, "accessories", Constants.ACCESSORY_LOADER_ID); + } + + /** + * This content provider does the database operations by this object + */ + DatabaseHandler mHandler; + + /** + * A callback method which is invoked when the content provider is starting up + */ + @Override + public boolean onCreate() { + mHandler = new DatabaseHandler(getContext()); + return true; + } + + @Override + public String getType(final Uri uri) { + return null; + } + + /** + * A callback method which is by the default content uri + */ + @Override + public Cursor query(final Uri uri, + final String[] projection, + final String selection, + final String[] selectionArgs, + final String sortOrder) { + Log.d(TAG, "query: Perform Query for [" + uri + "]"); + + final int resId = uriMatcher.match(uri); + + switch (resId) { + case Constants.CHARACTER_LOADER_ID: + Log.d(TAG, "query: Getting all Characters."); + return mHandler.getAllCharacters(Constants.PROJECTION_CHARACTER, null, null); + case Constants.KART_LOADER_ID: + Log.d(TAG, "query: Getting all Karts."); + return mHandler.getAllKarts(Constants.PROJECTION_KART, null, null); + case Constants.ACCESSORY_LOADER_ID: + Log.d(TAG, "query: Getting all Acessories."); + return mHandler.getAllAccessories(Constants.PROJECTION_ACCESSORY, null, null); + case Constants.TRACK_LOADER_ID: + Log.d(TAG, "query: Getting all Tracks."); + return mHandler.getAllTracks(Constants.PROJECTION_TRACK, null, null); + case Constants.WHEELS_LOADER_ID: + Log.d(TAG, "query: Getting all Wheels."); + return mHandler.getAllWheels(Constants.PROJECTION_WHEELS, null, null); + default: + Log.d(TAG, "query: UriMatcher returned: " + uriMatcher.match(uri)); + return null; + } + } + + @Override + public int delete(final Uri uri, final String selection, final String[] selectionArgs) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public Uri insert(final Uri uri, final ContentValues values) { + // TODO Auto-generated method stub + return null; + } + + @Override + public int update(final Uri uri, final ContentValues values, final String selection, + final String[] selectionArgs) { + // TODO Auto-generated method stub + return 0; + } +} diff --git a/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/PagerType.java b/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/PagerType.java new file mode 100644 index 0000000..1492b5a --- /dev/null +++ b/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/PagerType.java @@ -0,0 +1,13 @@ +package com.de.aldo_apps.aldo.mariokartcircuitselector; + +/** + * Created by aldo7224 on 16.08.17. + */ + +public enum PagerType { + CHARACTER, + KART, + TRACK, + ACCESSORY, + WHEEL +} diff --git a/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/TrackContentProvider.java b/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/TrackContentProvider.java new file mode 100644 index 0000000..29aa560 --- /dev/null +++ b/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/TrackContentProvider.java @@ -0,0 +1,110 @@ +package com.de.aldo_apps.aldo.mariokartcircuitselector; + +import android.content.ContentProvider; +import android.content.ContentValues; +import android.content.UriMatcher; +import android.database.Cursor; +import android.net.Uri; +import android.util.Log; + +import com.de.aldo_apps.aldo.mariokartcircuitselector.Constants; +import com.de.aldo_apps.aldo.mariokartcircuitselector.DatabaseHandler; + +/** + * Created by aldo7224 on 16.08.17. + */ + +public class TrackContentProvider extends ContentProvider { + + private static final String TAG = "TrackProvider"; + public static final String PROVIDER_NAME + = "com.de.aldo_apps.aldo.mariokartcircuitselector"; + + /** + * A uri to do operations on cust_master table. A content provider is identified by its uri + */ + public static final Uri CONTENT_URI = Uri.parse("content://" + PROVIDER_NAME + "/tracks"); + + private static final UriMatcher uriMatcher; + + static { + uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); + uriMatcher.addURI(PROVIDER_NAME, "characters", Constants.CHARACTER_LOADER_ID); + uriMatcher.addURI(PROVIDER_NAME, "tracks", Constants.TRACK_LOADER_ID); + uriMatcher.addURI(PROVIDER_NAME, "karts", Constants.KART_LOADER_ID); + uriMatcher.addURI(PROVIDER_NAME, "wheels", Constants.WHEELS_LOADER_ID); + uriMatcher.addURI(PROVIDER_NAME, "accessories", Constants.ACCESSORY_LOADER_ID); } + + /** + * This content provider does the database operations by this object + */ + DatabaseHandler mHandler; + + /** + * A callback method which is invoked when the content provider is starting up + */ + @Override + public boolean onCreate() { + mHandler = new DatabaseHandler(getContext()); + return true; + } + + @Override + public String getType(final Uri uri) { + return null; + } + + /** + * A callback method which is by the default content uri + */ + @Override + public Cursor query(final Uri uri, + final String[] projection, + final String selection, + final String[] selectionArgs, + final String sortOrder) { + Log.d(TAG, "query: Perform Query for [" + uri + "]"); + + final int resId = uriMatcher.match(uri); + + switch (resId) { + case Constants.CHARACTER_LOADER_ID: + Log.d(TAG, "query: Getting all Characters."); + return mHandler.getAllCharacters(Constants.PROJECTION_CHARACTER, null, null); + case Constants.KART_LOADER_ID: + Log.d(TAG, "query: Getting all Karts."); + return mHandler.getAllKarts(Constants.PROJECTION_KART, null, null); + case Constants.ACCESSORY_LOADER_ID: + Log.d(TAG, "query: Getting all Acessories."); + return mHandler.getAllAccessories(Constants.PROJECTION_ACCESSORY, null, null); + case Constants.TRACK_LOADER_ID: + Log.d(TAG, "query: Getting all Tracks."); + return mHandler.getAllTracks(Constants.PROJECTION_TRACK, null, null); + case Constants.WHEELS_LOADER_ID: + Log.d(TAG, "query: Getting all Wheels."); + return mHandler.getAllWheels(Constants.PROJECTION_WHEELS, null, null); + default: + Log.d(TAG, "query: UriMatcher returned: " + uriMatcher.match(uri)); + return null; + } + } + + @Override + public int delete(final Uri uri, final String selection, final String[] selectionArgs) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public Uri insert(final Uri uri, final ContentValues values) { + // TODO Auto-generated method stub + return null; + } + + @Override + public int update(final Uri uri, final ContentValues values, final String selection, + final String[] selectionArgs) { + // TODO Auto-generated method stub + return 0; + } +} diff --git a/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/WheelsContentProvider.java b/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/WheelsContentProvider.java new file mode 100644 index 0000000..596574c --- /dev/null +++ b/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/WheelsContentProvider.java @@ -0,0 +1,111 @@ +package com.de.aldo_apps.aldo.mariokartcircuitselector; + +import android.content.ContentProvider; +import android.content.ContentValues; +import android.content.UriMatcher; +import android.database.Cursor; +import android.net.Uri; +import android.util.Log; + +import com.de.aldo_apps.aldo.mariokartcircuitselector.Constants; +import com.de.aldo_apps.aldo.mariokartcircuitselector.DatabaseHandler; + +/** + * Created by aldo7224 on 16.08.17. + */ + +public class WheelsContentProvider extends ContentProvider { + + private static final String TAG = "WheelsProvider"; + public static final String PROVIDER_NAME + = "com.de.aldo_apps.aldo.mariokartcircuitselector"; + + /** + * A uri to do operations on cust_master table. A content provider is identified by its uri + */ + public static final Uri CONTENT_URI = Uri.parse("content://" + PROVIDER_NAME + "/wheels"); + + private static final UriMatcher uriMatcher; + + static { + uriMatcher = new UriMatcher(UriMatcher.NO_MATCH); + uriMatcher.addURI(PROVIDER_NAME, "characters", Constants.CHARACTER_LOADER_ID); + uriMatcher.addURI(PROVIDER_NAME, "tracks", Constants.TRACK_LOADER_ID); + uriMatcher.addURI(PROVIDER_NAME, "karts", Constants.KART_LOADER_ID); + uriMatcher.addURI(PROVIDER_NAME, "wheels", Constants.WHEELS_LOADER_ID); + uriMatcher.addURI(PROVIDER_NAME, "accessories", Constants.ACCESSORY_LOADER_ID); + } + + /** + * This content provider does the database operations by this object + */ + DatabaseHandler mHandler; + + /** + * A callback method which is invoked when the content provider is starting up + */ + @Override + public boolean onCreate() { + mHandler = new DatabaseHandler(getContext()); + return true; + } + + @Override + public String getType(final Uri uri) { + return null; + } + + /** + * A callback method which is by the default content uri + */ + @Override + public Cursor query(final Uri uri, + final String[] projection, + final String selection, + final String[] selectionArgs, + final String sortOrder) { + Log.d(TAG, "query: Perform Query for [" + uri + "]"); + + final int resId = uriMatcher.match(uri); + + switch (resId) { + case Constants.CHARACTER_LOADER_ID: + Log.d(TAG, "query: Getting all Characters."); + return mHandler.getAllCharacters(Constants.PROJECTION_CHARACTER, null, null); + case Constants.KART_LOADER_ID: + Log.d(TAG, "query: Getting all Karts."); + return mHandler.getAllKarts(Constants.PROJECTION_KART, null, null); + case Constants.ACCESSORY_LOADER_ID: + Log.d(TAG, "query: Getting all Acessories."); + return mHandler.getAllAccessories(Constants.PROJECTION_ACCESSORY, null, null); + case Constants.TRACK_LOADER_ID: + Log.d(TAG, "query: Getting all Tracks."); + return mHandler.getAllTracks(Constants.PROJECTION_TRACK, null, null); + case Constants.WHEELS_LOADER_ID: + Log.d(TAG, "query: Getting all Wheels."); + return mHandler.getAllWheels(Constants.PROJECTION_WHEELS, null, null); + default: + Log.d(TAG, "query: UriMatcher returned: " + uriMatcher.match(uri)); + return null; + } + } + + @Override + public int delete(final Uri uri, final String selection, final String[] selectionArgs) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public Uri insert(final Uri uri, final ContentValues values) { + // TODO Auto-generated method stub + return null; + } + + @Override + public int update(final Uri uri, final ContentValues values, final String selection, + final String[] selectionArgs) { + // TODO Auto-generated method stub + return 0; + } +} diff --git a/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/adapter/CharacterListAdapter.java b/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/adapter/CharacterListAdapter.java deleted file mode 100644 index 55ed404..0000000 --- a/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/adapter/CharacterListAdapter.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.de.aldo_apps.aldo.mariokartcircuitselector.adapter; - -import android.content.Context; -import android.provider.ContactsContract; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentStatePagerAdapter; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.ListAdapter; - -import com.de.aldo_apps.aldo.mariokartcircuitselector.DatabaseHandler; -import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Character; -import com.de.aldo_apps.aldo.mariokartcircuitselector.fragments.SingleCharacterFragment; - -import java.util.ArrayList; - -/** - * Created by aldo7224 on 10.08.17. - */ - -public class CharacterListAdapter extends ArrayAdapter { - - private ArrayList mList; - - private Context mContext; - - private DatabaseHandler mHandler; - - public CharacterListAdapter(final Context context, final ArrayList characters) { - super(context, 0, characters); - mContext = context; - } - - @Override - public View getView(int position, View convertView, ViewGroup parent) { - SingleCharacterFragment scf = new SingleCharacterFragment(); - final View view = scf.creatView(LayoutInflater.from(mContext)); - scf.initViews(view); - scf.setArguments(mList.get(position), mHandler); - return view; - } - - @Override - public int getCount() { - return mList.size(); - } - - public void setListOfItems(final ArrayList characters) { - mList = characters; - } - - public void setDatabaseHandler(final DatabaseHandler handler) { - mHandler = handler; - } - -} diff --git a/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/adapters/CursorPagerAdapter.java b/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/adapters/CursorPagerAdapter.java new file mode 100644 index 0000000..1d32cc1 --- /dev/null +++ b/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/adapters/CursorPagerAdapter.java @@ -0,0 +1,70 @@ +package com.de.aldo_apps.aldo.mariokartcircuitselector.adapters; + +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentPagerAdapter; +import android.util.Log; + +import com.de.aldo_apps.aldo.mariokartcircuitselector.Constants; +import com.de.aldo_apps.aldo.mariokartcircuitselector.PagerType; +import com.de.aldo_apps.aldo.mariokartcircuitselector.fragments.GenericListFragment; + +public class CursorPagerAdapter extends FragmentPagerAdapter { + + /** + * default constructor. + */ + public CursorPagerAdapter(final FragmentManager fm) { + super(fm); + } + + @Override + public Fragment getItem(int position) { + final Bundle bundle = new Bundle(); + final String[] projection; + final int loaderId; + switch (PagerType.values()[position]) { + case CHARACTER: + projection = Constants.PROJECTION_CHARACTER; + loaderId = Constants.CHARACTER_LOADER_ID; + break; + case KART: + projection = Constants.PROJECTION_KART; + loaderId = Constants.KART_LOADER_ID; + break; + case WHEEL: + projection = Constants.PROJECTION_WHEELS; + loaderId = Constants.WHEELS_LOADER_ID; + break; + case ACCESSORY: + projection = Constants.PROJECTION_ACCESSORY; + loaderId = Constants.ACCESSORY_LOADER_ID; + break; + case TRACK: + projection = Constants.PROJECTION_TRACK; + loaderId = Constants.TRACK_LOADER_ID; + break; + default: + projection = null; + loaderId = Constants.BASE_LOADER_ID; + } + + bundle.putStringArray("FOO", projection); + bundle.putInt("BAR", loaderId); + + Log.d("#####", "getItem: New GenericListFragment with loaderId = [" + loaderId + + "] and projection = [" + projection.toString() + "] on position [" + + position + "]"); + final GenericListFragment genericListFragment = new GenericListFragment(); + genericListFragment.setArguments(bundle); + + return genericListFragment; + } + + @Override + public int getCount() { + // TODO Auto-generated method stub + return PagerType.values().length; + } +} \ No newline at end of file diff --git a/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/fragments/GenericListFragment.java b/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/fragments/GenericListFragment.java new file mode 100644 index 0000000..9a4dd2b --- /dev/null +++ b/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/fragments/GenericListFragment.java @@ -0,0 +1,93 @@ +package com.de.aldo_apps.aldo.mariokartcircuitselector.fragments; + +import android.database.Cursor; +import android.os.Bundle; +import android.support.v4.app.ListFragment; +import android.support.v4.app.LoaderManager; +import android.support.v4.content.CursorLoader; +import android.support.v4.content.Loader; +import android.support.v4.widget.SimpleCursorAdapter; +import android.util.Log; + +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.TrackContentProvider; +import com.de.aldo_apps.aldo.mariokartcircuitselector.WheelsContentProvider; + +/** + * Created by aldo7224 on 16.08.17. + */ + +public class GenericListFragment extends ListFragment implements LoaderManager.LoaderCallbacks { + + private SimpleCursorAdapter mCursorAdapter; + + @Override + public void onCreate(final Bundle bundle) { + super.onCreate(bundle); + + final Bundle bundle2 = getArguments(); + if (bundle2 != null) { + final String[] projection = bundle2.getStringArray("FOO"); + final int loaderId = bundle2.getInt("BAR"); + Log.d("#####", "onCreate: New GenericListFragment with loaderId = [" + loaderId + + "] and projection = [" + projection.toString() + "]"); + final int[] values = new int[] {android.R.id.text1}; + mCursorAdapter = new SimpleCursorAdapter(getContext(), + android.R.layout.simple_list_item_1, + null, Constants.PROJECTION_TEST, values, 0); + + setListAdapter(mCursorAdapter); + + getLoaderManager().initLoader(loaderId, null, this); + } + + + } + + @Override + public CursorLoader onCreateLoader(int id, Bundle args) { + Log.d("########", "onCreateLoader: Creating Loader for ID [" + id + "]"); + switch (id) { + case Constants.CHARACTER_LOADER_ID: + Log.d("####", "onCreateLoader: Creating character loader"); + return new CursorLoader(getContext(), + CharacterContentProvider.CONTENT_URI, + Constants.PROJECTION_CHARACTER, null, null, null); + case Constants.KART_LOADER_ID: + Log.d("####", "onCreateLoader: Creating kart loader"); + return new CursorLoader(getContext(), + KartContentProvider.CONTENT_URI, + Constants.PROJECTION_KART, null, null, null); + case Constants.WHEELS_LOADER_ID: + Log.d("####", "onCreateLoader: Creating kart loader"); + return new CursorLoader(getContext(), + WheelsContentProvider.CONTENT_URI, + Constants.PROJECTION_WHEELS, null, null, null); + case Constants.ACCESSORY_LOADER_ID: + Log.d("####", "onCreateLoader: Creating kart loader"); + return new CursorLoader(getContext(), + AccessoryContentProvider.CONTENT_URI, + Constants.PROJECTION_ACCESSORY, null, null, null); + case Constants.TRACK_LOADER_ID: + Log.d("####", "onCreateLoader: Creating kart loader"); + return new CursorLoader(getContext(), + TrackContentProvider.CONTENT_URI, + Constants.PROJECTION_TRACK, null, null, null); + } + return null; + } + + @Override + public void onLoadFinished(Loader loader, Cursor cursor) { + Log.d("#####", "onLoadFinished: Finished Loading for " + loader.getId()); + mCursorAdapter.swapCursor(cursor); + } + + @Override + public void onLoaderReset(Loader loader) { + mCursorAdapter.swapCursor(null); + } +} diff --git a/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/fragments/PagerItem.java b/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/fragments/PagerItem.java deleted file mode 100644 index b6d0388..0000000 --- a/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/fragments/PagerItem.java +++ /dev/null @@ -1,99 +0,0 @@ -package com.de.aldo_apps.aldo.mariokartcircuitselector.fragments; - -import android.app.Activity; -import android.content.Context; -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.LinearLayout; -import android.widget.ListView; - -import com.de.aldo_apps.aldo.mariokartcircuitselector.DatabaseHandler; -import com.de.aldo_apps.aldo.mariokartcircuitselector.R; -import com.de.aldo_apps.aldo.mariokartcircuitselector.adapter.CharacterListAdapter; -import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Accessory; -import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Character; -import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Kart; -import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Track; -import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Wheels; - -import java.util.ArrayList; - -/** - * Created by aldo7224 on 10.08.17. - */ - -public class PagerItem { - - private static final String TAG = "PagerItem"; - - private View mView; - - private ListView mListView; - - private DatabaseHandler mHandler; - - private Activity mContext; - - private FragmentManager mFragmentManager; - - public PagerItem(final LayoutInflater inflater, - final DatabaseHandler databaseHandler, - final Activity context, - final FragmentManager fragmentManager) { - mView = inflater.inflate(R.layout.pager_item, null, false); - mHandler = databaseHandler; - mContext = context; - mFragmentManager = fragmentManager; - mListView = (ListView) mView.findViewById(R.id.all_items_list_view); - } - - /** - * Helper method which sets the real texts/arguments to the view objects. - * - * @param objects The List of objects of which we will retrieve our texts/arguments. - */ - public void setArguments(final ArrayList objects) { - if (objects.size() > 0) { - final Object bufferTestObject = objects.get(0); - if (bufferTestObject instanceof Character) { - handleCharacterObject((ArrayList) objects); - } else if (bufferTestObject instanceof Kart) { - handleKartObject((ArrayList) objects); - } else if (bufferTestObject instanceof Track) { - handleTrackObject((ArrayList) objects); - } else if (bufferTestObject instanceof Accessory) { - handleAccessoryObject((ArrayList) objects); - } else if (bufferTestObject instanceof Wheels) { - handleWheelsObject((ArrayList) objects); - } - } - } - - private void handleCharacterObject(final ArrayList characters) { - final CharacterListAdapter adapter = new CharacterListAdapter(mContext, characters); - adapter.setListOfItems(characters); - adapter.setDatabaseHandler(mHandler); - mListView.setAdapter(adapter); - } - - private void handleKartObject(final ArrayList karts) { - - } - - private void handleTrackObject(final ArrayList characters) { - - } - - private void handleAccessoryObject(final ArrayList accessories) { - - } - - private void handleWheelsObject(final ArrayList wheels) { - - } -} diff --git a/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/fragments/SingleAccessoryFragment.java b/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/fragments/SingleAccessoryFragment.java deleted file mode 100644 index 9b52bc5..0000000 --- a/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/fragments/SingleAccessoryFragment.java +++ /dev/null @@ -1,133 +0,0 @@ -package com.de.aldo_apps.aldo.mariokartcircuitselector.fragments; - -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.CheckBox; -import android.widget.CompoundButton; -import android.widget.TextView; - -import com.de.aldo_apps.aldo.mariokartcircuitselector.DatabaseHandler; -import com.de.aldo_apps.aldo.mariokartcircuitselector.R; -import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Accessory; - -/** - * The SingleAccessoryFragment which displays all information of a single accessory object. Also - * this fragment handles the onClick. Based on the Click we will toggle the availability of this - * object in the database. - * - * @author aldo7224 - * @version 0.1 - * @since 10.08.2017 - */ -public class SingleAccessoryFragment extends Fragment { - - /** - * The Tag for Debugging Output. - */ - private static final String TAG = "SingleAccessoryFragment"; - - /** - * Checkbox indicating the current availability status of the single accessory object. - */ - private CheckBox mAccessoryAvailable; - - /** - * TextView displaying the name of the single accessory object. - */ - private TextView mAccessoryName; - - /** - * The accessory object assigned to this fragment. - */ - private Accessory mAccessory; - - /** - * The Database handler passed from the activity to handle database operations. - */ - private DatabaseHandler mHandler; - - @Override - public View onCreateView(final LayoutInflater inflater, - final ViewGroup container, - final Bundle savedInstanceState) { - // Inflate the GenericListItem and return it. All Operations on the View will be handled - // in own functions. - return inflater.inflate(R.layout.generic_list_item, container, false); - } - - - @Override - public void onViewCreated(final View view, final Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - - // Initialize the Views and member variables. - // Make all the Visible/Invisible/Gone Actions here as we know which information will be - // shown here. - initViews(view); - view.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(final View view) { - if (mAccessoryAvailable != null) { - mAccessoryAvailable.toggle(); - } - } - }); - } - - /** - * Helper method to initialize all View objects and toggle the visibility as we now know which - * object should be passed into the fragment. - * - * @param view The Parent View. - */ - private void initViews(final View view) { - mAccessoryAvailable = (CheckBox) view.findViewById(R.id.availability_checkbox); - // Assign a CheckedChange Listener to the Checkbox, so we can update the status in the - // database as well. - mAccessoryAvailable.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(final CompoundButton compoundButton, - final boolean availability) { - if (mHandler != null && mAccessory != null) { - mHandler.changeAccessoryAvailability(mAccessory, availability); - } else { - Log.d(TAG, "onCheckedChanged: Either Handler or Accessory are null!"); - } - } - }); - - // Mark the Container as GONE. - final View additionalInfoContainer = view.findViewById(R.id.multiple_information_container); - additionalInfoContainer.setVisibility(View.GONE); - - // Initialize all single views and make them visible. - mAccessoryName = (TextView) view.findViewById(R.id.single_info_name); - mAccessoryName.setVisibility(View.VISIBLE); - - if (mAccessory != null) { - mAccessoryAvailable.setChecked(mAccessory.getAvailable()); - mAccessoryName.setText(mAccessory.getName()); - } - } - - /** - * Helper method which sets the real texts/arguments to the view objects. - * - * @param accessory The Accessory object of which we will retrieve our texts/arguments. - * @param handler The Database handler which handles the database operations. - */ - public void setArguments(final Accessory accessory, final DatabaseHandler handler) { - mAccessory = accessory; - mHandler = handler; - if (mAccessoryAvailable != null) { - mAccessoryAvailable.setChecked(accessory.getAvailable()); - } - if (mAccessoryName != null) { - mAccessoryName.setText(accessory.getName()); - } - } -} diff --git a/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/fragments/SingleCharacterFragment.java b/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/fragments/SingleCharacterFragment.java deleted file mode 100644 index 82daf04..0000000 --- a/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/fragments/SingleCharacterFragment.java +++ /dev/null @@ -1,155 +0,0 @@ -package com.de.aldo_apps.aldo.mariokartcircuitselector.fragments; - -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.CheckBox; -import android.widget.CompoundButton; -import android.widget.LinearLayout; -import android.widget.TextView; - -import com.de.aldo_apps.aldo.mariokartcircuitselector.DatabaseHandler; -import com.de.aldo_apps.aldo.mariokartcircuitselector.R; -import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Character; - -/** - * The SingleCharacterFragment which displays all information of a single character object. Also - * this fragment handles the onClick. Based on the Click we will toggle the availability of this - * object in the database. - * - * @author aldo7224 - * @version 0.1 - * @since 10.08.2017 - */ -public class SingleCharacterFragment { - - /** - * The Tag for Debugging Output. - */ - private static final String TAG = "SingleCharacterFragment"; - - /** - * Checkbox indicating the current availability status of the single character object. - */ - private CheckBox mCharacterAvailable; - - /** - * TextView displaying the name of the single character object. - */ - private TextView mCharacterName; - - /** - * TextView displaying the package (Cup) of the single character object. - */ - private TextView mCharacterWeight; - - /** - * The character object assigned to this fragment. - */ - private Character mCharacter; - - /** - * The Database handler passed from the activity to handle database operations. - */ - private DatabaseHandler mHandler; - - /** - * The View-Instance of this View. - */ - private View mView; - - public View creatView(final LayoutInflater inflater) { - // Inflate the GenericListItem and return it. All Operations on the View will be handled - // in own functions. - Log.d(TAG, "onCreateView: Creating View"); - return inflater.inflate(R.layout.generic_list_item, null, false); - } - - /** - * Helper method to initialize all View objects and toggle the visibility as we now know which - * object should be passed into the fragment. - * - * @param view The Parent View. - */ - public void initViews(final View view) { - mCharacterAvailable = (CheckBox) view.findViewById(R.id.availability_checkbox); - - view.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(final View view) { - if (mCharacterAvailable != null) { - mCharacterAvailable.toggle(); - } - } - }); - // Assign a CheckedChange Listener to the Checkbox, so we can update the status in the - // database as well. - mCharacterAvailable.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(final CompoundButton compoundButton, - final boolean availability) { - if (mHandler != null && mCharacter != null) { - mHandler.changeCharacterAvailability(mCharacter, availability); - } else { - Log.d(TAG, "onCheckedChanged: Either Handler or Character are null!"); - } - } - }); - - // Make the Container Visible. - final View additionalInfoContainer = view.findViewById(R.id.multiple_information_container); - additionalInfoContainer.setVisibility(View.VISIBLE); - - // Initialize all single views and make them visible. - mCharacterName = (TextView) view.findViewById(R.id.multi_view_name); - mCharacterWeight = (TextView) view.findViewById(R.id.additional_info_first); - mCharacterWeight.setVisibility(View.VISIBLE); - final View separator = view.findViewById(R.id.additional_information_separator); - separator.setVisibility(View.GONE); - final View secondInfo = view.findViewById(R.id.additional_info_second); - secondInfo.setVisibility(View.GONE); - - // Mark the single name view (without additional information) as GONE - final View singleName = view.findViewById(R.id.single_info_name); - singleName.setVisibility(View.GONE); - - if (mCharacter != null) { - mCharacterAvailable.setChecked(mCharacter.getAvailable()); - mCharacterName.setText(mCharacter.getName()); - mCharacterWeight.setText(mCharacter.getWeight()); - } - } - - /** - * Helper method which sets the real texts/arguments to the view objects. - * - * @param character The Character object of which we will retrieve our texts/arguments. - * @param handler The Database handler which handles the database operations. - */ - public void setArguments(final Character character, final DatabaseHandler handler) { - mCharacter = character; - mHandler = handler; - if (mCharacterAvailable != null) { - mCharacterAvailable.setChecked(character.getAvailable()); - } - if (mCharacterName != null) { - mCharacterName.setText(character.getName()); - } - if (mCharacterWeight != null) { - mCharacterWeight.setText(character.getWeight()); - } - } - - /** - * Returns the View Instance of this View. - * - * @return the View Instance of this View. - */ - public View getView() { - return mView; - } - -} diff --git a/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/fragments/SingleKartFragment.java b/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/fragments/SingleKartFragment.java deleted file mode 100644 index f1fe4da..0000000 --- a/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/fragments/SingleKartFragment.java +++ /dev/null @@ -1,161 +0,0 @@ -package com.de.aldo_apps.aldo.mariokartcircuitselector.fragments; - -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.CheckBox; -import android.widget.CompoundButton; -import android.widget.TextView; - -import com.de.aldo_apps.aldo.mariokartcircuitselector.DatabaseHandler; -import com.de.aldo_apps.aldo.mariokartcircuitselector.R; -import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Kart; - -/** - * The SingleKartFragment which displays all information of a single kart object. Also this fragment - * handles the onClick. Based on the Click we will toggle the availability of this object in the - * database. - * - * @author aldo7224 - * @version 0.1 - * @since 10.08.2017 - */ -public class SingleKartFragment extends Fragment { - - /** - * The Tag for Debugging Output. - */ - private static final String TAG = "SingleKartFragment"; - - /** - * Checkbox indicating the current availability status of the single kart object. - */ - private CheckBox mKartAvailable; - - /** - * TextView displaying the name of the single kart object. - */ - private TextView mKartName; - - /** - * TextView displaying the weight of the single kart object. - */ - private TextView mKartWeight; - - /** - * TextView displaying the dedicated Driver of the single kart object. - */ - private TextView mKartDedicatedDriver; - - /** - * The kart object assigned to this fragment. - */ - private Kart mKart; - - /** - * The Database handler passed from the activity to handle database operations. - */ - private DatabaseHandler mHandler; - - @Override - public View onCreateView(final LayoutInflater inflater, - final ViewGroup container, - final Bundle savedInstanceState) { - // Inflate the GenericListItem and return it. All Operations on the View will be handled - // in own functions. - return inflater.inflate(R.layout.generic_list_item, container, false); - } - - - @Override - public void onViewCreated(final View view, final Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - - // Initialize the Views and member variables. - // Make all the Visible/Invisible/Gone Actions here as we know which information will be - // shown here. - initViews(view); - view.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(final View view) { - if (mKartAvailable != null) { - mKartAvailable.toggle(); - } - } - }); - } - - /** - * Helper method to initialize all View objects and toggle the visibility as we now know which - * object should be passed into the fragment. - * - * @param view The Parent View. - */ - private void initViews(final View view) { - mKartAvailable = (CheckBox) view.findViewById(R.id.availability_checkbox); - // Assign a CheckedChange Listener to the Checkbox, so we can update the status in the - // database as well. - mKartAvailable.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(final CompoundButton compoundButton, - final boolean availability) { - if (mHandler != null && mKart != null) { - mHandler.changeKartAvailability(mKart, availability); - } else { - Log.d(TAG, "onCheckedChanged: Either Handler or Kart are null!"); - } - } - }); - - // Make the Container Visible. - final View additionalInfoContainer = view.findViewById(R.id.multiple_information_container); - additionalInfoContainer.setVisibility(View.VISIBLE); - - // Initialize all single views and make them visible. - mKartName = (TextView) view.findViewById(R.id.multi_view_name); - mKartWeight = (TextView) view.findViewById(R.id.additional_info_first); - mKartWeight.setVisibility(View.VISIBLE); - final View separator = view.findViewById(R.id.additional_information_separator); - separator.setVisibility(View.VISIBLE); - mKartDedicatedDriver = (TextView) view.findViewById(R.id.additional_info_second); - mKartDedicatedDriver.setVisibility(View.VISIBLE); - - // Mark the single name view (without additional information) as GONE - final View singleName = view.findViewById(R.id.single_info_name); - singleName.setVisibility(View.GONE); - - if (mKart != null) { - mKartAvailable.setChecked(mKart.getAvailable()); - mKartName.setText(mKart.getName()); - mKartWeight.setText(mKart.getWeight()); - mKartDedicatedDriver.setText(mKart.getDedicatedDriver()); - } - } - - /** - * Helper method which sets the real texts/arguments to the view objects. - * - * @param kart The Kart object of which we will retrieve our texts/arguments. - * @param handler The Database handler which handles the database operations. - */ - public void setArguments(final Kart kart, final DatabaseHandler handler) { - mKart = kart; - mHandler = handler; - if (mKartAvailable != null) { - mKartAvailable.setChecked(kart.getAvailable()); - } - if (mKartName != null) { - mKartName.setText(kart.getName()); - } - if (mKartWeight != null) { - mKartWeight.setText(kart.getWeight()); - } - if (mKartDedicatedDriver != null) { - mKartDedicatedDriver.setText(kart.getDedicatedDriver()); - } - } - -} diff --git a/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/fragments/SingleTrackFragment.java b/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/fragments/SingleTrackFragment.java deleted file mode 100644 index 68af948..0000000 --- a/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/fragments/SingleTrackFragment.java +++ /dev/null @@ -1,160 +0,0 @@ -package com.de.aldo_apps.aldo.mariokartcircuitselector.fragments; - -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.CheckBox; -import android.widget.CompoundButton; -import android.widget.TextView; - -import com.de.aldo_apps.aldo.mariokartcircuitselector.DatabaseHandler; -import com.de.aldo_apps.aldo.mariokartcircuitselector.R; -import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Track; - -/** - * The SingleTrackFragment which displays all information of a single track object. Also this - * fragment handles the onClick. Based on the Click we will toggle the availability of this object - * in the database. - * - * @author aldo7224 - * @version 0.1 - * @since 10.08.2017 - */ -public class SingleTrackFragment extends Fragment { - - /** - * The Tag for Debugging Output. - */ - private static final String TAG = "SingleTrackFragment"; - - /** - * Checkbox indicating the current availability status of the single track object. - */ - private CheckBox mTrackAvailable; - - /** - * TextView displaying the name of the single track object. - */ - private TextView mTrackName; - - /** - * TextView displaying the package (Cup) of the single track object. - */ - private TextView mTrackPackage; - - /** - * TextView displaying the number of the single track object. - */ - private TextView mTrackNumber; - - /** - * The track object assigned to this fragment. - */ - private Track mTrack; - - /** - * The Database handler passed from the activity to handle database operations. - */ - private DatabaseHandler mHandler; - - @Override - public View onCreateView(final LayoutInflater inflater, - final ViewGroup container, - final Bundle savedInstanceState) { - // Inflate the GenericListItem and return it. All Operations on the View will be handled - // in own functions. - return inflater.inflate(R.layout.generic_list_item, container, false); - } - - - @Override - public void onViewCreated(final View view, final Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - - // Initialize the Views and member variables. - // Make all the Visible/Invisible/Gone Actions here as we know which information will be - // shown here. - initViews(view); - view.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(final View view) { - if (mTrackAvailable != null) { - mTrackAvailable.toggle(); - } - } - }); - } - - /** - * Helper method to initialize all View objects and toggle the visibility as we now know which - * object should be passed into the fragment. - * - * @param view The Parent View. - */ - private void initViews(final View view) { - mTrackAvailable = (CheckBox) view.findViewById(R.id.availability_checkbox); - // Assign a CheckedChange Listener to the Checkbox, so we can update the status in the - // database as well. - mTrackAvailable.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(final CompoundButton compoundButton, - final boolean availability) { - if (mHandler != null && mTrack != null) { - mHandler.changeTrackAvailability(mTrack, availability); - } else { - Log.d(TAG, "onCheckedChanged: Either Handler or Track are null!"); - } - } - }); - - // Make the Container Visible. - final View additionalInfoContainer = view.findViewById(R.id.multiple_information_container); - additionalInfoContainer.setVisibility(View.VISIBLE); - - // Initialize all single views and make them visible. - mTrackName = (TextView) view.findViewById(R.id.multi_view_name); - mTrackPackage = (TextView) view.findViewById(R.id.additional_info_first); - mTrackPackage.setVisibility(View.VISIBLE); - final View separator = view.findViewById(R.id.additional_information_separator); - separator.setVisibility(View.VISIBLE); - mTrackNumber = (TextView) view.findViewById(R.id.additional_info_second); - mTrackNumber.setVisibility(View.VISIBLE); - - // Mark the single name view (without additional information) as GONE - final View singleName = view.findViewById(R.id.single_info_name); - singleName.setVisibility(View.GONE); - - if (mTrack != null) { - mTrackAvailable.setChecked(mTrack.getAvailable()); - mTrackName.setText(mTrack.getName()); - mTrackPackage.setText(mTrack.getPackage()); - mTrackNumber.setText(mTrack.getNumber()); - } - } - - /** - * Helper method which sets the real texts/arguments to the view objects. - * - * @param track The Track object of which we will retrieve our texts/arguments. - * @param handler The Database handler which handles the database operations. - */ - public void setArguments(final Track track, final DatabaseHandler handler) { - mTrack = track; - mHandler = handler; - if (mTrackAvailable != null) { - mTrackAvailable.setChecked(track.getAvailable()); - } - if (mTrackName != null) { - mTrackName.setText(track.getName()); - } - if (mTrackPackage != null) { - mTrackPackage.setText(track.getPackage()); - } - if (mTrackNumber != null) { - mTrackNumber.setText(track.getNumber()); - } - } -} diff --git a/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/fragments/SingleWheelsFragment.java b/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/fragments/SingleWheelsFragment.java deleted file mode 100644 index 6cbcba2..0000000 --- a/app/src/main/java/com/de/aldo_apps/aldo/mariokartcircuitselector/fragments/SingleWheelsFragment.java +++ /dev/null @@ -1,134 +0,0 @@ -package com.de.aldo_apps.aldo.mariokartcircuitselector.fragments; - -import android.os.Bundle; -import android.support.v4.app.Fragment; -import android.util.Log; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import android.widget.CheckBox; -import android.widget.CompoundButton; -import android.widget.TextView; - -import com.de.aldo_apps.aldo.mariokartcircuitselector.DatabaseHandler; -import com.de.aldo_apps.aldo.mariokartcircuitselector.R; -import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Wheels; - -/** - * The SingleWheelsFragment which displays all information of a single wheels object. Also this - * fragment handles the onClick. Based on the Click we will toggle the availability of this object - * in the database. - * - * @author aldo7224 - * @version 0.1 - * @since 10.08.2017 - */ -public class SingleWheelsFragment extends Fragment { - - /** - * The Tag for Debugging Output. - */ - private static final String TAG = "SingleWheelsFragment"; - - /** - * Checkbox indicating the current availability status of the single wheels object. - */ - private CheckBox mWheelsAvailable; - - /** - * TextView displaying the name of the single wheels object. - */ - private TextView mWheelsName; - - /** - * The wheels object assigned to this fragment. - */ - private Wheels mWheels; - - /** - * The Database handler passed from the activity to handle database operations. - */ - private DatabaseHandler mHandler; - - @Override - public View onCreateView(final LayoutInflater inflater, - final ViewGroup container, - final Bundle savedInstanceState) { - // Inflate the GenericListItem and return it. All Operations on the View will be handled - // in own functions. - return inflater.inflate(R.layout.generic_list_item, container, false); - } - - - @Override - public void onViewCreated(final View view, final Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - - // Initialize the Views and member variables. - // Make all the Visible/Invisible/Gone Actions here as we know which information will be - // shown here. - initViews(view); - view.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(final View view) { - if (mWheelsAvailable != null) { - mWheelsAvailable.toggle(); - } - } - }); - } - - /** - * Helper method to initialize all View objects and toggle the visibility as we now know which - * object should be passed into the fragment. - * - * @param view The Parent View. - */ - private void initViews(final View view) { - mWheelsAvailable = (CheckBox) view.findViewById(R.id.availability_checkbox); - // Assign a CheckedChange Listener to the Checkbox, so we can update the status in the - // database as well. - mWheelsAvailable.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(final CompoundButton compoundButton, - final boolean availability) { - if (mHandler != null && mWheels != null) { - mHandler.changeWheelsAvailability(mWheels, availability); - } else { - Log.d(TAG, "onCheckedChanged: Either Handler or Wheels are null!"); - } - } - }); - - // Mark the Container as GONE. - final View additionalInfoContainer = view.findViewById(R.id.multiple_information_container); - additionalInfoContainer.setVisibility(View.GONE); - - // Initialize all single views and make them visible. - mWheelsName = (TextView) view.findViewById(R.id.single_info_name); - mWheelsName.setVisibility(View.VISIBLE); - - if (mWheels != null) { - mWheelsAvailable.setChecked(mWheels.getAvailable()); - mWheelsName.setText(mWheels.getName()); - } - } - - /** - * Helper method which sets the real texts/arguments to the view objects. - * - * @param wheels The Wheels object of which we will retrieve our texts/arguments. - * @param handler The Database handler which handles the database operations. - */ - public void setArguments(final Wheels wheels, final DatabaseHandler handler) { - mWheels = wheels; - mHandler = handler; - if (mWheelsAvailable != null) { - mWheelsAvailable.setChecked(wheels.getAvailable()); - } - if (mWheelsName != null) { - mWheelsName.setText(wheels.getName()); - } - } - -} diff --git a/app/src/main/res/layout/activity_game_selection.xml b/app/src/main/res/layout/activity_game_selection.xml index ab426c1..38bec06 100644 --- a/app/src/main/res/layout/activity_game_selection.xml +++ b/app/src/main/res/layout/activity_game_selection.xml @@ -1,17 +1,17 @@ - + tools:context="com.de.aldo_apps.aldo.mariokartcircuitselector.GameSelection" + > + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_above="@+id/ntb_vertical"/> - +