handle devices without data better and other stuff

This commit is contained in:
vanous 2022-07-28 15:59:48 +02:00
parent 23a7f2da94
commit 8fb644dd00
5 changed files with 21 additions and 13 deletions

View File

@ -35,6 +35,7 @@ public class StepStreaksDashboard extends DialogFragment {
GBDevice gbDevice;
int goal;
boolean cancelTasks = false;
boolean backgroundFinished = false;
private View fragmentView;
private StepsStreaks stepsStreaks = new StepsStreaks();
@ -87,7 +88,7 @@ public class StepStreaksDashboard extends DialogFragment {
throw new IllegalArgumentException("Must provide a device when invoking this activity");
}
createTaskCalculateLatestStepsStreak("Visualizing data current", getActivity(), "current").execute();
createTaskCalculateLatestStepsStreak("Visualizing data maximum", getActivity(), "maximum").execute();
createTaskCalculateLatestStepsStreak("Visualizing data maximum", getActivity(), "totals").execute();
}
@ -133,10 +134,13 @@ public class StepStreaksDashboard extends DialogFragment {
date_maximum_value.setText(DateTimeUtils.formatDate(new Date(stepsStreaks.maximum.timestamp * 1000l)));
LOG.debug("petr " + stepsStreaks.total.timestamp);
}
if (stepsStreaks.total.days > 0) {
if (stepsStreaks.total.steps > 0 || backgroundFinished) {
total.setVisibility(View.VISIBLE);
days_total_label.setText("Achievement\n rate");
days_total.setText(String.format("%.1f%%", (float) stepsStreaks.total.days / stepsStreaks.total.total_days * 100));
days_total.setText(String.format("%.1f%%", 0.0));
if (stepsStreaks.total.total_days > 0) {
days_total.setText(String.format("%.1f%%", (float) stepsStreaks.total.days / stepsStreaks.total.total_days * 100));
}
total_total.setText(Integer.toString(stepsStreaks.total.steps));
}
}
@ -160,7 +164,7 @@ public class StepStreaksDashboard extends DialogFragment {
calculateStreakData(db, "current", gbDevice, goal);
break;
case "maximum":
case "totals":
calculateStreakData(db, "totals", gbDevice, goal);
break;
}
@ -176,11 +180,11 @@ public class StepStreaksDashboard extends DialogFragment {
super.onPostExecute(o);
FragmentActivity activity = getActivity();
if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
populateData();
if (period.equals("maximum")) {
if (period.equals("totals")) {
backgroundFinished = true;
indicate_progress(false);
}
populateData();
} else {
LOG.info("Not filling data because activity is not available anymore");
}
@ -200,25 +204,25 @@ public class StepStreaksDashboard extends DialogFragment {
DailyTotals dailyTotals = new DailyTotals();
ActivitySample firstSample = dailyTotals.getFirstSample(db, device);
Calendar firstDate = Calendar.getInstance();
firstDate.setTime(new Date(firstSample.getTimestamp() * 1000l));
firstDate.setTime(DateTimeUtils.shiftByDays(new Date(firstSample.getTimestamp() * 1000l), -1));
//go one day back, to ensure we are before the first day, to calculate first day data as well
//NOTE: getting the first sample as a first day reference is not reliable
while (true) {
if (cancelTasks) {
GB.toast("bailing out background jobs", Toast.LENGTH_SHORT, GB.INFO);
GB.toast("Bailing out background jobs", Toast.LENGTH_SHORT, GB.INFO);
break;
}
int steps_this_day = 0;
long[] daily_data = dailyTotals.getDailyTotalsForDevice(device, day, db);
steps_this_day = (int) daily_data[0];
int steps_this_day = (int) daily_data[0];
if (steps_this_day > 0) {
all_step_days++;
all_steps += steps_this_day;
}
if (steps_this_day > goal) {
if (steps_this_day >= goal) {
streak_steps += steps_this_day;
streak_days++;
all_streak_days++;

View File

@ -18,6 +18,7 @@
android:maxLines="2"
android:scrollHorizontally="false"
android:text="Average\n steps"
android:tooltipText="Average steps per day"
android:textAllCaps="true"
android:textColor="@color/accent"
android:textStyle="bold" />

View File

@ -20,6 +20,7 @@
android:maxLines="2"
android:scrollHorizontally="false"
android:text="Days\n"
android:tooltipText="Number of consecutive days with steps goal being reached"
android:textAllCaps="true"
android:textColor="@color/accent"
android:textStyle="bold" />

View File

@ -18,6 +18,7 @@
android:maxLines="2"
android:scrollHorizontally="false"
android:text="Total\n steps"
android:tooltipText="Total number of steps in the whole streak"
android:textAllCaps="true"
android:textColor="@color/accent"
android:textStyle="bold" />

View File

@ -25,6 +25,7 @@
android:maxLines="2"
android:scrollHorizontally="false"
android:text="Steps streaks"
android:tooltipText="Series of consecutive days without interruption with steps goal being reached"
android:textAllCaps="true"
android:textSize="24sp"
android:textStyle="bold" />