mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-24 19:06:53 +01:00
"Ported" to AbstractSampleProvider
This commit is contained in:
parent
21cafa83d8
commit
9532fc879f
@ -5,12 +5,22 @@ 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.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 {
|
||||
private static final WhereCondition[] NO_CONDITIONS = new WhereCondition[0];
|
||||
private final DaoSession mSession;
|
||||
|
||||
protected AbstractSampleProvider(DaoSession session) {
|
||||
mSession = session;
|
||||
}
|
||||
|
||||
public DaoSession getmSession() {
|
||||
return mSession;
|
||||
}
|
||||
|
||||
public List<T> getAllActivitySamples(int timestamp_from, int timestamp_to) {
|
||||
return getGBActivitySamples(timestamp_from, timestamp_to, ActivityKind.TYPE_ALL);
|
||||
|
@ -24,7 +24,7 @@ public class MiBandCoordinator extends AbstractDeviceCoordinator {
|
||||
private final MiBandSampleProvider sampleProvider;
|
||||
|
||||
public MiBandCoordinator() {
|
||||
sampleProvider = new MiBandSampleProvider();
|
||||
sampleProvider = new MiBandSampleProvider(GBApplication.getDaoSession());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,9 +1,14 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.devices.miband;
|
||||
|
||||
import de.greenrobot.dao.AbstractDao;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractSampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.MiBandActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.MiBandActivitySampleDao;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||
|
||||
public class MiBandSampleProvider implements SampleProvider {
|
||||
public class MiBandSampleProvider extends AbstractSampleProvider<MiBandActivitySample> {
|
||||
public static final int TYPE_DEEP_SLEEP = 5;
|
||||
public static final int TYPE_LIGHT_SLEEP = 4;
|
||||
public static final int TYPE_ACTIVITY = -1;
|
||||
@ -22,6 +27,10 @@ public class MiBandSampleProvider implements SampleProvider {
|
||||
// maybe this should be configurable 256 seems way off, though.
|
||||
private final float movementDivisor = 180.0f; //256.0f;
|
||||
|
||||
protected MiBandSampleProvider(DaoSession session) {
|
||||
super(session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int normalizeType(int rawType) {
|
||||
switch (rawType) {
|
||||
@ -67,4 +76,9 @@ public class MiBandSampleProvider implements SampleProvider {
|
||||
public int getID() {
|
||||
return SampleProvider.PROVIDER_MIBAND;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractDao<MiBandActivitySample, ?> getSampleDao() {
|
||||
return getmSession().getMiBandActivitySampleDao();
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,23 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.devices.pebble;
|
||||
|
||||
import de.greenrobot.dao.AbstractDao;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractSampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||
|
||||
public class HealthSampleProvider implements SampleProvider {
|
||||
public class HealthSampleProvider extends AbstractSampleProvider<PebbleActivitySample> {
|
||||
public static final int TYPE_DEEP_SLEEP = 5;
|
||||
public static final int TYPE_LIGHT_SLEEP = 4;
|
||||
public static final int TYPE_ACTIVITY = -1;
|
||||
|
||||
protected final float movementDivisor = 8000f;
|
||||
|
||||
protected HealthSampleProvider(DaoSession session) {
|
||||
super(session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int normalizeType(int rawType) {
|
||||
switch (rawType) {
|
||||
@ -49,4 +57,9 @@ public class HealthSampleProvider implements SampleProvider {
|
||||
public int getID() {
|
||||
return SampleProvider.PROVIDER_PEBBLE_HEALTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractDao<PebbleActivitySample, ?> getSampleDao() {
|
||||
return getmSession().getPebbleActivitySampleDao();
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,19 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.devices.pebble;
|
||||
|
||||
import de.greenrobot.dao.AbstractDao;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractSampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleActivitySample;
|
||||
|
||||
public class MisfitSampleProvider implements SampleProvider {
|
||||
public class MisfitSampleProvider extends AbstractSampleProvider<PebbleActivitySample> {
|
||||
|
||||
protected final float movementDivisor = 300f;
|
||||
|
||||
protected MisfitSampleProvider(DaoSession session) {
|
||||
super(session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int normalizeType(int rawType) {
|
||||
return (int) rawType;
|
||||
@ -27,4 +35,9 @@ public class MisfitSampleProvider implements SampleProvider {
|
||||
public int getID() {
|
||||
return SampleProvider.PROVIDER_PEBBLE_MISFIT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractDao<PebbleActivitySample, ?> getSampleDao() {
|
||||
return getmSession().getPebbleActivitySampleDao();
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,13 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.devices.pebble;
|
||||
|
||||
import de.greenrobot.dao.AbstractDao;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractSampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||
|
||||
public class MorpheuzSampleProvider implements SampleProvider {
|
||||
public class MorpheuzSampleProvider extends AbstractSampleProvider<PebbleActivitySample> {
|
||||
// raw types
|
||||
public static final int TYPE_DEEP_SLEEP = 5;
|
||||
public static final int TYPE_LIGHT_SLEEP = 4;
|
||||
@ -12,6 +16,10 @@ public class MorpheuzSampleProvider implements SampleProvider {
|
||||
|
||||
protected float movementDivisor = 5000f;
|
||||
|
||||
protected MorpheuzSampleProvider(DaoSession session) {
|
||||
super(session);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int normalizeType(int rawType) {
|
||||
switch (rawType) {
|
||||
@ -51,4 +59,9 @@ public class MorpheuzSampleProvider implements SampleProvider {
|
||||
public int getID() {
|
||||
return SampleProvider.PROVIDER_PEBBLE_MORPHEUZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractDao<PebbleActivitySample, ?> getSampleDao() {
|
||||
return getmSession().getPebbleActivitySampleDao();
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import nodomain.freeyourgadget.gadgetbridge.activities.AppManagerActivity;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.InstallHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceCandidate;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceType;
|
||||
@ -46,18 +47,19 @@ public class PebbleCoordinator extends AbstractDeviceCoordinator {
|
||||
@Override
|
||||
public SampleProvider getSampleProvider() {
|
||||
Prefs prefs = GBApplication.getPrefs();
|
||||
DaoSession session = GBApplication.getDaoSession();
|
||||
int activityTracker = prefs.getInt("pebble_activitytracker", SampleProvider.PROVIDER_PEBBLE_HEALTH);
|
||||
switch (activityTracker) {
|
||||
case SampleProvider.PROVIDER_PEBBLE_HEALTH:
|
||||
return new HealthSampleProvider();
|
||||
return new HealthSampleProvider(session);
|
||||
case SampleProvider.PROVIDER_PEBBLE_MISFIT:
|
||||
return new MisfitSampleProvider();
|
||||
return new MisfitSampleProvider(session);
|
||||
case SampleProvider.PROVIDER_PEBBLE_MORPHEUZ:
|
||||
return new MorpheuzSampleProvider();
|
||||
return new MorpheuzSampleProvider(session);
|
||||
case SampleProvider.PROVIDER_PEBBLE_GADGETBRIDGE:
|
||||
return new PebbleGadgetBridgeSampleProvider();
|
||||
return new PebbleGadgetBridgeSampleProvider(session);
|
||||
default:
|
||||
return new HealthSampleProvider();
|
||||
return new HealthSampleProvider(session);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,11 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.devices.pebble;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||
|
||||
public class PebbleGadgetBridgeSampleProvider extends MorpheuzSampleProvider {
|
||||
public PebbleGadgetBridgeSampleProvider() {
|
||||
public PebbleGadgetBridgeSampleProvider(DaoSession session) {
|
||||
super(session);
|
||||
movementDivisor = 63.0f;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user