mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-30 19:49:59 +02:00
Add MeasurementView::getKey method
Returns a stable, unique key for a measurement view.
This commit is contained in:
@@ -31,6 +31,11 @@ public class BMIMeasurementView extends FloatMeasurementView {
|
||||
super(context, context.getResources().getString(R.string.label_bmi), ContextCompat.getDrawable(context, R.drawable.ic_bmi));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return "bmi";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePreferences(SharedPreferences preferences) {
|
||||
setVisible(preferences.getBoolean("weightEnable", true));
|
||||
|
@@ -33,6 +33,11 @@ public class BMRMeasurementView extends FloatMeasurementView {
|
||||
super(context, context.getResources().getString(R.string.label_bmr), ContextCompat.getDrawable(context, R.drawable.ic_bmr));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return "bmr";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePreferences(SharedPreferences preferences) {
|
||||
setVisible(preferences.getBoolean("weightEnable", true));
|
||||
|
@@ -31,6 +31,11 @@ public class BoneMeasurementView extends FloatMeasurementView {
|
||||
super(context, context.getResources().getString(R.string.label_bone), ContextCompat.getDrawable(context, R.drawable.ic_bone));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return "bone";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePreferences(SharedPreferences preferences) {
|
||||
setVisible(preferences.getBoolean("boneEnable", false));
|
||||
|
@@ -27,12 +27,16 @@ import com.health.openscale.core.datatypes.ScaleMeasurement;
|
||||
|
||||
public class CommentMeasurementView extends MeasurementView {
|
||||
private String comment;
|
||||
private static String COMMENT_KEY = "comment";
|
||||
|
||||
public CommentMeasurementView(Context context) {
|
||||
super(context, context.getResources().getString(R.string.label_comment), ContextCompat.getDrawable(context, R.drawable.ic_comment));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return "comment";
|
||||
}
|
||||
|
||||
private void setValue(String newComment, boolean callListener) {
|
||||
if (!newComment.equals(comment)) {
|
||||
comment = newComment;
|
||||
@@ -52,12 +56,12 @@ public class CommentMeasurementView extends MeasurementView {
|
||||
|
||||
@Override
|
||||
public void restoreState(Bundle state) {
|
||||
setValue(state.getString(COMMENT_KEY), true);
|
||||
setValue(state.getString(getKey()), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveState(Bundle state) {
|
||||
state.putString(COMMENT_KEY, comment);
|
||||
state.putString(getKey(), comment);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -34,12 +34,17 @@ import java.util.Date;
|
||||
public class DateMeasurementView extends MeasurementView {
|
||||
private static DateFormat dateFormat = DateFormat.getDateInstance();
|
||||
private Date date;
|
||||
private static String DATE_KEY = "date";
|
||||
|
||||
public DateMeasurementView(Context context) {
|
||||
super(context, context.getResources().getString(R.string.label_date), ContextCompat.getDrawable(context, R.drawable.ic_lastmonth));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return "date";
|
||||
}
|
||||
|
||||
|
||||
private void setValue(Date newDate, boolean callListener) {
|
||||
if (!newDate.equals(date)) {
|
||||
date = newDate;
|
||||
@@ -70,12 +75,12 @@ public class DateMeasurementView extends MeasurementView {
|
||||
|
||||
@Override
|
||||
public void restoreState(Bundle state) {
|
||||
setValue(new Date(state.getLong(DATE_KEY)), true);
|
||||
setValue(new Date(state.getLong(getKey())), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveState(Bundle state) {
|
||||
state.putLong(DATE_KEY, date.getTime());
|
||||
state.putLong(getKey(), date.getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -34,6 +34,11 @@ public class FatMeasurementView extends FloatMeasurementView {
|
||||
super(context, context.getResources().getString(R.string.label_fat), ContextCompat.getDrawable(context, R.drawable.ic_fat));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return "fat";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePreferences(SharedPreferences preferences) {
|
||||
setVisible(preferences.getBoolean("fatEnable", true));
|
||||
|
@@ -251,12 +251,12 @@ public abstract class FloatMeasurementView extends MeasurementView {
|
||||
|
||||
@Override
|
||||
public void restoreState(Bundle state) {
|
||||
setValue(state.getFloat(nameText), previousValue, true);
|
||||
setValue(state.getFloat(getKey()), previousValue, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveState(Bundle state) {
|
||||
state.putFloat(nameText, value);
|
||||
state.putFloat(getKey(), value);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -31,6 +31,11 @@ public class HipMeasurementView extends FloatMeasurementView {
|
||||
super(context, context.getResources().getString(R.string.label_hip), ContextCompat.getDrawable(context, R.drawable.ic_hip));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return "hip";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePreferences(SharedPreferences preferences) {
|
||||
setVisible(preferences.getBoolean("hipEnable", false));
|
||||
|
@@ -33,6 +33,11 @@ public class LBWMeasurementView extends FloatMeasurementView {
|
||||
super(context, context.getResources().getString(R.string.label_lbw), ContextCompat.getDrawable(context, R.drawable.ic_lbw));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return "lbw";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePreferences(SharedPreferences preferences) {
|
||||
setVisible(preferences.getBoolean("lbwEnable", false));
|
||||
|
@@ -200,6 +200,8 @@ public abstract class MeasurementView extends TableLayout {
|
||||
return updateViews;
|
||||
}
|
||||
|
||||
public abstract String getKey();
|
||||
|
||||
public abstract void loadFrom(ScaleMeasurement measurement, ScaleMeasurement previousMeasurement);
|
||||
public abstract void saveTo(ScaleMeasurement measurement);
|
||||
|
||||
|
@@ -33,6 +33,11 @@ public class MuscleMeasurementView extends FloatMeasurementView {
|
||||
super(context, context.getResources().getString(R.string.label_muscle), ContextCompat.getDrawable(context, R.drawable.ic_muscle));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return "muscle";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePreferences(SharedPreferences preferences) {
|
||||
setVisible(preferences.getBoolean("muscleEnable", true));
|
||||
|
@@ -34,13 +34,17 @@ import java.util.Date;
|
||||
public class TimeMeasurementView extends MeasurementView {
|
||||
private DateFormat timeFormat;
|
||||
private Date time;
|
||||
private static String TIME_KEY = "time";
|
||||
|
||||
public TimeMeasurementView(Context context) {
|
||||
super(context, context.getResources().getString(R.string.label_time), ContextCompat.getDrawable(context, R.drawable.ic_daysleft));
|
||||
timeFormat = android.text.format.DateFormat.getTimeFormat(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return "time";
|
||||
}
|
||||
|
||||
private void setValue(Date newTime, boolean callListener) {
|
||||
if (!newTime.equals(time)) {
|
||||
time = newTime;
|
||||
@@ -73,12 +77,12 @@ public class TimeMeasurementView extends MeasurementView {
|
||||
|
||||
@Override
|
||||
public void restoreState(Bundle state) {
|
||||
setValue(new Date(state.getLong(TIME_KEY)), true);
|
||||
setValue(new Date(state.getLong(getKey())), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveState(Bundle state) {
|
||||
state.putLong(TIME_KEY, time.getTime());
|
||||
state.putLong(getKey(), time.getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -31,6 +31,11 @@ public class WHRMeasurementView extends FloatMeasurementView {
|
||||
super(context, context.getResources().getString(R.string.label_whr), ContextCompat.getDrawable(context, R.drawable.ic_whr));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return "whr";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePreferences(SharedPreferences preferences) {
|
||||
setVisible(preferences.getBoolean("hipEnable", false)
|
||||
|
@@ -31,6 +31,11 @@ public class WHtRMeasurementView extends FloatMeasurementView {
|
||||
super(context, context.getResources().getString(R.string.label_whtr), ContextCompat.getDrawable(context, R.drawable.ic_whtr));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return "whtr";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePreferences(SharedPreferences preferences) {
|
||||
setVisible(preferences.getBoolean("waistEnable", false));
|
||||
|
@@ -31,6 +31,11 @@ public class WaistMeasurementView extends FloatMeasurementView {
|
||||
super(context, context.getResources().getString(R.string.label_waist), ContextCompat.getDrawable(context, R.drawable.ic_waist));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return "waist";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePreferences(SharedPreferences preferences) {
|
||||
setVisible(preferences.getBoolean("waistEnable", false));
|
||||
|
@@ -34,6 +34,11 @@ public class WaterMeasurementView extends FloatMeasurementView {
|
||||
super(context, context.getResources().getString(R.string.label_water), ContextCompat.getDrawable(context, R.drawable.ic_water));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return "water";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePreferences(SharedPreferences preferences) {
|
||||
setVisible(preferences.getBoolean("waterEnable", true));
|
||||
|
@@ -32,6 +32,11 @@ public class WeightMeasurementView extends FloatMeasurementView {
|
||||
super(context, context.getResources().getString(R.string.label_weight), ContextCompat.getDrawable(context, R.drawable.ic_weight));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return "weight";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePreferences(SharedPreferences preferences) {
|
||||
setVisible(preferences.getBoolean("weightEnable", true));
|
||||
|
Reference in New Issue
Block a user