2016-05-16 23:54:51 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.database;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2016-06-16 21:54:53 +02:00
|
|
|
import android.database.Cursor;
|
2016-05-16 23:54:51 +02:00
|
|
|
import android.database.sqlite.SQLiteDatabase;
|
2016-06-17 00:07:50 +02:00
|
|
|
import android.support.annotation.Nullable;
|
2016-05-16 23:54:51 +02:00
|
|
|
|
2016-06-16 21:54:53 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2016-05-16 23:54:51 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.database.schema.SchemaMigration;
|
2016-06-16 21:54:53 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractSampleProvider;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample;
|
2016-05-16 23:54:51 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.entities.DaoMaster;
|
2016-06-16 21:54:53 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.entities.User;
|
2016-06-17 00:07:50 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
2016-06-16 21:54:53 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.HeartRateSample;
|
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
|
|
|
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_CUSTOM_SHORT;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_INTENSITY;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_STEPS;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_TIMESTAMP;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_TYPE;
|
|
|
|
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.TABLE_GBACTIVITYSAMPLES;
|
2016-05-16 23:54:51 +02:00
|
|
|
|
|
|
|
public class DBOpenHelper extends DaoMaster.OpenHelper {
|
2016-06-16 21:54:53 +02:00
|
|
|
private final String updaterClassNamePrefix;
|
|
|
|
private final Context context;
|
|
|
|
|
2016-05-16 23:54:51 +02:00
|
|
|
public DBOpenHelper(Context context, String dbName, SQLiteDatabase.CursorFactory factory) {
|
|
|
|
super(context, dbName, factory);
|
2016-06-16 21:54:53 +02:00
|
|
|
updaterClassNamePrefix = dbName + "Update_";
|
|
|
|
this.context = context;
|
|
|
|
}
|
|
|
|
|
2016-05-16 23:54:51 +02:00
|
|
|
@Override
|
|
|
|
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
2016-06-16 21:54:53 +02:00
|
|
|
new SchemaMigration(updaterClassNamePrefix).onUpgrade(db, oldVersion, newVersion);
|
2016-05-16 23:54:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
2016-06-16 21:54:53 +02:00
|
|
|
new SchemaMigration(updaterClassNamePrefix).onDowngrade(db, oldVersion, newVersion);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Context getContext() {
|
|
|
|
return context;
|
2016-05-16 23:54:51 +02:00
|
|
|
}
|
|
|
|
}
|