1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-25 01:26:08 +02:00

statistics: add total weight lost (#916)

* ci: simplify

* statistics: add total weight lost

* res: add weight loss icon
This commit is contained in:
Mickaël Schoentgen
2023-01-31 16:54:36 +01:00
committed by GitHub
parent c3e3d7aa06
commit 561bd1302e
5 changed files with 83 additions and 6 deletions

View File

@@ -6,7 +6,7 @@ name: CI
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master ]
branches: [master]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
@@ -30,8 +30,8 @@ jobs:
- name: Setup JDK
uses: actions/setup-java@v3
with:
distribution: 'zulu' # See 'Supported distributions' for available options
java-version: '11'
distribution: "zulu" # See 'Supported distributions' for available options
java-version: "11"
- name: Build APK
run: ./gradlew assembleDebug
- uses: "marvinpinto/action-automatic-releases@latest"
@@ -41,6 +41,4 @@ jobs:
prerelease: true
title: "openScale development build"
files: |
/home/runner/work/openScale/openScale/android_app/app/build/outputs/apk/debug/openScale-debug.apk
android_app/app/build/outputs/apk/debug/openScale-debug.apk

View File

@@ -67,15 +67,18 @@ public class StatisticsFragment extends Fragment {
private TextView txtGoalWeight;
private TextView txtGoalDiff;
private TextView txtGoalDayLeft;
private TextView txtTotalWeightLost;
private TextView txtLabelGoalWeight;
private TextView txtLabelGoalDiff;
private TextView txtLabelDayLeft;
private TextView txtLabelTotalWeightLost;
private RadarChart radarChartWeek;
private RadarChart radarChartMonth;
private ScaleUser currentScaleUser;
private ScaleMeasurement firstScaleMeasurement;
private ScaleMeasurement lastScaleMeasurement;
private ArrayList <MeasurementView> viewMeasurementsStatistics;
@@ -90,6 +93,8 @@ public class StatisticsFragment extends Fragment {
txtGoalDiff.setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
txtGoalDayLeft = statisticsView.findViewById(R.id.txtGoalDayLeft);
txtGoalDayLeft.setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
txtTotalWeightLost = statisticsView.findViewById(R.id.txtTotalWeightLost);
txtTotalWeightLost.setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
txtLabelGoalWeight = statisticsView.findViewById(R.id.txtLabelGoalWeight);
txtLabelGoalWeight.setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
@@ -97,6 +102,8 @@ public class StatisticsFragment extends Fragment {
txtLabelGoalDiff.setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
txtLabelDayLeft = statisticsView.findViewById(R.id.txtLabelDayLeft);
txtLabelDayLeft.setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
txtLabelTotalWeightLost = statisticsView.findViewById(R.id.txtLabelTotalWeightLost);
txtLabelTotalWeightLost.setTextColor(ColorUtil.getTintColor(statisticsView.getContext()));
viewMeasurementsStatistics = new ArrayList<>();
@@ -171,8 +178,10 @@ public class StatisticsFragment extends Fragment {
lastScaleMeasurement = new ScaleMeasurement();
lastScaleMeasurement.setUserId(currentScaleUser.getId());
lastScaleMeasurement.setWeight(currentScaleUser.getInitialWeight());
firstScaleMeasurement = lastScaleMeasurement;
} else {
lastScaleMeasurement = scaleMeasurementList.get(0);
firstScaleMeasurement = scaleMeasurementList.get(scaleMeasurementList.size() - 1);
}
updateStatistics(scaleMeasurementList);
@@ -194,6 +203,10 @@ public class StatisticsFragment extends Fragment {
Converters.fromKilogram(goalScaleMeasurement.getWeight() - lastScaleMeasurement.getWeight(), unit),
unit.toString()));
txtTotalWeightLost.setText(String.format("%.1f %s",
Converters.fromKilogram(firstScaleMeasurement.getWeight() - lastScaleMeasurement.getWeight(), unit),
unit.toString()));
Calendar goalCalendar = Calendar.getInstance();
goalCalendar.setTime(currentScaleUser.getGoalDate());
int days = Math.max(0, DateTimeHelpers.daysBetween(Calendar.getInstance(), goalCalendar));
@@ -228,6 +241,14 @@ public class StatisticsFragment extends Fragment {
getResources().getString(R.string.label_days_left),
getResources().getString(R.string.label_goal_date_is),
DateFormat.getDateInstance(DateFormat.LONG).format(currentScaleUser.getGoalDate()))));
txtLabelTotalWeightLost.setText(
Html.fromHtml(String.format(
"%s<br><font color='grey'><small>%s %.1f %s</small></font>",
getResources().getString(R.string.label_total_weight_lost),
getResources().getString(R.string.label_total_weight_lost_weight_reference),
Converters.fromKilogram(firstScaleMeasurement.getWeight(), unit),
unit.toString())));
}
private void updateStatistics(List<ScaleMeasurement> scaleMeasurementList) {

View File

@@ -0,0 +1,13 @@
<vector
xmlns:android="http://schemas.android.com/apk/res/android"
android:name="vector"
android:width="135dp"
android:height="135dp"
android:viewportWidth="135"
android:viewportHeight="135">
<path
android:name="path"
android:pathData="M 93.942 134.013 C 83.31 132.192 73.144 125.236 69.08 117 C 68.538 115.901 68.538 115.901 44.646 115.827 C 20.754 115.752 20.754 115.752 18.667 115.016 C 11.893 112.626 7.153 106.85 6.428 100.103 C 6.002 96.134 0.794 20.569 0.794 18.352 C 0.794 10.379 6.442 3.199 14.25 1.248 C 17.587 0.415 99.104 0.826 101.466 1.688 C 107.213 3.787 111.505 8.49 112.998 14.324 C 113.701 17.071 113.709 16.855 111.952 41.889 C 111.094 54.11 110.363 64.563 110.328 65.117 C 110.265 66.125 110.265 66.125 112.279 66.859 C 133.195 74.481 141.278 102.319 127.78 120.242 C 126.079 122.5 125.259 123.068 124.113 122.78 C 122.165 122.291 122.186 120.611 124.174 117.974 C 146.858 87.882 104.393 51.12 77.733 77.77 C 53.313 102.181 82.231 142.475 113.137 127.099 C 116.695 125.329 117.627 125.175 118.45 126.221 C 121.871 130.568 105.053 135.915 93.943 134.013 Z M 66.423 111.253 C 66.037 110.263 64.982 106.069 64.981 105.521 C 64.98 104.94 64.98 104.94 48.78 104.869 C 30.654 104.79 31.582 104.902 31.582 102.764 C 31.582 100.665 30.82 100.755 48.548 100.755 C 64.38 100.755 64.38 100.755 64.544 97.429 C 65.529 77.501 84.077 62.063 103.835 64.726 C 105.043 64.889 106.056 64.993 106.086 64.957 C 106.446 64.527 109.389 17.759 109.145 16.338 C 108.296 11.382 104.441 7.014 99.563 5.48 C 96.919 4.648 17.708 4.556 15.014 5.381 C 8.955 7.238 4.971 12.418 4.967 18.447 C 4.965 22.007 10.391 98.411 10.795 100.52 C 11.797 105.738 15.907 110.05 21.073 111.301 C 23.645 111.924 66.668 111.879 66.423 111.253 Z M 25.742 42.207 C 22.449 41.034 22.091 39.891 21.283 27.985 C 20.363 14.443 20.383 14.214 22.619 12.372 C 24.539 10.789 33.28 10.42 33.651 11.718 C 34.447 14.505 33.951 15.204 29.376 15.204 C 25.3 15.204 24.799 15.426 24.798 17.226 C 24.797 22.224 26.176 37.288 26.685 37.83 C 27.597 38.8 86.59 38.749 87.562 37.778 C 87.936 37.404 88.203 36.834 88.203 36.408 C 88.203 36.007 88.497 31.457 88.855 26.296 C 89.214 21.135 89.507 16.763 89.507 16.58 C 89.507 15.145 90.548 15.204 65.389 15.204 C 52.05 15.204 42.049 15.104 41.686 14.965 C 40.457 14.499 40.183 12.62 41.177 11.488 C 41.554 11.059 43.037 11.031 65.361 11.031 C 96.895 11.031 94.191 9.514 93.046 26.565 C 92.113 40.473 91.892 41.194 88.222 42.293 C 86.625 42.772 27.096 42.689 25.742 42.207 Z M 43.516 34.962 C 42.002 33.812 42.071 19.405 43.595 18.59 C 45.228 17.716 46.529 18.547 46.711 20.581 C 46.846 22.094 46.846 22.094 48.542 20.514 C 51.09 18.14 52.382 17.787 53.369 19.195 C 54.309 20.538 53.962 21.24 50.996 23.988 C 48.231 26.55 48.231 26.55 51.133 29.289 C 54.49 32.456 54.924 33.366 53.673 34.617 C 52.488 35.801 51.728 35.564 49.068 33.177 C 46.716 31.066 46.716 31.066 46.716 32.645 C 46.716 34.907 45.041 36.12 43.516 34.962 Z M 61.402 34.925 C 52.101 31.887 54.142 18.334 63.9 18.334 C 68.214 18.334 70.961 20.743 68.945 22.758 C 68.008 23.695 67.422 23.742 65.968 23.001 C 62.857 21.414 59.083 23.962 59.615 27.291 C 60.205 30.98 65.124 32.55 66.679 29.545 C 67.081 28.767 67.081 28.767 65.929 28.767 C 63.789 28.767 62.754 26.704 64.179 25.28 C 66.096 23.363 71.503 24.769 71.503 27.184 C 71.503 32.729 66.476 36.582 61.402 34.925 Z M 96.64 121.776 C 95.598 121.181 88.909 115.535 86.289 113.041 C 81.078 108.077 85.773 99.991 92.287 102.711 C 92.802 102.926 93.268 103.102 93.322 103.102 C 93.376 103.102 93.422 98.202 93.423 92.213 C 93.426 81.324 93.426 81.324 94.042 80.001 C 96.184 75.403 102.565 75.311 104.879 79.846 C 105.405 80.877 105.423 81.274 105.423 92.109 C 105.423 103.307 105.423 103.307 106.391 102.813 C 111.333 100.295 117.243 106.275 114.476 110.994 C 113.672 112.366 104.164 120.784 102.252 121.817 C 100.706 122.652 98.139 122.633 96.64 121.776 Z M 105.49 113.763 C 110.99 109.011 111.357 108.533 110.454 107.318 C 109.512 106.052 108.629 106.234 106.304 108.174 C 104.166 109.958 103.218 110.274 102.237 109.528 C 101.306 108.822 101.248 107.953 101.248 94.749 C 101.248 80.311 101.293 80.672 99.491 80.672 C 97.583 80.672 97.595 80.578 97.595 95.278 C 97.595 112.093 97.451 112.412 92.023 107.614 C 89.224 105.14 86.632 107.48 89.311 110.061 C 99.091 119.484 98.917 119.444 105.49 113.763 Z"
android:fillColor="#000"
android:strokeWidth="1"/>
</vector>

View File

@@ -120,6 +120,49 @@
android:textSize="15dp" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="10dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageTotalWeightLoss"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center"
android:src="@drawable/ic_weight_loss"
android:tint="?attr/colorControlNormal" />
<TextView
android:id="@+id/txtLabelTotalWeightLost"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_marginLeft="5dp"
android:layout_weight="80"
android:lines="2"
android:password="false"
android:phoneNumber="false"
android:singleLine="false"
android:text="Target weight"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="15dp" />
<TextView
android:id="@+id/txtTotalWeightLost"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_gravity="center_vertical"
android:layout_weight="20"
android:gravity="right"
android:text="0 kg"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="15dp" />
</TableRow>
<TableRow
android:id="@+id/tableRow10"
android:layout_width="fill_parent"

View File

@@ -47,6 +47,8 @@
<string name="label_last_week">Average past week</string>
<string name="label_last_month">Average past month</string>
<string name="label_weight_difference">Weight difference</string>
<string name="label_total_weight_lost">Total weight lost</string>
<string name="label_total_weight_lost_weight_reference">Reference weight:</string>
<string name="label_goal_date_is">Goal date:</string>
<string name="label_days_left">Days left</string>
<string name="label_date">Date</string>