mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-04 01:09:47 +01:00
More WIP: remove now unused code, better use of generics
This commit is contained in:
parent
40a376bbd0
commit
876bdac918
@ -39,52 +39,13 @@ public class LockHandler implements DBHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ActivitySample> getAllActivitySamples(int tsFrom, int tsTo, SampleProvider provider) {
|
||||
return provider.getAllActivitySamples(tsFrom, tsTo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ActivitySample> getActivitySamples(int tsFrom, int tsTo, SampleProvider provider) {
|
||||
return provider.getActivitySamples(tsFrom, tsTo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ActivitySample> getSleepSamples(int tsFrom, int tsTo, SampleProvider provider) {
|
||||
return provider.getSleepSamples(tsFrom, tsTo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fetchLatestTimestamp(SampleProvider provider) {
|
||||
return provider.fetchLatestTimestamp();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DaoSession getDaoSession() {
|
||||
return session;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGBActivitySample(AbstractActivitySample sample) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGBActivitySamples(AbstractActivitySample[] activitySamples) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public SQLiteDatabase getWritableDatabase() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeStoredSamplesType(int timestampFrom, int timestampTo, int kind, SampleProvider provider) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeStoredSamplesType(int timestampFrom, int timestampTo, int fromKind, int toKind, SampleProvider provider) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ import nodomain.freeyourgadget.gadgetbridge.database.DBAccess;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
||||
@ -293,7 +294,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||
return akActivity.color;
|
||||
}
|
||||
|
||||
protected SampleProvider getProvider(DBHandler db, GBDevice device) {
|
||||
protected SampleProvider<AbstractActivitySample> getProvider(DBHandler db, GBDevice device) {
|
||||
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
|
||||
return coordinator.getSampleProvider(db);
|
||||
}
|
||||
@ -306,27 +307,27 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||
* @param tsFrom
|
||||
* @param tsTo
|
||||
*/
|
||||
protected List<ActivitySample> getAllSamples(DBHandler db, GBDevice device, int tsFrom, int tsTo) {
|
||||
SampleProvider provider = getProvider(db, device);
|
||||
return db.getAllActivitySamples(tsFrom, tsTo, provider);
|
||||
protected List<? extends ActivitySample> getAllSamples(DBHandler db, GBDevice device, int tsFrom, int tsTo) {
|
||||
SampleProvider<? extends ActivitySample> provider = getProvider(db, device);
|
||||
return provider.getAllActivitySamples(tsFrom, tsTo);
|
||||
}
|
||||
|
||||
private int getTSLast24Hours(int tsTo) {
|
||||
return (tsTo) - (24 * 60 * 60); // -24 hours
|
||||
}
|
||||
|
||||
protected List<ActivitySample> getActivitySamples(DBHandler db, GBDevice device, int tsFrom, int tsTo) {
|
||||
SampleProvider provider = getProvider(db, device);
|
||||
return db.getActivitySamples(tsFrom, tsTo, provider);
|
||||
protected List<? extends ActivitySample> getActivitySamples(DBHandler db, GBDevice device, int tsFrom, int tsTo) {
|
||||
SampleProvider<AbstractActivitySample> provider = getProvider(db, device);
|
||||
return provider.getActivitySamples(tsFrom, tsTo);
|
||||
}
|
||||
|
||||
|
||||
protected List<ActivitySample> getSleepSamples(DBHandler db, GBDevice device, int tsFrom, int tsTo) {
|
||||
SampleProvider provider = getProvider(db, device);
|
||||
return db.getSleepSamples(tsFrom, tsTo, provider);
|
||||
protected List<? extends ActivitySample> getSleepSamples(DBHandler db, GBDevice device, int tsFrom, int tsTo) {
|
||||
SampleProvider<? extends ActivitySample> provider = getProvider(db, device);
|
||||
return provider.getSleepSamples(tsFrom, tsTo);
|
||||
}
|
||||
|
||||
protected List<ActivitySample> getTestSamples(DBHandler db, GBDevice device, int tsFrom, int tsTo) {
|
||||
protected List<? extends ActivitySample> getTestSamples(DBHandler db, GBDevice device, int tsFrom, int tsTo) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.clear();
|
||||
cal.set(2015, Calendar.JUNE, 10, 6, 40);
|
||||
@ -334,8 +335,8 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||
tsTo = (int) ((cal.getTimeInMillis() / 1000));
|
||||
tsFrom = tsTo - (24 * 60 * 60);
|
||||
|
||||
SampleProvider provider = getProvider(db, device);
|
||||
return db.getAllActivitySamples(tsFrom, tsTo, provider);
|
||||
SampleProvider<? extends ActivitySample> provider = getProvider(db, device);
|
||||
return provider.getAllActivitySamples(tsFrom, tsTo);
|
||||
}
|
||||
|
||||
protected void configureChartDefaults(Chart<?> chart) {
|
||||
@ -398,7 +399,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||
*/
|
||||
protected abstract void renderCharts();
|
||||
|
||||
protected DefaultChartsData refresh(GBDevice gbDevice, List<ActivitySample> samples) {
|
||||
protected DefaultChartsData refresh(GBDevice gbDevice, List<? extends ActivitySample> samples) {
|
||||
Calendar cal = GregorianCalendar.getInstance();
|
||||
cal.clear();
|
||||
Date date;
|
||||
@ -541,7 +542,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||
* @param tsTo
|
||||
* @return
|
||||
*/
|
||||
protected abstract List<ActivitySample> getSamples(DBHandler db, GBDevice device, int tsFrom, int tsTo);
|
||||
protected abstract List<? extends ActivitySample> getSamples(DBHandler db, GBDevice device, int tsFrom, int tsTo);
|
||||
|
||||
protected abstract void setupLegend(Chart chart);
|
||||
|
||||
@ -689,7 +690,7 @@ public abstract class AbstractChartFragment extends AbstractGBFragment {
|
||||
}
|
||||
}
|
||||
|
||||
protected List<ActivitySample> getSamples(DBHandler db, GBDevice device) {
|
||||
protected List<? extends ActivitySample> getSamples(DBHandler db, GBDevice device) {
|
||||
return getSamples(db, device, getTSStart(), getTSEnd());
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
||||
|
||||
public class ActivityAnalysis {
|
||||
public ActivityAmounts calculateActivityAmounts(List<ActivitySample> samples) {
|
||||
public ActivityAmounts calculateActivityAmounts(List<? extends ActivitySample> samples) {
|
||||
ActivityAmount deepSleep = new ActivityAmount(ActivityKind.TYPE_DEEP_SLEEP);
|
||||
ActivityAmount lightSleep = new ActivityAmount(ActivityKind.TYPE_LIGHT_SLEEP);
|
||||
ActivityAmount notWorn = new ActivityAmount(ActivityKind.TYPE_NOT_WORN);
|
||||
@ -66,7 +66,7 @@ public class ActivityAnalysis {
|
||||
return result;
|
||||
}
|
||||
|
||||
public int calculateTotalSteps(List<ActivitySample> samples) {
|
||||
public int calculateTotalSteps(List<? extends ActivitySample> samples) {
|
||||
int totalSteps = 0;
|
||||
for (ActivitySample sample : samples) {
|
||||
totalSteps += sample.getSteps();
|
||||
|
@ -108,7 +108,7 @@ public class ActivitySleepChartFragment extends AbstractChartFragment {
|
||||
|
||||
@Override
|
||||
protected ChartsData refreshInBackground(ChartsHost chartsHost, DBHandler db, GBDevice device) {
|
||||
List<ActivitySample> samples = getSamples(db, device);
|
||||
List<? extends ActivitySample> samples = getSamples(db, device);
|
||||
return refresh(device, samples);
|
||||
}
|
||||
|
||||
@ -142,7 +142,7 @@ public class ActivitySleepChartFragment extends AbstractChartFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<ActivitySample> getSamples(DBHandler db, GBDevice device, int tsFrom, int tsTo) {
|
||||
protected List<? extends ActivitySample> getSamples(DBHandler db, GBDevice device, int tsFrom, int tsTo) {
|
||||
return getAllSamples(db, device, tsFrom, tsTo);
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ public class SleepChartFragment extends AbstractChartFragment {
|
||||
|
||||
@Override
|
||||
protected ChartsData refreshInBackground(ChartsHost chartsHost, DBHandler db, GBDevice device) {
|
||||
List<ActivitySample> samples = getSamples(db, device);
|
||||
List<? extends ActivitySample> samples = getSamples(db, device);
|
||||
|
||||
MySleepChartsData mySleepChartsData = refreshSleepAmounts(device, samples);
|
||||
DefaultChartsData chartsData = refresh(device, samples);
|
||||
@ -58,7 +58,7 @@ public class SleepChartFragment extends AbstractChartFragment {
|
||||
return new MyChartsData(mySleepChartsData, chartsData);
|
||||
}
|
||||
|
||||
private MySleepChartsData refreshSleepAmounts(GBDevice mGBDevice, List<ActivitySample> samples) {
|
||||
private MySleepChartsData refreshSleepAmounts(GBDevice mGBDevice, List<? extends ActivitySample> samples) {
|
||||
ActivityAnalysis analysis = new ActivityAnalysis();
|
||||
ActivityAmounts amounts = analysis.calculateActivityAmounts(samples);
|
||||
PieData data = new PieData();
|
||||
@ -195,7 +195,7 @@ public class SleepChartFragment extends AbstractChartFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<ActivitySample> getSamples(DBHandler db, GBDevice device, int tsFrom, int tsTo) {
|
||||
protected List<? extends ActivitySample> getSamples(DBHandler db, GBDevice device, int tsFrom, int tsTo) {
|
||||
// temporary fix for totally wrong sleep amounts
|
||||
// return super.getSleepSamples(db, device, tsFrom, tsTo);
|
||||
return super.getAllSamples(db, device, tsFrom, tsTo);
|
||||
|
@ -214,7 +214,7 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
|
||||
// chart.getLegend().setTextColor(LEGEND_TEXT_COLOR);
|
||||
}
|
||||
|
||||
private List<ActivitySample> getSamplesOfDay(DBHandler db, Calendar day, GBDevice device) {
|
||||
private List<? extends ActivitySample> getSamplesOfDay(DBHandler db, Calendar day, GBDevice device) {
|
||||
int startTs;
|
||||
int endTs;
|
||||
|
||||
@ -233,7 +233,7 @@ public class WeekStepsChartFragment extends AbstractChartFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<ActivitySample> getSamples(DBHandler db, GBDevice device, int tsFrom, int tsTo) {
|
||||
protected List<? extends ActivitySample> getSamples(DBHandler db, GBDevice device, int tsFrom, int tsTo) {
|
||||
return super.getAllSamples(db, device, tsFrom, tsTo);
|
||||
}
|
||||
|
||||
|
@ -33,6 +33,8 @@ import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_TIME
|
||||
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.KEY_TYPE;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.database.DBConstants.TABLE_GBACTIVITYSAMPLES;
|
||||
|
||||
// TODO: can be removed entirely
|
||||
// TODO: port schema migration to greendao first
|
||||
public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHandler {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ActivityDatabaseHandler.class);
|
||||
@ -87,7 +89,6 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHandl
|
||||
* @param kind the raw activity kind of the sample
|
||||
* @param customShortValue
|
||||
*/
|
||||
@Override
|
||||
public void addGBActivitySample(AbstractActivitySample sample) {
|
||||
float intensity = sample.getIntensity();
|
||||
int steps = sample.getSteps();
|
||||
@ -122,7 +123,6 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHandl
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGBActivitySamples(AbstractActivitySample[] activitySamples) {
|
||||
try (SQLiteDatabase db = this.getWritableDatabase()) {
|
||||
|
||||
@ -231,7 +231,6 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHandl
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
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 "
|
||||
@ -247,7 +246,6 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHandl
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
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 "
|
||||
@ -265,7 +263,6 @@ public class ActivityDatabaseHandler extends SQLiteOpenHelper implements DBHandl
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
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")) {
|
||||
|
@ -3,13 +3,8 @@ package nodomain.freeyourgadget.gadgetbridge.database;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
||||
|
||||
public interface DBHandler extends AutoCloseable {
|
||||
/**
|
||||
@ -25,23 +20,7 @@ public interface DBHandler extends AutoCloseable {
|
||||
*/
|
||||
void close() throws Exception;
|
||||
|
||||
List<ActivitySample> getAllActivitySamples(int tsFrom, int tsTo, SampleProvider provider);
|
||||
|
||||
List<ActivitySample> getActivitySamples(int tsFrom, int tsTo, SampleProvider provider);
|
||||
|
||||
List<ActivitySample> getSleepSamples(int tsFrom, int tsTo, SampleProvider provider);
|
||||
|
||||
void addGBActivitySample(AbstractActivitySample sample);
|
||||
|
||||
void addGBActivitySamples(AbstractActivitySample[] activitySamples);
|
||||
|
||||
SQLiteDatabase getWritableDatabase();
|
||||
|
||||
void changeStoredSamplesType(int timestampFrom, int timestampTo, int kind, SampleProvider provider);
|
||||
|
||||
void changeStoredSamplesType(int timestampFrom, int timestampTo, int fromKind, int toKind, SampleProvider provider);
|
||||
|
||||
int fetchLatestTimestamp(SampleProvider provider);
|
||||
|
||||
DaoSession getDaoSession();
|
||||
}
|
||||
|
@ -1,22 +1,16 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.devices;
|
||||
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import de.greenrobot.dao.AbstractDao;
|
||||
import de.greenrobot.dao.query.QueryBuilder;
|
||||
import de.greenrobot.dao.query.WhereCondition;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.MiBandActivitySampleDao;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
||||
|
||||
public abstract class AbstractSampleProvider<T extends ActivitySample> implements SampleProvider {
|
||||
public abstract class AbstractSampleProvider<T extends AbstractActivitySample> implements SampleProvider<T> {
|
||||
private static final WhereCondition[] NO_CONDITIONS = new WhereCondition[0];
|
||||
private final DaoSession mSession;
|
||||
|
||||
@ -56,13 +50,13 @@ public abstract class AbstractSampleProvider<T extends ActivitySample> implement
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGBActivitySample(AbstractActivitySample activitySample) {
|
||||
getSampleDao().insert((T) activitySample);
|
||||
public void addGBActivitySample(T activitySample) {
|
||||
getSampleDao().insert(activitySample);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addGBActivitySamples(AbstractActivitySample[] activitySamples) {
|
||||
getSampleDao().insertInTx((T[]) activitySamples);
|
||||
public void addGBActivitySamples(T[] activitySamples) {
|
||||
getSampleDao().insertInTx(activitySamples);
|
||||
}
|
||||
|
||||
// @Override
|
||||
@ -102,30 +96,16 @@ public abstract class AbstractSampleProvider<T extends ActivitySample> implement
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void changeStoredSamplesType(int timestampFrom, int timestampTo, int kind, SampleProvider provider) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void changeStoredSamplesType(int timestampFrom, int timestampTo, int fromKind, int toKind, SampleProvider provider) {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public int fetchLatestTimestamp(SampleProvider provider) {
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
|
||||
public void changeStoredSamplesType(int timestampFrom, int timestampTo, int kind) {
|
||||
// TODO: implement
|
||||
}
|
||||
|
||||
public void changeStoredSamplesType(int timestampFrom, int timestampTo, int fromKind, int toKind) {
|
||||
// TODO: implement
|
||||
}
|
||||
|
||||
//// SQLiteDatabase getWritableDatabase();
|
||||
//
|
||||
// public void changeStoredSamplesType(int timestampFrom, int timestampTo, int kind) {
|
||||
// // TODO: implement
|
||||
// }
|
||||
//
|
||||
// public void changeStoredSamplesType(int timestampFrom, int timestampTo, int fromKind, int toKind) {
|
||||
// // TODO: implement
|
||||
// }
|
||||
|
||||
protected List<T> getGBActivitySamples(int timestamp_from, int timestamp_to, int activityType) {
|
||||
QueryBuilder<T> qb = getSampleDao().queryBuilder();
|
||||
@ -133,7 +113,7 @@ public abstract class AbstractSampleProvider<T extends ActivitySample> implement
|
||||
.where(MiBandActivitySampleDao.Properties.Timestamp.le(timestamp_to), getClauseForActivityType(qb, activityType));
|
||||
List<T> samples = qb.build().list();
|
||||
for (T sample : samples) {
|
||||
((AbstractActivitySample) sample).setProvider(this);
|
||||
sample.setProvider(this);
|
||||
}
|
||||
return samples;
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||
@ -83,7 +84,7 @@ public interface DeviceCoordinator {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
SampleProvider getSampleProvider(DBHandler db);
|
||||
SampleProvider<AbstractActivitySample> getSampleProvider(DBHandler db);
|
||||
|
||||
/**
|
||||
* Finds an install handler for the given uri that can install the given
|
||||
|
@ -3,9 +3,9 @@ package nodomain.freeyourgadget.gadgetbridge.devices;
|
||||
import java.util.List;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
||||
|
||||
public interface SampleProvider<T extends ActivitySample> {
|
||||
public interface SampleProvider<T extends AbstractActivitySample> {
|
||||
// TODO: these constants can all be removed
|
||||
int PROVIDER_MIBAND = 0;
|
||||
int PROVIDER_PEBBLE_MORPHEUZ = 1;
|
||||
int PROVIDER_PEBBLE_GADGETBRIDGE = 2;
|
||||
@ -13,6 +13,8 @@ public interface SampleProvider<T extends ActivitySample> {
|
||||
int PROVIDER_PEBBLE_HEALTH = 4;
|
||||
|
||||
int PROVIDER_UNKNOWN = 100;
|
||||
// TODO: can also be removed
|
||||
int getID();
|
||||
|
||||
int normalizeType(int rawType);
|
||||
|
||||
@ -26,11 +28,13 @@ public interface SampleProvider<T extends ActivitySample> {
|
||||
|
||||
List<T> getSleepSamples(int timestamp_from, int timestamp_to);
|
||||
|
||||
void changeStoredSamplesType(int timestampFrom, int timestampTo, int kind);
|
||||
|
||||
void changeStoredSamplesType(int timestampFrom, int timestampTo, int fromKind, int toKind);
|
||||
|
||||
int fetchLatestTimestamp();
|
||||
|
||||
void addGBActivitySample(AbstractActivitySample activitySample);
|
||||
void addGBActivitySample(T activitySample);
|
||||
|
||||
void addGBActivitySamples(AbstractActivitySample[] activitySamples);
|
||||
|
||||
int getID();
|
||||
void addGBActivitySamples(T[] activitySamples);
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||
|
||||
public class UnknownDeviceCoordinator extends AbstractDeviceCoordinator {
|
||||
private final UnknownSampleProvider sampleProvider;
|
||||
|
||||
private static final class UnknownSampleProvider implements SampleProvider {
|
||||
@Override
|
||||
@ -47,6 +48,14 @@ public class UnknownDeviceCoordinator extends AbstractDeviceCoordinator {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeStoredSamplesType(int timestampFrom, int timestampTo, int kind) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeStoredSamplesType(int timestampFrom, int timestampTo, int fromKind, int toKind) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fetchLatestTimestamp() {
|
||||
return 0;
|
||||
@ -67,6 +76,7 @@ public class UnknownDeviceCoordinator extends AbstractDeviceCoordinator {
|
||||
}
|
||||
|
||||
public UnknownDeviceCoordinator() {
|
||||
sampleProvider = new UnknownSampleProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,7 +2,6 @@ package nodomain.freeyourgadget.gadgetbridge.service.devices.miband.operations;
|
||||
|
||||
import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@ -19,20 +18,11 @@ import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractSampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandConst;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandDateConverter;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandSampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.miband.MiBandService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.MiBandActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.MiBandActivitySampleDao;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.User;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceBusyAction;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.MiBandSupport;
|
||||
@ -319,13 +309,13 @@ public class FetchActivityOperation extends AbstractMiBandOperation {
|
||||
Long userId = DBHelper.getUser(dbHandler.getDaoSession()).getId();
|
||||
Long deviceId = DBHelper.getDevice(getDevice(), dbHandler.getDaoSession()).getId();
|
||||
int minutes = 0;
|
||||
try (SQLiteDatabase db = dbHandler.getWritableDatabase()) { // explicitly keep the db open while looping over the samples
|
||||
try {
|
||||
int timestampInSeconds = (int) (activityStruct.activityDataTimestampProgress.getTimeInMillis() / 1000);
|
||||
if ((activityStruct.activityDataHolderProgress % bpm) != 0) {
|
||||
throw new IllegalStateException("Unexpected data, progress should be mutiple of " + bpm + ": " + activityStruct.activityDataHolderProgress);
|
||||
}
|
||||
int numSamples = activityStruct.activityDataHolderProgress / bpm;
|
||||
AbstractActivitySample[] samples = new AbstractActivitySample[numSamples];
|
||||
MiBandActivitySample[] samples = new MiBandActivitySample[numSamples];
|
||||
|
||||
for (int i = 0; i < activityStruct.activityDataHolderProgress; i += bpm) {
|
||||
category = activityStruct.activityDataHolder[i];
|
||||
|
@ -22,6 +22,7 @@ import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleGadgetBridgeSampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.User;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
||||
@ -58,7 +59,7 @@ public class AppMessageHandlerGBPebble extends AppMessageHandler {
|
||||
User user = DBHelper.getUser(db.getDaoSession());
|
||||
Device device = DBHelper.getDevice(getDevice(), db.getDaoSession());
|
||||
PebbleGadgetBridgeSampleProvider sampleProvider = new PebbleGadgetBridgeSampleProvider(db.getDaoSession());
|
||||
AbstractActivitySample[] activitySamples = new AbstractActivitySample[samples_remaining];
|
||||
PebbleActivitySample[] activitySamples = new PebbleActivitySample[samples_remaining];
|
||||
int i = 0;
|
||||
while (samples_remaining-- > 0) {
|
||||
short sample = samplesBuffer.getShort();
|
||||
|
@ -71,7 +71,7 @@ public class AppMessageHandlerMisfit extends AppMessageHandler {
|
||||
LOG.info("got data from " + startDate + " to " + endDate);
|
||||
|
||||
int totalSteps = 0;
|
||||
AbstractActivitySample[] activitySamples = new AbstractActivitySample[samples];
|
||||
PebbleActivitySample[] activitySamples = new PebbleActivitySample[samples];
|
||||
try (DBHandler db = GBApplication.acquireDB()) {
|
||||
Long userId = DBHelper.getUser(db.getDaoSession()).getId();
|
||||
Long deviceId = DBHelper.getDevice(getDevice(), db.getDaoSession()).getId();
|
||||
|
@ -68,14 +68,14 @@ class DatalogSessionHealthSleep extends DatalogSession {
|
||||
private boolean store84(SleepRecord84[] sleepRecords) {
|
||||
try (DBHandler dbHandler = GBApplication.acquireDB()) {
|
||||
SampleProvider sampleProvider = new HealthSampleProvider(dbHandler.getDaoSession());
|
||||
int latestTimestamp = dbHandler.fetchLatestTimestamp(sampleProvider);
|
||||
int latestTimestamp = sampleProvider.fetchLatestTimestamp();
|
||||
for (SleepRecord84 sleepRecord : sleepRecords) {
|
||||
if (latestTimestamp < (sleepRecord.timestampStart + sleepRecord.durationSeconds))
|
||||
return false;
|
||||
if (sleepRecord.type == 2) {
|
||||
dbHandler.changeStoredSamplesType(sleepRecord.timestampStart, (sleepRecord.timestampStart + sleepRecord.durationSeconds), sampleProvider.toRawActivityKind(ActivityKind.TYPE_DEEP_SLEEP), sampleProvider);
|
||||
sampleProvider.changeStoredSamplesType(sleepRecord.timestampStart, (sleepRecord.timestampStart + sleepRecord.durationSeconds), sampleProvider.toRawActivityKind(ActivityKind.TYPE_DEEP_SLEEP));
|
||||
} else {
|
||||
dbHandler.changeStoredSamplesType(sleepRecord.timestampStart, (sleepRecord.timestampStart + sleepRecord.durationSeconds), sampleProvider.toRawActivityKind(ActivityKind.TYPE_ACTIVITY), sampleProvider.toRawActivityKind(ActivityKind.TYPE_LIGHT_SLEEP), sampleProvider);
|
||||
sampleProvider.changeStoredSamplesType(sleepRecord.timestampStart, (sleepRecord.timestampStart + sleepRecord.durationSeconds), sampleProvider.toRawActivityKind(ActivityKind.TYPE_ACTIVITY), sampleProvider.toRawActivityKind(ActivityKind.TYPE_LIGHT_SLEEP));
|
||||
}
|
||||
|
||||
}
|
||||
@ -116,11 +116,11 @@ class DatalogSessionHealthSleep extends DatalogSession {
|
||||
try (DBHandler dbHandler = GBApplication.acquireDB()) {
|
||||
SampleProvider sampleProvider = new HealthSampleProvider(dbHandler.getDaoSession());
|
||||
GB.toast("Deep sleep is supported only from firmware 3.11 onwards.", Toast.LENGTH_LONG, GB.INFO);
|
||||
int latestTimestamp = dbHandler.fetchLatestTimestamp(sampleProvider);
|
||||
int latestTimestamp = sampleProvider.fetchLatestTimestamp();
|
||||
for (SleepRecord83 sleepRecord : sleepRecords) {
|
||||
if (latestTimestamp < sleepRecord.bedTimeEnd)
|
||||
return false;
|
||||
dbHandler.changeStoredSamplesType(sleepRecord.bedTimeStart, sleepRecord.bedTimeEnd, sampleProvider.toRawActivityKind(ActivityKind.TYPE_ACTIVITY), sampleProvider.toRawActivityKind(ActivityKind.TYPE_LIGHT_SLEEP), sampleProvider);
|
||||
sampleProvider.changeStoredSamplesType(sleepRecord.bedTimeStart, sleepRecord.bedTimeEnd, sampleProvider.toRawActivityKind(ActivityKind.TYPE_ACTIVITY), sampleProvider.toRawActivityKind(ActivityKind.TYPE_LIGHT_SLEEP));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LOG.debug(ex.getMessage());
|
||||
|
@ -78,7 +78,7 @@ public class DatalogSessionHealthSteps extends DatalogSession {
|
||||
|
||||
try (DBHandler dbHandler = GBApplication.acquireDB()) {
|
||||
HealthSampleProvider sampleProvider = new HealthSampleProvider(dbHandler.getDaoSession());
|
||||
AbstractActivitySample[] samples = new AbstractActivitySample[stepsRecords.length];
|
||||
PebbleActivitySample[] samples = new PebbleActivitySample[stepsRecords.length];
|
||||
// TODO: user and device
|
||||
Long userId = DBHelper.getUser(dbHandler.getDaoSession()).getId();
|
||||
Long deviceId = DBHelper.getDevice(device, dbHandler.getDaoSession()).getId();
|
||||
|
Loading…
Reference in New Issue
Block a user