mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-20 07:21:40 +02:00
Move enable logic to base class
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
package com.health.openscale.gui.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
||||
@@ -38,8 +37,8 @@ public class BMIMeasurementView extends FloatMeasurementView {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePreferences(SharedPreferences preferences) {
|
||||
setVisible(preferences.getBoolean("weightEnable", true));
|
||||
public String[] getDependencyKeys() {
|
||||
return new String[] {WeightMeasurementView.KEY};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -16,7 +16,6 @@
|
||||
package com.health.openscale.gui.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
||||
@@ -40,8 +39,8 @@ public class BMRMeasurementView extends FloatMeasurementView {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePreferences(SharedPreferences preferences) {
|
||||
setVisible(preferences.getBoolean("weightEnable", true));
|
||||
public String[] getDependencyKeys() {
|
||||
return new String[] {WeightMeasurementView.KEY};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -16,7 +16,6 @@
|
||||
package com.health.openscale.gui.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
||||
@@ -37,11 +36,6 @@ public class BoneMeasurementView extends FloatMeasurementView {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePreferences(SharedPreferences preferences) {
|
||||
setVisible(preferences.getBoolean("boneEnable", false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getMeasurementValue(ScaleMeasurement measurement) {
|
||||
return measurement.getBone();
|
||||
|
@@ -16,7 +16,6 @@
|
||||
package com.health.openscale.gui.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.text.InputType;
|
||||
@@ -67,11 +66,6 @@ public class CommentMeasurementView extends MeasurementView {
|
||||
state.putString(getKey(), comment);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePreferences(SharedPreferences preferences) {
|
||||
// Empty
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValueAsString() {
|
||||
return comment;
|
||||
|
@@ -16,7 +16,6 @@
|
||||
package com.health.openscale.gui.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.View;
|
||||
@@ -82,11 +81,6 @@ public class DateMeasurementView extends MeasurementView {
|
||||
state.putLong(getKey(), date.getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePreferences(SharedPreferences preferences) {
|
||||
// Empty
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValueAsString() {
|
||||
return dateFormat.format(date);
|
||||
|
@@ -42,7 +42,7 @@ public class FatMeasurementView extends FloatMeasurementView {
|
||||
|
||||
@Override
|
||||
public void updatePreferences(SharedPreferences preferences) {
|
||||
setVisible(preferences.getBoolean("fatEnable", true));
|
||||
super.updatePreferences(preferences);
|
||||
estimateFatEnable = preferences.getBoolean("estimateFatEnable", false);
|
||||
percentageEnable = preferences.getBoolean("fatPercentageEnable", true);
|
||||
}
|
||||
|
@@ -16,7 +16,6 @@
|
||||
package com.health.openscale.gui.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
||||
@@ -37,11 +36,6 @@ public class HipMeasurementView extends FloatMeasurementView {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePreferences(SharedPreferences preferences) {
|
||||
setVisible(preferences.getBoolean("hipEnable", false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getMeasurementValue(ScaleMeasurement measurement) {
|
||||
return measurement.getHip();
|
||||
|
@@ -41,7 +41,7 @@ public class LBWMeasurementView extends FloatMeasurementView {
|
||||
|
||||
@Override
|
||||
public void updatePreferences(SharedPreferences preferences) {
|
||||
setVisible(preferences.getBoolean("lbwEnable", false));
|
||||
super.updatePreferences(preferences);
|
||||
estimateLBWEnable = preferences.getBoolean("estimateLBWEnable", false);
|
||||
}
|
||||
|
||||
|
@@ -23,6 +23,7 @@ import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.CallSuper;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.TextUtils;
|
||||
@@ -61,6 +62,8 @@ public abstract class MeasurementView extends TableLayout {
|
||||
|
||||
public static String PREF_MEASUREMENT_ORDER = "measurementOrder";
|
||||
|
||||
private static String PREFERENCE_SUFFIX_ENABLE = "Enable";
|
||||
|
||||
private TableRow measurementRow;
|
||||
private ImageView iconView;
|
||||
private TextView nameView;
|
||||
@@ -242,6 +245,11 @@ public abstract class MeasurementView extends TableLayout {
|
||||
}
|
||||
|
||||
public abstract String getKey();
|
||||
public String[] getDependencyKeys() { return new String[]{}; }
|
||||
|
||||
public static String getPreferenceKey(String key, String suffix) {
|
||||
return key + suffix;
|
||||
}
|
||||
|
||||
public abstract void loadFrom(ScaleMeasurement measurement, ScaleMeasurement previousMeasurement);
|
||||
public abstract void saveTo(ScaleMeasurement measurement);
|
||||
@@ -249,7 +257,23 @@ public abstract class MeasurementView extends TableLayout {
|
||||
public abstract void restoreState(Bundle state);
|
||||
public abstract void saveState(Bundle state);
|
||||
|
||||
public abstract void updatePreferences(SharedPreferences preferences);
|
||||
@CallSuper
|
||||
public void updatePreferences(SharedPreferences prefs) {
|
||||
boolean enable = prefs.getBoolean(
|
||||
getPreferenceKey(getKey(), PREFERENCE_SUFFIX_ENABLE), true);
|
||||
|
||||
if (enable) {
|
||||
for (String dep : getDependencyKeys()) {
|
||||
if (!prefs.getBoolean(
|
||||
getPreferenceKey(dep, PREFERENCE_SUFFIX_ENABLE), true)) {
|
||||
enable = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setVisible(enable);
|
||||
}
|
||||
|
||||
public CharSequence getName() { return nameView.getText(); }
|
||||
public abstract String getValueAsString();
|
||||
|
@@ -41,7 +41,7 @@ public class MuscleMeasurementView extends FloatMeasurementView {
|
||||
|
||||
@Override
|
||||
public void updatePreferences(SharedPreferences preferences) {
|
||||
setVisible(preferences.getBoolean("muscleEnable", true));
|
||||
super.updatePreferences(preferences);
|
||||
percentageEnable = preferences.getBoolean("musclePercentageEnable", true);
|
||||
}
|
||||
|
||||
|
@@ -16,7 +16,6 @@
|
||||
package com.health.openscale.gui.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.View;
|
||||
@@ -85,11 +84,6 @@ public class TimeMeasurementView extends MeasurementView {
|
||||
state.putLong(getKey(), time.getTime());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePreferences(SharedPreferences preferences) {
|
||||
// Empty
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValueAsString() {
|
||||
return timeFormat.format(time);
|
||||
|
@@ -16,7 +16,6 @@
|
||||
package com.health.openscale.gui.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
||||
@@ -38,9 +37,8 @@ public class WHRMeasurementView extends FloatMeasurementView {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePreferences(SharedPreferences preferences) {
|
||||
setVisible(preferences.getBoolean("hipEnable", false)
|
||||
&& preferences.getBoolean("waistEnable", false));
|
||||
public String[] getDependencyKeys() {
|
||||
return new String[] {HipMeasurementView.KEY, WaistMeasurementView.KEY};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -16,7 +16,6 @@
|
||||
package com.health.openscale.gui.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
||||
@@ -38,8 +37,8 @@ public class WHtRMeasurementView extends FloatMeasurementView {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePreferences(SharedPreferences preferences) {
|
||||
setVisible(preferences.getBoolean("waistEnable", false));
|
||||
public String[] getDependencyKeys() {
|
||||
return new String[] {WaistMeasurementView.KEY};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -16,7 +16,6 @@
|
||||
package com.health.openscale.gui.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
||||
@@ -37,11 +36,6 @@ public class WaistMeasurementView extends FloatMeasurementView {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePreferences(SharedPreferences preferences) {
|
||||
setVisible(preferences.getBoolean("waistEnable", false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getMeasurementValue(ScaleMeasurement measurement) {
|
||||
return measurement.getWaist();
|
||||
|
@@ -42,7 +42,7 @@ public class WaterMeasurementView extends FloatMeasurementView {
|
||||
|
||||
@Override
|
||||
public void updatePreferences(SharedPreferences preferences) {
|
||||
setVisible(preferences.getBoolean("waterEnable", true));
|
||||
super.updatePreferences(preferences);
|
||||
estimateWaterEnable = preferences.getBoolean("estimateWaterEnable", false);
|
||||
percentageEnable = preferences.getBoolean("waterPercentageEnable", true);
|
||||
}
|
||||
|
@@ -16,7 +16,6 @@
|
||||
package com.health.openscale.gui.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
|
||||
@@ -38,11 +37,6 @@ public class WeightMeasurementView extends FloatMeasurementView {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePreferences(SharedPreferences preferences) {
|
||||
setVisible(preferences.getBoolean("weightEnable", true));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getMeasurementValue(ScaleMeasurement measurement) {
|
||||
return measurement.getConvertedWeight(getScaleUser().getScaleUnit());
|
||||
|
Reference in New Issue
Block a user