mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-27 20:36:51 +01:00
WIP: schema update, ... #206
This commit is contained in:
parent
97cac282c8
commit
a45eacf9b8
@ -38,7 +38,8 @@ public class GBDaoGenerator {
|
|||||||
Entity deviceAttributes = addDeviceAttributes(schema);
|
Entity deviceAttributes = addDeviceAttributes(schema);
|
||||||
Entity device = addDevice(schema, deviceAttributes);
|
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");
|
new DaoGenerator().generateAll(schema, "app/src/main/java");
|
||||||
}
|
}
|
||||||
@ -93,20 +94,31 @@ public class GBDaoGenerator {
|
|||||||
return deviceAttributes;
|
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) {
|
// 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.addIdProperty();
|
||||||
activitySample.addIntProperty("timestamp").notNull();
|
activitySample.addIntProperty("timestamp").notNull();
|
||||||
activitySample.addIntProperty("intensity").notNull();
|
activitySample.addIntProperty("intensity").notNull();
|
||||||
activitySample.addIntProperty("steps").notNull();
|
activitySample.addIntProperty("steps").notNull();
|
||||||
activitySample.addIntProperty("type").notNull();
|
activitySample.addIntProperty("type").notNull();
|
||||||
activitySample.addIntProperty("customValue").notNull();
|
|
||||||
Property userId = activitySample.addLongProperty("userId").getProperty();
|
Property userId = activitySample.addLongProperty("userId").getProperty();
|
||||||
activitySample.addToOne(user, userId);
|
activitySample.addToOne(user, userId);
|
||||||
Property deviceId = activitySample.addLongProperty("deviceId").getProperty();
|
Property deviceId = activitySample.addLongProperty("deviceId").getProperty();
|
||||||
activitySample.addToOne(device, deviceId);
|
activitySample.addToOne(device, deviceId);
|
||||||
|
|
||||||
return activitySample;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Build.VERSION;
|
import android.os.Build.VERSION;
|
||||||
import android.preference.PreferenceManager;
|
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.ActivityDatabaseHandler;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.database.DBConstants;
|
import nodomain.freeyourgadget.gadgetbridge.database.DBConstants;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
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.impl.GBDeviceService;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceService;
|
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
|
//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 final int CURRENT_PREFS_VERSION = 2;
|
||||||
private static LimitedQueue mIDSenderLookup = new LimitedQueue(16);
|
private static LimitedQueue mIDSenderLookup = new LimitedQueue(16);
|
||||||
|
private static DaoSession daoSession;
|
||||||
|
|
||||||
public static final String ACTION_QUIT
|
public static final String ACTION_QUIT
|
||||||
= "nodomain.freeyourgadget.gadgetbridge.gbapplication.action.quit";
|
= "nodomain.freeyourgadget.gadgetbridge.gbapplication.action.quit";
|
||||||
@ -99,6 +103,8 @@ public class GBApplication extends Application {
|
|||||||
// StatusPrinter.print(lc);
|
// StatusPrinter.print(lc);
|
||||||
// Logger logger = LoggerFactory.getLogger(GBApplication.class);
|
// Logger logger = LoggerFactory.getLogger(GBApplication.class);
|
||||||
|
|
||||||
|
setupDatabase();
|
||||||
|
|
||||||
deviceService = createDeviceService();
|
deviceService = createDeviceService();
|
||||||
GB.environment = GBEnvironment.createDeviceEnvironment();
|
GB.environment = GBEnvironment.createDeviceEnvironment();
|
||||||
mActivityDatabaseHandler = new ActivityDatabaseHandler(context);
|
mActivityDatabaseHandler = new ActivityDatabaseHandler(context);
|
||||||
@ -151,6 +157,17 @@ public class GBApplication extends Application {
|
|||||||
return LoggerFactory.getLogger(GBApplication.class);
|
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() {
|
public static Context getContext() {
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import android.support.v7.app.AppCompatActivity;
|
|||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||||
|
|
||||||
|
|
||||||
public class GBActivity extends AppCompatActivity {
|
public class GBActivity extends AppCompatActivity {
|
||||||
@ -19,4 +20,8 @@ public class GBActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected DaoSession getDAOSession() {
|
||||||
|
return GBApplication.getDaoSession();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user