1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-27 20:36:51 +01:00

rename some classes, remove obsolete ones

This commit is contained in:
Andreas Shimokawa 2016-07-30 23:22:27 +02:00
parent b43b7948b0
commit eabe625c47
17 changed files with 46 additions and 158 deletions

View File

@ -45,7 +45,7 @@ public class GBDaoGenerator {
Entity device = addDevice(schema, deviceAttributes);
addMiBandActivitySample(schema, user, device);
addPebbleActivitySample(schema, user, device);
addPebbleHealthActivitySample(schema, user, device);
addPebbleMisfitActivitySample(schema, user, device);
new DaoGenerator().generateAll(schema, "app/src/main/java");
@ -142,9 +142,9 @@ public class GBDaoGenerator {
activitySample.addIntProperty("heartRate").notNull();
}
private static Entity addPebbleActivitySample(Schema schema, Entity user, Entity device) {
private static Entity addPebbleHealthActivitySample(Schema schema, Entity user, Entity device) {
// public GBActivitySample(SampleProvider provider, int timestamp, int intensity, int steps, int type, int customValue) {
Entity activitySample = addEntity(schema, "PebbleActivitySample");
Entity activitySample = addEntity(schema, "PebbleHealthActivitySample");
addCommonActivitySampleProperties("AbstractActivitySample", activitySample, user, device);
addDefaultActivitySampleAttributes(activitySample);
addCommonActivitySampleProperties2(activitySample, user, device);

View File

@ -345,7 +345,7 @@ public class DBHelper {
private boolean isEmpty(DaoSession session) {
long totalSamplesCount = session.getMiBandActivitySampleDao().count();
totalSamplesCount += session.getPebbleActivitySampleDao().count();
totalSamplesCount += session.getPebbleHealthActivitySampleDao().count();
return totalSamplesCount == 0;
}

View File

@ -8,7 +8,7 @@ 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;
int PROVIDER_PEBBLE_GADGETBRIDGE = 2; // removed
int PROVIDER_PEBBLE_MISFIT = 3;
int PROVIDER_PEBBLE_HEALTH = 4;

View File

@ -4,38 +4,37 @@ import de.greenrobot.dao.AbstractDao;
import de.greenrobot.dao.Property;
import nodomain.freeyourgadget.gadgetbridge.devices.AbstractSampleProvider;
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.entities.MiBandActivitySampleDao;
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleActivitySample;
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleActivitySampleDao;
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivitySample;
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivitySampleDao;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
public abstract class AbstractPebbleSampleProvider extends AbstractSampleProvider<PebbleActivitySample> {
public abstract class AbstractPebbleSampleProvider extends AbstractSampleProvider<PebbleHealthActivitySample> {
protected AbstractPebbleSampleProvider(GBDevice device, DaoSession session) {
super(device, session);
}
@Override
public AbstractDao<PebbleActivitySample, ?> getSampleDao() {
return getSession().getPebbleActivitySampleDao();
public AbstractDao<PebbleHealthActivitySample, ?> getSampleDao() {
return getSession().getPebbleHealthActivitySampleDao();
}
@Override
protected Property getTimestampSampleProperty() {
return PebbleActivitySampleDao.Properties.Timestamp;
return PebbleHealthActivitySampleDao.Properties.Timestamp;
}
@Override
protected Property getRawKindSampleProperty() {
return PebbleActivitySampleDao.Properties.RawKind;
return PebbleHealthActivitySampleDao.Properties.RawKind;
}
@Override
protected Property getDeviceIdentifierSampleProperty() {
return PebbleActivitySampleDao.Properties.DeviceId;
return PebbleHealthActivitySampleDao.Properties.DeviceId;
}
@Override
public PebbleActivitySample createActivitySample() {
return new PebbleActivitySample();
public PebbleHealthActivitySample createActivitySample() {
return new PebbleHealthActivitySample();
}
}

View File

@ -52,15 +52,13 @@ public class PebbleCoordinator extends AbstractDeviceCoordinator {
int activityTracker = prefs.getInt("pebble_activitytracker", SampleProvider.PROVIDER_PEBBLE_HEALTH);
switch (activityTracker) {
case SampleProvider.PROVIDER_PEBBLE_HEALTH:
return new HealthSampleProvider(device, session);
return new PebbleHealthSampleProvider(device, session);
case SampleProvider.PROVIDER_PEBBLE_MISFIT:
return new MisfitSampleProvider(device, session);
return new PebbleMisfitSampleProvider(device, session);
case SampleProvider.PROVIDER_PEBBLE_MORPHEUZ:
return new MorpheuzSampleProvider(device, session);
case SampleProvider.PROVIDER_PEBBLE_GADGETBRIDGE:
return new PebbleGadgetBridgeSampleProvider(device, session);
return new PebbleMorpheuzSampleProvider(device, session);
default:
return new HealthSampleProvider(device, session);
return new PebbleHealthSampleProvider(device, session);
}
}

View File

@ -1,17 +0,0 @@
package nodomain.freeyourgadget.gadgetbridge.devices.pebble;
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
public class PebbleGadgetBridgeSampleProvider extends MorpheuzSampleProvider {
public PebbleGadgetBridgeSampleProvider(GBDevice device, DaoSession session) {
super(device, session);
movementDivisor = 63.0f;
}
@Override
public int getID() {
return SampleProvider.PROVIDER_PEBBLE_GADGETBRIDGE;
}
}

View File

@ -2,18 +2,17 @@ package nodomain.freeyourgadget.gadgetbridge.devices.pebble;
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleActivitySample;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
public class HealthSampleProvider extends AbstractPebbleSampleProvider {
public class PebbleHealthSampleProvider extends AbstractPebbleSampleProvider {
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;
public HealthSampleProvider(GBDevice device, DaoSession session) {
public PebbleHealthSampleProvider(GBDevice device, DaoSession session) {
super(device, session);
}

View File

@ -16,13 +16,13 @@ import nodomain.freeyourgadget.gadgetbridge.entities.PebbleMisfitSampleDao;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
public class MisfitSampleProvider implements SampleProvider<PebbleMisfitSample> {
public class PebbleMisfitSampleProvider implements SampleProvider<PebbleMisfitSample> {
private final DaoSession mSession;
private final GBDevice mDevice;
protected final float movementDivisor = 300f;
public MisfitSampleProvider(GBDevice device, DaoSession session) {
public PebbleMisfitSampleProvider(GBDevice device, DaoSession session) {
mSession = session;
mDevice = device;
}

View File

@ -5,7 +5,7 @@ import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
public class MorpheuzSampleProvider extends AbstractPebbleSampleProvider {
public class PebbleMorpheuzSampleProvider extends AbstractPebbleSampleProvider {
// raw types
public static final int TYPE_DEEP_SLEEP = 5;
public static final int TYPE_LIGHT_SLEEP = 4;
@ -14,7 +14,7 @@ public class MorpheuzSampleProvider extends AbstractPebbleSampleProvider {
protected float movementDivisor = 5000f;
public MorpheuzSampleProvider(GBDevice device, DaoSession session) {
public PebbleMorpheuzSampleProvider(GBDevice device, DaoSession session) {
super(device, session);
}

View File

@ -6,11 +6,9 @@ import android.util.Pair;
import java.util.ArrayList;
import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleActivitySample;
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivitySample;
import nodomain.freeyourgadget.gadgetbridge.entities.User;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
@ -39,8 +37,8 @@ public class AppMessageHandler {
return null;
}
protected PebbleActivitySample createSample(int timestamp, int intensity, int steps, int type, User user, Device device) {
return new PebbleActivitySample(null, timestamp, intensity, steps, type, user.getId(), device.getId());
protected PebbleHealthActivitySample createSample(int timestamp, int intensity, int steps, int type, User user, Device device) {
return new PebbleHealthActivitySample(null, timestamp, intensity, steps, type, user.getId(), device.getId());
}
protected GBDevice getDevice() {

View File

@ -1,87 +0,0 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.pebble;
import android.util.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.SimpleTimeZone;
import java.util.TimeZone;
import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.GBException;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes;
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;
public class AppMessageHandlerGBPebble extends AppMessageHandler {
public static final int KEY_TIMESTAMP = 1;
public static final int KEY_SAMPLES = 2;
private static final Logger LOG = LoggerFactory.getLogger(AppMessageHandlerGBPebble.class);
AppMessageHandlerGBPebble(UUID uuid, PebbleProtocol pebbleProtocol) {
super(uuid, pebbleProtocol);
}
@Override
public GBDeviceEvent[] handleMessage(ArrayList<Pair<Integer, Object>> pairs) {
int timestamp = 0;
for (Pair<Integer, Object> pair : pairs) {
switch (pair.first) {
case KEY_TIMESTAMP:
TimeZone tz = SimpleTimeZone.getDefault();
timestamp = (int) pair.second - (tz.getOffset(System.currentTimeMillis())) / 1000;
LOG.info("got timestamp " + timestamp);
break;
case KEY_SAMPLES:
byte[] samples = (byte[]) pair.second;
ByteBuffer samplesBuffer = ByteBuffer.wrap(samples);
samplesBuffer.order(ByteOrder.LITTLE_ENDIAN);
int samples_remaining = samples.length / 2;
LOG.info("got " + samples_remaining + " samples");
int offset_seconds = 0;
try (DBHandler db = GBApplication.acquireDB()) {
User user = DBHelper.getUser(db.getDaoSession());
Device device = DBHelper.getDevice(getDevice(), db.getDaoSession());
PebbleGadgetBridgeSampleProvider sampleProvider = new PebbleGadgetBridgeSampleProvider(getDevice(), db.getDaoSession());
PebbleActivitySample[] activitySamples = new PebbleActivitySample[samples_remaining];
int i = 0;
while (samples_remaining-- > 0) {
short sample = samplesBuffer.getShort();
int type = ((sample & 0xe000) >>> 13);
int intensity = ((sample & 0x1f80) >>> 7);
int steps = (sample & 0x007f);
activitySamples[i++] = createSample(timestamp + offset_seconds, intensity, steps, type, user, device);
activitySamples[i].setProvider(sampleProvider);
offset_seconds += 60;
}
sampleProvider.addGBActivitySamples(activitySamples);
} catch (Exception e) {
LOG.error("Error acquiring database", e);
}
break;
default:
LOG.info("unhandled key: " + pair.first);
break;
}
}
GBDeviceEventSendBytes sendBytes = new GBDeviceEventSendBytes();
sendBytes.encodedBytes = mPebbleProtocol.encodeApplicationMessageAck(mUUID, mPebbleProtocol.last_id);
return new GBDeviceEvent[]{sendBytes};
}
}

View File

@ -17,7 +17,7 @@ import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes;
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.MisfitSampleProvider;
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleMisfitSampleProvider;
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleMisfitSample;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
@ -78,7 +78,7 @@ public class AppMessageHandlerMisfit extends AppMessageHandler {
int totalSteps = 0;
PebbleMisfitSample[] misfitSamples = new PebbleMisfitSample[samples];
try (DBHandler db = GBApplication.acquireDB()) {
MisfitSampleProvider sampleProvider = new MisfitSampleProvider(device, db.getDaoSession());
PebbleMisfitSampleProvider sampleProvider = new PebbleMisfitSampleProvider(device, db.getDaoSession());
Long userId = DBHelper.getUser(db.getDaoSession()).getId();
Long deviceId = DBHelper.getDevice(getDevice(), db.getDaoSession()).getId();
for (int i = 0; i < samples; i++) {

View File

@ -16,10 +16,9 @@ import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEvent;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSendBytes;
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventSleepMonitorResult;
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.MorpheuzSampleProvider;
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleMorpheuzSampleProvider;
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleActivitySample;
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivitySample;
import nodomain.freeyourgadget.gadgetbridge.entities.User;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
@ -93,18 +92,18 @@ public class AppMessageHandlerMorpheuz extends AppMessageHandler {
int index = ((int) pair.second >> 16);
int intensity = ((int) pair.second & 0xffff);
LOG.info("got point:" + index + " " + intensity);
int type = MorpheuzSampleProvider.TYPE_UNKNOWN;
int type = PebbleMorpheuzSampleProvider.TYPE_UNKNOWN;
if (intensity <= 120) {
type = MorpheuzSampleProvider.TYPE_DEEP_SLEEP;
type = PebbleMorpheuzSampleProvider.TYPE_DEEP_SLEEP;
} else if (intensity <= 1000) {
type = MorpheuzSampleProvider.TYPE_LIGHT_SLEEP;
type = PebbleMorpheuzSampleProvider.TYPE_LIGHT_SLEEP;
}
if (index >= 0) {
try (DBHandler db = GBApplication.acquireDB()) {
User user = DBHelper.getUser(db.getDaoSession());
Device device = DBHelper.getDevice(getDevice(), db.getDaoSession());
MorpheuzSampleProvider sampleProvider = new MorpheuzSampleProvider(getDevice(), db.getDaoSession());
PebbleActivitySample sample = createSample(recording_base_timestamp + index * 600, intensity, 0, type, user, device);
PebbleMorpheuzSampleProvider sampleProvider = new PebbleMorpheuzSampleProvider(getDevice(), db.getDaoSession());
PebbleHealthActivitySample sample = createSample(recording_base_timestamp + index * 600, intensity, 0, type, user, device);
sample.setProvider(sampleProvider);
sampleProvider.addGBActivitySample(sample);
} catch (Exception e) {

View File

@ -9,7 +9,7 @@ import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.HealthSampleProvider;
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleHealthSampleProvider;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
@ -60,7 +60,7 @@ class DatalogSessionHealthOverlayData extends DatalogSessionPebbleHealth {
private boolean store(OverlayRecord[] overlayRecords) {
try (DBHandler dbHandler = GBApplication.acquireDB()) {
SampleProvider sampleProvider = new HealthSampleProvider(getDevice(), dbHandler.getDaoSession());
SampleProvider sampleProvider = new PebbleHealthSampleProvider(getDevice(), dbHandler.getDaoSession());
int latestTimestamp = sampleProvider.fetchLatestTimestamp();
for (OverlayRecord overlayRecord : overlayRecords) {
if (latestTimestamp < (overlayRecord.timestampStart + overlayRecord.durationSeconds))

View File

@ -9,7 +9,7 @@ import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.HealthSampleProvider;
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleHealthSampleProvider;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
@ -59,7 +59,7 @@ class DatalogSessionHealthSleep extends DatalogSessionPebbleHealth {
private boolean store(SleepRecord[] sleepRecords) {
try (DBHandler dbHandler = GBApplication.acquireDB()) {
SampleProvider sampleProvider = new HealthSampleProvider(getDevice(), dbHandler.getDaoSession());
SampleProvider sampleProvider = new PebbleHealthSampleProvider(getDevice(), dbHandler.getDaoSession());
int latestTimestamp = sampleProvider.fetchLatestTimestamp();
for (SleepRecord sleepRecord : sleepRecords) {
if (latestTimestamp < sleepRecord.bedTimeEnd)

View File

@ -10,8 +10,8 @@ import java.util.UUID;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.HealthSampleProvider;
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleActivitySample;
import nodomain.freeyourgadget.gadgetbridge.devices.pebble.PebbleHealthSampleProvider;
import nodomain.freeyourgadget.gadgetbridge.entities.PebbleHealthActivitySample;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
@ -75,14 +75,14 @@ public class DatalogSessionHealthSteps extends DatalogSessionPebbleHealth {
private void store(StepsRecord[] stepsRecords) {
try (DBHandler dbHandler = GBApplication.acquireDB()) {
HealthSampleProvider sampleProvider = new HealthSampleProvider(getDevice(), dbHandler.getDaoSession());
PebbleActivitySample[] samples = new PebbleActivitySample[stepsRecords.length];
PebbleHealthSampleProvider sampleProvider = new PebbleHealthSampleProvider(getDevice(), dbHandler.getDaoSession());
PebbleHealthActivitySample[] samples = new PebbleHealthActivitySample[stepsRecords.length];
// TODO: user and device
Long userId = DBHelper.getUser(dbHandler.getDaoSession()).getId();
Long deviceId = DBHelper.getDevice(getDevice(), dbHandler.getDaoSession()).getId();
for (int j = 0; j < stepsRecords.length; j++) {
StepsRecord stepsRecord = stepsRecords[j];
samples[j] = new PebbleActivitySample(
samples[j] = new PebbleHealthActivitySample(
null,
stepsRecord.timestamp,
stepsRecord.intensity,

View File

@ -378,7 +378,6 @@ public class PebbleProtocol extends GBDeviceProtocol {
public PebbleProtocol(GBDevice device) {
super(device);
mAppMessageHandlers.put(UUID_GBPEBBLE, new AppMessageHandlerGBPebble(UUID_GBPEBBLE, PebbleProtocol.this));
mAppMessageHandlers.put(UUID_MORPHEUZ, new AppMessageHandlerMorpheuz(UUID_MORPHEUZ, PebbleProtocol.this));
mAppMessageHandlers.put(UUID_WHETHERNEAT, new AppMessageHandlerWeatherNeat(UUID_WHETHERNEAT, PebbleProtocol.this));
mAppMessageHandlers.put(UUID_MISFIT, new AppMessageHandlerMisfit(UUID_MISFIT, PebbleProtocol.this));