Cleanup and Javadoc.
This commit is contained in:
parent
8f993b749d
commit
2750147dc2
11 changed files with 63 additions and 132 deletions
18
.idea/misc.xml
generated
18
.idea/misc.xml
generated
|
|
@ -3,6 +3,24 @@
|
|||
<component name="EntryPointsManager">
|
||||
<entry_points version="2.0" />
|
||||
</component>
|
||||
<component name="JavadocGenerationManager">
|
||||
<option name="OUTPUT_DIRECTORY" />
|
||||
<option name="OPTION_SCOPE" value="protected" />
|
||||
<option name="OPTION_HIERARCHY" value="true" />
|
||||
<option name="OPTION_NAVIGATOR" value="true" />
|
||||
<option name="OPTION_INDEX" value="true" />
|
||||
<option name="OPTION_SEPARATE_INDEX" value="true" />
|
||||
<option name="OPTION_DOCUMENT_TAG_USE" value="false" />
|
||||
<option name="OPTION_DOCUMENT_TAG_AUTHOR" value="false" />
|
||||
<option name="OPTION_DOCUMENT_TAG_VERSION" value="false" />
|
||||
<option name="OPTION_DOCUMENT_TAG_DEPRECATED" value="true" />
|
||||
<option name="OPTION_DEPRECATED_LIST" value="true" />
|
||||
<option name="OTHER_OPTIONS" value="" />
|
||||
<option name="HEAP_SIZE" />
|
||||
<option name="LOCALE" />
|
||||
<option name="OPEN_IN_BROWSER" value="true" />
|
||||
<option name="OPTION_INCLUDE_LIBS" value="false" />
|
||||
</component>
|
||||
<component name="NullableNotNullManager">
|
||||
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
|
||||
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
|
||||
|
|
|
|||
|
|
@ -25,13 +25,15 @@ import java.util.ArrayList;
|
|||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Christopher Beckmann
|
||||
* @version 2.0
|
||||
*/
|
||||
public class SQLiteHelper extends SQLiteAssetHelper {
|
||||
|
||||
private static final String TAG = SQLiteHelper.class.getSimpleName();
|
||||
|
||||
private Context mContext;
|
||||
private static final String DATABASE_NAME = "exercises.sqlite";
|
||||
private static final String DATABASE_PATH = "/data/data/org.secuso.privacyfriendlybreakreminder/databases/";
|
||||
private static final int DATABASE_VERSION = 1;
|
||||
|
||||
private static final String[] deleteQueryList = {
|
||||
|
|
@ -39,37 +41,11 @@ public class SQLiteHelper extends SQLiteAssetHelper {
|
|||
ExerciseLocalColumns.SQL_DELETE_ENTRIES,
|
||||
ExerciseSetColumns.SQL_DELETE_ENTRIES};
|
||||
|
||||
// private boolean onCreate;
|
||||
// private boolean onUpgrade;
|
||||
|
||||
public SQLiteHelper(Context context) {
|
||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||
mContext = context;
|
||||
super.setForcedUpgrade();
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void onOpen(SQLiteDatabase db) {
|
||||
// if (onCreate || onUpgrade) {
|
||||
// onCreate = onUpgrade = false;
|
||||
// copyDatabaseFromAssets(db);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onCreate(SQLiteDatabase db) {
|
||||
// onCreate = true;
|
||||
// }
|
||||
//
|
||||
// public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
// onUpgrade = true;
|
||||
// }
|
||||
//
|
||||
// public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
// onUpgrade(db, oldVersion, newVersion);
|
||||
// }
|
||||
|
||||
|
||||
public synchronized void deleteExerciseSet(long id) {
|
||||
SQLiteDatabase database = getReadableDatabase();
|
||||
database.delete(ExerciseSetColumns.TABLE_NAME, ExerciseSetColumns._ID + " = ?", new String[]{String.valueOf(id)});
|
||||
|
|
@ -182,19 +158,6 @@ public class SQLiteHelper extends SQLiteAssetHelper {
|
|||
"WHERE ES."+ExerciseSetColumns._ID+" = ? AND L."+ExerciseLocalColumns.LANGUAGE+" = ?\n" +
|
||||
"ORDER BY ESE."+ExerciseColumns._ID+" ASC";
|
||||
|
||||
// String sql2 = "SELECT *\n" +
|
||||
// "\tFROM (SELECT * \n" +
|
||||
// "\t\t\tFROM (SELECT *\n" +
|
||||
// "\t\t\t\tFROM "+ExerciseSetColumns.TABLE_NAME+" ES LEFT OUTER JOIN exercise_set_exercises ESE\n" +
|
||||
// "\t\t\t\tON ES."+ExerciseSetColumns._ID+" = ESE."+ExerciseSetColumns._ID+"\n" +
|
||||
// "\t\t\t\tWHERE ES."+ExerciseSetColumns._ID+" = ?\n" +
|
||||
// "\t\t\t\tORDER BY ESE."+ExerciseColumns._ID+" ASC) ES_ESE \n" +
|
||||
// "\t\t\tLEFT OUTER JOIN "+ExerciseColumns.TABLE_NAME+" E\n" +
|
||||
// "\t\t\tON ES_ESE."+ExerciseColumns._ID+" = E."+ExerciseColumns._ID+") ES_ESE_E \n" +
|
||||
// "\t\tLEFT OUTER JOIN "+ExerciseLocalColumns.TABLE_NAME+" L\n" +
|
||||
// "\t\tON ES_ESE_E."+ExerciseColumns._ID+" = L."+ExerciseLocalColumns.EXERCISE_ID+"\n" +
|
||||
// "\t\tWHERE L."+ExerciseLocalColumns.LANGUAGE+" = ?";
|
||||
|
||||
return database.rawQuery(sql, new String[]{String.valueOf(setId), language});
|
||||
}
|
||||
|
||||
|
|
@ -260,14 +223,6 @@ public class SQLiteHelper extends SQLiteAssetHelper {
|
|||
return buildExerciseList(c);
|
||||
}
|
||||
|
||||
public synchronized List<Exercise> getExercisesFromSection(String language, String section) { // TODO: REMOVE after old activities are deleted
|
||||
SQLiteDatabase database = getReadableDatabase();
|
||||
|
||||
Cursor c = database.rawQuery(buildQuery(1), new String[]{language, "%"+section+"%"});
|
||||
|
||||
return buildExerciseList(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* SELECT *
|
||||
* FROM exercises E LEFT OUTER JOIN exercises_local L
|
||||
|
|
@ -331,77 +286,4 @@ public class SQLiteHelper extends SQLiteAssetHelper {
|
|||
|
||||
return sqlQuery.toString();
|
||||
}
|
||||
|
||||
private void copyDataBase(Context context) throws IOException {
|
||||
InputStream myInput = context.getAssets().open(DATABASE_NAME);
|
||||
String outFileName = DATABASE_PATH + DATABASE_NAME;
|
||||
OutputStream myOutput = new FileOutputStream(outFileName);
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
int length;
|
||||
while ((length = myInput.read(buffer)) > 0) {
|
||||
myOutput.write(buffer, 0, length);
|
||||
}
|
||||
|
||||
myOutput.flush();
|
||||
myOutput.close();
|
||||
myInput.close();
|
||||
|
||||
SQLiteDatabase copiedDb = context.openOrCreateDatabase(DATABASE_NAME, 0, null);
|
||||
copiedDb.execSQL("PRAGMA user_version = " + DATABASE_VERSION);
|
||||
copiedDb.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy packaged database from assets folder to the database created in the
|
||||
* application package context.
|
||||
*
|
||||
* @param db
|
||||
* The target database in the application package context.
|
||||
*/
|
||||
private void copyDatabaseFromAssets(SQLiteDatabase db) {
|
||||
Log.i(TAG, "copyDatabase");
|
||||
InputStream myInput = null;
|
||||
OutputStream myOutput = null;
|
||||
try {
|
||||
// Open db packaged as asset as the input stream
|
||||
mContext.deleteDatabase(DATABASE_NAME);
|
||||
|
||||
myInput = mContext.getAssets().open(DATABASE_NAME);
|
||||
|
||||
// Open the db in the application package context:
|
||||
myOutput = new FileOutputStream(db.getPath());
|
||||
|
||||
// Transfer db file contents:
|
||||
byte[] buffer = new byte[1024];
|
||||
int length;
|
||||
while ((length = myInput.read(buffer)) > 0) {
|
||||
myOutput.write(buffer, 0, length);
|
||||
}
|
||||
myOutput.flush();
|
||||
|
||||
// Set the version of the copied database to the current
|
||||
// version:
|
||||
SQLiteDatabase copiedDb = mContext.openOrCreateDatabase(DATABASE_NAME, 0, null);
|
||||
copiedDb.execSQL("PRAGMA user_version = " + DATABASE_VERSION);
|
||||
copiedDb.close();
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new Error(TAG + " Error copying database");
|
||||
} finally {
|
||||
// Close the streams
|
||||
try {
|
||||
if (myOutput != null) {
|
||||
myOutput.close();
|
||||
}
|
||||
if (myInput != null) {
|
||||
myInput.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new Error(TAG + " Error closing streams");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,9 +6,12 @@ import android.database.Cursor;
|
|||
import org.secuso.privacyfriendlybreakreminder.database.data.Exercise;
|
||||
|
||||
/**
|
||||
* Created by Christopher Beckmann on 23.08.2017.
|
||||
* Database representation of an exercise.
|
||||
* @author Christopher Beckmann
|
||||
* @version 2.0
|
||||
* @since 23.08.2017
|
||||
* created 23.08.2017
|
||||
*/
|
||||
|
||||
public final class ExerciseColumns {
|
||||
|
||||
public static final String TABLE_NAME = "exercises";
|
||||
|
|
|
|||
|
|
@ -6,9 +6,12 @@ import android.database.Cursor;
|
|||
import org.secuso.privacyfriendlybreakreminder.database.data.Exercise;
|
||||
|
||||
/**
|
||||
* Created by Christopher Beckmann on 25.08.2017.
|
||||
* Localised strings of an exercise.
|
||||
* @author Christopher Beckmann
|
||||
* @version 2.0
|
||||
* @since 25.08.2017
|
||||
* created 25.08.2017
|
||||
*/
|
||||
|
||||
public final class ExerciseLocalColumns {
|
||||
|
||||
public static final String TABLE_NAME = "exercises_local";
|
||||
|
|
|
|||
|
|
@ -8,9 +8,12 @@ import org.secuso.privacyfriendlybreakreminder.database.data.Exercise;
|
|||
import org.secuso.privacyfriendlybreakreminder.database.data.ExerciseSet;
|
||||
|
||||
/**
|
||||
* Created by Christopher Beckmann on 03.09.2017.
|
||||
* Database columns and utility methods for exercise sets.
|
||||
* @author Christopher Beckmann
|
||||
* @version 2.0
|
||||
* @since 03.09.2017
|
||||
* created 03.09.2017
|
||||
*/
|
||||
|
||||
public final class ExerciseSetColumns {
|
||||
|
||||
public static final String TABLE_NAME = "exercise_set";
|
||||
|
|
|
|||
|
|
@ -7,6 +7,11 @@ import android.support.annotation.IdRes;
|
|||
|
||||
import org.secuso.privacyfriendlybreakreminder.exercises.ExerciseSections;
|
||||
|
||||
/**
|
||||
* Model for an exercise.
|
||||
* @author Christopher Beckmann
|
||||
* @version 2.0
|
||||
*/
|
||||
public class Exercise {
|
||||
private int id;
|
||||
private int localId;
|
||||
|
|
|
|||
|
|
@ -4,9 +4,12 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Christopher Beckmann on 03.09.2017.
|
||||
* Model for an exercise set. It holds {@link Exercise}s.
|
||||
* @author Christopher Beckmann
|
||||
* @version 2.0
|
||||
* @since 03.09.2017
|
||||
* created 03.09.2017
|
||||
*/
|
||||
|
||||
public class ExerciseSet {
|
||||
private long id = -1L;
|
||||
private String name = null;
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ import org.secuso.privacyfriendlybreakreminder.R;
|
|||
import org.secuso.privacyfriendlybreakreminder.database.data.Exercise;
|
||||
|
||||
/**
|
||||
* @author Christopher Beckmann
|
||||
* @version 2.0
|
||||
* Use {@link ExerciseDialog#showExerciseDialog(Context, Exercise)} to show the dialog.
|
||||
*/
|
||||
public final class ExerciseDialog {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import java.util.Locale;
|
|||
/**
|
||||
* This class saves the available languages for the exercises.
|
||||
* @author Christopher Beckmann
|
||||
* @version 2.0
|
||||
*/
|
||||
public final class ExerciseLocale {
|
||||
|
||||
|
|
|
|||
|
|
@ -9,9 +9,12 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by Christopher Beckmann on 06.09.2017.
|
||||
* All available sections.
|
||||
* @author Christopher Beckmann
|
||||
* @version 2.0
|
||||
* @since 06.09.2017
|
||||
* created 06.09.2017
|
||||
*/
|
||||
|
||||
public enum ExerciseSections {
|
||||
Head(R.string.exercise_section_head),
|
||||
Neck(R.string.exercise_section_neck),
|
||||
|
|
@ -21,6 +24,7 @@ public enum ExerciseSections {
|
|||
Pelvis(R.string.exercise_section_pelvis),
|
||||
Legs(R.string.exercise_section_legs);
|
||||
|
||||
|
||||
private final @StringRes int nameResId;
|
||||
|
||||
ExerciseSections(@StringRes int resId) {
|
||||
|
|
|
|||
|
|
@ -31,6 +31,13 @@ import static android.app.PendingIntent.FLAG_CANCEL_CURRENT;
|
|||
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
|
||||
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
|
||||
|
||||
/**
|
||||
* The main timer service. It handles the work timer and sends updates to the notification and the {@link TimerActivity}.
|
||||
* When the work time is up, an alarm will fire to start the exercises.
|
||||
* @author Christopher Beckmann
|
||||
* @version 2.0
|
||||
* @see TimerActivity
|
||||
*/
|
||||
public class TimerService extends Service {
|
||||
|
||||
public static final String TAG = TimerService.class.getSimpleName();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue