From 71f6fd77cb7f80233ae5c33fc14b0b91bf24d4f4 Mon Sep 17 00:00:00 2001 From: vanous Date: Fri, 13 Nov 2020 14:21:23 +0100 Subject: [PATCH] Add final tweaks to Daily Sessions List Dashboard view --- .../charts/ActivityListingAdapter.java | 118 +++++++---------- .../charts/ActivityListingChartFragment.java | 6 +- app/src/main/res/drawable/ic_star_gold.xml | 9 ++ .../layout/activity_list_dashboard_item.xml | 125 ++++++++++-------- 4 files changed, 130 insertions(+), 128 deletions(-) create mode 100644 app/src/main/res/drawable/ic_star_gold.xml diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivityListingAdapter.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivityListingAdapter.java index cac1e5e23..c7ceeb25d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivityListingAdapter.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/charts/ActivityListingAdapter.java @@ -8,10 +8,12 @@ import android.view.ViewGroup; import android.widget.LinearLayout; import android.widget.TextView; +import com.github.mikephil.charting.animation.Easing; import com.github.mikephil.charting.charts.PieChart; import com.github.mikephil.charting.data.PieData; import com.github.mikephil.charting.data.PieDataSet; import com.github.mikephil.charting.data.PieEntry; +import com.github.mikephil.charting.utils.MPPointF; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,15 +31,15 @@ import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser; import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils; public class ActivityListingAdapter extends AbstractActivityListingAdapter { - public static final String ACTIVE_STEPS_CHART_COLOR = "#3498db"; - public static final String DISTANCE_CHART_COLOR = "#f1c40f"; - public static final String ACTIVE_TIME_CHART_COLOR = "#e74c3c"; + public static final String CHART_COLOR_START = "#e74c3c"; + public static final String CHART_COLOR_END = "#2ecc71"; protected static final Logger LOG = LoggerFactory.getLogger(AbstractWeekChartFragment.class); + protected final int ANIM_TIME = 250; private final int SESSION_SUMMARY = ActivitySession.SESSION_SUMMARY; ActivityUser activityUser = new ActivityUser(); int stepsGoal = activityUser.getStepsGoal(); - int distanceMeters = activityUser.getDistanceMeters(); - long activeTimeMillis = activityUser.getActiveTimeMinutes() * 60 * 1000L; + int distanceGoalMeters = activityUser.getDistanceMeters(); + long activeTimeGoalTimeMillis = activityUser.getActiveTimeMinutes() * 60 * 1000L; public ActivityListingAdapter(Context context) { super(context); @@ -48,53 +50,44 @@ public class ActivityListingAdapter extends AbstractActivityListingAdapter entries = new ArrayList<>(); - int steps = item.getActiveSteps(); - entries.add(new PieEntry((float) steps)); + entries.add(new PieEntry((float) value, context.getResources().getDrawable(R.drawable.ic_star_gold))); - if (steps < stepsGoal) { - entries.add(new PieEntry((float) (stepsGoal - steps))); + Easing.EasingFunction animationEffect = Easing.EaseInOutSine; + + if (value < target) { + entries.add(new PieEntry((float) (target - value))); } - DashboardChart.setCenterText(String.format("%d%%\n%s", (int) (steps * 100 / stepsGoal), context.getString(R.string.activity_list_summary_active_steps))); + pieChart.setCenterText(String.format("%d%%\n%s", (int) (value * 100 / target), label)); + float colorValue = Math.max(0, Math.min(1, value / target)); + int chartColor = interpolateColor(Color.parseColor(CHART_COLOR_START), Color.parseColor(CHART_COLOR_END), colorValue); PieDataSet dataSet = new PieDataSet(entries, ""); + dataSet.setDrawIcons(false); + dataSet.setIconsOffset(new MPPointF(0, -66)); + + if (colorValue == 1) { + dataSet.setDrawIcons(true); + } dataSet.setSliceSpace(0f); dataSet.setSelectionShift(5f); + dataSet.setColors(chartColor, Color.LTGRAY); - dataSet.setColors(Color.parseColor(ACTIVE_STEPS_CHART_COLOR), Color.LTGRAY); PieData data = new PieData(dataSet); data.setValueTextSize(0f); data.setValueTextColor(Color.WHITE); - DashboardChart.setData(data); - DashboardChart.invalidate(); - } - private void setDistanceData(ActivitySession item, PieChart DashboardChart, Context context) { - ArrayList entries = new ArrayList<>(); - float distance = item.getDistance(); - entries.add(new PieEntry(distance)); - - if (distance < distanceMeters) { - entries.add(new PieEntry((float) (distanceMeters - distance))); - } - - DashboardChart.setCenterText(String.format("%d%%\n%s", (int) (distance * 100 / distanceMeters), context.getString(R.string.distance))); - PieDataSet dataSet = new PieDataSet(entries, ""); - dataSet.setSliceSpace(0f); - dataSet.setSelectionShift(5f); - - dataSet.setColors(Color.parseColor(DISTANCE_CHART_COLOR), Color.LTGRAY); - PieData data = new PieData(dataSet); - data.setValueTextSize(0f); - data.setValueTextColor(Color.WHITE); - DashboardChart.setData(data); - DashboardChart.invalidate(); - } - - private void setDurationData(ActivitySession item, PieChart DashboardChart, Context context) { - ArrayList entries = new ArrayList<>(); - long duration = item.getEndTime().getTime() - item.getStartTime().getTime(); - entries.add(new PieEntry((float) duration)); - - if (duration < activeTimeMillis) { - entries.add(new PieEntry((float) (activeTimeMillis - duration))); - } - - DashboardChart.setCenterText(String.format("%d%%\n%s", (int) (duration * 100 / activeTimeMillis), context.getString(R.string.activity_list_summary_active_time))); - PieDataSet dataSet = new PieDataSet(entries, ""); - dataSet.setSliceSpace(0f); - dataSet.setSelectionShift(5f); - dataSet.setColors(Color.parseColor(ACTIVE_TIME_CHART_COLOR), Color.LTGRAY); - PieData data = new PieData(dataSet); - data.setValueTextSize(0f); - data.setValueTextColor(Color.WHITE); - DashboardChart.setData(data); - DashboardChart.invalidate(); + pieChart.setData(data); + pieChart.invalidate(); + pieChart.animateY(ANIM_TIME, animationEffect); } private void setUpChart(PieChart DashboardChart) { @@ -229,6 +190,21 @@ public class ActivityListingAdapter extends AbstractActivityListingAdapter + + diff --git a/app/src/main/res/layout/activity_list_dashboard_item.xml b/app/src/main/res/layout/activity_list_dashboard_item.xml index 188a546f3..0be889885 100644 --- a/app/src/main/res/layout/activity_list_dashboard_item.xml +++ b/app/src/main/res/layout/activity_list_dashboard_item.xml @@ -16,39 +16,34 @@ + android:layout_height="wrap_content" + android:gravity="center" + android:orientation="horizontal"> - + - + - - - - - - @@ -99,15 +92,15 @@ + android:text="@string/activity_list_summary_active_steps" + android:textAllCaps="true" + android:textColor="@color/accent" + android:textStyle="bold" /> + android:text="15000" + android:textSize="24sp" /> + android:text="@string/distance" + android:textAllCaps="true" + android:textColor="@color/accent" + android:textStyle="bold" /> + android:text="15.1km" + android:textSize="24sp" /> + android:text="@string/activity_list_summary_active_time" + android:textAllCaps="true" + android:textColor="@color/accent" + android:textStyle="bold" /> + android:text="122" + android:textSize="24sp" /> @@ -247,7 +252,7 @@ + android:text="@string/live_activity_total_steps" + android:textAllCaps="true" + android:textColor="@color/accent" + android:textStyle="bold" /> + android:text="15000" + android:textSize="24sp" /> + android:text="@string/activity_list_summary_activities" + android:textAllCaps="true" + android:textColor="@color/accent" + android:textStyle="bold" /> + android:text="15" + android:textSize="24sp" /> + android:text="@string/activity_list_summary_intensity" + android:textAllCaps="true" + android:textColor="@color/accent" + android:textStyle="bold" /> + android:text="15" + android:textSize="24sp" />