mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-23 16:53:04 +02:00
convert initial weight into user scale unit
This commit is contained in:
@@ -93,7 +93,7 @@ public class OpenScale {
|
|||||||
scaleUser.body_height = body_height;
|
scaleUser.body_height = body_height;
|
||||||
scaleUser.scale_unit = scale_unit;
|
scaleUser.scale_unit = scale_unit;
|
||||||
scaleUser.gender = gender;
|
scaleUser.gender = gender;
|
||||||
scaleUser.initial_weight = initial_weight;
|
scaleUser.setConvertedInitialWeight(initial_weight);
|
||||||
scaleUser.goal_weight = goal_weight;
|
scaleUser.goal_weight = goal_weight;
|
||||||
scaleUser.goal_date = new SimpleDateFormat("dd.MM.yyyy").parse(goal_date);
|
scaleUser.goal_date = new SimpleDateFormat("dd.MM.yyyy").parse(goal_date);
|
||||||
|
|
||||||
@@ -150,7 +150,7 @@ public class OpenScale {
|
|||||||
scaleUser.body_height = body_height;
|
scaleUser.body_height = body_height;
|
||||||
scaleUser.scale_unit = scale_unit;
|
scaleUser.scale_unit = scale_unit;
|
||||||
scaleUser.gender = gender;
|
scaleUser.gender = gender;
|
||||||
scaleUser.initial_weight = initial_weight;
|
scaleUser.setConvertedInitialWeight(initial_weight);
|
||||||
scaleUser.goal_weight = goal_weight;
|
scaleUser.goal_weight = goal_weight;
|
||||||
scaleUser.goal_date = new SimpleDateFormat("dd.MM.yyyy").parse(goal_date);
|
scaleUser.goal_date = new SimpleDateFormat("dd.MM.yyyy").parse(goal_date);
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
@@ -212,7 +212,7 @@ public class OpenScale {
|
|||||||
if (scaleUserData.size() > 0) {
|
if (scaleUserData.size() > 0) {
|
||||||
lastWeight = scaleUserData.get(0).getWeight();
|
lastWeight = scaleUserData.get(0).getWeight();
|
||||||
} else {
|
} else {
|
||||||
lastWeight = scaleUser.get(i).initial_weight;
|
lastWeight = scaleUser.get(i).getInitialWeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((lastWeight - range) <= weight && (lastWeight + range) >= weight) {
|
if ((lastWeight - range) <= weight && (lastWeight + range) >= weight) {
|
||||||
|
@@ -113,7 +113,7 @@ public class ScaleUserDatabase extends SQLiteOpenHelper {
|
|||||||
values.put(COLUMN_NAME_BODY_HEIGHT, scaleUser.body_height);
|
values.put(COLUMN_NAME_BODY_HEIGHT, scaleUser.body_height);
|
||||||
values.put(COLUMN_NAME_SCALE_UNIT, scaleUser.scale_unit);
|
values.put(COLUMN_NAME_SCALE_UNIT, scaleUser.scale_unit);
|
||||||
values.put(COLUMN_NAME_GENDER, scaleUser.gender);
|
values.put(COLUMN_NAME_GENDER, scaleUser.gender);
|
||||||
values.put(COLUMN_NAME_INITIAL_WEIGHT, scaleUser.initial_weight);
|
values.put(COLUMN_NAME_INITIAL_WEIGHT, scaleUser.getInitialWeight());
|
||||||
values.put(COLUMN_NAME_GOAL_WEIGHT, scaleUser.goal_weight);
|
values.put(COLUMN_NAME_GOAL_WEIGHT, scaleUser.goal_weight);
|
||||||
values.put(COLUMN_NAME_GOAL_DATE, formatDateTime.format(scaleUser.goal_date));
|
values.put(COLUMN_NAME_GOAL_DATE, formatDateTime.format(scaleUser.goal_date));
|
||||||
|
|
||||||
@@ -146,7 +146,7 @@ public class ScaleUserDatabase extends SQLiteOpenHelper {
|
|||||||
values.put(COLUMN_NAME_BODY_HEIGHT, scaleUser.body_height);
|
values.put(COLUMN_NAME_BODY_HEIGHT, scaleUser.body_height);
|
||||||
values.put(COLUMN_NAME_SCALE_UNIT, scaleUser.scale_unit);
|
values.put(COLUMN_NAME_SCALE_UNIT, scaleUser.scale_unit);
|
||||||
values.put(COLUMN_NAME_GENDER, scaleUser.gender);
|
values.put(COLUMN_NAME_GENDER, scaleUser.gender);
|
||||||
values.put(COLUMN_NAME_INITIAL_WEIGHT, scaleUser.initial_weight);
|
values.put(COLUMN_NAME_INITIAL_WEIGHT, scaleUser.getInitialWeight());
|
||||||
values.put(COLUMN_NAME_GOAL_WEIGHT, scaleUser.goal_weight);
|
values.put(COLUMN_NAME_GOAL_WEIGHT, scaleUser.goal_weight);
|
||||||
values.put(COLUMN_NAME_GOAL_DATE, formatDateTime.format(scaleUser.goal_date));
|
values.put(COLUMN_NAME_GOAL_DATE, formatDateTime.format(scaleUser.goal_date));
|
||||||
|
|
||||||
@@ -222,7 +222,7 @@ public class ScaleUserDatabase extends SQLiteOpenHelper {
|
|||||||
scaleUser.birthday = formatDateTime.parse(birthday);
|
scaleUser.birthday = formatDateTime.parse(birthday);
|
||||||
scaleUser.goal_date = formatDateTime.parse(goal_date);
|
scaleUser.goal_date = formatDateTime.parse(goal_date);
|
||||||
|
|
||||||
scaleUser.initial_weight = Math.round(initial_weight * 100.0f) / 100.0f;
|
scaleUser.setInitialWeight(Math.round(initial_weight * 100.0f) / 100.0f);
|
||||||
scaleUser.goal_weight = Math.round(goal_weight * 100.0f) / 100.0f;
|
scaleUser.goal_weight = Math.round(goal_weight * 100.0f) / 100.0f;
|
||||||
} catch (ParseException ex) {
|
} catch (ParseException ex) {
|
||||||
Log.e("ScaleDatabase", "Can't parse the date time string: " + ex.getMessage());
|
Log.e("ScaleDatabase", "Can't parse the date time string: " + ex.getMessage());
|
||||||
|
@@ -21,6 +21,8 @@ import java.util.Date;
|
|||||||
|
|
||||||
public class ScaleUser {
|
public class ScaleUser {
|
||||||
public static final String[] UNIT_STRING = new String[] {"kg", "lb", "st"};
|
public static final String[] UNIT_STRING = new String[] {"kg", "lb", "st"};
|
||||||
|
private static float KG_LB = 2.20462f;
|
||||||
|
private static float KG_ST = 0.157473f;
|
||||||
|
|
||||||
public int id;
|
public int id;
|
||||||
public String user_name;
|
public String user_name;
|
||||||
@@ -28,7 +30,7 @@ public class ScaleUser {
|
|||||||
public int body_height;
|
public int body_height;
|
||||||
public int scale_unit;
|
public int scale_unit;
|
||||||
public int gender;
|
public int gender;
|
||||||
public float initial_weight;
|
private float initial_weight;
|
||||||
public float goal_weight;
|
public float goal_weight;
|
||||||
public Date goal_date;
|
public Date goal_date;
|
||||||
|
|
||||||
@@ -62,6 +64,47 @@ public class ScaleUser {
|
|||||||
return userAge;
|
return userAge;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setInitialWeight(float weight) {
|
||||||
|
this.initial_weight = weight;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConvertedInitialWeight(float weight) {
|
||||||
|
switch (ScaleUser.UNIT_STRING[scale_unit]) {
|
||||||
|
case "kg":
|
||||||
|
this.initial_weight = weight;
|
||||||
|
break;
|
||||||
|
case "lb":
|
||||||
|
this.initial_weight = weight / KG_LB;
|
||||||
|
break;
|
||||||
|
case "st":
|
||||||
|
this.initial_weight = weight / KG_ST;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getInitialWeight() {
|
||||||
|
return initial_weight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getConvertedInitialWeight() {
|
||||||
|
float converted_weight = 0.0f;
|
||||||
|
|
||||||
|
switch (ScaleUser.UNIT_STRING[scale_unit]) {
|
||||||
|
case "kg":
|
||||||
|
converted_weight = initial_weight;
|
||||||
|
break;
|
||||||
|
case "lb":
|
||||||
|
converted_weight = initial_weight * KG_LB;
|
||||||
|
break;
|
||||||
|
case "st":
|
||||||
|
converted_weight = initial_weight * KG_ST;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return converted_weight;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
|
@@ -133,7 +133,7 @@ public class UserSettingsActivity extends Activity {
|
|||||||
txtBodyHeight.setText(Integer.toString(scaleUser.body_height));
|
txtBodyHeight.setText(Integer.toString(scaleUser.body_height));
|
||||||
txtBirthday.setText(dateFormat.format(scaleUser.birthday));
|
txtBirthday.setText(dateFormat.format(scaleUser.birthday));
|
||||||
txtGoalDate.setText(dateFormat.format(scaleUser.goal_date));
|
txtGoalDate.setText(dateFormat.format(scaleUser.goal_date));
|
||||||
txtInitialWeight.setText(scaleUser.initial_weight+"");
|
txtInitialWeight.setText(Math.round(scaleUser.getConvertedInitialWeight()*100.0f)/100.0f + "");
|
||||||
txtGoalWeight.setText(scaleUser.goal_weight+"");
|
txtGoalWeight.setText(scaleUser.goal_weight+"");
|
||||||
|
|
||||||
switch (scaleUser.scale_unit)
|
switch (scaleUser.scale_unit)
|
||||||
|
Reference in New Issue
Block a user