1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-09-01 20:33:31 +02:00

Add MeasurementView::getKey method

Returns a stable, unique key for a measurement view.
This commit is contained in:
Erik Johansson
2018-02-20 23:02:14 +01:00
parent a88592008f
commit fcff5243b9
17 changed files with 86 additions and 11 deletions

View File

@@ -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)); super(context, context.getResources().getString(R.string.label_bmi), ContextCompat.getDrawable(context, R.drawable.ic_bmi));
} }
@Override
public String getKey() {
return "bmi";
}
@Override @Override
public void updatePreferences(SharedPreferences preferences) { public void updatePreferences(SharedPreferences preferences) {
setVisible(preferences.getBoolean("weightEnable", true)); setVisible(preferences.getBoolean("weightEnable", true));

View File

@@ -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)); super(context, context.getResources().getString(R.string.label_bmr), ContextCompat.getDrawable(context, R.drawable.ic_bmr));
} }
@Override
public String getKey() {
return "bmr";
}
@Override @Override
public void updatePreferences(SharedPreferences preferences) { public void updatePreferences(SharedPreferences preferences) {
setVisible(preferences.getBoolean("weightEnable", true)); setVisible(preferences.getBoolean("weightEnable", true));

View File

@@ -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)); super(context, context.getResources().getString(R.string.label_bone), ContextCompat.getDrawable(context, R.drawable.ic_bone));
} }
@Override
public String getKey() {
return "bone";
}
@Override @Override
public void updatePreferences(SharedPreferences preferences) { public void updatePreferences(SharedPreferences preferences) {
setVisible(preferences.getBoolean("boneEnable", false)); setVisible(preferences.getBoolean("boneEnable", false));

View File

@@ -27,12 +27,16 @@ import com.health.openscale.core.datatypes.ScaleMeasurement;
public class CommentMeasurementView extends MeasurementView { public class CommentMeasurementView extends MeasurementView {
private String comment; private String comment;
private static String COMMENT_KEY = "comment";
public CommentMeasurementView(Context context) { public CommentMeasurementView(Context context) {
super(context, context.getResources().getString(R.string.label_comment), ContextCompat.getDrawable(context, R.drawable.ic_comment)); 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) { private void setValue(String newComment, boolean callListener) {
if (!newComment.equals(comment)) { if (!newComment.equals(comment)) {
comment = newComment; comment = newComment;
@@ -52,12 +56,12 @@ public class CommentMeasurementView extends MeasurementView {
@Override @Override
public void restoreState(Bundle state) { public void restoreState(Bundle state) {
setValue(state.getString(COMMENT_KEY), true); setValue(state.getString(getKey()), true);
} }
@Override @Override
public void saveState(Bundle state) { public void saveState(Bundle state) {
state.putString(COMMENT_KEY, comment); state.putString(getKey(), comment);
} }
@Override @Override

View File

@@ -34,12 +34,17 @@ import java.util.Date;
public class DateMeasurementView extends MeasurementView { public class DateMeasurementView extends MeasurementView {
private static DateFormat dateFormat = DateFormat.getDateInstance(); private static DateFormat dateFormat = DateFormat.getDateInstance();
private Date date; private Date date;
private static String DATE_KEY = "date";
public DateMeasurementView(Context context) { public DateMeasurementView(Context context) {
super(context, context.getResources().getString(R.string.label_date), ContextCompat.getDrawable(context, R.drawable.ic_lastmonth)); 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) { private void setValue(Date newDate, boolean callListener) {
if (!newDate.equals(date)) { if (!newDate.equals(date)) {
date = newDate; date = newDate;
@@ -70,12 +75,12 @@ public class DateMeasurementView extends MeasurementView {
@Override @Override
public void restoreState(Bundle state) { public void restoreState(Bundle state) {
setValue(new Date(state.getLong(DATE_KEY)), true); setValue(new Date(state.getLong(getKey())), true);
} }
@Override @Override
public void saveState(Bundle state) { public void saveState(Bundle state) {
state.putLong(DATE_KEY, date.getTime()); state.putLong(getKey(), date.getTime());
} }
@Override @Override

View File

@@ -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)); super(context, context.getResources().getString(R.string.label_fat), ContextCompat.getDrawable(context, R.drawable.ic_fat));
} }
@Override
public String getKey() {
return "fat";
}
@Override @Override
public void updatePreferences(SharedPreferences preferences) { public void updatePreferences(SharedPreferences preferences) {
setVisible(preferences.getBoolean("fatEnable", true)); setVisible(preferences.getBoolean("fatEnable", true));

View File

@@ -251,12 +251,12 @@ public abstract class FloatMeasurementView extends MeasurementView {
@Override @Override
public void restoreState(Bundle state) { public void restoreState(Bundle state) {
setValue(state.getFloat(nameText), previousValue, true); setValue(state.getFloat(getKey()), previousValue, true);
} }
@Override @Override
public void saveState(Bundle state) { public void saveState(Bundle state) {
state.putFloat(nameText, value); state.putFloat(getKey(), value);
} }
@Override @Override

View File

@@ -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)); super(context, context.getResources().getString(R.string.label_hip), ContextCompat.getDrawable(context, R.drawable.ic_hip));
} }
@Override
public String getKey() {
return "hip";
}
@Override @Override
public void updatePreferences(SharedPreferences preferences) { public void updatePreferences(SharedPreferences preferences) {
setVisible(preferences.getBoolean("hipEnable", false)); setVisible(preferences.getBoolean("hipEnable", false));

View File

@@ -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)); super(context, context.getResources().getString(R.string.label_lbw), ContextCompat.getDrawable(context, R.drawable.ic_lbw));
} }
@Override
public String getKey() {
return "lbw";
}
@Override @Override
public void updatePreferences(SharedPreferences preferences) { public void updatePreferences(SharedPreferences preferences) {
setVisible(preferences.getBoolean("lbwEnable", false)); setVisible(preferences.getBoolean("lbwEnable", false));

View File

@@ -200,6 +200,8 @@ public abstract class MeasurementView extends TableLayout {
return updateViews; return updateViews;
} }
public abstract String getKey();
public abstract void loadFrom(ScaleMeasurement measurement, ScaleMeasurement previousMeasurement); public abstract void loadFrom(ScaleMeasurement measurement, ScaleMeasurement previousMeasurement);
public abstract void saveTo(ScaleMeasurement measurement); public abstract void saveTo(ScaleMeasurement measurement);

View File

@@ -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)); super(context, context.getResources().getString(R.string.label_muscle), ContextCompat.getDrawable(context, R.drawable.ic_muscle));
} }
@Override
public String getKey() {
return "muscle";
}
@Override @Override
public void updatePreferences(SharedPreferences preferences) { public void updatePreferences(SharedPreferences preferences) {
setVisible(preferences.getBoolean("muscleEnable", true)); setVisible(preferences.getBoolean("muscleEnable", true));

View File

@@ -34,13 +34,17 @@ import java.util.Date;
public class TimeMeasurementView extends MeasurementView { public class TimeMeasurementView extends MeasurementView {
private DateFormat timeFormat; private DateFormat timeFormat;
private Date time; private Date time;
private static String TIME_KEY = "time";
public TimeMeasurementView(Context context) { public TimeMeasurementView(Context context) {
super(context, context.getResources().getString(R.string.label_time), ContextCompat.getDrawable(context, R.drawable.ic_daysleft)); super(context, context.getResources().getString(R.string.label_time), ContextCompat.getDrawable(context, R.drawable.ic_daysleft));
timeFormat = android.text.format.DateFormat.getTimeFormat(context); timeFormat = android.text.format.DateFormat.getTimeFormat(context);
} }
@Override
public String getKey() {
return "time";
}
private void setValue(Date newTime, boolean callListener) { private void setValue(Date newTime, boolean callListener) {
if (!newTime.equals(time)) { if (!newTime.equals(time)) {
time = newTime; time = newTime;
@@ -73,12 +77,12 @@ public class TimeMeasurementView extends MeasurementView {
@Override @Override
public void restoreState(Bundle state) { public void restoreState(Bundle state) {
setValue(new Date(state.getLong(TIME_KEY)), true); setValue(new Date(state.getLong(getKey())), true);
} }
@Override @Override
public void saveState(Bundle state) { public void saveState(Bundle state) {
state.putLong(TIME_KEY, time.getTime()); state.putLong(getKey(), time.getTime());
} }
@Override @Override

View File

@@ -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)); super(context, context.getResources().getString(R.string.label_whr), ContextCompat.getDrawable(context, R.drawable.ic_whr));
} }
@Override
public String getKey() {
return "whr";
}
@Override @Override
public void updatePreferences(SharedPreferences preferences) { public void updatePreferences(SharedPreferences preferences) {
setVisible(preferences.getBoolean("hipEnable", false) setVisible(preferences.getBoolean("hipEnable", false)

View File

@@ -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)); super(context, context.getResources().getString(R.string.label_whtr), ContextCompat.getDrawable(context, R.drawable.ic_whtr));
} }
@Override
public String getKey() {
return "whtr";
}
@Override @Override
public void updatePreferences(SharedPreferences preferences) { public void updatePreferences(SharedPreferences preferences) {
setVisible(preferences.getBoolean("waistEnable", false)); setVisible(preferences.getBoolean("waistEnable", false));

View File

@@ -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)); super(context, context.getResources().getString(R.string.label_waist), ContextCompat.getDrawable(context, R.drawable.ic_waist));
} }
@Override
public String getKey() {
return "waist";
}
@Override @Override
public void updatePreferences(SharedPreferences preferences) { public void updatePreferences(SharedPreferences preferences) {
setVisible(preferences.getBoolean("waistEnable", false)); setVisible(preferences.getBoolean("waistEnable", false));

View File

@@ -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)); super(context, context.getResources().getString(R.string.label_water), ContextCompat.getDrawable(context, R.drawable.ic_water));
} }
@Override
public String getKey() {
return "water";
}
@Override @Override
public void updatePreferences(SharedPreferences preferences) { public void updatePreferences(SharedPreferences preferences) {
setVisible(preferences.getBoolean("waterEnable", true)); setVisible(preferences.getBoolean("waterEnable", true));

View File

@@ -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)); super(context, context.getResources().getString(R.string.label_weight), ContextCompat.getDrawable(context, R.drawable.ic_weight));
} }
@Override
public String getKey() {
return "weight";
}
@Override @Override
public void updatePreferences(SharedPreferences preferences) { public void updatePreferences(SharedPreferences preferences) {
setVisible(preferences.getBoolean("weightEnable", true)); setVisible(preferences.getBoolean("weightEnable", true));