From a45eacf9b83f1b8709018ae0eb301eb737901e8e Mon Sep 17 00:00:00 2001 From: cpfeiffer Date: Sun, 17 Apr 2016 19:52:51 +0200 Subject: [PATCH] WIP: schema update, ... #206 --- .../gadgetbridge/daogen/GBDaoGenerator.java | 24 ++++++++++++++----- .../gadgetbridge/GBApplication.java | 17 +++++++++++++ .../gadgetbridge/activities/GBActivity.java | 5 ++++ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java b/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java index 5d1cb4579..3d14794c3 100644 --- a/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java +++ b/GBDaoGenerator/src/nodomain/freeyourgadget/gadgetbridge/daogen/GBDaoGenerator.java @@ -38,7 +38,8 @@ public class GBDaoGenerator { Entity deviceAttributes = addDeviceAttributes(schema); Entity device = addDevice(schema, deviceAttributes); - addActivitySample(schema, user, device); + addMiBandActivitySample(schema, user, device); + addPebbleActivitySample(schema, user, device); new DaoGenerator().generateAll(schema, "app/src/main/java"); } @@ -93,20 +94,31 @@ public class GBDaoGenerator { return deviceAttributes; } - private static Entity addActivitySample(Schema schema, Entity user, Entity device) { + private static Entity addMiBandActivitySample(Schema schema, Entity user, Entity device) { // public GBActivitySample(SampleProvider provider, int timestamp, int intensity, int steps, int type, int customValue) { - Entity activitySample = schema.addEntity("ActivitySample"); + Entity activitySample = schema.addEntity("MiBandActivitySample"); + addCommonAcivitySampleProperties(schema, activitySample, user, device); + activitySample.addIntProperty("heartrate"); + return activitySample; + } + + private static Entity addPebbleActivitySample(Schema schema, Entity user, Entity device) { +// public GBActivitySample(SampleProvider provider, int timestamp, int intensity, int steps, int type, int customValue) { + Entity activitySample = schema.addEntity("PebbleActivitySample"); + addCommonAcivitySampleProperties(schema, activitySample, user, device); +// activitySample.addIntProperty("heartrate").notNull(); + return activitySample; + } + + private static void addCommonAcivitySampleProperties(Schema schema, Entity activitySample, Entity user, Entity device) { activitySample.addIdProperty(); activitySample.addIntProperty("timestamp").notNull(); activitySample.addIntProperty("intensity").notNull(); activitySample.addIntProperty("steps").notNull(); activitySample.addIntProperty("type").notNull(); - activitySample.addIntProperty("customValue").notNull(); Property userId = activitySample.addLongProperty("userId").getProperty(); activitySample.addToOne(user, userId); Property deviceId = activitySample.addLongProperty("deviceId").getProperty(); activitySample.addToOne(device, deviceId); - - return activitySample; } } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java index f292133af..2667274b8 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/GBApplication.java @@ -6,6 +6,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; +import android.database.sqlite.SQLiteDatabase; import android.os.Build; import android.os.Build.VERSION; import android.preference.PreferenceManager; @@ -25,6 +26,8 @@ import java.util.concurrent.locks.ReentrantLock; import nodomain.freeyourgadget.gadgetbridge.database.ActivityDatabaseHandler; import nodomain.freeyourgadget.gadgetbridge.database.DBConstants; import nodomain.freeyourgadget.gadgetbridge.database.DBHandler; +import nodomain.freeyourgadget.gadgetbridge.entities.DaoMaster; +import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceService; import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser; import nodomain.freeyourgadget.gadgetbridge.model.DeviceService; @@ -50,6 +53,7 @@ public class GBApplication extends Application { //if preferences have to be migrated, increment the following and add the migration logic in migratePrefs below; see http://stackoverflow.com/questions/16397848/how-can-i-migrate-android-preferences-with-a-new-version private static final int CURRENT_PREFS_VERSION = 2; private static LimitedQueue mIDSenderLookup = new LimitedQueue(16); + private static DaoSession daoSession; public static final String ACTION_QUIT = "nodomain.freeyourgadget.gadgetbridge.gbapplication.action.quit"; @@ -99,6 +103,8 @@ public class GBApplication extends Application { // StatusPrinter.print(lc); // Logger logger = LoggerFactory.getLogger(GBApplication.class); + setupDatabase(); + deviceService = createDeviceService(); GB.environment = GBEnvironment.createDeviceEnvironment(); mActivityDatabaseHandler = new ActivityDatabaseHandler(context); @@ -151,6 +157,17 @@ public class GBApplication extends Application { return LoggerFactory.getLogger(GBApplication.class); } + private void setupDatabase() { + DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "test-db", null); + SQLiteDatabase db = helper.getWritableDatabase(); + DaoMaster daoMaster = new DaoMaster(db); + daoSession = daoMaster.newSession(); + } + + public static DaoSession getDaoSession() { + return daoSession; + } + public static Context getContext() { return context; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/GBActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/GBActivity.java index 39c972ea1..5eb566b8c 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/GBActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/GBActivity.java @@ -6,6 +6,7 @@ import android.support.v7.app.AppCompatActivity; import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; +import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession; public class GBActivity extends AppCompatActivity { @@ -19,4 +20,8 @@ public class GBActivity extends AppCompatActivity { super.onCreate(savedInstanceState); } + + protected DaoSession getDAOSession() { + return GBApplication.getDaoSession(); + } }