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