mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-15 20:27:32 +01:00
Calories: Fix some crashes
This commit is contained in:
parent
b722969a68
commit
3ad2e827c2
@ -29,7 +29,6 @@ import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.TimeSampleProvider;
|
import nodomain.freeyourgadget.gadgetbridge.devices.TimeSampleProvider;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample;
|
import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.GarminRestingMetabolicRateSample;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
|
||||||
@ -121,7 +120,7 @@ public class CaloriesDailyFragment extends AbstractChartFragment<CaloriesDailyFr
|
|||||||
return device.getDeviceCoordinator().supportsActiveCalories();
|
return device.getDeviceCoordinator().supportsActiveCalories();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TimeSample getRestingMetabolicRate(DBHandler db, GBDevice device) {
|
protected RestingMetabolicRateSample getRestingMetabolicRate(DBHandler db, GBDevice device) {
|
||||||
TimeSampleProvider<? extends RestingMetabolicRateSample> provider = device.getDeviceCoordinator().getRestingMetabolicRateProvider(device, db.getDaoSession());
|
TimeSampleProvider<? extends RestingMetabolicRateSample> provider = device.getDeviceCoordinator().getRestingMetabolicRateProvider(device, db.getDaoSession());
|
||||||
return provider.getLatestSample();
|
return provider.getLatestSample();
|
||||||
}
|
}
|
||||||
@ -155,7 +154,10 @@ public class CaloriesDailyFragment extends AbstractChartFragment<CaloriesDailyFr
|
|||||||
String formattedDate = new SimpleDateFormat("E, MMM dd").format(date);
|
String formattedDate = new SimpleDateFormat("E, MMM dd").format(date);
|
||||||
dateView.setText(formattedDate);
|
dateView.setText(formattedDate);
|
||||||
List<? extends ActivitySample> samples = getActivitySamples(db, device, startTs, endTs);
|
List<? extends ActivitySample> samples = getActivitySamples(db, device, startTs, endTs);
|
||||||
TimeSample metabolicRate = getRestingMetabolicRate(db, device);
|
RestingMetabolicRateSample metabolicRate = getRestingMetabolicRate(db, device);
|
||||||
|
if (metabolicRate == null) {
|
||||||
|
return new CaloriesData(0, 0, 0);
|
||||||
|
}
|
||||||
int totalBurnt;
|
int totalBurnt;
|
||||||
int activeBurnt = 0;
|
int activeBurnt = 0;
|
||||||
boolean sameDay = calendar.get(Calendar.DAY_OF_YEAR) == day.get(Calendar.DAY_OF_YEAR) &&
|
boolean sameDay = calendar.get(Calendar.DAY_OF_YEAR) == day.get(Calendar.DAY_OF_YEAR) &&
|
||||||
@ -164,7 +166,7 @@ public class CaloriesDailyFragment extends AbstractChartFragment<CaloriesDailyFr
|
|||||||
if (sameDay) {
|
if (sameDay) {
|
||||||
passedDayProportion = (double) (calendar.getTimeInMillis() - day.getTimeInMillis()) / (24L * 60 * 60 * 1000);
|
passedDayProportion = (double) (calendar.getTimeInMillis() - day.getTimeInMillis()) / (24L * 60 * 60 * 1000);
|
||||||
}
|
}
|
||||||
int restingBurnt = (int) ((double) ((GarminRestingMetabolicRateSample) metabolicRate).getRestingMetabolicRate() * passedDayProportion);
|
int restingBurnt = (int) (metabolicRate.getRestingMetabolicRate() * passedDayProportion);
|
||||||
|
|
||||||
for (int i = 0; i <= samples.size() - 1; i++) {
|
for (int i = 0; i <= samples.size() - 1; i++) {
|
||||||
ActivitySample sample = samples.get(i);
|
ActivitySample sample = samples.get(i);
|
||||||
|
@ -24,7 +24,6 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -35,7 +34,6 @@ import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
|||||||
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.TimeSampleProvider;
|
import nodomain.freeyourgadget.gadgetbridge.devices.TimeSampleProvider;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample;
|
import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.GarminRestingMetabolicRateSample;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
|
|
||||||
|
|
||||||
@ -162,21 +160,24 @@ public class DailyTotals implements Serializable {
|
|||||||
day.set(Calendar.MINUTE, 0);
|
day.set(Calendar.MINUTE, 0);
|
||||||
day.set(Calendar.SECOND, 0);
|
day.set(Calendar.SECOND, 0);
|
||||||
day.add(Calendar.HOUR, 0);
|
day.add(Calendar.HOUR, 0);
|
||||||
TimeSample metabolicRate = getRestingMetabolicRate(db, device);
|
RestingMetabolicRateSample metabolicRate = getRestingMetabolicRate(db, device);
|
||||||
|
if (metabolicRate == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
double passedDayProportion = 1;
|
double passedDayProportion = 1;
|
||||||
boolean sameDay = calendar.get(Calendar.DAY_OF_YEAR) == day.get(Calendar.DAY_OF_YEAR) &&
|
boolean sameDay = calendar.get(Calendar.DAY_OF_YEAR) == day.get(Calendar.DAY_OF_YEAR) &&
|
||||||
calendar.get(Calendar.YEAR) == day.get(Calendar.YEAR);
|
calendar.get(Calendar.YEAR) == day.get(Calendar.YEAR);
|
||||||
if (sameDay) {
|
if (sameDay) {
|
||||||
passedDayProportion = (double) (calendar.getTimeInMillis() - day.getTimeInMillis()) / (24L * 60 * 60 * 1000);
|
passedDayProportion = (double) (calendar.getTimeInMillis() - day.getTimeInMillis()) / (24L * 60 * 60 * 1000);
|
||||||
}
|
}
|
||||||
return (int) ((double) ((GarminRestingMetabolicRateSample) metabolicRate).getRestingMetabolicRate() * passedDayProportion);
|
return (int) (metabolicRate.getRestingMetabolicRate() * passedDayProportion);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<? extends ActivitySample> getSamples(DBHandler db, GBDevice device, int tsFrom, int tsTo) {
|
public static List<? extends ActivitySample> getSamples(DBHandler db, GBDevice device, int tsFrom, int tsTo) {
|
||||||
return getAllSamples(db, device, tsFrom, tsTo);
|
return getAllSamples(db, device, tsFrom, tsTo);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static TimeSample getRestingMetabolicRate(DBHandler db, GBDevice device) {
|
protected static RestingMetabolicRateSample getRestingMetabolicRate(DBHandler db, GBDevice device) {
|
||||||
TimeSampleProvider<? extends RestingMetabolicRateSample> provider = device.getDeviceCoordinator().getRestingMetabolicRateProvider(device, db.getDaoSession());
|
TimeSampleProvider<? extends RestingMetabolicRateSample> provider = device.getDeviceCoordinator().getRestingMetabolicRateProvider(device, db.getDaoSession());
|
||||||
return provider.getLatestSample();
|
return provider.getLatestSample();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user