From 34aead6c63f18f5bd2a353c6f3743a7becbf373f Mon Sep 17 00:00:00 2001 From: Andreas Shimokawa Date: Fri, 26 Aug 2016 23:36:54 +0200 Subject: [PATCH] remove obsolte stuff --- .../activities/ControlCenter.java | 1 - .../database/ActivityDatabaseHandler.java | 211 ------------------ .../gadgetbridge/database/EntitiesTest.java | 3 +- .../service/AbstractServiceTestCase.java | 2 - .../DeviceCommunicationServiceTestCase.java | 1 - .../gadgetbridge/test/GBMockApplication.java | 2 +- 6 files changed, 3 insertions(+), 217 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenter.java index 09d6b6de7..a247a4877 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenter.java @@ -339,7 +339,6 @@ public class ControlCenter extends GBActivity { if (device.isConnected() || device.isConnecting()) { connectedDevice = device; if (device.isInitialized()) { - LOG.info("will try"); try (DBHandler dbHandler = GBApplication.acquireDB()) { DaoSession session = dbHandler.getDaoSession(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/ActivityDatabaseHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/ActivityDatabaseHandler.java index 1e941ee1a..1521fbfb6 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/ActivityDatabaseHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/database/ActivityDatabaseHandler.java @@ -37,8 +37,6 @@ import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.TABLE_GB // TODO: can be removed entirely public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHandler { - private static final Logger LOG = LoggerFactory.getLogger(ActivityDatabaseHandler.class); - private static final int DATABASE_VERSION = 7; private static final String UPDATER_CLASS_NAME_PREFIX = "ActivityDBUpdate_"; @@ -71,96 +69,6 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHandl return super.getWritableDatabase(); } - public void addGBActivitySample(ActivitySample sample) { - try (SQLiteDatabase db = this.getWritableDatabase()) { - ContentValues values = new ContentValues(); - values.put(KEY_TIMESTAMP, sample.getTimestamp()); - values.put(KEY_PROVIDER, sample.getProvider().getID()); - values.put(KEY_INTENSITY, sample.getRawIntensity()); - values.put(KEY_STEPS, sample.getSteps()); -// values.put(KEY_CUSTOM_SHORT, sample.getCustomValue()); - values.put(KEY_TYPE, sample.getRawKind()); - - db.insert(TABLE_GBACTIVITYSAMPLES, null, values); - } - } - - /** - * Adds the a new sample to the database - * - * @param timestamp the timestamp of the same, second-based! - * @param provider the SampleProvider ID - * @param intensity the sample's raw intensity value - * @param steps the sample's steps value - * @param kind the raw activity kind of the sample - * @param customShortValue - */ - public void addGBActivitySample(AbstractActivitySample sample) { - float intensity = sample.getIntensity(); - int steps = sample.getSteps(); - int kind = sample.getRawKind(); - int timestamp = sample.getTimestamp(); - int customShortValue = 0; - - if (intensity < 0) { - LOG.error("negative intensity received, ignoring"); - intensity = 0; - } - if (steps < 0) { - LOG.error("negative steps received, ignoring"); - steps = 0; - } - - if (customShortValue < 0) { - LOG.error("negative short value received, ignoring"); - customShortValue = 0; - } - - try (SQLiteDatabase db = this.getWritableDatabase()) { - ContentValues values = new ContentValues(); - values.put(KEY_TIMESTAMP, timestamp); -// values.put(KEY_PROVIDER, provider); - values.put(KEY_INTENSITY, intensity); - values.put(KEY_STEPS, steps); - values.put(KEY_TYPE, kind); - values.put(KEY_CUSTOM_SHORT, customShortValue); - - db.insert(TABLE_GBACTIVITYSAMPLES, null, values); - } - } - - public void addGBActivitySamples(AbstractActivitySample[] activitySamples) { - try (SQLiteDatabase db = this.getWritableDatabase()) { - - String sql = "INSERT INTO " + TABLE_GBACTIVITYSAMPLES + " (" + KEY_TIMESTAMP + "," + - KEY_PROVIDER + "," + KEY_INTENSITY + "," + KEY_STEPS + "," + KEY_TYPE + "," + KEY_CUSTOM_SHORT + ")" + - " VALUES (?,?,?,?,?,?);"; - SQLiteStatement statement = db.compileStatement(sql); - db.beginTransaction(); - - for (ActivitySample activitySample : activitySamples) { - statement.clearBindings(); - statement.bindLong(1, activitySample.getTimestamp()); - statement.bindLong(2, activitySample.getProvider().getID()); - statement.bindLong(3, activitySample.getRawIntensity()); - statement.bindLong(4, activitySample.getSteps()); - statement.bindLong(5, activitySample.getRawKind()); -// statement.bindLong(6, activitySample.getCustomValue()); - statement.execute(); - } - db.setTransactionSuccessful(); - db.endTransaction(); - } - } - - public ArrayList getSleepSamples(int timestamp_from, int timestamp_to, SampleProvider provider) { - return getGBActivitySamples(timestamp_from, timestamp_to, ActivityKind.TYPE_SLEEP, provider); - } - - public ArrayList getActivitySamples(int timestamp_from, int timestamp_to, SampleProvider provider) { - return getGBActivitySamples(timestamp_from, timestamp_to, ActivityKind.TYPE_ACTIVITY, provider); - } - @Override public void closeDb() { } @@ -174,125 +82,6 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHandl return this; } - public ArrayList getAllActivitySamples(int timestamp_from, int timestamp_to, SampleProvider provider) { - return getGBActivitySamples(timestamp_from, timestamp_to, ActivityKind.TYPE_ALL, provider); - } - - public ArrayList getAllActivitySamples() { - return getActivitySamples(null, "timestamp", null); - } - - /** - * Returns all available activity samples from between the two timestamps (inclusive), of the given - * provided and type(s). - * - * @param timestamp_from - * @param timestamp_to - * @param activityTypes ORed combination of #TYPE_DEEP_SLEEP, #TYPE_LIGHT_SLEEP, #TYPE_ACTIVITY - * @param provider the producer of the samples to be sought - * @return - */ - private ArrayList getGBActivitySamples(int timestamp_from, int timestamp_to, int activityTypes, SampleProvider provider) { - if (timestamp_to < 0) { - throw new IllegalArgumentException("negative timestamp_to"); - } - if (timestamp_from < 0) { - throw new IllegalArgumentException("negative timestamp_from"); - } - final String where = "(provider=" + provider.getID() + " and timestamp>=" + timestamp_from + " and timestamp<=" + timestamp_to + getWhereClauseFor(activityTypes, provider) + ")"; - LOG.info("Activity query where: " + where); - final String order = "timestamp"; - - ArrayList samples = getActivitySamples(where, order, null); - - return samples; - } - - private ArrayList getActivitySamples(String where, String order, SampleProvider provider) { - ArrayList samples = new ArrayList<>(); - try (SQLiteDatabase db = this.getReadableDatabase()) { - try (Cursor cursor = db.query(TABLE_GBACTIVITYSAMPLES, null, where, null, null, null, order)) { - LOG.info("Activity query result: " + cursor.getCount() + " samples"); - int colTimeStamp = cursor.getColumnIndex(KEY_TIMESTAMP); - int colIntensity = cursor.getColumnIndex(KEY_INTENSITY); - int colSteps = cursor.getColumnIndex(KEY_STEPS); - int colType = cursor.getColumnIndex(KEY_TYPE); - int colCustomShort = cursor.getColumnIndex(KEY_CUSTOM_SHORT); - while (cursor.moveToNext()) { - GBActivitySample sample = new GBActivitySample( - provider, - cursor.getInt(colTimeStamp), - cursor.getInt(colIntensity), - cursor.getInt(colSteps), - cursor.getInt(colType), - cursor.getInt(colCustomShort)); - samples.add(sample); - } - } - } - return samples; - } - - private String getWhereClauseFor(int activityTypes, SampleProvider provider) { - if (activityTypes == ActivityKind.TYPE_ALL) { - return ""; // no further restriction - } - - StringBuilder builder = new StringBuilder(" and ("); - int[] dbActivityTypes = ActivityKind.mapToDBActivityTypes(activityTypes, provider); - for (int i = 0; i < dbActivityTypes.length; i++) { - builder.append(" type=").append(dbActivityTypes[i]); - if (i + 1 < dbActivityTypes.length) { - builder.append(" or "); - } - } - builder.append(')'); - return builder.toString(); - } - - public void changeStoredSamplesType(int timestampFrom, int timestampTo, int kind, SampleProvider provider) { - try (SQLiteDatabase db = this.getReadableDatabase()) { - String sql = "UPDATE " + TABLE_GBACTIVITYSAMPLES + " SET " + KEY_TYPE + "= ? WHERE " - + KEY_PROVIDER + " = ? AND " - + KEY_TIMESTAMP + " >= ? AND " + KEY_TIMESTAMP + " < ? ;"; //do not use BETWEEN because the range is inclusive in that case! - - SQLiteStatement statement = db.compileStatement(sql); - statement.bindLong(1, kind); - statement.bindLong(2, provider.getID()); - statement.bindLong(3, timestampFrom); - statement.bindLong(4, timestampTo); - statement.execute(); - } - } - - public void changeStoredSamplesType(int timestampFrom, int timestampTo, int fromKind, int toKind, SampleProvider provider) { - try (SQLiteDatabase db = this.getReadableDatabase()) { - String sql = "UPDATE " + TABLE_GBACTIVITYSAMPLES + " SET " + KEY_TYPE + "= ? WHERE " - + KEY_TYPE + " = ? AND " - + KEY_PROVIDER + " = ? AND " - + KEY_TIMESTAMP + " >= ? AND " + KEY_TIMESTAMP + " < ? ;"; //do not use BETWEEN because the range is inclusive in that case! - - SQLiteStatement statement = db.compileStatement(sql); - statement.bindLong(1, toKind); - statement.bindLong(2, fromKind); - statement.bindLong(3, provider.getID()); - statement.bindLong(4, timestampFrom); - statement.bindLong(5, timestampTo); - statement.execute(); - } - } - - public int fetchLatestTimestamp(SampleProvider provider) { - try (SQLiteDatabase db = this.getReadableDatabase()) { - try (Cursor cursor = db.query(TABLE_GBACTIVITYSAMPLES, new String[]{KEY_TIMESTAMP}, KEY_PROVIDER + "=" + String.valueOf(provider.getID()), null, null, null, KEY_TIMESTAMP + " DESC", "1")) { - if (cursor.moveToFirst()) { - return cursor.getInt(0); - } - } - } - return -1; - } - public boolean hasContent() { try { try (SQLiteDatabase db = this.getReadableDatabase()) { diff --git a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/database/EntitiesTest.java b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/database/EntitiesTest.java index c4f331d29..9a2fc039b 100644 --- a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/database/EntitiesTest.java +++ b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/database/EntitiesTest.java @@ -33,7 +33,8 @@ import static junit.framework.Assert.assertNotNull; import static junit.framework.Assert.assertNull; @RunWith(RobolectricTestRunner.class) -@Config(constants = BuildConfig.class, sdk = 19) // need sdk 19 because "WITHOUT ROWID" is not supported in robolectric/sqlite4java +@Config(constants = BuildConfig.class, sdk = 19) +// need sdk 19 because "WITHOUT ROWID" is not supported in robolectric/sqlite4java public class EntitiesTest { private DaoSession daoSession; diff --git a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractServiceTestCase.java b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractServiceTestCase.java index b3b426bfd..802c5607e 100644 --- a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractServiceTestCase.java +++ b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/AbstractServiceTestCase.java @@ -5,9 +5,7 @@ import android.app.NotificationManager; import android.app.Service; import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; import android.content.pm.PackageManager; -import android.preference.PreferenceManager; import junit.framework.Assert; diff --git a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationServiceTestCase.java b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationServiceTestCase.java index 8fa5ea5f7..cd9ff019c 100644 --- a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationServiceTestCase.java +++ b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/service/DeviceCommunicationServiceTestCase.java @@ -1,6 +1,5 @@ package nodomain.freeyourgadget.gadgetbridge.service; -import android.app.Application; import android.app.NotificationManager; import android.content.Context; diff --git a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/test/GBMockApplication.java b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/test/GBMockApplication.java index 2fb2ffbff..f833453ff 100644 --- a/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/test/GBMockApplication.java +++ b/app/src/test/java/nodomain/freeyourgadget/gadgetbridge/test/GBMockApplication.java @@ -1,7 +1,6 @@ package nodomain.freeyourgadget.gadgetbridge.test; import android.content.Context; -import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.preference.PreferenceManager; import android.test.mock.MockApplication; @@ -37,6 +36,7 @@ public class GBMockApplication extends MockApplication { public Prefs getPrefs() { return prefs; } + public GBPrefs getGBPrefs() { return gbPrefs; }