1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-27 20:36:51 +01:00

Widget: change float to int where appropriate, remove code that did nothing from getTotalsStepsForActivityAmounts()

This commit is contained in:
Andreas Shimokawa 2019-09-01 22:48:52 +02:00
parent 3389fcdfdd
commit 4780c26dd8
2 changed files with 18 additions and 26 deletions

View File

@ -66,12 +66,12 @@ public class Widget extends AppWidgetProvider {
return gbApp.getDeviceManager().getSelectedDevice(); return gbApp.getDeviceManager().getSelectedDevice();
} }
private float[] getSteps() { private int[] getSteps() {
Context context = GBApplication.getContext(); Context context = GBApplication.getContext();
Calendar day = GregorianCalendar.getInstance(); Calendar day = GregorianCalendar.getInstance();
if (!(context instanceof GBApplication)) { if (!(context instanceof GBApplication)) {
return new float[]{0, 0, 0}; return new int[]{0, 0, 0};
} }
DailyTotals ds = new DailyTotals(); DailyTotals ds = new DailyTotals();
return ds.getDailyTotalsForAllDevices(day); 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_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]))); views.setTextViewText(R.id.todaywidget_sleep, context.getString(R.string.widget_sleep_label, getHM((long) DailyTotals[1])));

View File

@ -40,11 +40,11 @@ public class DailyTotals {
private static final Logger LOG = LoggerFactory.getLogger(DailyTotals.class); private static final Logger LOG = LoggerFactory.getLogger(DailyTotals.class);
public float[] getDailyTotalsForAllDevices(Calendar day) { public int[] getDailyTotalsForAllDevices(Calendar day) {
Context context = GBApplication.getContext(); Context context = GBApplication.getContext();
//get today's steps for all devices in GB //get today's steps for all devices in GB
float all_steps = 0; int all_steps = 0;
float all_sleep = 0; int all_sleep = 0;
if (context instanceof GBApplication) { if (context instanceof GBApplication) {
@ -55,18 +55,18 @@ public class DailyTotals {
if (!coordinator.supportsActivityDataFetching()) { if (!coordinator.supportsActivityDataFetching()) {
continue; continue;
} }
float[] all_daily = getDailyTotalsForDevice(device, day); int[] 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];
} }
} }
LOG.debug("gbwidget daily totals, all steps:" + all_steps); LOG.debug("gbwidget daily totals, all steps:" + all_steps);
LOG.debug("gbwidget daily totals, all sleep:" + all_sleep); 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()) { try (DBHandler handler = GBApplication.acquireDB()) {
ActivityAnalysis analysis = new ActivityAnalysis(); ActivityAnalysis analysis = new ActivityAnalysis();
@ -76,19 +76,19 @@ public class DailyTotals {
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));
float[] Sleep = getTotalsSleepForActivityAmounts(amountsSleep); int[] Sleep = getTotalsSleepForActivityAmounts(amountsSleep);
float Steps = getTotalsStepsForActivityAmounts(amountsSteps); int Steps = getTotalsStepsForActivityAmounts(amountsSteps);
return new float[]{Steps, Sleep[0], Sleep[1]}; return new int[]{Steps, Sleep[0], Sleep[1]};
} catch (Exception e) { } catch (Exception e) {
GB.toast("Error loading activity summaries.", Toast.LENGTH_SHORT, GB.ERROR, 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 totalSecondsDeepSleep = 0;
long totalSecondsLightSleep = 0; long totalSecondsLightSleep = 0;
for (ActivityAmount amount : activityAmounts.getAmounts()) { for (ActivityAmount amount : activityAmounts.getAmounts()) {
@ -100,25 +100,17 @@ public class DailyTotals {
} }
int totalMinutesDeepSleep = (int) (totalSecondsDeepSleep / 60); int totalMinutesDeepSleep = (int) (totalSecondsDeepSleep / 60);
int totalMinutesLightSleep = (int) (totalSecondsLightSleep / 60); int totalMinutesLightSleep = (int) (totalSecondsLightSleep / 60);
return new float[]{totalMinutesDeepSleep, totalMinutesLightSleep}; return new int[]{totalMinutesDeepSleep, totalMinutesLightSleep};
} }
private float getTotalsStepsForActivityAmounts(ActivityAmounts activityAmounts) { private int getTotalsStepsForActivityAmounts(ActivityAmounts activityAmounts) {
long totalSteps = 0; int totalSteps = 0;
float totalValue = 0;
for (ActivityAmount amount : activityAmounts.getAmounts()) { for (ActivityAmount amount : activityAmounts.getAmounts()) {
totalSteps += amount.getTotalSteps(); totalSteps += amount.getTotalSteps();
} }
return totalSteps;
float[] totalValues = new float[]{totalSteps};
for (int i = 0; i < totalValues.length; i++) {
float value = totalValues[i];
totalValue += value;
}
return totalValue;
} }