Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9494c081d1 | ||
|
|
8967107045 | ||
|
|
8e5791d35e | ||
|
|
05076a01f1 |
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -56,7 +56,7 @@
|
|||||||
<ConfirmationsSetting value="0" id="Add" />
|
<ConfirmationsSetting value="0" id="Add" />
|
||||||
<ConfirmationsSetting value="0" id="Remove" />
|
<ConfirmationsSetting value="0" id="Remove" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectType">
|
<component name="ProjectType">
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
We have three Branches Up and Running:
|
|
||||||
|
|
||||||
MASTER:
|
|
||||||
As soon as enough features are completed so that we have a fully implemented
|
|
||||||
version up and running which contains most/nearly all/all of the function, this
|
|
||||||
will be merged into master.
|
|
||||||
Of course some stable releases will also be merged into master to get a rough
|
|
||||||
overview of where we are.
|
|
||||||
|
|
||||||
FEATURE:
|
|
||||||
All Features that are completed or Milestones that are reached will be merged
|
|
||||||
into the feature branch. Version numbering should only change in the second
|
|
||||||
digit (e.g. 0.1.0 --> 0.2.0).
|
|
||||||
Software pushed to this branch should be a possible stable software release
|
|
||||||
candidate.
|
|
||||||
NOTE: Possible Crashes should of course be fixed, which will result in the
|
|
||||||
last digit being edited into the real release versioning.
|
|
||||||
|
|
||||||
DEVEL:
|
|
||||||
All possible instable intermidiate states should be pushed to devel
|
|
||||||
branch. Version Number is only allowed to be changed in the last digit
|
|
||||||
(e.g. 0.0.1 --> 0.0.2). As soon as a feature is completed -> Merge to
|
|
||||||
FEATURE branch.
|
|
||||||
|
|
||||||
More Branches might be added for some special features or to have a trial
|
|
||||||
branch to try some new features or libraries.
|
|
||||||
These branches MIGHT get deleted afterwards except the feature will be
|
|
||||||
integrated into the final software, then the branch will be left open, to
|
|
||||||
see the progrewss of the project.
|
|
||||||
@@ -7,8 +7,8 @@ android {
|
|||||||
applicationId "com.de.aldo_apps.aldo.mariokartcircuitselector"
|
applicationId "com.de.aldo_apps.aldo.mariokartcircuitselector"
|
||||||
minSdkVersion 16
|
minSdkVersion 16
|
||||||
targetSdkVersion 25
|
targetSdkVersion 25
|
||||||
versionCode 5
|
versionCode 7
|
||||||
versionName "0.1.5"
|
versionName "0.1.7"
|
||||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
|
|||||||
@@ -1,15 +1,19 @@
|
|||||||
package com.de.aldo_apps.aldo.mariokartcircuitselector;
|
package com.de.aldo_apps.aldo.mariokartcircuitselector;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by aldo7224 on 07.08.17.
|
* Constants that are used within the whole project. Therefore we have instantiated them in a single
|
||||||
|
* centralized class.
|
||||||
|
*
|
||||||
|
* @author aldo7224
|
||||||
|
* @version 0.1
|
||||||
|
* @since 07.08.2017
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class Constants {
|
public class Constants {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Version Code of the Database.
|
* The Version Code of the Database.
|
||||||
*/
|
*/
|
||||||
public static final Integer DATABASE_VERSION = 1;
|
static final Integer DATABASE_VERSION = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* As SQLite does not have a native boolean value, we use integers to represent true and false.
|
* As SQLite does not have a native boolean value, we use integers to represent true and false.
|
||||||
@@ -21,151 +25,222 @@ public class Constants {
|
|||||||
* As SQLite does not have a native boolean value, we use integers to represent true and false.
|
* As SQLite does not have a native boolean value, we use integers to represent true and false.
|
||||||
* This is the value for a false statement.
|
* This is the value for a false statement.
|
||||||
*/
|
*/
|
||||||
public final static Integer FALSE = 0;
|
final static Integer FALSE = 0;
|
||||||
|
|
||||||
/**
|
|
||||||
* The Path to the Database
|
|
||||||
*/
|
|
||||||
public static final String DATABASE_PATH
|
|
||||||
= "/data/data/com.de.aldo_apps.aldo.mariokartcircuitselector/databases/";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Name of the complete database.
|
* The Name of the complete database.
|
||||||
*/
|
*/
|
||||||
public static final String DATABASE_NAME = "mario_kart_circuit_selector";
|
static final String DATABASE_NAME = "mario_kart_circuit_selector";
|
||||||
|
|
||||||
/**
|
|
||||||
* Modificator String to modify path of OLD database.
|
|
||||||
*/
|
|
||||||
public static final String DATABASE_OLD = "old_";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the table containing all information according accessories.
|
* The name of the table containing all information according accessories.
|
||||||
*/
|
*/
|
||||||
public static final String TABLE_ACCESSORY = "accessory";
|
static final String TABLE_ACCESSORY = "accessory";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the table containing all information according characters.
|
* The name of the table containing all information according characters.
|
||||||
*/
|
*/
|
||||||
public static final String TABLE_CHARACTER = "character";
|
static final String TABLE_CHARACTER = "character";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the table containing all information according games.
|
* The name of the table containing all information according games.
|
||||||
*/
|
*/
|
||||||
public static final String TABLE_GAME = "game";
|
static final String TABLE_GAME = "game";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the table containing all information according karts.
|
* The name of the table containing all information according karts.
|
||||||
*/
|
*/
|
||||||
public static final String TABLE_KART = "kart";
|
static final String TABLE_KART = "kart";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the table containing all information according rulesets.
|
* The name of the table containing all information according rulesets.
|
||||||
*/
|
*/
|
||||||
public static final String TABLE_RULESET = "ruleset";
|
static final String TABLE_RULESET = "ruleset";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the table containing all information according tracks.
|
* The name of the table containing all information according tracks.
|
||||||
*/
|
*/
|
||||||
public static final String TABLE_TRACK = "track";
|
static final String TABLE_TRACK = "track";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the table containing all information according wheels.
|
* The name of the table containing all information according wheels.
|
||||||
*/
|
*/
|
||||||
public static final String TABLE_WHEELS = "wheels";
|
static final String TABLE_WHEELS = "wheels";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The global KEY for the _id field in the database.
|
* The global KEY for the _id field in the database.
|
||||||
*/
|
*/
|
||||||
public static final String KEY_ID = "_id";
|
static final String KEY_ID = "_id";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The global KEY for the name field in the database.
|
* The global KEY for the name field in the database.
|
||||||
*/
|
*/
|
||||||
public static final String KEY_NAME = "name";
|
static final String KEY_NAME = "name";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The global KEY for the game field in the database.
|
* The global KEY for the game field in the database.
|
||||||
*/
|
*/
|
||||||
public static final String KEY_GAME = "game";
|
static final String KEY_GAME = "game";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The global KEY for the available field in the database.
|
* The global KEY for the available field in the database.
|
||||||
*/
|
*/
|
||||||
public static final String KEY_AVAILABLE = "available";
|
static final String KEY_AVAILABLE = "available";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The global KEY for the weight field in the database.
|
* The global KEY for the weight field in the database.
|
||||||
*/
|
*/
|
||||||
public static final String KEY_WEIGHT = "weight";
|
static final String KEY_WEIGHT = "weight";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The global KEY for the cover uri field in the database.
|
* The global KEY for the cover uri field in the database.
|
||||||
*/
|
*/
|
||||||
public static final String KEY_COVER_URI = "cover_uri";
|
static final String KEY_COVER_URI = "cover_uri";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The global KEY for the wheels field in the database.
|
* The global KEY for the wheels field in the database.
|
||||||
*/
|
*/
|
||||||
public static final String KEY_WHEELS = "wheels";
|
static final String KEY_WHEELS = "wheels";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The global KEY for the accessory field in the database.
|
* The global KEY for the accessory field in the database.
|
||||||
*/
|
*/
|
||||||
public static final String KEY_ACCESSORY = "accessory";
|
static final String KEY_ACCESSORY = "accessory";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The global KEY for the dedicated driver field in the database.
|
* The global KEY for the dedicated driver field in the database.
|
||||||
*/
|
*/
|
||||||
public static final String KEY_DEDICATED_DRIVER = "dedicated_driver";
|
static final String KEY_DEDICATED_DRIVER = "dedicated_driver";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The global KEY for the free for all field in the database.
|
* The global KEY for the free for all field in the database.
|
||||||
*/
|
*/
|
||||||
public static final String KEY_FREE_FOR_ALL = "free_for_all";
|
static final String KEY_FREE_FOR_ALL = "free_for_all";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The global KEY for the mirror class field in the database.
|
* The global KEY for the mirror class field in the database.
|
||||||
*/
|
*/
|
||||||
public static final String KEY_MIRROR_CLASS = "mirror_class";
|
static final String KEY_MIRROR_CLASS = "mirror_class";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The global KEY for the 50 ccm field in the database.
|
* The global KEY for the 50 ccm field in the database.
|
||||||
*/
|
*/
|
||||||
public static final String KEY_50_CCM = "50_ccm";
|
static final String KEY_50_CCM = "50_ccm";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The global KEY for the 100 ccm field in the database.
|
* The global KEY for the 100 ccm field in the database.
|
||||||
*/
|
*/
|
||||||
public static final String KEY_100_CCM = "100_ccm";
|
static final String KEY_100_CCM = "100_ccm";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The global KEY for the 150 ccm field in the database.
|
* The global KEY for the 150 ccm field in the database.
|
||||||
*/
|
*/
|
||||||
public static final String KEY_150_CCM = "150_ccm";
|
static final String KEY_150_CCM = "150_ccm";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The global KEY for the 200 ccm field in the database.
|
* The global KEY for the 200 ccm field in the database.
|
||||||
*/
|
*/
|
||||||
public static final String KEY_200_CCM = "200_ccm";
|
static final String KEY_200_CCM = "200_ccm";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The global KEY for the kart free for all field in the database.
|
* The global KEY for the kart free for all field in the database.
|
||||||
*/
|
*/
|
||||||
public static final String KEY_KART_FREE_FOR_ALL = "kart_free_for_all";
|
static final String KEY_KART_FREE_FOR_ALL = "kart_free_for_all";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The global KEY for the bikes field in the database.
|
* The global KEY for the bikes field in the database.
|
||||||
*/
|
*/
|
||||||
public static final String KEY_BIKES = "bikes";
|
static final String KEY_BIKES = "bikes";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The global KEY for the package field in the database.
|
* The global KEY for the package field in the database.
|
||||||
*/
|
*/
|
||||||
public static final String KEY_PACKAGE = "package";
|
static final String KEY_PACKAGE = "package";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The global KEY for the number field in the database.
|
* The global KEY for the number field in the database.
|
||||||
*/
|
*/
|
||||||
public static final String KEY_NUMBER = "number";
|
static final String KEY_NUMBER = "number";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Projection to retrieve all Information of a game object from database.
|
||||||
|
*/
|
||||||
|
static final String[] PROJECTION_GAME = {
|
||||||
|
KEY_ID,
|
||||||
|
KEY_NAME,
|
||||||
|
KEY_COVER_URI
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Projection to retrieve all Information of a track object from database.
|
||||||
|
*/
|
||||||
|
static final String[] PROJECTION_TRACK = {
|
||||||
|
KEY_ID,
|
||||||
|
KEY_NAME,
|
||||||
|
KEY_GAME,
|
||||||
|
KEY_PACKAGE,
|
||||||
|
KEY_NUMBER,
|
||||||
|
KEY_AVAILABLE
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Projection to retrieve all Information of a character object from database.
|
||||||
|
*/
|
||||||
|
static final String[] PROJECTION_CHARACTER = {
|
||||||
|
KEY_ID,
|
||||||
|
KEY_NAME,
|
||||||
|
KEY_GAME,
|
||||||
|
KEY_WEIGHT,
|
||||||
|
KEY_AVAILABLE
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Projection to retrieve all Information of a kart object from database.
|
||||||
|
*/
|
||||||
|
static final String[] PROJECTION_KART = {
|
||||||
|
KEY_ID,
|
||||||
|
KEY_NAME,
|
||||||
|
KEY_GAME,
|
||||||
|
KEY_WEIGHT,
|
||||||
|
KEY_WHEELS,
|
||||||
|
KEY_ACCESSORY,
|
||||||
|
KEY_DEDICATED_DRIVER,
|
||||||
|
KEY_FREE_FOR_ALL,
|
||||||
|
KEY_AVAILABLE
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Projection to retrieve all Information of a ruleset object from database.
|
||||||
|
*/
|
||||||
|
static final String[] PROJECTION_RULESET = {
|
||||||
|
KEY_ID,
|
||||||
|
KEY_GAME,
|
||||||
|
KEY_MIRROR_CLASS,
|
||||||
|
KEY_50_CCM,
|
||||||
|
KEY_100_CCM,
|
||||||
|
KEY_150_CCM,
|
||||||
|
KEY_200_CCM,
|
||||||
|
KEY_KART_FREE_FOR_ALL,
|
||||||
|
KEY_BIKES
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Projection to retrieve all Information of a accessory object from database.
|
||||||
|
*/
|
||||||
|
static final String[] PROJECTION_ACCESSORY = {
|
||||||
|
KEY_ID,
|
||||||
|
KEY_NAME,
|
||||||
|
KEY_GAME,
|
||||||
|
KEY_AVAILABLE
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Projection to retrieve all Information of a wheels object from database.
|
||||||
|
*/
|
||||||
|
static final String[] PROJECTION_WHEELS = {
|
||||||
|
KEY_ID,
|
||||||
|
KEY_NAME,
|
||||||
|
KEY_GAME,
|
||||||
|
KEY_AVAILABLE
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,29 +5,19 @@ import android.content.Context;
|
|||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.DatabaseUtils;
|
import android.database.DatabaseUtils;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Accessory;
|
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.Character;
|
||||||
|
import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Game;
|
||||||
import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Kart;
|
import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Kart;
|
||||||
|
import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Ruleset;
|
||||||
import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Track;
|
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.database_models.Wheels;
|
||||||
import com.readystatesoftware.sqliteasset.SQLiteAssetHelper;
|
import com.readystatesoftware.sqliteasset.SQLiteAssetHelper;
|
||||||
|
|
||||||
import java.io.FileOutputStream;
|
import java.util.ArrayList;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
import static com.de.aldo_apps.aldo.mariokartcircuitselector.Constants.DATABASE_NAME;
|
|
||||||
import static com.de.aldo_apps.aldo.mariokartcircuitselector.Constants.DATABASE_OLD;
|
|
||||||
import static com.de.aldo_apps.aldo.mariokartcircuitselector.Constants.DATABASE_PATH;
|
|
||||||
import static com.de.aldo_apps.aldo.mariokartcircuitselector.Constants.KEY_AVAILABLE;
|
|
||||||
import static com.de.aldo_apps.aldo.mariokartcircuitselector.Constants.KEY_GAME;
|
|
||||||
import static com.de.aldo_apps.aldo.mariokartcircuitselector.Constants.KEY_ID;
|
|
||||||
import static com.de.aldo_apps.aldo.mariokartcircuitselector.Constants.KEY_NAME;
|
|
||||||
import static com.de.aldo_apps.aldo.mariokartcircuitselector.Constants.TABLE_TRACK;
|
|
||||||
import static com.de.aldo_apps.aldo.mariokartcircuitselector.Constants.TABLE_WHEELS;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Database Handler class which opens/closes connection and handles all CRUD Operations
|
* The Database Handler class which opens/closes connection and handles all CRUD Operations
|
||||||
@@ -44,8 +34,16 @@ public class DatabaseHandler extends SQLiteAssetHelper {
|
|||||||
*/
|
*/
|
||||||
private static final String TAG = "DatabaseHandler";
|
private static final String TAG = "DatabaseHandler";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The context from which this Handler was called.
|
||||||
|
*/
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The default constructor of the DatabaseHandler.
|
||||||
|
*
|
||||||
|
* @param context The context from which this Handler was called.
|
||||||
|
*/
|
||||||
public DatabaseHandler(final Context context) {
|
public DatabaseHandler(final Context context) {
|
||||||
super(context, Constants.DATABASE_NAME, null, Constants.DATABASE_VERSION);
|
super(context, Constants.DATABASE_NAME, null, Constants.DATABASE_VERSION);
|
||||||
mContext = context;
|
mContext = context;
|
||||||
@@ -61,23 +59,25 @@ public class DatabaseHandler extends SQLiteAssetHelper {
|
|||||||
*
|
*
|
||||||
* @param track The track which should be marked as available/unavailable.
|
* @param track The track which should be marked as available/unavailable.
|
||||||
* @param isAvailable The status of availability to be set.
|
* @param isAvailable The status of availability to be set.
|
||||||
|
*
|
||||||
* @return The result code of the update function.
|
* @return The result code of the update function.
|
||||||
*/
|
*/
|
||||||
public int changeTrackAvailability(final Track track, final boolean isAvailable) {
|
public int changeTrackAvailability(final Track track,
|
||||||
|
final boolean isAvailable) {
|
||||||
final SQLiteDatabase db = this.getWritableDatabase();
|
final SQLiteDatabase db = this.getWritableDatabase();
|
||||||
|
|
||||||
final ContentValues values = new ContentValues();
|
final ContentValues values = new ContentValues();
|
||||||
values.put(Constants.KEY_GAME, track.getGame());
|
values.put(Constants.KEY_GAME, track.getGame());
|
||||||
values.put(KEY_NAME, track.getName());
|
values.put(Constants.KEY_NAME, track.getName());
|
||||||
values.put(Constants.KEY_PACKAGE, track.getPackage());
|
values.put(Constants.KEY_PACKAGE, track.getPackage());
|
||||||
values.put(Constants.KEY_NUMBER, track.getmNumber());
|
values.put(Constants.KEY_NUMBER, track.getNumber());
|
||||||
if (isAvailable) {
|
if (isAvailable) {
|
||||||
values.put(KEY_AVAILABLE, Constants.TRUE);
|
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.TRUE));
|
||||||
} else {
|
} else {
|
||||||
values.put(KEY_AVAILABLE, Constants.FALSE);
|
values.put(Constants.KEY_AVAILABLE, Constants.FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return db.update(Constants.TABLE_TRACK, values, KEY_ID + " = ?",
|
return db.update(Constants.TABLE_TRACK, values, Constants.KEY_ID + " = ?",
|
||||||
new String[]{String.valueOf(track.getId())});
|
new String[]{String.valueOf(track.getId())});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,22 +86,24 @@ public class DatabaseHandler extends SQLiteAssetHelper {
|
|||||||
*
|
*
|
||||||
* @param character The character which should be marked as available/unavailable.
|
* @param character The character which should be marked as available/unavailable.
|
||||||
* @param isAvailable The status of availability to be set.
|
* @param isAvailable The status of availability to be set.
|
||||||
|
*
|
||||||
* @return The result code of the update function.
|
* @return The result code of the update function.
|
||||||
*/
|
*/
|
||||||
public int changeCharacterAvailability(final Character character, final boolean isAvailable) {
|
public int changeCharacterAvailability(final Character character,
|
||||||
|
final boolean isAvailable) {
|
||||||
final SQLiteDatabase db = this.getWritableDatabase();
|
final SQLiteDatabase db = this.getWritableDatabase();
|
||||||
|
|
||||||
final ContentValues values = new ContentValues();
|
final ContentValues values = new ContentValues();
|
||||||
values.put(Constants.KEY_GAME, character.getGame());
|
values.put(Constants.KEY_GAME, character.getGame());
|
||||||
values.put(KEY_NAME, character.getName());
|
values.put(Constants.KEY_NAME, character.getName());
|
||||||
values.put(Constants.KEY_WEIGHT, character.getWeight());
|
values.put(Constants.KEY_WEIGHT, character.getWeight());
|
||||||
if (isAvailable) {
|
if (isAvailable) {
|
||||||
values.put(KEY_AVAILABLE, Constants.TRUE);
|
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.TRUE));
|
||||||
} else {
|
} else {
|
||||||
values.put(KEY_AVAILABLE, Constants.FALSE);
|
values.put(Constants.KEY_AVAILABLE, Constants.FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return db.update(Constants.TABLE_CHARACTER, values, KEY_ID + " = ?",
|
return db.update(Constants.TABLE_CHARACTER, values, Constants.KEY_ID + " = ?",
|
||||||
new String[]{String.valueOf(character.getId())});
|
new String[]{String.valueOf(character.getId())});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,26 +112,28 @@ public class DatabaseHandler extends SQLiteAssetHelper {
|
|||||||
*
|
*
|
||||||
* @param kart The kart which should be marked as available/unavailable.
|
* @param kart The kart which should be marked as available/unavailable.
|
||||||
* @param isAvailable The status of availability to be set.
|
* @param isAvailable The status of availability to be set.
|
||||||
|
*
|
||||||
* @return The result code of the update function.
|
* @return The result code of the update function.
|
||||||
*/
|
*/
|
||||||
public int changeKartAvailability(final Kart kart, final boolean isAvailable) {
|
public int changeKartAvailability(final Kart kart,
|
||||||
|
final boolean isAvailable) {
|
||||||
final SQLiteDatabase db = this.getWritableDatabase();
|
final SQLiteDatabase db = this.getWritableDatabase();
|
||||||
|
|
||||||
final ContentValues values = new ContentValues();
|
final ContentValues values = new ContentValues();
|
||||||
values.put(Constants.KEY_GAME, kart.getGame());
|
values.put(Constants.KEY_GAME, kart.getGame());
|
||||||
values.put(KEY_NAME, kart.getName());
|
values.put(Constants.KEY_NAME, kart.getName());
|
||||||
values.put(Constants.KEY_WEIGHT, kart.getWeight());
|
values.put(Constants.KEY_WEIGHT, kart.getWeight());
|
||||||
values.put(Constants.KEY_WHEELS, kart.getWheels());
|
values.put(Constants.KEY_WHEELS, kart.getWheels());
|
||||||
values.put(Constants.KEY_ACCESSORY, kart.getAccessory());
|
values.put(Constants.KEY_ACCESSORY, kart.getAccessory());
|
||||||
values.put(Constants.KEY_DEDICATED_DRIVER, kart.getDedicatedDriver());
|
values.put(Constants.KEY_DEDICATED_DRIVER, kart.getDedicatedDriver());
|
||||||
values.put(Constants.KEY_FREE_FOR_ALL, kart.getFreeForAll());
|
values.put(Constants.KEY_FREE_FOR_ALL, kart.getFreeForAll());
|
||||||
if (isAvailable) {
|
if (isAvailable) {
|
||||||
values.put(KEY_AVAILABLE, Constants.TRUE);
|
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.TRUE));
|
||||||
} else {
|
} else {
|
||||||
values.put(KEY_AVAILABLE, Constants.FALSE);
|
values.put(Constants.KEY_AVAILABLE, Constants.FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return db.update(Constants.TABLE_KART, values, KEY_ID + " = ?",
|
return db.update(Constants.TABLE_KART, values, Constants.KEY_ID + " = ?",
|
||||||
new String[]{String.valueOf(kart.getId())});
|
new String[]{String.valueOf(kart.getId())});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,21 +142,23 @@ public class DatabaseHandler extends SQLiteAssetHelper {
|
|||||||
*
|
*
|
||||||
* @param accessory The accessory which should be marked as available/unavailable.
|
* @param accessory The accessory which should be marked as available/unavailable.
|
||||||
* @param isAvailable The status of availability to be set.
|
* @param isAvailable The status of availability to be set.
|
||||||
|
*
|
||||||
* @return The result code of the update function.
|
* @return The result code of the update function.
|
||||||
*/
|
*/
|
||||||
public int changeAccessoryAvailability(final Accessory accessory, final boolean isAvailable) {
|
public int changeAccessoryAvailability(final Accessory accessory,
|
||||||
|
final boolean isAvailable) {
|
||||||
final SQLiteDatabase db = this.getWritableDatabase();
|
final SQLiteDatabase db = this.getWritableDatabase();
|
||||||
|
|
||||||
final ContentValues values = new ContentValues();
|
final ContentValues values = new ContentValues();
|
||||||
values.put(Constants.KEY_GAME, accessory.getGame());
|
values.put(Constants.KEY_GAME, accessory.getGame());
|
||||||
values.put(KEY_NAME, accessory.getName());
|
values.put(Constants.KEY_NAME, accessory.getName());
|
||||||
if (isAvailable) {
|
if (isAvailable) {
|
||||||
values.put(KEY_AVAILABLE, Constants.TRUE);
|
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.TRUE));
|
||||||
} else {
|
} else {
|
||||||
values.put(KEY_AVAILABLE, Constants.FALSE);
|
values.put(Constants.KEY_AVAILABLE, Constants.FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return db.update(Constants.TABLE_ACCESSORY, values, KEY_ID + " = ?",
|
return db.update(Constants.TABLE_ACCESSORY, values, Constants.KEY_ID + " = ?",
|
||||||
new String[]{String.valueOf(accessory.getId())});
|
new String[]{String.valueOf(accessory.getId())});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,32 +167,740 @@ public class DatabaseHandler extends SQLiteAssetHelper {
|
|||||||
*
|
*
|
||||||
* @param wheels The wheels which should be marked as available/unavailable.
|
* @param wheels The wheels which should be marked as available/unavailable.
|
||||||
* @param isAvailable The status of availability to be set.
|
* @param isAvailable The status of availability to be set.
|
||||||
|
*
|
||||||
* @return The result code of the update function.
|
* @return The result code of the update function.
|
||||||
*/
|
*/
|
||||||
public int changeWheelsAvailability(final Wheels wheels, final boolean isAvailable) {
|
public int changeWheelsAvailability(final Wheels wheels,
|
||||||
|
final boolean isAvailable) {
|
||||||
final SQLiteDatabase db = this.getWritableDatabase();
|
final SQLiteDatabase db = this.getWritableDatabase();
|
||||||
|
|
||||||
final ContentValues values = new ContentValues();
|
final ContentValues values = new ContentValues();
|
||||||
values.put(Constants.KEY_GAME, wheels.getGame());
|
values.put(Constants.KEY_GAME, wheels.getGame());
|
||||||
values.put(KEY_NAME, wheels.getGame());
|
values.put(Constants.KEY_NAME, wheels.getGame());
|
||||||
if (isAvailable) {
|
if (isAvailable) {
|
||||||
values.put(KEY_AVAILABLE, Constants.TRUE);
|
values.put(Constants.KEY_AVAILABLE, String.valueOf(Constants.TRUE));
|
||||||
} else {
|
} else {
|
||||||
values.put(KEY_AVAILABLE, Constants.FALSE);
|
values.put(Constants.KEY_AVAILABLE, Constants.FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
return db.update(TABLE_WHEELS, values, KEY_ID + " = ?",
|
return db.update(Constants.TABLE_WHEELS, values, Constants.KEY_ID + " = ?",
|
||||||
new String[]{String.valueOf(wheels.getId())});
|
new String[]{String.valueOf(wheels.getId())});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------------------------
|
||||||
|
// -------------------------- "G E T A L L" F U N C T I O N S ----------------------------
|
||||||
|
// -------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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<Track> getAllTracks(@Nullable final Game game,
|
||||||
|
final boolean onlyAvailable) {
|
||||||
|
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) {
|
||||||
|
Log.d(TAG, "getAllTracks: Moving cursor to first.");
|
||||||
|
cursor.moveToFirst();
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "getAllTracks: cursor is null");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final ArrayList<Track> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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<Kart> getAllKarts(@Nullable final Game game,
|
||||||
|
final boolean onlyAvailable) {
|
||||||
|
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) {
|
||||||
|
Log.d(TAG, "getAllKarts: Moving cursor to first.");
|
||||||
|
cursor.moveToFirst();
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "getAllKarts: cursor is null");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final ArrayList<Kart> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
* @return List containing all Character Objects retrieved from Database.
|
||||||
|
*/
|
||||||
|
public ArrayList<Character> getAllCharacters(@Nullable final Game game,
|
||||||
|
final boolean onlyAvailable) {
|
||||||
|
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_CHARACTER,
|
||||||
|
Constants.PROJECTION_CHARACTER, selectionClause, selectionArgs, null, null, null,
|
||||||
|
null);
|
||||||
|
|
||||||
|
final ArrayList<Character> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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<Ruleset> getAllRulesets(@Nullable final Game game,
|
||||||
|
final boolean onlyAvailable) {
|
||||||
|
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);
|
||||||
|
|
||||||
|
final ArrayList<Ruleset> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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<Accessory> getAllAccessories(@Nullable final Game game,
|
||||||
|
final boolean onlyAvailable) {
|
||||||
|
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,
|
||||||
|
null);
|
||||||
|
|
||||||
|
final ArrayList<Accessory> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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<Wheels> getAllWheels(@Nullable final Game game,
|
||||||
|
final boolean onlyAvailable) {
|
||||||
|
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) {
|
||||||
|
Log.d(TAG, "getAllWheels: Moving cursor to first.");
|
||||||
|
cursor.moveToFirst();
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "getAllWheels: cursor is null");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final ArrayList<Wheels> 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();
|
||||||
|
|
||||||
|
// return contact
|
||||||
|
return allAvailableWheels;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves all Games from Database.
|
||||||
|
*
|
||||||
|
* @return List containing all Game Objects retrieved from Database.
|
||||||
|
*/
|
||||||
|
public ArrayList<Game> getAllGames() {
|
||||||
|
final SQLiteDatabase database = this.getReadableDatabase();
|
||||||
|
|
||||||
|
final Cursor cursor = database.query(Constants.TABLE_GAME, Constants.PROJECTION_GAME, null,
|
||||||
|
null, null, null, null, null);
|
||||||
|
if (cursor != null) {
|
||||||
|
Log.d(TAG, "getAllGames: Moving cursor to first.");
|
||||||
|
cursor.moveToFirst();
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "getAllGames: cursor is null");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final ArrayList<Game> allAvailableGames = new ArrayList<>();
|
||||||
|
|
||||||
|
do {
|
||||||
|
final int idIdx = cursor.getColumnIndex(Constants.KEY_ID);
|
||||||
|
final int nameIdx = cursor.getColumnIndex(Constants.KEY_NAME);
|
||||||
|
final int coverUriIdx = cursor.getColumnIndex(Constants.KEY_COVER_URI);
|
||||||
|
|
||||||
|
final Game game = new Game();
|
||||||
|
boolean isValid = true;
|
||||||
|
if (idIdx >= 0) {
|
||||||
|
game.setId(cursor.getInt(idIdx));
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "getAllGames: No such column [" + Constants.KEY_ID + "]");
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nameIdx >= 0) {
|
||||||
|
game.setName(cursor.getString(nameIdx));
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "getAllGames: No such column [" + Constants.KEY_NAME + "]");
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (coverUriIdx >= 0) {
|
||||||
|
game.setCoverUri(cursor.getString(coverUriIdx));
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "getAllGames: No such column [" + Constants.KEY_COVER_URI + "]");
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isValid) {
|
||||||
|
allAvailableGames.add(game);
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "getAllGames: Do not add Game as one or more arguments are invalid.");
|
||||||
|
}
|
||||||
|
|
||||||
|
} while (cursor.moveToNext());
|
||||||
|
|
||||||
|
cursor.close();
|
||||||
|
database.close();
|
||||||
|
|
||||||
|
// return contact
|
||||||
|
return allAvailableGames;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------------------------
|
||||||
|
// ------------------------------ T E S T F U N C T I O N S -------------------------------
|
||||||
|
// -------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// TODO: This is only an intermediate state and can be removed later on
|
||||||
public Track testDBConnection(final int id) {
|
public Track testDBConnection(final int id) {
|
||||||
Log.d(TAG, "testDBConnection: Opening Readable Database.");
|
Log.d(TAG, "testDBConnection: Opening Readable Database.");
|
||||||
final SQLiteDatabase database = this.getReadableDatabase();
|
final SQLiteDatabase database = this.getReadableDatabase();
|
||||||
|
|
||||||
Log.d(TAG, "testDBConnection: Query a single track for id = [" + id + "]");
|
Log.d(TAG, "testDBConnection: Query a single track for id = [" + id + "]");
|
||||||
final Cursor cursor = database.query(TABLE_TRACK, new String[]{KEY_ID,
|
final Cursor cursor = database.query(Constants.TABLE_TRACK, new String[]{Constants.KEY_ID,
|
||||||
KEY_NAME, KEY_GAME, KEY_AVAILABLE}, KEY_ID + "=?",
|
Constants.KEY_NAME, Constants.KEY_GAME, Constants.KEY_AVAILABLE},
|
||||||
new String[]{String.valueOf(id)}, null, null, null, null);
|
Constants.KEY_ID + "=?", new String[]{String.valueOf(id)}, null, null, null, null);
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
Log.d(TAG, "testDBConnection: Moving cursor to first.");
|
Log.d(TAG, "testDBConnection: Moving cursor to first.");
|
||||||
cursor.moveToFirst();
|
cursor.moveToFirst();
|
||||||
@@ -197,36 +911,37 @@ public class DatabaseHandler extends SQLiteAssetHelper {
|
|||||||
|
|
||||||
DatabaseUtils.dumpCursor(cursor);
|
DatabaseUtils.dumpCursor(cursor);
|
||||||
|
|
||||||
final int nameIdx = cursor.getColumnIndex(KEY_NAME);
|
final int nameIdx = cursor.getColumnIndex(Constants.KEY_NAME);
|
||||||
final int gameIdx = cursor.getColumnIndex(KEY_GAME);
|
final int gameIdx = cursor.getColumnIndex(Constants.KEY_GAME);
|
||||||
final int idIdx = cursor.getColumnIndex(KEY_ID);
|
final int idIdx = cursor.getColumnIndex(Constants.KEY_ID);
|
||||||
final int availableIdx = cursor.getColumnIndex(KEY_AVAILABLE);
|
final int availableIdx = cursor.getColumnIndex(Constants.KEY_AVAILABLE);
|
||||||
|
|
||||||
if (nameIdx < 0) {
|
if (nameIdx < 0) {
|
||||||
Log.d(TAG, "testDBConnection: No such column [" + KEY_NAME + "]");
|
Log.d(TAG, "testDBConnection: No such column [" + Constants.KEY_NAME + "]");
|
||||||
}
|
}
|
||||||
if (gameIdx < 0) {
|
if (gameIdx < 0) {
|
||||||
Log.d(TAG, "testDBConnection: No such column [" + KEY_GAME + "]");
|
Log.d(TAG, "testDBConnection: No such column [" + Constants.KEY_GAME + "]");
|
||||||
}
|
}
|
||||||
if (idIdx < 0) {
|
if (idIdx < 0) {
|
||||||
Log.d(TAG, "testDBConnection: No such column [" + KEY_ID + "]");
|
Log.d(TAG, "testDBConnection: No such column [" + Constants.KEY_ID + "]");
|
||||||
}
|
}
|
||||||
if (availableIdx < 0) {
|
if (availableIdx < 0) {
|
||||||
Log.d(TAG, "testDBConnection: No such column [" + KEY_AVAILABLE + "]");
|
Log.d(TAG, "testDBConnection: No such column [" + Constants.KEY_AVAILABLE + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (availableIdx >= 0 && idIdx >= 0 && gameIdx >= 0 && nameIdx >= 0) {
|
if (availableIdx >= 0 && idIdx >= 0 && gameIdx >= 0 && nameIdx >= 0) {
|
||||||
final Track track = new Track();
|
final Track track = new Track();
|
||||||
track.setName(cursor.getString(cursor.getColumnIndex(KEY_NAME)));
|
track.setName(cursor.getString(nameIdx));
|
||||||
track.setGame(cursor.getString(cursor.getColumnIndex(KEY_GAME)));
|
track.setGame(cursor.getString(gameIdx));
|
||||||
track.setId(Integer.parseInt(cursor.getString(cursor.getColumnIndex(KEY_ID))));
|
track.setId(Integer.parseInt(cursor.getString(idIdx)));
|
||||||
track.setAvailable(Integer.parseInt(cursor.getString(cursor.getColumnIndex(KEY_AVAILABLE))));
|
track.setAvailable(Integer.parseInt(cursor.getString(availableIdx)));
|
||||||
database.close();
|
database.close();
|
||||||
|
|
||||||
// return contact
|
// return contact
|
||||||
return track;
|
return track;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
cursor.close();
|
||||||
database.close();
|
database.close();
|
||||||
|
|
||||||
// return contact
|
// return contact
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.de.aldo_apps.aldo.mariokartcircuitselector;
|
package com.de.aldo_apps.aldo.mariokartcircuitselector;
|
||||||
|
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -13,7 +12,7 @@ import com.de.aldo_apps.aldo.mariokartcircuitselector.database_models.Track;
|
|||||||
public class GameSelection extends AppCompatActivity {
|
public class GameSelection extends AppCompatActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(final Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_game_selection);
|
setContentView(R.layout.activity_game_selection);
|
||||||
|
|
||||||
@@ -27,7 +26,7 @@ public class GameSelection extends AppCompatActivity {
|
|||||||
|
|
||||||
button.setOnClickListener(new View.OnClickListener() {
|
button.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(final View view) {
|
||||||
final int id = Integer.parseInt(editText.getText().toString());
|
final int id = Integer.parseInt(editText.getText().toString());
|
||||||
final Track track = handler.testDBConnection(id);
|
final Track track = handler.testDBConnection(id);
|
||||||
if (track != null) {
|
if (track != null) {
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ public class Track {
|
|||||||
*
|
*
|
||||||
* @return the number of the track within the package.
|
* @return the number of the track within the package.
|
||||||
*/
|
*/
|
||||||
public int getmNumber() {
|
public int getNumber() {
|
||||||
return mNumber;
|
return mNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,7 +161,7 @@ public class Track {
|
|||||||
*
|
*
|
||||||
* @param number the number of the track within the package.
|
* @param number the number of the track within the package.
|
||||||
*/
|
*/
|
||||||
public void setmNumber(int number) {
|
public void setNumber(int number) {
|
||||||
mNumber = number;
|
mNumber = number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,124 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
mAccessoryAvailable.setChecked(accessory.getAvailable());
|
||||||
|
mAccessoryName.setText(accessory.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
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.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 extends Fragment {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
@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 (mCharacterAvailable != null) {
|
||||||
|
mCharacterAvailable.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) {
|
||||||
|
mCharacterAvailable = (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.
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
mCharacterAvailable.setChecked(character.getAvailable());
|
||||||
|
mCharacterName.setText(character.getName());
|
||||||
|
mCharacterWeight.setText(character.getWeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,146 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
mKartAvailable.setChecked(kart.getAvailable());
|
||||||
|
mKartName.setText(kart.getName());
|
||||||
|
mKartWeight.setText(kart.getWeight());
|
||||||
|
mKartDedicatedDriver.setText(kart.getDedicatedDriver());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,145 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
mTrackAvailable.setChecked(track.getAvailable());
|
||||||
|
mTrackName.setText(track.getName());
|
||||||
|
mTrackPackage.setText(track.getPackage());
|
||||||
|
mTrackNumber.setText(track.getNumber());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,125 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
mWheelsAvailable.setChecked(wheels.getAvailable());
|
||||||
|
mWheelsName.setText(wheels.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
63
app/src/main/res/layout/generic_list_item.xml
Normal file
63
app/src/main/res/layout/generic_list_item.xml
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:orientation="horizontal" android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content" android:layout_centerHorizontal="true">
|
||||||
|
|
||||||
|
<!-- CheckBox indicating the current availability status -->
|
||||||
|
<CheckBox
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/availability_checkbox"/>
|
||||||
|
|
||||||
|
<!-- LinearLayout container which holds multiple TextViews for multiple information
|
||||||
|
(e.g. name and weight) -->
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:id="@+id/multiple_information_container">
|
||||||
|
|
||||||
|
<!-- The TextView containing the objects name -->
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/multi_view_name" />
|
||||||
|
|
||||||
|
<!-- LinearLayout which aligns the additional information properly -->
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<!-- TextView holding the first value (e.g. weight) -->
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/additional_info_first" />
|
||||||
|
|
||||||
|
<!-- TextView which has a function as a separator between the first and the second
|
||||||
|
value -->
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/additional_information_separator"
|
||||||
|
android:layout_marginLeft="@dimen/separator_margin"
|
||||||
|
android:layout_marginRight="@dimen/separator_margin"
|
||||||
|
android:text="@string/separator"/>
|
||||||
|
|
||||||
|
<!-- TextView holding the second value (e.g. dedicated driver) -->
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/additional_info_second"
|
||||||
|
/>
|
||||||
|
</LinearLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<!-- TextView which simply holds a name without additional information -->
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:id="@+id/single_info_name"
|
||||||
|
android:visibility="gone"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
6
app/src/main/res/values/dimens.xml
Normal file
6
app/src/main/res/values/dimens.xml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<dimen name="separator_margin">10dp</dimen>
|
||||||
|
|
||||||
|
|
||||||
|
</resources>
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">MarioKartCircuitSelector</string>
|
<string name="app_name">MarioKartCircuitSelector</string>
|
||||||
|
|
||||||
|
<string name="separator">-</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user