mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 04:46:51 +01:00
NO.1 F1: Show data fetching progress.
This commit is contained in:
parent
bf34586a22
commit
23b66459f5
@ -69,6 +69,7 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
|
|||||||
public BluetoothGattCharacteristic measureCharacteristic = null;
|
public BluetoothGattCharacteristic measureCharacteristic = null;
|
||||||
private List<No1F1ActivitySample> samples = new ArrayList<>();
|
private List<No1F1ActivitySample> samples = new ArrayList<>();
|
||||||
private byte crc = 0;
|
private byte crc = 0;
|
||||||
|
private int firstTimestamp = 0;
|
||||||
|
|
||||||
public No1F1Support() {
|
public No1F1Support() {
|
||||||
super(LOG);
|
super(LOG);
|
||||||
@ -248,6 +249,7 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
|
|||||||
try {
|
try {
|
||||||
samples.clear();
|
samples.clear();
|
||||||
crc = 0;
|
crc = 0;
|
||||||
|
firstTimestamp = 0;
|
||||||
TransactionBuilder builder = performInitialized("fetchSteps");
|
TransactionBuilder builder = performInitialized("fetchSteps");
|
||||||
builder.add(new SetDeviceBusyAction(getDevice(), getContext().getString(R.string.busy_task_fetch_activity_data), getContext()));
|
builder.add(new SetDeviceBusyAction(getDevice(), getContext().getString(R.string.busy_task_fetch_activity_data), getContext()));
|
||||||
byte[] msg = new byte[]{
|
byte[] msg = new byte[]{
|
||||||
@ -531,6 +533,7 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
|
|||||||
LOG.info("CRC received: " + (data[2] & 0xff) + ", calculated: " + (crc & 0xff));
|
LOG.info("CRC received: " + (data[2] & 0xff) + ", calculated: " + (crc & 0xff));
|
||||||
if (data[2] != crc) {
|
if (data[2] != crc) {
|
||||||
GB.toast(getContext(), "Incorrect CRC. Try fetching data again.", Toast.LENGTH_LONG, GB.ERROR);
|
GB.toast(getContext(), "Incorrect CRC. Try fetching data again.", Toast.LENGTH_LONG, GB.ERROR);
|
||||||
|
GB.updateTransferNotification("Data transfer failed", false, 0, getContext());
|
||||||
if (getDevice().isBusy()) {
|
if (getDevice().isBusy()) {
|
||||||
getDevice().unsetBusyTask();
|
getDevice().unsetBusyTask();
|
||||||
getDevice().sendDeviceUpdateIntent(getContext());
|
getDevice().sendDeviceUpdateIntent(getContext());
|
||||||
@ -549,6 +552,7 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
|
|||||||
}
|
}
|
||||||
samples.clear();
|
samples.clear();
|
||||||
crc = 0;
|
crc = 0;
|
||||||
|
firstTimestamp = 0;
|
||||||
LOG.info("Steps data saved");
|
LOG.info("Steps data saved");
|
||||||
try {
|
try {
|
||||||
TransactionBuilder builder = performInitialized("fetchSleep");
|
TransactionBuilder builder = performInitialized("fetchSleep");
|
||||||
@ -564,6 +568,7 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
|
|||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
GB.toast(getContext(), "Error saving step data: " + ex.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
|
GB.toast(getContext(), "Error saving step data: " + ex.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
|
||||||
|
GB.updateTransferNotification("Data transfer failed", false, 0, getContext());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -585,6 +590,11 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
|
|||||||
LOG.info("Received steps data for " + String.format("%1$TD %1$TT", timestamp) + ": " +
|
LOG.info("Received steps data for " + String.format("%1$TD %1$TT", timestamp) + ": " +
|
||||||
sample.getSteps() + " steps"
|
sample.getSteps() + " steps"
|
||||||
);
|
);
|
||||||
|
if (firstTimestamp == 0)
|
||||||
|
firstTimestamp = sample.getTimestamp();
|
||||||
|
int progress = 33 * (sample.getTimestamp() - firstTimestamp) /
|
||||||
|
((int) (Calendar.getInstance().getTimeInMillis() / 1000L) - firstTimestamp);
|
||||||
|
GB.updateTransferNotification(getContext().getString(R.string.busy_task_fetch_activity_data), true, progress, getContext());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -593,6 +603,7 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
|
|||||||
LOG.info("CRC received: " + (data[2] & 0xff) + ", calculated: " + (crc & 0xff));
|
LOG.info("CRC received: " + (data[2] & 0xff) + ", calculated: " + (crc & 0xff));
|
||||||
if (data[2] != crc) {
|
if (data[2] != crc) {
|
||||||
GB.toast(getContext(), "Incorrect CRC. Try fetching data again.", Toast.LENGTH_LONG, GB.ERROR);
|
GB.toast(getContext(), "Incorrect CRC. Try fetching data again.", Toast.LENGTH_LONG, GB.ERROR);
|
||||||
|
GB.updateTransferNotification("Data transfer failed", false, 0, getContext());
|
||||||
if (getDevice().isBusy()) {
|
if (getDevice().isBusy()) {
|
||||||
getDevice().unsetBusyTask();
|
getDevice().unsetBusyTask();
|
||||||
getDevice().sendDeviceUpdateIntent(getContext());
|
getDevice().sendDeviceUpdateIntent(getContext());
|
||||||
@ -613,6 +624,7 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
|
|||||||
}
|
}
|
||||||
samples.clear();
|
samples.clear();
|
||||||
crc = 0;
|
crc = 0;
|
||||||
|
firstTimestamp = 0;
|
||||||
LOG.info("Sleep data saved");
|
LOG.info("Sleep data saved");
|
||||||
try {
|
try {
|
||||||
TransactionBuilder builder = performInitialized("fetchHeartRate");
|
TransactionBuilder builder = performInitialized("fetchHeartRate");
|
||||||
@ -628,6 +640,7 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
|
|||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
GB.toast(getContext(), "Error saving sleep data: " + ex.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
|
GB.toast(getContext(), "Error saving sleep data: " + ex.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
|
||||||
|
GB.updateTransferNotification("Data transfer failed", false, 0, getContext());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -649,6 +662,11 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
|
|||||||
LOG.info("Received sleep data for " + String.format("%1$TD %1$TT", timestamp) + ": " +
|
LOG.info("Received sleep data for " + String.format("%1$TD %1$TT", timestamp) + ": " +
|
||||||
sample.getRawIntensity() + " rolls"
|
sample.getRawIntensity() + " rolls"
|
||||||
);
|
);
|
||||||
|
if (firstTimestamp == 0)
|
||||||
|
firstTimestamp = sample.getTimestamp();
|
||||||
|
int progress = 33 * (sample.getTimestamp() - firstTimestamp) /
|
||||||
|
((int) (Calendar.getInstance().getTimeInMillis() / 1000L) - firstTimestamp);
|
||||||
|
GB.updateTransferNotification(getContext().getString(R.string.busy_task_fetch_activity_data), true, progress + 33, getContext());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -657,6 +675,7 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
|
|||||||
LOG.info("CRC received: " + (data[2] & 0xff) + ", calculated: " + (crc & 0xff));
|
LOG.info("CRC received: " + (data[2] & 0xff) + ", calculated: " + (crc & 0xff));
|
||||||
if (data[2] != crc) {
|
if (data[2] != crc) {
|
||||||
GB.toast(getContext(), "Incorrect CRC. Try fetching data again.", Toast.LENGTH_LONG, GB.ERROR);
|
GB.toast(getContext(), "Incorrect CRC. Try fetching data again.", Toast.LENGTH_LONG, GB.ERROR);
|
||||||
|
GB.updateTransferNotification("Data transfer failed", false, 0, getContext());
|
||||||
if (getDevice().isBusy()) {
|
if (getDevice().isBusy()) {
|
||||||
getDevice().unsetBusyTask();
|
getDevice().unsetBusyTask();
|
||||||
getDevice().sendDeviceUpdateIntent(getContext());
|
getDevice().sendDeviceUpdateIntent(getContext());
|
||||||
@ -673,13 +692,16 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
|
|||||||
}
|
}
|
||||||
samples.clear();
|
samples.clear();
|
||||||
crc = 0;
|
crc = 0;
|
||||||
|
firstTimestamp = 0;
|
||||||
LOG.info("Heart rate data saved");
|
LOG.info("Heart rate data saved");
|
||||||
|
GB.updateTransferNotification("", false, 100, getContext());
|
||||||
if (getDevice().isBusy()) {
|
if (getDevice().isBusy()) {
|
||||||
getDevice().unsetBusyTask();
|
getDevice().unsetBusyTask();
|
||||||
getDevice().sendDeviceUpdateIntent(getContext());
|
getDevice().sendDeviceUpdateIntent(getContext());
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
GB.toast(getContext(), "Error saving heart rate data: " + ex.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
|
GB.toast(getContext(), "Error saving heart rate data: " + ex.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
|
||||||
|
GB.updateTransferNotification("Data transfer failed", false, 0, getContext());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -701,6 +723,11 @@ public class No1F1Support extends AbstractBTLEDeviceSupport {
|
|||||||
LOG.info("Received heart rate data for " + String.format("%1$TD %1$TT", timestamp) + ": " +
|
LOG.info("Received heart rate data for " + String.format("%1$TD %1$TT", timestamp) + ": " +
|
||||||
sample.getHeartRate() + " BPM"
|
sample.getHeartRate() + " BPM"
|
||||||
);
|
);
|
||||||
|
if (firstTimestamp == 0)
|
||||||
|
firstTimestamp = sample.getTimestamp();
|
||||||
|
int progress = 33 * (sample.getTimestamp() - firstTimestamp) /
|
||||||
|
((int) (Calendar.getInstance().getTimeInMillis() / 1000L) - firstTimestamp);
|
||||||
|
GB.updateTransferNotification(getContext().getString(R.string.busy_task_fetch_activity_data), true, progress + 66, getContext());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user