mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-27 20:36:51 +01:00
Identify device in realtime samples
This commit is contained in:
parent
aaff8db9f4
commit
b40749d53c
@ -77,9 +77,11 @@ import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
@ -88,11 +90,9 @@ import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.discovery.DiscoveryActivityV2;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.RecordedDataTypes;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.DeviceCommunicationService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.AndroidUtils;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||
@ -135,7 +135,8 @@ public class ControlCenterv2 extends AppCompatActivity
|
||||
finish();
|
||||
break;
|
||||
case DeviceService.ACTION_REALTIME_SAMPLES:
|
||||
handleRealtimeSample(intent.getSerializableExtra(DeviceService.EXTRA_REALTIME_SAMPLE));
|
||||
final GBDevice device = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE);
|
||||
handleRealtimeSample(device, intent.getSerializableExtra(DeviceService.EXTRA_REALTIME_SAMPLE));
|
||||
break;
|
||||
case ACTION_REQUEST_PERMISSIONS:
|
||||
checkAndRequestPermissions();
|
||||
@ -153,22 +154,22 @@ public class ControlCenterv2 extends AppCompatActivity
|
||||
}
|
||||
};
|
||||
private boolean pesterWithPermissions = true;
|
||||
private ActivitySample currentHRSample;
|
||||
private final Map<GBDevice, ActivitySample> currentHRSample = new HashMap<>();
|
||||
|
||||
public ActivitySample getCurrentHRSample() {
|
||||
return currentHRSample;
|
||||
public ActivitySample getCurrentHRSample(final GBDevice device) {
|
||||
return currentHRSample.get(device);
|
||||
}
|
||||
|
||||
private void setCurrentHRSample(ActivitySample sample) {
|
||||
private void setCurrentHRSample(final GBDevice device, ActivitySample sample) {
|
||||
if (HeartRateUtils.getInstance().isValidHeartRateValue(sample.getHeartRate())) {
|
||||
currentHRSample = sample;
|
||||
currentHRSample.put(device, sample);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleRealtimeSample(Serializable extra) {
|
||||
private void handleRealtimeSample(final GBDevice device, Serializable extra) {
|
||||
if (extra instanceof ActivitySample) {
|
||||
ActivitySample sample = (ActivitySample) extra;
|
||||
setCurrentHRSample(sample);
|
||||
setCurrentHRSample(device, sample);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,10 +72,10 @@ public class DevicesFragment extends Fragment {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
final GBDevice device = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE);
|
||||
switch (Objects.requireNonNull(action)) {
|
||||
case DeviceManager.ACTION_DEVICES_CHANGED:
|
||||
case GBApplication.ACTION_NEW_DATA:
|
||||
final GBDevice device = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE);
|
||||
if (action.equals(GBApplication.ACTION_NEW_DATA)) {
|
||||
createRefreshTask("get activity data", requireContext(), device).execute();
|
||||
}
|
||||
@ -88,20 +88,24 @@ public class DevicesFragment extends Fragment {
|
||||
|
||||
break;
|
||||
case DeviceService.ACTION_REALTIME_SAMPLES:
|
||||
handleRealtimeSample(intent.getSerializableExtra(DeviceService.EXTRA_REALTIME_SAMPLE));
|
||||
handleRealtimeSample(device, intent.getSerializableExtra(DeviceService.EXTRA_REALTIME_SAMPLE));
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private void handleRealtimeSample(Serializable extra) {
|
||||
private void handleRealtimeSample(GBDevice device, Serializable extra) {
|
||||
if (extra instanceof ActivitySample) {
|
||||
ActivitySample sample = (ActivitySample) extra;
|
||||
if (HeartRateUtils.getInstance().isValidHeartRateValue(sample.getHeartRate())) {
|
||||
if (device != null) {
|
||||
refreshSingleDevice(device);
|
||||
} else {
|
||||
refreshPairedDevices();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
|
||||
|
@ -38,11 +38,14 @@ import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.HeartRateSample;
|
||||
|
||||
public class HeartRateDialog extends Dialog {
|
||||
private final GBDevice device;
|
||||
|
||||
protected static final Logger LOG = LoggerFactory.getLogger(HeartRateDialog.class);
|
||||
LinearLayout heart_rate_dialog_results_layout;
|
||||
RelativeLayout heart_rate_dialog_loading_layout;
|
||||
@ -62,7 +65,10 @@ public class HeartRateDialog extends Dialog {
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
switch (Objects.requireNonNull(intent.getAction())) {
|
||||
case DeviceService.ACTION_REALTIME_SAMPLES:
|
||||
final GBDevice incomingDevice = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE);
|
||||
if (device.equals(incomingDevice)) {
|
||||
setMeasurementResults(intent.getSerializableExtra(DeviceService.EXTRA_REALTIME_SAMPLE));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG.info("ignoring intent action {}", intent.getAction());
|
||||
@ -71,8 +77,9 @@ public class HeartRateDialog extends Dialog {
|
||||
}
|
||||
};
|
||||
|
||||
public HeartRateDialog(@NonNull Context context) {
|
||||
public HeartRateDialog(final GBDevice device, @NonNull Context context) {
|
||||
super(context);
|
||||
this.device = device;
|
||||
}
|
||||
|
||||
private void setMeasurementResults(Serializable result) {
|
||||
|
@ -411,7 +411,7 @@ public class GBDeviceAdapterv2 extends ListAdapter<GBDevice, GBDeviceAdapterv2.V
|
||||
}
|
||||
holder.heartRateStatusBox.setVisibility((device.isInitialized() && coordinator.supportsRealtimeData() && coordinator.supportsManualHeartRateMeasurement(device)) ? View.VISIBLE : View.GONE);
|
||||
if (parent.getContext() instanceof ControlCenterv2) {
|
||||
ActivitySample sample = ((ControlCenterv2) parent.getContext()).getCurrentHRSample();
|
||||
ActivitySample sample = ((ControlCenterv2) parent.getContext()).getCurrentHRSample(device);
|
||||
if (sample != null) {
|
||||
holder.heartRateStatusLabel.setText(String.valueOf(sample.getHeartRate()));
|
||||
} else {
|
||||
@ -430,7 +430,7 @@ public class GBDeviceAdapterv2 extends ListAdapter<GBDevice, GBDeviceAdapterv2.V
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
GBApplication.deviceService(device).onHeartRateTest();
|
||||
HeartRateDialog dialog = new HeartRateDialog(context);
|
||||
HeartRateDialog dialog = new HeartRateDialog(device, context);
|
||||
dialog.show();
|
||||
}
|
||||
}
|
||||
|
@ -138,6 +138,7 @@ public class ColmiR0xPacketHandler {
|
||||
sampleProvider.addSample(gbSample);
|
||||
// Send local intent with sample for listeners like the heart rate dialog
|
||||
Intent liveIntent = new Intent(DeviceService.ACTION_REALTIME_SAMPLES);
|
||||
liveIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
|
||||
liveIntent.putExtra(DeviceService.EXTRA_REALTIME_SAMPLE, gbSample);
|
||||
LocalBroadcastManager.getInstance(context)
|
||||
.sendBroadcast(liveIntent);
|
||||
|
@ -858,6 +858,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
// push realtime data
|
||||
if (realtime && (realtimeHRM || realtimeStep)) {
|
||||
Intent intent = new Intent(DeviceService.ACTION_REALTIME_SAMPLES)
|
||||
.putExtra(GBDevice.EXTRA_DEVICE, getDevice())
|
||||
.putExtra(DeviceService.EXTRA_REALTIME_SAMPLE, sample);
|
||||
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
|
||||
}
|
||||
|
@ -212,6 +212,7 @@ public class CyclingSensorSupport extends CyclingSensorBaseSupport {
|
||||
sample.setTimestamp(now);
|
||||
|
||||
Intent liveIntent = new Intent(DeviceService.ACTION_REALTIME_SAMPLES);
|
||||
liveIntent.putExtra(GBDevice.EXTRA_DEVICE, getDevice());
|
||||
liveIntent.putExtra(DeviceService.EXTRA_REALTIME_SAMPLE, sample);
|
||||
liveIntent.putExtra("EXTRA_DEVICE_ADDRESS", getDevice().getAddress());
|
||||
LocalBroadcastManager.getInstance(getContext())
|
||||
|
@ -1328,6 +1328,7 @@ public class FitProDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
|
||||
public void broadcastSample(FitProActivitySample sample) {
|
||||
Intent intent = new Intent(DeviceService.ACTION_REALTIME_SAMPLES)
|
||||
.putExtra(GBDevice.EXTRA_DEVICE, getDevice())
|
||||
.putExtra(DeviceService.EXTRA_REALTIME_SAMPLE, sample);
|
||||
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
|
||||
}
|
||||
|
@ -446,6 +446,7 @@ class HPlusHandlerThread extends GBDeviceIoThread {
|
||||
sample.setSteps(sample.getSteps() - prevRealTimeRecord.steps);
|
||||
|
||||
Intent intent = new Intent(DeviceService.ACTION_REALTIME_SAMPLES)
|
||||
.putExtra(GBDevice.EXTRA_DEVICE, getDevice())
|
||||
.putExtra(DeviceService.EXTRA_REALTIME_SAMPLE, sample)
|
||||
.putExtra(DeviceService.EXTRA_TIMESTAMP, System.currentTimeMillis());
|
||||
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
|
||||
|
@ -2616,6 +2616,7 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
|
||||
}
|
||||
|
||||
Intent intent = new Intent(DeviceService.ACTION_REALTIME_SAMPLES)
|
||||
.putExtra(GBDevice.EXTRA_DEVICE, getDevice())
|
||||
.putExtra(DeviceService.EXTRA_REALTIME_SAMPLE, sample);
|
||||
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
|
||||
|
||||
|
@ -37,6 +37,7 @@ import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.JYouActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.User;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
|
||||
@ -178,6 +179,7 @@ public class Y5Support extends JYouSupport {
|
||||
}
|
||||
|
||||
Intent intent = new Intent(DeviceService.ACTION_REALTIME_SAMPLES)
|
||||
.putExtra(GBDevice.EXTRA_DEVICE, getDevice())
|
||||
.putExtra(DeviceService.EXTRA_REALTIME_SAMPLE, sample);
|
||||
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
|
||||
|
||||
|
@ -756,6 +756,7 @@ public class LefunDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
sample.setSteps(diff);
|
||||
lastStepsCount = command.getSteps();
|
||||
Intent intent = new Intent(DeviceService.ACTION_REALTIME_SAMPLES)
|
||||
.putExtra(GBDevice.EXTRA_DEVICE, getDevice())
|
||||
.putExtra(DeviceService.EXTRA_REALTIME_SAMPLE, sample)
|
||||
.putExtra(DeviceService.EXTRA_TIMESTAMP, sample.getTimestamp());
|
||||
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
|
||||
@ -910,6 +911,7 @@ public class LefunDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
session.getLefunActivitySampleDao().insertOrReplace(sample);
|
||||
|
||||
final Intent intent = new Intent(DeviceService.ACTION_REALTIME_SAMPLES)
|
||||
.putExtra(GBDevice.EXTRA_DEVICE, getDevice())
|
||||
.putExtra(DeviceService.EXTRA_REALTIME_SAMPLE, sample);
|
||||
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
|
||||
}
|
||||
|
@ -557,6 +557,7 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implement
|
||||
*/
|
||||
private void broadcastSample(MakibesHR3ActivitySample sample) {
|
||||
Intent intent = new Intent(DeviceService.ACTION_REALTIME_SAMPLES)
|
||||
.putExtra(GBDevice.EXTRA_DEVICE, getDevice())
|
||||
.putExtra(DeviceService.EXTRA_REALTIME_SAMPLE, sample)
|
||||
.putExtra(DeviceService.EXTRA_TIMESTAMP, sample.getTimestamp());
|
||||
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
|
||||
|
@ -971,6 +971,7 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
|
||||
Intent intent = new Intent(DeviceService.ACTION_REALTIME_SAMPLES)
|
||||
.putExtra(GBDevice.EXTRA_DEVICE, getDevice())
|
||||
.putExtra(DeviceService.EXTRA_REALTIME_SAMPLE, sample);
|
||||
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
|
||||
|
||||
|
@ -1131,6 +1131,7 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuL
|
||||
this.addGBActivitySample(sample);
|
||||
|
||||
Intent intent = new Intent(DeviceService.ACTION_REALTIME_SAMPLES)
|
||||
.putExtra(GBDevice.EXTRA_DEVICE, getDevice())
|
||||
.putExtra(DeviceService.EXTRA_REALTIME_SAMPLE, sample)
|
||||
.putExtra(DeviceService.EXTRA_TIMESTAMP, sample.getTimestamp());
|
||||
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
|
||||
@ -1157,6 +1158,7 @@ public class PineTimeJFSupport extends AbstractBTLEDeviceSupport implements DfuL
|
||||
this.addGBActivitySample(sample);
|
||||
|
||||
Intent intent = new Intent(DeviceService.ACTION_REALTIME_SAMPLES)
|
||||
.putExtra(GBDevice.EXTRA_DEVICE, getDevice())
|
||||
.putExtra(DeviceService.EXTRA_REALTIME_SAMPLE, sample)
|
||||
.putExtra(DeviceService.EXTRA_TIMESTAMP, sample.getTimestamp());
|
||||
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
|
||||
|
@ -71,6 +71,7 @@ public class SonySWR12HandlerThread extends GBDeviceIoThread {
|
||||
provider.addGBActivitySample(sample);
|
||||
GBApplication.releaseDB();
|
||||
Intent intent = new Intent(DeviceService.ACTION_REALTIME_SAMPLES)
|
||||
.putExtra(GBDevice.EXTRA_DEVICE, getDevice())
|
||||
.putExtra(DeviceService.EXTRA_REALTIME_SAMPLE, sample)
|
||||
.putExtra(DeviceService.EXTRA_TIMESTAMP, timestamp);
|
||||
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(intent);
|
||||
|
@ -30,6 +30,7 @@ import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.withingssteelhr.WithingsSteelHRSampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.WithingsSteelHRActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.withingssteelhr.WithingsSteelHRDeviceSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.withingssteelhr.activity.SleepActivitySampleHelper;
|
||||
@ -78,6 +79,7 @@ public class HeartRateHandler extends AbstractResponseHandler {
|
||||
sample = SleepActivitySampleHelper.mergeIfNecessary(provider, sample);
|
||||
provider.addGBActivitySample(sample);
|
||||
Intent intent = new Intent(DeviceService.ACTION_REALTIME_SAMPLES)
|
||||
.putExtra(GBDevice.EXTRA_DEVICE, support.getDevice())
|
||||
.putExtra(DeviceService.EXTRA_REALTIME_SAMPLE, sample);
|
||||
LocalBroadcastManager.getInstance(support.getContext()).sendBroadcast(intent);
|
||||
} catch (Exception ex) {
|
||||
|
@ -31,6 +31,7 @@ import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.devices.withingssteelhr.WithingsSteelHRSampleProvider;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.WithingsSteelHRActivitySample;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.DeviceService;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.withingssteelhr.WithingsSteelHRDeviceSupport;
|
||||
import nodomain.freeyourgadget.gadgetbridge.service.devices.withingssteelhr.activity.SleepActivitySampleHelper;
|
||||
@ -82,6 +83,7 @@ public class LiveHeartrateHandler implements IncomingMessageHandler {
|
||||
logger.warn("Error saving current heart rate: " + ex.getLocalizedMessage());
|
||||
}
|
||||
Intent intent = new Intent(DeviceService.ACTION_REALTIME_SAMPLES)
|
||||
.putExtra(GBDevice.EXTRA_DEVICE, support.getDevice())
|
||||
.putExtra(DeviceService.EXTRA_REALTIME_SAMPLE, sample);
|
||||
LocalBroadcastManager.getInstance(support.getContext()).sendBroadcast(intent);
|
||||
}
|
||||
|
@ -940,6 +940,7 @@ public class XiaomiHealthService extends AbstractXiaomiService {
|
||||
previousSteps = realTimeStats.getSteps();
|
||||
|
||||
final Intent intent = new Intent(DeviceService.ACTION_REALTIME_SAMPLES)
|
||||
.putExtra(GBDevice.EXTRA_DEVICE, getSupport().getDevice())
|
||||
.putExtra(DeviceService.EXTRA_REALTIME_SAMPLE, sample);
|
||||
LocalBroadcastManager.getInstance(getSupport().getContext()).sendBroadcast(intent);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user