diff --git a/android_app/app/schemas/com.health.openscale.core.database.AppDatabase/6.json b/android_app/app/schemas/com.health.openscale.core.database.AppDatabase/6.json
new file mode 100644
index 00000000..b7d0a2b5
--- /dev/null
+++ b/android_app/app/schemas/com.health.openscale.core.database.AppDatabase/6.json
@@ -0,0 +1,287 @@
+{
+ "formatVersion": 1,
+ "database": {
+ "version": 6,
+ "identityHash": "363295f46fda89cfa9f94179971dc240",
+ "entities": [
+ {
+ "tableName": "scaleMeasurements",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `userId` INTEGER NOT NULL, `enabled` INTEGER NOT NULL, `datetime` INTEGER, `weight` REAL NOT NULL, `fat` REAL NOT NULL, `water` REAL NOT NULL, `muscle` REAL NOT NULL, `visceralFat` REAL NOT NULL, `lbm` REAL NOT NULL, `waist` REAL NOT NULL, `hip` REAL NOT NULL, `bone` REAL NOT NULL, `chest` REAL NOT NULL, `thigh` REAL NOT NULL, `biceps` REAL NOT NULL, `neck` REAL NOT NULL, `caliper1` REAL NOT NULL, `caliper2` REAL NOT NULL, `caliper3` REAL NOT NULL, `calories` REAL NOT NULL, `comment` TEXT, FOREIGN KEY(`userId`) REFERENCES `scaleUsers`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userId",
+ "columnName": "userId",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "enabled",
+ "columnName": "enabled",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "dateTime",
+ "columnName": "datetime",
+ "affinity": "INTEGER",
+ "notNull": false
+ },
+ {
+ "fieldPath": "weight",
+ "columnName": "weight",
+ "affinity": "REAL",
+ "notNull": true
+ },
+ {
+ "fieldPath": "fat",
+ "columnName": "fat",
+ "affinity": "REAL",
+ "notNull": true
+ },
+ {
+ "fieldPath": "water",
+ "columnName": "water",
+ "affinity": "REAL",
+ "notNull": true
+ },
+ {
+ "fieldPath": "muscle",
+ "columnName": "muscle",
+ "affinity": "REAL",
+ "notNull": true
+ },
+ {
+ "fieldPath": "visceralFat",
+ "columnName": "visceralFat",
+ "affinity": "REAL",
+ "notNull": true
+ },
+ {
+ "fieldPath": "lbm",
+ "columnName": "lbm",
+ "affinity": "REAL",
+ "notNull": true
+ },
+ {
+ "fieldPath": "waist",
+ "columnName": "waist",
+ "affinity": "REAL",
+ "notNull": true
+ },
+ {
+ "fieldPath": "hip",
+ "columnName": "hip",
+ "affinity": "REAL",
+ "notNull": true
+ },
+ {
+ "fieldPath": "bone",
+ "columnName": "bone",
+ "affinity": "REAL",
+ "notNull": true
+ },
+ {
+ "fieldPath": "chest",
+ "columnName": "chest",
+ "affinity": "REAL",
+ "notNull": true
+ },
+ {
+ "fieldPath": "thigh",
+ "columnName": "thigh",
+ "affinity": "REAL",
+ "notNull": true
+ },
+ {
+ "fieldPath": "biceps",
+ "columnName": "biceps",
+ "affinity": "REAL",
+ "notNull": true
+ },
+ {
+ "fieldPath": "neck",
+ "columnName": "neck",
+ "affinity": "REAL",
+ "notNull": true
+ },
+ {
+ "fieldPath": "caliper1",
+ "columnName": "caliper1",
+ "affinity": "REAL",
+ "notNull": true
+ },
+ {
+ "fieldPath": "caliper2",
+ "columnName": "caliper2",
+ "affinity": "REAL",
+ "notNull": true
+ },
+ {
+ "fieldPath": "caliper3",
+ "columnName": "caliper3",
+ "affinity": "REAL",
+ "notNull": true
+ },
+ {
+ "fieldPath": "calories",
+ "columnName": "calories",
+ "affinity": "REAL",
+ "notNull": true
+ },
+ {
+ "fieldPath": "comment",
+ "columnName": "comment",
+ "affinity": "TEXT",
+ "notNull": false
+ }
+ ],
+ "primaryKey": {
+ "columnNames": [
+ "id"
+ ],
+ "autoGenerate": true
+ },
+ "indices": [
+ {
+ "name": "index_scaleMeasurements_userId_datetime",
+ "unique": true,
+ "columnNames": [
+ "userId",
+ "datetime"
+ ],
+ "orders": [],
+ "createSql": "CREATE UNIQUE INDEX IF NOT EXISTS `index_scaleMeasurements_userId_datetime` ON `${TABLE_NAME}` (`userId`, `datetime`)"
+ }
+ ],
+ "foreignKeys": [
+ {
+ "table": "scaleUsers",
+ "onDelete": "CASCADE",
+ "onUpdate": "NO ACTION",
+ "columns": [
+ "userId"
+ ],
+ "referencedColumns": [
+ "id"
+ ]
+ }
+ ]
+ },
+ {
+ "tableName": "scaleUsers",
+ "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `username` TEXT NOT NULL, `birthday` INTEGER NOT NULL, `bodyHeight` REAL NOT NULL, `scaleUnit` INTEGER NOT NULL, `gender` INTEGER NOT NULL, `goalEnabled` INTEGER NOT NULL, `initialWeight` REAL NOT NULL, `goalWeight` REAL NOT NULL, `goalDate` INTEGER, `measureUnit` INTEGER NOT NULL, `activityLevel` INTEGER NOT NULL, `assistedWeighing` INTEGER NOT NULL, `leftAmputationLevel` INTEGER NOT NULL, `rightAmputationLevel` INTEGER NOT NULL)",
+ "fields": [
+ {
+ "fieldPath": "id",
+ "columnName": "id",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "userName",
+ "columnName": "username",
+ "affinity": "TEXT",
+ "notNull": true
+ },
+ {
+ "fieldPath": "birthday",
+ "columnName": "birthday",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "bodyHeight",
+ "columnName": "bodyHeight",
+ "affinity": "REAL",
+ "notNull": true
+ },
+ {
+ "fieldPath": "scaleUnit",
+ "columnName": "scaleUnit",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "gender",
+ "columnName": "gender",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "goalEnabled",
+ "columnName": "goalEnabled",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "initialWeight",
+ "columnName": "initialWeight",
+ "affinity": "REAL",
+ "notNull": true
+ },
+ {
+ "fieldPath": "goalWeight",
+ "columnName": "goalWeight",
+ "affinity": "REAL",
+ "notNull": true
+ },
+ {
+ "fieldPath": "goalDate",
+ "columnName": "goalDate",
+ "affinity": "INTEGER",
+ "notNull": false
+ },
+ {
+ "fieldPath": "measureUnit",
+ "columnName": "measureUnit",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "activityLevel",
+ "columnName": "activityLevel",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "assistedWeighing",
+ "columnName": "assistedWeighing",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "leftAmputationLevel",
+ "columnName": "leftAmputationLevel",
+ "affinity": "INTEGER",
+ "notNull": true
+ },
+ {
+ "fieldPath": "rightAmputationLevel",
+ "columnName": "rightAmputationLevel",
+ "affinity": "INTEGER",
+ "notNull": true
+ }
+ ],
+ "primaryKey": {
+ "columnNames": [
+ "id"
+ ],
+ "autoGenerate": true
+ },
+ "indices": [],
+ "foreignKeys": []
+ }
+ ],
+ "views": [],
+ "setupQueries": [
+ "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
+ "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '363295f46fda89cfa9f94179971dc240')"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/android_app/app/src/main/java/com/health/openscale/core/OpenScale.java b/android_app/app/src/main/java/com/health/openscale/core/OpenScale.java
index dc2914cc..7c493876 100644
--- a/android_app/app/src/main/java/com/health/openscale/core/OpenScale.java
+++ b/android_app/app/src/main/java/com/health/openscale/core/OpenScale.java
@@ -131,7 +131,7 @@ public class OpenScale {
db.setForeignKeyConstraintsEnabled(true);
}
})
- .addMigrations(AppDatabase.MIGRATION_1_2, AppDatabase.MIGRATION_2_3, AppDatabase.MIGRATION_3_4, AppDatabase.MIGRATION_4_5)
+ .addMigrations(AppDatabase.MIGRATION_1_2, AppDatabase.MIGRATION_2_3, AppDatabase.MIGRATION_3_4, AppDatabase.MIGRATION_4_5, AppDatabase.MIGRATION_5_6)
.build();
measurementDAO = appDB.measurementDAO();
userDAO = appDB.userDAO();
diff --git a/android_app/app/src/main/java/com/health/openscale/core/database/AppDatabase.java b/android_app/app/src/main/java/com/health/openscale/core/database/AppDatabase.java
index 6a5e1eab..f15b4d26 100644
--- a/android_app/app/src/main/java/com/health/openscale/core/database/AppDatabase.java
+++ b/android_app/app/src/main/java/com/health/openscale/core/database/AppDatabase.java
@@ -26,7 +26,7 @@ import com.health.openscale.core.datatypes.ScaleMeasurement;
import com.health.openscale.core.datatypes.ScaleUser;
import com.health.openscale.core.utils.Converters;
-@Database(entities = {ScaleMeasurement.class, ScaleUser.class}, version = 5)
+@Database(entities = {ScaleMeasurement.class, ScaleUser.class}, version = 6)
@TypeConverters({Converters.class})
public abstract class AppDatabase extends RoomDatabase {
public abstract ScaleMeasurementDAO measurementDAO();
@@ -194,4 +194,20 @@ public abstract class AppDatabase extends RoomDatabase {
}
}
};
+
+ public static final Migration MIGRATION_5_6 = new Migration(5, 6) {
+ @Override
+ public void migrate(SupportSQLiteDatabase database) {
+ database.beginTransaction();
+ try {
+ // Add goal enabled to scale user table
+ database.execSQL("ALTER TABLE scaleUsers ADD goalEnabled INTEGER NOT NULL default 0");
+
+ database.setTransactionSuccessful();
+ }
+ finally {
+ database.endTransaction();
+ }
+ }
+ };
}
diff --git a/android_app/app/src/main/java/com/health/openscale/core/datatypes/ScaleUser.java b/android_app/app/src/main/java/com/health/openscale/core/datatypes/ScaleUser.java
index 1b781438..5be6d42e 100644
--- a/android_app/app/src/main/java/com/health/openscale/core/datatypes/ScaleUser.java
+++ b/android_app/app/src/main/java/com/health/openscale/core/datatypes/ScaleUser.java
@@ -46,6 +46,8 @@ public class ScaleUser {
@ColumnInfo(name = "gender")
@NonNull
private Converters.Gender gender;
+ @ColumnInfo(name = "goalEnabled")
+ private boolean goalEnabled;
@ColumnInfo(name = "initialWeight")
private float initialWeight;
@ColumnInfo(name = "goalWeight")
@@ -74,6 +76,7 @@ public class ScaleUser {
scaleUnit = Converters.WeightUnit.KG;
gender = Converters.Gender.MALE;
initialWeight = -1;
+ goalEnabled = false;
goalWeight = -1;
goalDate = new Date();
measureUnit = Converters.MeasureUnit.CM;
@@ -131,6 +134,14 @@ public class ScaleUser {
this.gender = gender;
}
+ public boolean isGoalEnabled() {
+ return goalEnabled;
+ }
+
+ public void setGoalEnabled(boolean goalEnabled) {
+ this.goalEnabled = goalEnabled;
+ }
+
public float getGoalWeight() {
return goalWeight;
}
@@ -278,10 +289,10 @@ public class ScaleUser {
{
return String.format(
"id(%d) name(%s) birthday(%s) age(%d) body height(%.2f) scale unit(%s) " +
- "gender(%s) initial weight(%.2f) goal weight(%.2f) goal date(%s) " +
+ "gender(%s) initial weight(%.2f) goal enabled(%b) goal weight(%.2f) goal date(%s) " +
"measure unt(%s) activity level(%d) assisted weighing(%b)",
id, userName, birthday.toString(), getAge(), bodyHeight, scaleUnit.toString(),
- gender.toString().toLowerCase(), initialWeight, goalWeight, goalDate.toString(),
+ gender.toString().toLowerCase(), initialWeight, goalEnabled, goalWeight, goalDate.toString(),
measureUnit.toString(), activityLevel.toInt(), assistedWeighing);
}
}
diff --git a/android_app/app/src/main/java/com/health/openscale/gui/overview/OverviewFragment.java b/android_app/app/src/main/java/com/health/openscale/gui/overview/OverviewFragment.java
index ceff9f95..d241d779 100644
--- a/android_app/app/src/main/java/com/health/openscale/gui/overview/OverviewFragment.java
+++ b/android_app/app/src/main/java/com/health/openscale/gui/overview/OverviewFragment.java
@@ -30,6 +30,7 @@ import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
+import android.widget.LinearLayout;
import android.widget.PopupMenu;
import android.widget.Spinner;
import android.widget.TextView;
@@ -73,6 +74,7 @@ public class OverviewFragment extends Fragment {
private PopupMenu rangePopupMenu;
+ private LinearLayout rowGoal;
private TextView differenceWeightView;
private TextView initialWeightView;
private TextView goalWeightView;
@@ -92,6 +94,7 @@ public class OverviewFragment extends Fragment {
prefs = PreferenceManager.getDefaultSharedPreferences(overviewView.getContext());
+ rowGoal = overviewView.findViewById(R.id.rowGoal);
differenceWeightView = overviewView.findViewById(R.id.differenceWeightView);
initialWeightView = overviewView.findViewById(R.id.initialWeightView);
goalWeightView = overviewView.findViewById(R.id.goalWeightView);
@@ -270,73 +273,78 @@ public class OverviewFragment extends Fragment {
int visibility = spinUserAdapter.getCount() < 2 ? View.GONE : View.VISIBLE;
spinUser.setVisibility(visibility);
+ if (currentScaleUser.isGoalEnabled()) {
+ rowGoal.setVisibility(View.VISIBLE);
- WeightMeasurementView weightMeasurementView = new WeightMeasurementView(getContext());
- ScaleMeasurement initialWeightMeasurement = OpenScale.getInstance().getLastScaleMeasurement();
+ WeightMeasurementView weightMeasurementView = new WeightMeasurementView(getContext());
+ ScaleMeasurement initialWeightMeasurement = OpenScale.getInstance().getLastScaleMeasurement();
- if (initialWeightMeasurement == null) {
- initialWeightMeasurement = new ScaleMeasurement();
- }
+ if (initialWeightMeasurement == null) {
+ initialWeightMeasurement = new ScaleMeasurement();
+ }
- initialWeightMeasurement.setWeight(initialWeightMeasurement.getWeight());
- weightMeasurementView.loadFrom(initialWeightMeasurement, null);
+ initialWeightMeasurement.setWeight(initialWeightMeasurement.getWeight());
+ weightMeasurementView.loadFrom(initialWeightMeasurement, null);
- SpannableStringBuilder initialWeightValue = new SpannableStringBuilder();
- initialWeightValue.append(getResources().getString(R.string.label_weight));
- initialWeightValue.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, initialWeightValue.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
- initialWeightValue.append("\n");
- initialWeightValue.append(weightMeasurementView.getValueAsString(true));
- initialWeightValue.append(("\n"));
- int start = initialWeightValue.length();
- initialWeightValue.append(DateFormat.getDateInstance(DateFormat.MEDIUM).format(initialWeightMeasurement.getDateTime()));
- initialWeightValue.setSpan(new RelativeSizeSpan(0.8f), start, initialWeightValue.length(),
- Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ SpannableStringBuilder initialWeightValue = new SpannableStringBuilder();
+ initialWeightValue.append(getResources().getString(R.string.label_weight));
+ initialWeightValue.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, initialWeightValue.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ initialWeightValue.append("\n");
+ initialWeightValue.append(weightMeasurementView.getValueAsString(true));
+ initialWeightValue.append(("\n"));
+ int start = initialWeightValue.length();
+ initialWeightValue.append(DateFormat.getDateInstance(DateFormat.MEDIUM).format(initialWeightMeasurement.getDateTime()));
+ initialWeightValue.setSpan(new RelativeSizeSpan(0.8f), start, initialWeightValue.length(),
+ Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
- initialWeightView.setText(initialWeightValue);
+ initialWeightView.setText(initialWeightValue);
- ScaleMeasurement goalWeightMeasurement = new ScaleMeasurement();
- goalWeightMeasurement.setWeight(currentScaleUser.getGoalWeight());
- weightMeasurementView.loadFrom(goalWeightMeasurement, null);
+ ScaleMeasurement goalWeightMeasurement = new ScaleMeasurement();
+ goalWeightMeasurement.setWeight(currentScaleUser.getGoalWeight());
+ weightMeasurementView.loadFrom(goalWeightMeasurement, null);
- SpannableStringBuilder goalWeightValue = new SpannableStringBuilder();
- goalWeightValue.append(getResources().getString(R.string.label_goal_weight));
- goalWeightValue.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, goalWeightValue.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
- goalWeightValue.append("\n");
- goalWeightValue.append(weightMeasurementView.getValueAsString(true));
- goalWeightValue.append(("\n"));
- start = goalWeightValue.length();
- goalWeightValue.append(DateFormat.getDateInstance(DateFormat.MEDIUM).format(currentScaleUser.getGoalDate()));
- goalWeightValue.setSpan(new RelativeSizeSpan(0.8f), start, goalWeightValue.length(),
- Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ SpannableStringBuilder goalWeightValue = new SpannableStringBuilder();
+ goalWeightValue.append(getResources().getString(R.string.label_goal_weight));
+ goalWeightValue.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, goalWeightValue.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ goalWeightValue.append("\n");
+ goalWeightValue.append(weightMeasurementView.getValueAsString(true));
+ goalWeightValue.append(("\n"));
+ start = goalWeightValue.length();
+ goalWeightValue.append(DateFormat.getDateInstance(DateFormat.MEDIUM).format(currentScaleUser.getGoalDate()));
+ goalWeightValue.setSpan(new RelativeSizeSpan(0.8f), start, goalWeightValue.length(),
+ Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
- goalWeightView.setText(goalWeightValue);
+ goalWeightView.setText(goalWeightValue);
- ScaleMeasurement differenceWeightMeasurement = new ScaleMeasurement();
- if (initialWeightMeasurement.getWeight() > goalWeightMeasurement.getWeight()) {
- differenceWeightMeasurement.setWeight(initialWeightMeasurement.getWeight() -goalWeightMeasurement.getWeight());
+ ScaleMeasurement differenceWeightMeasurement = new ScaleMeasurement();
+ if (initialWeightMeasurement.getWeight() > goalWeightMeasurement.getWeight()) {
+ differenceWeightMeasurement.setWeight(initialWeightMeasurement.getWeight() - goalWeightMeasurement.getWeight());
+ } else {
+ differenceWeightMeasurement.setWeight(goalWeightMeasurement.getWeight() - initialWeightMeasurement.getWeight());
+ }
+ weightMeasurementView.loadFrom(differenceWeightMeasurement, null);
+
+ Calendar initialCalendar = Calendar.getInstance();
+ initialCalendar.setTime(initialWeightMeasurement.getDateTime());
+ Calendar goalCalendar = Calendar.getInstance();
+ goalCalendar.setTime(currentScaleUser.getGoalDate());
+ int daysBetween = Math.max(0, DateTimeHelpers.daysBetween(initialCalendar, goalCalendar));
+
+ SpannableStringBuilder differenceWeightValue = new SpannableStringBuilder();
+ differenceWeightValue.append(getResources().getString(R.string.label_weight_difference));
+ differenceWeightValue.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, differenceWeightValue.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ differenceWeightValue.append("\n");
+ differenceWeightValue.append(weightMeasurementView.getValueAsString(true));
+ differenceWeightValue.append(("\n"));
+ start = differenceWeightValue.length();
+ differenceWeightValue.append(daysBetween + " " + getString(R.string.label_days_left));
+ differenceWeightValue.setSpan(new RelativeSizeSpan(0.8f), start, differenceWeightValue.length(),
+ Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+
+ differenceWeightView.setText(differenceWeightValue);
} else {
- differenceWeightMeasurement.setWeight(goalWeightMeasurement.getWeight() - initialWeightMeasurement.getWeight());
+ rowGoal.setVisibility(View.GONE);
}
- weightMeasurementView.loadFrom(differenceWeightMeasurement, null);
-
- Calendar initialCalendar = Calendar.getInstance();
- initialCalendar.setTime(initialWeightMeasurement.getDateTime());
- Calendar goalCalendar = Calendar.getInstance();
- goalCalendar.setTime(currentScaleUser.getGoalDate());
- int daysBetween = Math.max(0, DateTimeHelpers.daysBetween(initialCalendar, goalCalendar));
-
- SpannableStringBuilder differenceWeightValue = new SpannableStringBuilder();
- differenceWeightValue.append(getResources().getString(R.string.label_weight_difference));
- differenceWeightValue.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, differenceWeightValue.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
- differenceWeightValue.append("\n");
- differenceWeightValue.append(weightMeasurementView.getValueAsString(true));
- differenceWeightValue.append(("\n"));
- start = differenceWeightValue.length();
- differenceWeightValue.append(daysBetween + " " + getString(R.string.label_days_left));
- differenceWeightValue.setSpan(new RelativeSizeSpan(0.8f), start, differenceWeightValue.length(),
- Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
-
- differenceWeightView.setText(differenceWeightValue);
}
private class onChartSelectedListener implements OnChartValueSelectedListener {
diff --git a/android_app/app/src/main/java/com/health/openscale/gui/preferences/UserSettingsFragment.java b/android_app/app/src/main/java/com/health/openscale/gui/preferences/UserSettingsFragment.java
index 04f85b01..b0d861bd 100644
--- a/android_app/app/src/main/java/com/health/openscale/gui/preferences/UserSettingsFragment.java
+++ b/android_app/app/src/main/java/com/health/openscale/gui/preferences/UserSettingsFragment.java
@@ -29,10 +29,12 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
+import android.widget.CompoundButton;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.Spinner;
+import android.widget.TableRow;
import android.widget.Toast;
import androidx.core.graphics.drawable.DrawableCompat;
@@ -61,6 +63,7 @@ public class UserSettingsFragment extends Fragment {
private EditText txtBodyHeight;
private EditText txtBirthday;
private EditText txtInitialWeight;
+ private CheckBox chkGoalEnabled;
private EditText txtGoalWeight;
private EditText txtGoalDate;
private RadioGroup radioScaleUnit;
@@ -70,6 +73,8 @@ public class UserSettingsFragment extends Fragment {
private Spinner spinnerActivityLevel;
private Spinner spinnerLeftAmputationLevel;
private Spinner spinnerRightAmputationLevel;
+ private TableRow rowGoalWeight;
+ private TableRow rowGoalDate;
private final DateFormat dateFormat = DateFormat.getDateInstance();
@@ -98,10 +103,13 @@ public class UserSettingsFragment extends Fragment {
spinnerLeftAmputationLevel = root.findViewById(R.id.spinnerLeftAmputationLevel);
spinnerRightAmputationLevel = root.findViewById(R.id.spinnerRightAmputationLevel);
txtInitialWeight = root.findViewById(R.id.txtInitialWeight);
+ chkGoalEnabled = root.findViewById(R.id.chkGoalEnabled);
txtGoalWeight = root.findViewById(R.id.txtGoalWeight);
+ txtGoalDate = root.findViewById(R.id.txtGoalDate);
+ rowGoalWeight = root.findViewById(R.id.rowGoalWeight);
+ rowGoalDate = root.findViewById(R.id.rowGoalDate);
txtBirthday = root.findViewById(R.id.txtBirthday);
- txtGoalDate = root.findViewById(R.id.txtGoalDate);
txtBodyHeight.setHint(getResources().getString(R.string.info_enter_value_in) + " " + Converters.MeasureUnit.CM.toString());
txtInitialWeight.setHint(getResources().getString(R.string.info_enter_value_in) + " " + Converters.WeightUnit.KG.toString());
@@ -132,6 +140,19 @@ public class UserSettingsFragment extends Fragment {
}
});
+ chkGoalEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
+ if (b) {
+ rowGoalDate.setVisibility(View.VISIBLE);
+ rowGoalWeight.setVisibility(View.VISIBLE);
+ } else {
+ rowGoalDate.setVisibility(View.GONE);
+ rowGoalWeight.setVisibility(View.GONE);
+ }
+ }
+ });
+
txtGoalDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -301,8 +322,17 @@ public class UserSettingsFragment extends Fragment {
break;
}
+ chkGoalEnabled.setChecked(scaleUser.isGoalEnabled());
assistedWeighing.setChecked(scaleUser.isAssistedWeighing());
+ if (chkGoalEnabled.isChecked()) {
+ rowGoalDate.setVisibility(View.VISIBLE);
+ rowGoalWeight.setVisibility(View.VISIBLE);
+ } else {
+ rowGoalDate.setVisibility(View.GONE);
+ rowGoalWeight.setVisibility(View.GONE);
+ }
+
spinnerActivityLevel.setSelection(scaleUser.getActivityLevel().toInt());
spinnerLeftAmputationLevel.setSelection(scaleUser.getLeftAmputationLevel().toInt());
spinnerRightAmputationLevel.setSelection(scaleUser.getRightAmputationLevel().toInt());
@@ -327,9 +357,11 @@ public class UserSettingsFragment extends Fragment {
validate = false;
}
- if (txtGoalWeight.getText().toString().length() == 0) {
- txtGoalWeight.setError(getResources().getString(R.string.error_goal_weight_required));
- validate = false;
+ if (chkGoalEnabled.isChecked()) {
+ if (txtGoalWeight.getText().toString().length() == 0) {
+ txtGoalWeight.setError(getResources().getString(R.string.error_goal_weight_required));
+ validate = false;
+ }
}
return validate;
@@ -405,7 +437,6 @@ public class UserSettingsFragment extends Fragment {
String name = txtUserName.getText().toString();
float body_height = Float.valueOf(txtBodyHeight.getText().toString());
float initial_weight = Float.valueOf(txtInitialWeight.getText().toString());
- float goal_weight = Float.valueOf(txtGoalWeight.getText().toString());
Converters.MeasureUnit measure_unit = Converters.MeasureUnit.CM;
@@ -456,8 +487,12 @@ public class UserSettingsFragment extends Fragment {
scaleUser.setGender(gender);
scaleUser.setAssistedWeighing(assistedWeighing.isChecked());
scaleUser.setInitialWeight(Converters.toKilogram(initial_weight, scale_unit));
- scaleUser.setGoalWeight(Converters.toKilogram(goal_weight, scale_unit));
- scaleUser.setGoalDate(goal_date);
+ scaleUser.setGoalEnabled(chkGoalEnabled.isChecked());
+ if (chkGoalEnabled.isChecked()) {
+ float goal_weight = Float.valueOf(txtGoalWeight.getText().toString());
+ scaleUser.setGoalWeight(Converters.toKilogram(goal_weight, scale_unit));
+ scaleUser.setGoalDate(goal_date);
+ }
switch (mode) {
case ADD:
diff --git a/android_app/app/src/main/res/drawable/flat_selector.xml b/android_app/app/src/main/res/drawable/flat_selector.xml
deleted file mode 100644
index 224c8210..00000000
--- a/android_app/app/src/main/res/drawable/flat_selector.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
diff --git a/android_app/app/src/main/res/drawable/ic_chart_marker.xml b/android_app/app/src/main/res/drawable/ic_chart_marker.xml
deleted file mode 100644
index e51fecb5..00000000
--- a/android_app/app/src/main/res/drawable/ic_chart_marker.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
diff --git a/android_app/app/src/main/res/drawable/ic_difference.xml b/android_app/app/src/main/res/drawable/ic_difference.xml
deleted file mode 100644
index ddb188a7..00000000
--- a/android_app/app/src/main/res/drawable/ic_difference.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
-
-
-
diff --git a/android_app/app/src/main/res/layout/fragment_dataentry.xml b/android_app/app/src/main/res/layout/fragment_dataentry.xml
index 578f5acc..b4bb46c4 100644
--- a/android_app/app/src/main/res/layout/fragment_dataentry.xml
+++ b/android_app/app/src/main/res/layout/fragment_dataentry.xml
@@ -14,12 +14,10 @@
+ android:layout_height="wrap_content"
+ android:text="<"/>
+ android:text=">"/>
diff --git a/android_app/app/src/main/res/layout/fragment_graph.xml b/android_app/app/src/main/res/layout/fragment_graph.xml
index 5bd1452d..29887ee4 100644
--- a/android_app/app/src/main/res/layout/fragment_graph.xml
+++ b/android_app/app/src/main/res/layout/fragment_graph.xml
@@ -23,16 +23,14 @@
android:layout_weight="1"
android:background="?attr/colorPrimaryDark"
android:gravity="left"
- android:orientation="horizontal">
+ android:orientation="horizontal"/>
+ android:layout_height="wrap_content"
+ android:text="<" />
+ android:text=">" />
+
+
+ app:layout_constraintTop_toBottomOf="@+id/chartActionBar" />
-
-
+ app:layout_constraintTop_toBottomOf="@+id/spinUser" />
-
-
-
-
-
+ app:layout_constraintHorizontal_bias="0.0"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toBottomOf="@+id/chartView">
+
+
+
+
+
+
+
+
+
+ app:layout_constraintTop_toBottomOf="@+id/rowGoal" />
+
+
+
+
+
+
+
@@ -292,6 +311,7 @@
Amputation right
Male
Female
+ Goal enabled
Goal weight
Goal date
user