1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-27 19:15:50 +01:00

Calories: remove total goal

This commit is contained in:
a0z 2024-11-22 18:55:39 +01:00 committed by José Rebelo
parent 3ad2e827c2
commit 27c4cc95c9
9 changed files with 21 additions and 161 deletions

View File

@ -68,7 +68,6 @@ import nodomain.freeyourgadget.gadgetbridge.activities.dashboard.DashboardActive
import nodomain.freeyourgadget.gadgetbridge.activities.dashboard.DashboardBodyEnergyWidget;
import nodomain.freeyourgadget.gadgetbridge.activities.dashboard.DashboardCalendarActivity;
import nodomain.freeyourgadget.gadgetbridge.activities.dashboard.DashboardCaloriesTotalSegmentedWidget;
import nodomain.freeyourgadget.gadgetbridge.activities.dashboard.DashboardCaloriesGoalWidget;
import nodomain.freeyourgadget.gadgetbridge.activities.dashboard.DashboardDistanceWidget;
import nodomain.freeyourgadget.gadgetbridge.activities.dashboard.DashboardGoalsWidget;
import nodomain.freeyourgadget.gadgetbridge.activities.dashboard.DashboardHrvWidget;
@ -313,9 +312,6 @@ public class DashboardFragment extends Fragment implements MenuProvider {
case "vo2max":
widget = DashboardVO2MaxAnyWidget.newInstance(dashboardData);
break;
case "calories":
widget = DashboardCaloriesGoalWidget.newInstance(dashboardData);
break;
case "calories_active":
widget = DashboardCaloriesActiveGoalWidget.newInstance(dashboardData);
break;
@ -388,7 +384,6 @@ public class DashboardFragment extends Fragment implements MenuProvider {
private int activeCaloriesTotal;
private float activeCaloriesGoalFactor;
private int caloriesTotal;
private float caloriesGoalFactor;
private long sleepTotalMinutes;
private float sleepGoalFactor;
private float distanceTotalMeters;
@ -400,9 +395,7 @@ public class DashboardFragment extends Fragment implements MenuProvider {
public void clear() {
restingCaloriesTotal = 0;
activeCaloriesTotal = 0;
activeCaloriesGoalFactor = 0;
caloriesTotal = 0;
caloriesGoalFactor = 0;
stepsTotal = 0;
stepsGoalFactor = 0;
sleepTotalMinutes = 0;
@ -420,9 +413,7 @@ public class DashboardFragment extends Fragment implements MenuProvider {
stepsGoalFactor == 0 &&
restingCaloriesTotal == 0 &&
activeCaloriesTotal == 0 &&
activeCaloriesGoalFactor == 0 &&
caloriesTotal == 0 &&
caloriesGoalFactor == 0 &&
sleepTotalMinutes == 0 &&
sleepGoalFactor == 0 &&
distanceTotalMeters == 0 &&
@ -499,18 +490,6 @@ public class DashboardFragment extends Fragment implements MenuProvider {
return activeCaloriesGoalFactor;
}
public synchronized int getCaloriesTotal() {
if (caloriesTotal == 0)
caloriesTotal = getRestingCaloriesTotal() + getActiveCaloriesTotal();
return caloriesTotal;
}
public synchronized float getCaloriesGoalFactor() {
if (caloriesGoalFactor == 0)
caloriesGoalFactor = DashboardUtils.getCaloriesGoalFactor(this);
return caloriesGoalFactor;
}
public void put(final String key, final Serializable value) {
genericData.put(key, value);
}

View File

@ -33,7 +33,6 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
import nodomain.freeyourgadget.gadgetbridge.model.ActivityUser;
import nodomain.freeyourgadget.gadgetbridge.model.RestingMetabolicRateSample;
import nodomain.freeyourgadget.gadgetbridge.model.TimeSample;
public class CaloriesDailyFragment extends AbstractChartFragment<CaloriesDailyFragment.CaloriesData> {
@ -44,13 +43,10 @@ public class CaloriesDailyFragment extends AbstractChartFragment<CaloriesDailyFr
private LinearLayout caloriesActiveWrapper;
private TextView caloriesActiveGoal;
private LinearLayout caloriesActiveGoalWrapper;
private TextView caloriesTotalGoal;
protected int CALORIES_GOAL;
protected int TOTAL_CALORIES_GOAL;
protected int ACTIVE_CALORIES_GOAL;
public enum GaugeViewMode {
ACTIVE_CALORIES_GOAL,
TOTAL_CALORIES_GOAL,
TOTAL_CALORIES_SEGMENT
}
private GaugeViewMode gaugeViewMode;
@ -91,10 +87,8 @@ public class CaloriesDailyFragment extends AbstractChartFragment<CaloriesDailyFr
caloriesActiveWrapper = rootView.findViewById(R.id.calories_active_wrapper);
caloriesActiveGoal = rootView.findViewById(R.id.calories_active_goal);
caloriesActiveGoalWrapper = rootView.findViewById(R.id.calories_active_goal_wrapper);
caloriesTotalGoal = rootView.findViewById(R.id.calories_total_goal);
ActivityUser activityUser = new ActivityUser();
TOTAL_CALORIES_GOAL = activityUser.getCaloriesBurntGoal();
ACTIVE_CALORIES_GOAL = activityUser.getActiveCaloriesBurntGoal();
ACTIVE_CALORIES_GOAL = activityUser.getCaloriesBurntGoal();
refresh();
if (!supportsActiveCalories()) {
@ -108,8 +102,6 @@ public class CaloriesDailyFragment extends AbstractChartFragment<CaloriesDailyFr
if (gaugeViewMode.equals(GaugeViewMode.ACTIVE_CALORIES_GOAL)) {
CALORIES_GOAL = ACTIVE_CALORIES_GOAL;
} else if (gaugeViewMode.equals(GaugeViewMode.TOTAL_CALORIES_GOAL)) {
CALORIES_GOAL = TOTAL_CALORIES_GOAL;
}
return rootView;
@ -186,7 +178,6 @@ public class CaloriesDailyFragment extends AbstractChartFragment<CaloriesDailyFr
int totalCalories = activeCalories + restingCalories;
caloriesActive.setText(String.valueOf(activeCalories));
caloriesResting.setText(String.valueOf(restingCalories));
caloriesTotalGoal.setText(String.valueOf(TOTAL_CALORIES_GOAL));
caloriesActiveGoal.setText(String.valueOf(ACTIVE_CALORIES_GOAL));
if (gaugeViewMode.equals(GaugeViewMode.TOTAL_CALORIES_SEGMENT)) {
@ -217,8 +208,6 @@ public class CaloriesDailyFragment extends AbstractChartFragment<CaloriesDailyFr
int value = 0;
if (gaugeViewMode.equals(GaugeViewMode.ACTIVE_CALORIES_GOAL)) {
value = activeCalories;
} else if (gaugeViewMode.equals(GaugeViewMode.TOTAL_CALORIES_GOAL)) {
value = totalCalories;
}
final int width = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,

View File

@ -1,58 +0,0 @@
package nodomain.freeyourgadget.gadgetbridge.activities.dashboard;
import android.os.Bundle;
import androidx.core.content.ContextCompat;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.R;
import nodomain.freeyourgadget.gadgetbridge.activities.DashboardFragment;
import nodomain.freeyourgadget.gadgetbridge.activities.charts.CaloriesDailyFragment;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
/**
* A simple {@link AbstractDashboardWidget} subclass.
* Use the {@link DashboardCaloriesGoalWidget#newInstance} factory method to
* create an instance of this fragment.
*/
public class DashboardCaloriesGoalWidget extends AbstractGaugeWidget {
public DashboardCaloriesGoalWidget() {
super(R.string.calories, "calories", CaloriesDailyFragment.GaugeViewMode.TOTAL_CALORIES_GOAL.toString());
}
/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @param dashboardData An instance of DashboardFragment.DashboardData.
* @return A new instance of fragment DashboardStepsWidget.
*/
public static DashboardCaloriesGoalWidget newInstance(final DashboardFragment.DashboardData dashboardData) {
final DashboardCaloriesGoalWidget fragment = new DashboardCaloriesGoalWidget();
final Bundle args = new Bundle();
args.putSerializable(ARG_DASHBOARD_DATA, dashboardData);
fragment.setArguments(args);
return fragment;
}
@Override
protected boolean isSupportedBy(final GBDevice device) {
return device.getDeviceCoordinator().supportsActiveCalories();
}
@Override
protected void populateData(final DashboardFragment.DashboardData dashboardData) {
dashboardData.getCaloriesTotal();
dashboardData.getCaloriesGoalFactor();
}
@Override
protected void draw(final DashboardFragment.DashboardData dashboardData) {
setText(String.valueOf(dashboardData.getCaloriesTotal()));
final int colorCalories = ContextCompat.getColor(GBApplication.getContext(), R.color.calories_color);
drawSimpleGauge(
colorCalories,
dashboardData.getCaloriesGoalFactor()
);
}
}

View File

@ -58,8 +58,7 @@ public class ActivityUser {
public static final int defaultUserWeightKg = 70;
public static final int defaultUserSleepDurationGoal = 7;
public static final int defaultUserStepsGoal = 8000;
public static final int defaultUserCaloriesBurntGoal = 2000;
public static final int defaultUserActiveCaloriesBurntGoal = 350;
public static final int defaultUserCaloriesBurntGoal = 350;
public static final int defaultUserDistanceGoalMeters = 5000;
public static final int defaultUserActiveTimeGoalMinutes = 60;
public static final int defaultUserStepLengthCm = 0;
@ -75,7 +74,6 @@ public class ActivityUser {
public static final String PREF_USER_SLEEP_DURATION = "activity_user_sleep_duration";
public static final String PREF_USER_STEPS_GOAL = "fitness_goal"; // FIXME: for compatibility
public static final String PREF_USER_CALORIES_BURNT = "activity_user_calories_burnt";
public static final String PREF_USER_ACTIVE_CALORIES_BURNT = "activity_user_active_calories_burnt";
public static final String PREF_USER_DISTANCE_METERS = "activity_user_distance_meters";
public static final String PREF_USER_ACTIVETIME_MINUTES = "activity_user_activetime_minutes";
public static final String PREF_USER_STEP_LENGTH_CM = "activity_user_step_length_cm";
@ -163,7 +161,6 @@ public class ActivityUser {
activityUserSleepDurationGoal = prefs.getInt(PREF_USER_SLEEP_DURATION, defaultUserSleepDurationGoal);
activityUserStepsGoal = prefs.getInt(PREF_USER_STEPS_GOAL, defaultUserStepsGoal);
activityUserCaloriesBurntGoal = prefs.getInt(PREF_USER_CALORIES_BURNT, defaultUserCaloriesBurntGoal);
activityUserActiveCaloriesBurntGoal = prefs.getInt(PREF_USER_ACTIVE_CALORIES_BURNT, defaultUserActiveCaloriesBurntGoal);
activityUserDistanceGoalMeters = prefs.getInt(PREF_USER_DISTANCE_METERS, defaultUserDistanceGoalMeters);
activityUserActiveTimeGoalMinutes = prefs.getInt(PREF_USER_ACTIVETIME_MINUTES, defaultUserActiveTimeGoalMinutes);
activityUserStandingTimeGoalHours = prefs.getInt(PREF_USER_GOAL_STANDING_TIME_HOURS, defaultUserGoalStandingTimeHours);
@ -191,14 +188,6 @@ public class ActivityUser {
return activityUserCaloriesBurntGoal;
}
public int getActiveCaloriesBurntGoal()
{
if (activityUserActiveCaloriesBurntGoal < 1) {
activityUserActiveCaloriesBurntGoal = defaultUserActiveCaloriesBurntGoal;
}
return activityUserActiveCaloriesBurntGoal;
}
public int getDistanceGoalMeters()
{
if (activityUserDistanceGoalMeters < 1) {

View File

@ -165,18 +165,9 @@ public class DashboardUtils {
}
public static float getActiveCaloriesGoalFactor(DashboardFragment.DashboardData dashboardData) {
ActivityUser activityUser = new ActivityUser();
int caloriesGoal = activityUser.getActiveCaloriesBurntGoal();
float goalFactor = (float) getActiveCaloriesTotal(dashboardData) / caloriesGoal;
if (goalFactor > 1) goalFactor = 1;
return goalFactor;
}
public static float getCaloriesGoalFactor(DashboardFragment.DashboardData dashboardData) {
ActivityUser activityUser = new ActivityUser();
int caloriesGoal = activityUser.getCaloriesBurntGoal();
float goalFactor = (float) (getRestingCaloriesTotal(dashboardData) + getActiveCaloriesTotal(dashboardData)) / caloriesGoal;
float goalFactor = (float) getActiveCaloriesTotal(dashboardData) / caloriesGoal;
if (goalFactor > 1) goalFactor = 1;
return goalFactor;

View File

@ -52,7 +52,24 @@
android:text="@string/active"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/calories_resting_wrapper"
style="@style/GridTile"
android:layout_marginEnd="1dp"
>
<TextView
android:id="@+id/calories_resting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/stats_empty_value"
android:textSize="20sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hr_resting"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/calories_active_goal_wrapper"
style="@style/GridTile"
@ -72,43 +89,10 @@
android:text="@string/active_goal"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/calories_resting_wrapper"
style="@style/GridTile"
android:layout_marginEnd="1dp"
>
<TextView
android:id="@+id/calories_resting"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/stats_empty_value"
android:textSize="20sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hr_resting"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:id="@+id/calories_total_goal_wrapper"
style="@style/GridTile"
android:layout_marginStart="1dp"
>
<TextView
android:id="@+id/calories_total_goal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/stats_empty_value"
android:textSize="20sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/total_goal"
android:textSize="12sp" />
</LinearLayout>
</GridLayout>

View File

@ -4279,7 +4279,6 @@
<item>@string/menuitem_vo2_max</item>
<item>@string/vo2max_running</item>
<item>@string/vo2max_cycling</item>
<item>@string/menuitem_calories_goal</item>
<item>@string/menuitem_calories_active_goal</item>
<item>@string/menuitem_calories_segmented</item>
</string-array>
@ -4299,7 +4298,6 @@
<item>vo2max</item>
<item>vo2max_running</item>
<item>vo2max_cycling</item>
<item>calories</item>
<item>calories_active</item>
<item>calories_segmented</item>
</string-array>
@ -4315,7 +4313,6 @@
<item>stress_segmented</item>
<item>hrv</item>
<item>vo2max</item>
<item>calories</item>
<item>calories_active</item>
<item>calories_segmented</item>
</string-array>

View File

@ -938,7 +938,6 @@
<string name="hr_average">Average</string>
<string name="active">Active</string>
<string name="active_goal">Active goal</string>
<string name="total_goal">Total goal</string>
<string name="total_burnt">Total burnt</string>
<string name="goal">Goal</string>
<string name="blood_pressure">Blood pressure</string>
@ -1948,7 +1947,6 @@
<string name="menuitem_stress_breakdown">Stress (breakdown)</string>
<string name="menuitem_calories_segmented">Calories(segmented)</string>
<string name="menuitem_calories_active_goal">Calories goal(active)</string>
<string name="menuitem_calories_goal">Calories goal(total)</string>
<string name="menuitem_pai">PAI</string>
<string name="menuitem_hr">Heart Rate</string>
<string name="menuitem_spo2">SpO2</string>

View File

@ -86,19 +86,10 @@
<EditTextPreference
app:iconSpaceReserved="false"
android:defaultValue="2000"
android:defaultValue="350"
android:inputType="number"
android:key="activity_user_calories_burnt"
android:maxLength="4"
android:title="@string/activity_prefs_calories_burnt"
app:useSimpleSummaryProvider="true" />
<EditTextPreference
app:iconSpaceReserved="false"
android:defaultValue="350"
android:inputType="number"
android:key="activity_user_goal_active_calories_burnt"
android:maxLength="3"
android:title="@string/activity_prefs_goal_active_calories_burnt"
app:useSimpleSummaryProvider="true" />