mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-24 02:46:50 +01:00
Widget: change float to int where appropriate, remove code that did nothing from getTotalsStepsForActivityAmounts()
This commit is contained in:
parent
3389fcdfdd
commit
4780c26dd8
@ -66,12 +66,12 @@ public class Widget extends AppWidgetProvider {
|
||||
return gbApp.getDeviceManager().getSelectedDevice();
|
||||
}
|
||||
|
||||
private float[] getSteps() {
|
||||
private int[] getSteps() {
|
||||
Context context = GBApplication.getContext();
|
||||
Calendar day = GregorianCalendar.getInstance();
|
||||
|
||||
if (!(context instanceof GBApplication)) {
|
||||
return new float[]{0, 0, 0};
|
||||
return new int[]{0, 0, 0};
|
||||
}
|
||||
DailyTotals ds = new DailyTotals();
|
||||
return ds.getDailyTotalsForAllDevices(day);
|
||||
@ -114,7 +114,7 @@ public class Widget extends AppWidgetProvider {
|
||||
}
|
||||
|
||||
|
||||
float[] DailyTotals = getSteps();
|
||||
int[] DailyTotals = getSteps();
|
||||
|
||||
views.setTextViewText(R.id.todaywidget_steps, context.getString(R.string.widget_steps_label, (int) DailyTotals[0]));
|
||||
views.setTextViewText(R.id.todaywidget_sleep, context.getString(R.string.widget_sleep_label, getHM((long) DailyTotals[1])));
|
||||
|
@ -40,11 +40,11 @@ public class DailyTotals {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(DailyTotals.class);
|
||||
|
||||
|
||||
public float[] getDailyTotalsForAllDevices(Calendar day) {
|
||||
public int[] getDailyTotalsForAllDevices(Calendar day) {
|
||||
Context context = GBApplication.getContext();
|
||||
//get today's steps for all devices in GB
|
||||
float all_steps = 0;
|
||||
float all_sleep = 0;
|
||||
int all_steps = 0;
|
||||
int all_sleep = 0;
|
||||
|
||||
|
||||
if (context instanceof GBApplication) {
|
||||
@ -55,18 +55,18 @@ public class DailyTotals {
|
||||
if (!coordinator.supportsActivityDataFetching()) {
|
||||
continue;
|
||||
}
|
||||
float[] all_daily = getDailyTotalsForDevice(device, day);
|
||||
int[] all_daily = getDailyTotalsForDevice(device, day);
|
||||
all_steps += all_daily[0];
|
||||
all_sleep += all_daily[1] + all_daily[2];
|
||||
}
|
||||
}
|
||||
LOG.debug("gbwidget daily totals, all steps:" + all_steps);
|
||||
LOG.debug("gbwidget daily totals, all sleep:" + all_sleep);
|
||||
return new float[]{all_steps, all_sleep};
|
||||
return new int[]{all_steps, all_sleep};
|
||||
}
|
||||
|
||||
|
||||
public float[] getDailyTotalsForDevice(GBDevice device, Calendar day) {
|
||||
public int[] getDailyTotalsForDevice(GBDevice device, Calendar day) {
|
||||
|
||||
try (DBHandler handler = GBApplication.acquireDB()) {
|
||||
ActivityAnalysis analysis = new ActivityAnalysis();
|
||||
@ -76,19 +76,19 @@ public class DailyTotals {
|
||||
amountsSteps = analysis.calculateActivityAmounts(getSamplesOfDay(handler, day, 0, device));
|
||||
amountsSleep = analysis.calculateActivityAmounts(getSamplesOfDay(handler, day, -12, device));
|
||||
|
||||
float[] Sleep = getTotalsSleepForActivityAmounts(amountsSleep);
|
||||
float Steps = getTotalsStepsForActivityAmounts(amountsSteps);
|
||||
int[] Sleep = getTotalsSleepForActivityAmounts(amountsSleep);
|
||||
int Steps = getTotalsStepsForActivityAmounts(amountsSteps);
|
||||
|
||||
return new float[]{Steps, Sleep[0], Sleep[1]};
|
||||
return new int[]{Steps, Sleep[0], Sleep[1]};
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
GB.toast("Error loading activity summaries.", Toast.LENGTH_SHORT, GB.ERROR, e);
|
||||
return new float[]{0, 0, 0};
|
||||
return new int[]{0, 0, 0};
|
||||
}
|
||||
}
|
||||
|
||||
private float[] getTotalsSleepForActivityAmounts(ActivityAmounts activityAmounts) {
|
||||
private int[] getTotalsSleepForActivityAmounts(ActivityAmounts activityAmounts) {
|
||||
long totalSecondsDeepSleep = 0;
|
||||
long totalSecondsLightSleep = 0;
|
||||
for (ActivityAmount amount : activityAmounts.getAmounts()) {
|
||||
@ -100,25 +100,17 @@ public class DailyTotals {
|
||||
}
|
||||
int totalMinutesDeepSleep = (int) (totalSecondsDeepSleep / 60);
|
||||
int totalMinutesLightSleep = (int) (totalSecondsLightSleep / 60);
|
||||
return new float[]{totalMinutesDeepSleep, totalMinutesLightSleep};
|
||||
return new int[]{totalMinutesDeepSleep, totalMinutesLightSleep};
|
||||
}
|
||||
|
||||
|
||||
private float getTotalsStepsForActivityAmounts(ActivityAmounts activityAmounts) {
|
||||
long totalSteps = 0;
|
||||
float totalValue = 0;
|
||||
private int getTotalsStepsForActivityAmounts(ActivityAmounts activityAmounts) {
|
||||
int totalSteps = 0;
|
||||
|
||||
for (ActivityAmount amount : activityAmounts.getAmounts()) {
|
||||
totalSteps += amount.getTotalSteps();
|
||||
}
|
||||
|
||||
float[] totalValues = new float[]{totalSteps};
|
||||
|
||||
for (int i = 0; i < totalValues.length; i++) {
|
||||
float value = totalValues[i];
|
||||
totalValue += value;
|
||||
}
|
||||
return totalValue;
|
||||
return totalSteps;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user