mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-11 17:41:57 +01:00
Widget: Fix null pointer exception when a device which has no activity database is used in Gadgetbridge
For example a vibratissimo :D
This commit is contained in:
parent
8eb494ab85
commit
3389fcdfdd
@ -36,9 +36,8 @@ import nodomain.freeyourgadget.gadgetbridge.util.DeviceHelper;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
import nodomain.freeyourgadget.gadgetbridge.util.GB;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class DailyTotals {
|
public class DailyTotals {
|
||||||
Logger LOG = LoggerFactory.getLogger(DailyTotals.class);
|
private static final Logger LOG = LoggerFactory.getLogger(DailyTotals.class);
|
||||||
|
|
||||||
|
|
||||||
public float[] getDailyTotalsForAllDevices(Calendar day) {
|
public float[] getDailyTotalsForAllDevices(Calendar day) {
|
||||||
@ -52,6 +51,10 @@ public class DailyTotals {
|
|||||||
GBApplication gbApp = (GBApplication) context;
|
GBApplication gbApp = (GBApplication) context;
|
||||||
List<? extends GBDevice> devices = gbApp.getDeviceManager().getDevices();
|
List<? extends GBDevice> devices = gbApp.getDeviceManager().getDevices();
|
||||||
for (GBDevice device : devices) {
|
for (GBDevice device : devices) {
|
||||||
|
DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
|
||||||
|
if (!coordinator.supportsActivityDataFetching()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
float[] all_daily = getDailyTotalsForDevice(device, day);
|
float[] all_daily = getDailyTotalsForDevice(device, day);
|
||||||
all_steps += all_daily[0];
|
all_steps += all_daily[0];
|
||||||
all_sleep += all_daily[1] + all_daily[2];
|
all_sleep += all_daily[1] + all_daily[2];
|
||||||
@ -63,13 +66,12 @@ public class DailyTotals {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public float[] getDailyTotalsForDevice(GBDevice device, Calendar day
|
public float[] getDailyTotalsForDevice(GBDevice device, Calendar day) {
|
||||||
) {
|
|
||||||
|
|
||||||
try (DBHandler handler = GBApplication.acquireDB()) {
|
try (DBHandler handler = GBApplication.acquireDB()) {
|
||||||
ActivityAnalysis analysis = new ActivityAnalysis();
|
ActivityAnalysis analysis = new ActivityAnalysis();
|
||||||
ActivityAmounts amountsSteps = null;
|
ActivityAmounts amountsSteps;
|
||||||
ActivityAmounts amountsSleep = null;
|
ActivityAmounts amountsSleep;
|
||||||
|
|
||||||
amountsSteps = analysis.calculateActivityAmounts(getSamplesOfDay(handler, day, 0, device));
|
amountsSteps = analysis.calculateActivityAmounts(getSamplesOfDay(handler, day, 0, device));
|
||||||
amountsSleep = analysis.calculateActivityAmounts(getSamplesOfDay(handler, day, -12, device));
|
amountsSleep = analysis.calculateActivityAmounts(getSamplesOfDay(handler, day, -12, device));
|
||||||
|
Loading…
Reference in New Issue
Block a user