1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-13 20:24:14 +02:00

- added user option to enable/disable goal

- use material button style (app:background are ignored)
This commit is contained in:
oliexdev
2023-02-12 09:30:02 +01:00
parent 8f7c311395
commit 8965e2876c
16 changed files with 513 additions and 167 deletions

View File

@@ -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')"
]
}
}

View File

@@ -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();

View File

@@ -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();
}
}
};
}

View File

@@ -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);
}
}

View File

@@ -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 {

View File

@@ -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:

View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/rect_pressed"/>
<item android:state_enabled="false" android:drawable="@drawable/rect_disabled" />
<item android:drawable="@drawable/rect_normal"/>
</selector>

View File

@@ -1,13 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="100dp"
android:height="24dp"
android:viewportWidth="100"
android:viewportHeight="24">
<path
android:pathData="m27.128,-0.188h45.169l-21.782,20.179c0,0 -10.156,-9.087 -23.386,-20.179z"
android:strokeLineJoin="miter"
android:strokeWidth="0.26458332"
android:fillColor="#33b5e5"
android:strokeColor="#00000000"
android:strokeLineCap="butt"/>
</vector>

View File

@@ -1,18 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:viewportWidth="355.89"
android:viewportHeight="355.89">
<path
android:pathData="M145.291,240.842c2.225,-3.6 2.284,-8.097 0.163,-12.338L83.808,105.211c-2.252,-4.504 -6.009,-7.087 -10.306,-7.087s-8.053,2.583 -10.306,7.088L1.549,228.503c-2.121,4.242 -2.062,8.739 0.163,12.338c2.224,3.599 6.22,5.664 10.963,5.664h121.653C139.07,246.505 143.067,244.441 145.291,240.842zM73.502,120.958c1.218,0 1.982,1.772 1.982,1.772l43.684,87.369c3.115,5.901 -0.783,4.245 -2.572,3.82c-11.933,-2.837 -26.871,-4.527 -43.094,-4.527c-16.021,0 -30.79,1.648 -42.647,4.422c-1.95,0.457 -6.49,2.187 -3.008,-3.74l43.625,-87.25C71.472,122.824 72.365,120.958 73.502,120.958z"
android:fillColor="#000000"/>
<path
android:pathData="M354.34,187.478L292.694,64.185c-2.252,-4.504 -6.009,-7.087 -10.306,-7.087s-8.053,2.583 -10.306,7.088l-61.646,123.292c-2.121,4.242 -2.062,8.739 0.163,12.338c2.224,3.599 6.22,5.664 10.963,5.664h121.653c4.743,0 8.739,-2.065 10.963,-5.664C356.402,196.216 356.462,191.719 354.34,187.478zM282.388,81c1.648,0 2.949,2.639 2.949,2.639l42.158,84.316c3.578,6.336 -1.296,5.086 -3.692,4.55c-11.642,-2.603 -25.944,-4.14 -41.414,-4.14c-15.884,0 -30.537,1.62 -42.341,4.351c-2.06,0.477 -6.398,1.05 -2.167,-5.959l41.45,-82.901C279.33,83.856 280.678,81 282.388,81z"
android:fillColor="#000000"/>
<path
android:pathData="M15.47,79.549c0.588,0 1.186,-0.047 1.785,-0.145l324.924,-53.033c5.996,-0.979 10.063,-6.633 9.085,-12.628c-0.979,-5.996 -6.631,-10.059 -12.629,-9.085L206.702,26.192c-3.379,0.85 -3.925,-2.526 -4.41,-3.982c-3.399,-10.192 -13.013,-17.54 -24.347,-17.54c-14.175,0 -25.667,11.491 -25.667,25.667c0,1.801 0.67,4.579 -2.242,5.104L13.711,57.691C7.715,58.67 3.648,64.324 4.627,70.319C5.507,75.716 10.174,79.549 15.47,79.549z"
android:fillColor="#000000"/>
<path
android:pathData="M188.945,283.083V81.52c0,-6.075 -4.925,-11 -11,-11c-6.075,0 -11,4.925 -11,11v201.562c0,4.167 -3.689,4.55 -5.519,4.672c-61.963,4.15 -112.644,30.803 -128.826,52.722c-2.825,3.826 -6.651,10.901 8.349,10.901h274c15,0 11.497,-6.369 9.128,-9.801c-15.241,-22.076 -66.418,-49.5 -129.262,-53.798C192.869,287.646 188.945,287.75 188.945,283.083z"
android:fillColor="#000000"/>
</vector>

View File

@@ -14,12 +14,10 @@
<Button
android:id="@+id/btnLeft"
style="?android:attr/buttonStyleSmall"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:background="@drawable/flat_selector"
android:text="&lt;"
android:textColor="@android:color/white" />
android:layout_height="wrap_content"
android:text="&lt;"/>
<TextView
android:id="@+id/txtDataNr"
@@ -36,13 +34,11 @@
<Button
android:id="@+id/btnRight"
style="?android:attr/buttonStyleSmall"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_height="wrap_content"
android:layout_weight="0"
android:background="@drawable/flat_selector"
android:text=">"
android:textColor="@android:color/white" />
android:text=">"/>
</LinearLayout>

View File

@@ -23,16 +23,14 @@
android:layout_weight="1"
android:background="?attr/colorPrimaryDark"
android:gravity="left"
android:orientation="horizontal"></LinearLayout>
android:orientation="horizontal"/>
<Button
android:id="@+id/btnLeftYear"
style="?android:attr/buttonStyleSmall"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:background="@drawable/flat_selector"
android:text="&lt;"
android:textColor="@android:color/white" />
android:layout_height="wrap_content"
android:text="&lt;" />
<TextView
android:id="@+id/txtYear"
@@ -49,13 +47,11 @@
<Button
android:id="@+id/btnRightYear"
style="?android:attr/buttonStyleSmall"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_height="wrap_content"
android:layout_weight="0"
android:background="@drawable/flat_selector"
android:text=">"
android:textColor="@android:color/white" />
android:text=">" />
<LinearLayout
android:layout_width="wrap_content"

View File

@@ -3,6 +3,16 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.health.openscale.gui.measurement.ChartActionBarView
android:id="@+id/chartActionBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:fillViewport="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Spinner
android:id="@+id/spinUser"
android:layout_width="match_parent"
@@ -11,28 +21,20 @@
android:textAlignment="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toBottomOf="@+id/chartActionBar" />
<ImageView
android:id="@+id/rangeOptionMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginBottom="16dp"
android:layout_marginBottom="40dp"
android:scaleType="centerInside"
android:translationZ="10dp"
app:layout_constraintBottom_toBottomOf="@+id/chartView"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/ic_options" />
<com.health.openscale.gui.measurement.ChartActionBarView
android:id="@+id/chartActionBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:fillViewport="true"
app:layout_constraintTop_toTopOf="parent" />
<com.health.openscale.gui.measurement.ChartMeasurementView
android:id="@+id/chartView"
android:layout_width="match_parent"
@@ -40,37 +42,50 @@
android:layout_gravity="center"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/spinUser"></com.health.openscale.gui.measurement.ChartMeasurementView>
app:layout_constraintTop_toBottomOf="@+id/spinUser" />
<TextView
android:id="@+id/initialWeightView"
<LinearLayout
android:id="@+id/rowGoal"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="TextView"
app:layout_constraintEnd_toStartOf="@+id/differenceWeightView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/chartView" />
<TextView
android:id="@+id/differenceWeightView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="TextView"
app:layout_constraintEnd_toStartOf="@+id/goalWeightView"
app:layout_constraintStart_toEndOf="@+id/initialWeightView"
app:layout_constraintTop_toTopOf="@+id/initialWeightView" />
<TextView
android:id="@+id/goalWeightView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:text="TextView"
android:orientation="horizontal"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/differenceWeightView"
app:layout_constraintTop_toTopOf="@+id/differenceWeightView" />
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/chartView">
<TextView
android:id="@+id/initialWeightView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="TextView" />
<TextView
android:id="@+id/differenceWeightView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="TextView" />
<TextView
android:id="@+id/goalWeightView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="TextView" />
</LinearLayout>
<androidx.constraintlayout.widget.Barrier
android:id="@+id/barrier"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:barrierDirection="bottom"
app:constraint_referenced_ids="rowGoal,chartView,chartActionBar,rangeOptionMenu,spinUser" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
@@ -80,7 +95,7 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/differenceWeightView" />
app:layout_constraintTop_toBottomOf="@+id/rowGoal" />
<ProgressBar
android:id="@+id/progressBar"

View File

@@ -270,8 +270,27 @@
android:inputType="numberDecimal|numberSigned" />
</TableRow>
<TableRow
android:id="@+id/rowGoalEnabled"
android:layout_weight="1"
android:gravity="center_vertical">
<TextView
android:id="@+id/lblGoalEnabled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/label_goal_enabled" />
<CheckBox
android:id="@+id/chkGoalEnabled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10" />
</TableRow>
<TableRow
android:id="@+id/rowGoalWeight"
android:visibility="gone"
android:layout_weight="1"
android:gravity="center_vertical">
@@ -292,6 +311,7 @@
<TableRow
android:id="@+id/rowGoalDate"
android:layout_weight="1"
android:visibility="gone"
android:gravity="center_vertical">
<TextView

View File

@@ -79,13 +79,12 @@
<Button
android:id="@+id/btnSearchScale"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/flat_selector"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Add Bluetooth scale"
android:textColor="@android:color/white"
android:textSize="14sp" />
<TextView

View File

@@ -69,13 +69,12 @@
<Button
android:id="@+id/btnAddUser"
style="@style/Widget.MaterialComponents.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/flat_selector"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="@string/label_add_user"
android:textColor="@android:color/white"
android:textSize="14sp" />
<TextView

View File

@@ -74,6 +74,7 @@
<string name="label_amputation_right">Amputation right</string>
<string name="label_male">Male</string>
<string name="label_female">Female</string>
<string name="label_goal_enabled">Goal enabled</string>
<string name="label_goal_weight">Goal weight</string>
<string name="label_goal_date">Goal date</string>
<string name="label_title_user">user</string>