mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-03 17:02:13 +01:00
Activity card: simplify the layout and only show each chart if there is data
This commit is contained in:
parent
0c919d2e2f
commit
a7620e2748
@ -770,15 +770,6 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter<GBDeviceAdapterv2.Vi
|
||||
|
||||
//activity card
|
||||
LinearLayout cardViewActivityCardLayout;
|
||||
LinearLayout cardViewActivityCardStepsLayout;
|
||||
LinearLayout cardViewActivityCardSleepLayout;
|
||||
LinearLayout cardViewActivityCardDistanceLayout;
|
||||
TextView cardViewActivityCardSteps;
|
||||
TextView cardViewActivityCardDistance;
|
||||
TextView cardViewActivityCardSleep;
|
||||
ProgressBar cardViewActivityCardStepsProgress;
|
||||
ProgressBar cardViewActivityCardDistanceProgress;
|
||||
ProgressBar cardViewActivityCardSleepProgress;
|
||||
PieChart TotalStepsChart;
|
||||
PieChart TotalDistanceChart;
|
||||
PieChart SleepTimeChart;
|
||||
@ -831,16 +822,6 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter<GBDeviceAdapterv2.Vi
|
||||
heartRateIcon = view.findViewById(R.id.device_heart_rate_status);
|
||||
|
||||
cardViewActivityCardLayout = view.findViewById(R.id.card_view_activity_card_layout);
|
||||
cardViewActivityCardStepsLayout = view.findViewById(R.id.card_view_activity_card_steps_layout);
|
||||
cardViewActivityCardSleepLayout = view.findViewById(R.id.card_view_activity_card_sleep_layout);
|
||||
cardViewActivityCardDistanceLayout = view.findViewById(R.id.card_view_activity_card_distance_layout);
|
||||
|
||||
cardViewActivityCardSteps = view.findViewById(R.id.card_view_activity_card_steps);
|
||||
cardViewActivityCardDistance = view.findViewById(R.id.card_view_activity_card_distance);
|
||||
cardViewActivityCardSleep = view.findViewById(R.id.card_view_activity_card_sleep);
|
||||
cardViewActivityCardStepsProgress = view.findViewById(R.id.card_view_activity_card_steps_progress);
|
||||
cardViewActivityCardDistanceProgress = view.findViewById(R.id.card_view_activity_card_distance_progress);
|
||||
cardViewActivityCardSleepProgress = view.findViewById(R.id.card_view_activity_card_sleep_progress);
|
||||
|
||||
TotalStepsChart = view.findViewById(R.id.activity_dashboard_piechart1);
|
||||
TotalDistanceChart = view.findViewById(R.id.activity_dashboard_piechart2);
|
||||
@ -940,43 +921,26 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter<GBDeviceAdapterv2.Vi
|
||||
}
|
||||
DecimalFormat df = new DecimalFormat(unit);
|
||||
|
||||
|
||||
holder.cardViewActivityCardSteps.setText(String.format("%1s", steps));
|
||||
holder.cardViewActivityCardSleep.setText(String.format("%1s", getHM(sleep)));
|
||||
holder.cardViewActivityCardDistance.setText(df.format(distanceFormatted));
|
||||
|
||||
holder.cardViewActivityCardStepsProgress.setMax(stepGoal);
|
||||
holder.cardViewActivityCardStepsProgress.setProgress(steps);
|
||||
|
||||
holder.cardViewActivityCardSleepProgress.setMax(sleepGoalMinutes);
|
||||
holder.cardViewActivityCardSleepProgress.setProgress(sleep);
|
||||
|
||||
holder.cardViewActivityCardDistanceProgress.setMax(distanceGoal);
|
||||
holder.cardViewActivityCardDistanceProgress.setProgress(steps * stepLength);
|
||||
|
||||
setUpChart(holder.TotalStepsChart);
|
||||
setChartsData(holder.TotalStepsChart, steps, stepGoal, context.getString(R.string.steps), context);
|
||||
setChartsData(holder.TotalStepsChart, steps, stepGoal, context.getString(R.string.steps), String.valueOf(steps), context);
|
||||
|
||||
setUpChart(holder.TotalDistanceChart);
|
||||
setChartsData(holder.TotalDistanceChart, steps * stepLength, distanceGoal, context.getString(R.string.distance), context);
|
||||
setChartsData(holder.TotalDistanceChart, steps * stepLength, distanceGoal, context.getString(R.string.distance), df.format(distanceFormatted), context);
|
||||
|
||||
setUpChart(holder.SleepTimeChart);
|
||||
setChartsData(holder.SleepTimeChart, sleep, sleepGoalMinutes, context.getString(R.string.prefs_activity_in_device_card_sleep_title), context);
|
||||
setChartsData(holder.SleepTimeChart, sleep, sleepGoalMinutes, context.getString(R.string.prefs_activity_in_device_card_sleep_title), String.format("%1s", getHM(sleep)), context);
|
||||
|
||||
boolean showActivityCard = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).getBoolean(DeviceSettingsPreferenceConst.PREFS_ACTIVITY_IN_DEVICE_CARD, true);
|
||||
holder.cardViewActivityCardLayout.setVisibility(showActivityCard ? View.VISIBLE : View.GONE);
|
||||
|
||||
boolean showActivitySteps = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).getBoolean(DeviceSettingsPreferenceConst.PREFS_ACTIVITY_IN_DEVICE_CARD_STEPS, true);
|
||||
holder.cardViewActivityCardStepsLayout.setVisibility(showActivitySteps ? View.VISIBLE : View.GONE);
|
||||
holder.TotalStepsChart.setVisibility(showActivitySteps ? View.VISIBLE : View.GONE);
|
||||
holder.TotalStepsChart.setVisibility((showActivitySteps && steps > 0) ? View.VISIBLE : View.GONE);
|
||||
|
||||
boolean showActivitySleep = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).getBoolean(DeviceSettingsPreferenceConst.PREFS_ACTIVITY_IN_DEVICE_CARD_SLEEP, true);
|
||||
holder.cardViewActivityCardSleepLayout.setVisibility(showActivitySleep ? View.VISIBLE : View.GONE);
|
||||
holder.SleepTimeChart.setVisibility(showActivitySleep ? View.VISIBLE : View.GONE);
|
||||
holder.SleepTimeChart.setVisibility((showActivitySleep && sleep > 0) ? View.VISIBLE : View.GONE);
|
||||
|
||||
boolean showActivityDistance = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).getBoolean(DeviceSettingsPreferenceConst.PREFS_ACTIVITY_IN_DEVICE_CARD_DISTANCE, true);
|
||||
holder.cardViewActivityCardDistanceLayout.setVisibility(showActivityDistance ? View.VISIBLE : View.GONE);
|
||||
holder.TotalDistanceChart.setVisibility(showActivityDistance ? View.VISIBLE : View.GONE);
|
||||
holder.TotalDistanceChart.setVisibility((showActivityDistance && steps > 0) ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
private String getHM(long value) {
|
||||
@ -998,7 +962,7 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter<GBDeviceAdapterv2.Vi
|
||||
DashboardChart.setHighlightPerTapEnabled(true);
|
||||
DashboardChart.setCenterTextOffset(0, 0);
|
||||
}
|
||||
private void setChartsData(PieChart pieChart, float value, float target, String label, Context context) {
|
||||
private void setChartsData(PieChart pieChart, float value, float target, String label, String stringValue, Context context) {
|
||||
final String CHART_COLOR_START = "#e74c3c";
|
||||
final String CHART_COLOR_END = "#2ecc71";
|
||||
|
||||
@ -1009,7 +973,7 @@ public class GBDeviceAdapterv2 extends RecyclerView.Adapter<GBDeviceAdapterv2.Vi
|
||||
entries.add(new PieEntry((float) (target - value)));
|
||||
}
|
||||
|
||||
pieChart.setCenterText(String.format("%d%%\n%s", (int) (value * 100 / target), label));
|
||||
pieChart.setCenterText(String.format("%s\n%s", stringValue, 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);
|
||||
|
||||
|
@ -472,145 +472,6 @@
|
||||
android:layout_marginBottom="10dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="horizontal"
|
||||
android:paddingLeft="0dp"
|
||||
android:paddingRight="0dp"
|
||||
android:paddingBottom="15dp">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/card_view_activity_card_steps_layout"
|
||||
android:layout_width="110dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|center"
|
||||
android:layout_marginBottom="0dp"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/card_view_activity_card_steps_icon"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_gravity="center|bottom"
|
||||
android:background="@drawable/ic_shoe_prints_many"
|
||||
android:contentDescription="@string/icon_placeholder"
|
||||
android:padding="0dp" />
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingEnd="10dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/card_view_activity_card_steps"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical|center_horizontal"
|
||||
android:text=""
|
||||
android:textSize="18sp" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/card_view_activity_card_steps_progress"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="3dp"
|
||||
android:background="#FFFFFF" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/card_view_activity_card_distance_layout"
|
||||
android:layout_width="110dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|center"
|
||||
android:layout_marginBottom="0dp"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/card_view_activity_card_distance_icon"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_gravity="center|bottom"
|
||||
android:background="@drawable/ic_distance_total"
|
||||
android:contentDescription="@string/icon_placeholder"
|
||||
android:padding="0dp" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingEnd="10dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/card_view_activity_card_distance"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical|center_horizontal"
|
||||
android:text=""
|
||||
android:textSize="18sp" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/card_view_activity_card_distance_progress"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="3dp"
|
||||
android:layout_weight="1"
|
||||
android:background="#FFFFFF" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/card_view_activity_card_sleep_layout"
|
||||
android:layout_width="110dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|center"
|
||||
android:layout_marginBottom="0dp"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/card_view_activity_card_sleep_icon"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="20dp"
|
||||
android:layout_gravity="center|bottom"
|
||||
android:background="@drawable/ic_activity_sleep"
|
||||
android:contentDescription="@string/icon_placeholder" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="10dp"
|
||||
android:paddingEnd="10dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/card_view_activity_card_sleep"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical|center_horizontal"
|
||||
android:text=""
|
||||
android:textSize="18sp" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/card_view_activity_card_sleep_progress"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="3dp"
|
||||
android:layout_weight="1"
|
||||
android:background="#FFFFFF" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
Loading…
Reference in New Issue
Block a user