use of com.health.openscale.core.datatypes.ScaleUser in project openScale by oliexdev.
the class ChartMeasurementView method addGoalLine.
private void addGoalLine(List<ILineDataSet> lineDataSets) {
List<Entry> valuesGoalLine = new Stack<>();
ScaleUser user = OpenScale.getInstance().getSelectedScaleUser();
float goalWeight = Converters.fromKilogram(user.getGoalWeight(), user.getScaleUnit());
valuesGoalLine.add(new Entry(getXChartMin(), goalWeight));
valuesGoalLine.add(new Entry(getXChartMax(), goalWeight));
LineDataSet goalLine = new LineDataSet(valuesGoalLine, getContext().getString(R.string.label_goal_line));
goalLine.setLineWidth(1.5f);
goalLine.setColor(ColorUtil.COLOR_GREEN);
goalLine.setAxisDependency(prefs.getBoolean("weightOnRightAxis", true) ? YAxis.AxisDependency.RIGHT : YAxis.AxisDependency.LEFT);
goalLine.setDrawValues(false);
goalLine.setDrawCircles(false);
goalLine.setHighlightEnabled(false);
goalLine.enableDashedLine(10, 30, 0);
lineDataSets.add(goalLine);
}
use of com.health.openscale.core.datatypes.ScaleUser in project openScale by oliexdev.
the class UserSettingsActivity method saveUserData.
private boolean saveUserData() {
try {
if (validateInput()) {
OpenScale openScale = OpenScale.getInstance(getApplicationContext());
String name = txtUserName.getText().toString();
int body_height = Integer.valueOf(txtBodyHeight.getText().toString());
int checkedRadioButtonId = radioScaleUnit.getCheckedRadioButtonId();
int checkedGenderId = radioGender.getCheckedRadioButtonId();
float initial_weight = Float.valueOf(txtInitialWeight.getText().toString());
float goal_weight = Float.valueOf(txtGoalWeight.getText().toString());
Converters.WeightUnit scale_unit = Converters.WeightUnit.KG;
switch(checkedRadioButtonId) {
case R.id.btnRadioKG:
scale_unit = Converters.WeightUnit.KG;
break;
case R.id.btnRadioLB:
scale_unit = Converters.WeightUnit.LB;
break;
case R.id.btnRadioST:
scale_unit = Converters.WeightUnit.ST;
break;
}
Converters.Gender gender = Converters.Gender.MALE;
switch(checkedGenderId) {
case R.id.btnRadioMale:
gender = Converters.Gender.MALE;
break;
case R.id.btnRadioWoman:
gender = Converters.Gender.FEMALE;
break;
}
final ScaleUser scaleUser = new ScaleUser();
scaleUser.setUserName(name);
scaleUser.setBirthday(birthday);
scaleUser.setBodyHeight(body_height);
scaleUser.setScaleUnit(scale_unit);
scaleUser.setGender(gender);
scaleUser.setConvertedInitialWeight(initial_weight);
scaleUser.setGoalWeight(goal_weight);
scaleUser.setGoalDate(goal_date);
if (getIntent().getExtras().getInt(EXTRA_MODE) == EDIT_USER_REQUEST) {
int id = getIntent().getExtras().getInt(EXTRA_ID);
scaleUser.setId(id);
openScale.updateScaleUser(scaleUser);
} else {
int id = openScale.addScaleUser(scaleUser);
scaleUser.setId(id);
}
openScale.selectScaleUser(scaleUser.getId());
openScale.updateScaleData();
return true;
}
} catch (NumberFormatException ex) {
Toast.makeText(context, getResources().getString(R.string.error_value_range) + "(" + ex.getMessage() + ")", Toast.LENGTH_SHORT).show();
}
return false;
}
use of com.health.openscale.core.datatypes.ScaleUser in project openScale by oliexdev.
the class UserSettingsActivity method editMode.
private void editMode() {
int id = getIntent().getExtras().getInt(EXTRA_ID);
OpenScale openScale = OpenScale.getInstance(getApplicationContext());
ScaleUser scaleUser = openScale.getScaleUser(id);
getSupportActionBar().setTitle(scaleUser.getUserName());
birthday = scaleUser.getBirthday();
goal_date = scaleUser.getGoalDate();
txtUserName.setText(scaleUser.getUserName());
txtBodyHeight.setText(Integer.toString(scaleUser.getBodyHeight()));
txtBirthday.setText(dateFormat.format(birthday));
txtGoalDate.setText(dateFormat.format(goal_date));
txtInitialWeight.setText(Math.round(scaleUser.getConvertedInitialWeight() * 100.0f) / 100.0f + "");
txtGoalWeight.setText(scaleUser.getGoalWeight() + "");
switch(scaleUser.getScaleUnit()) {
case KG:
radioScaleUnit.check(R.id.btnRadioKG);
break;
case LB:
radioScaleUnit.check(R.id.btnRadioLB);
break;
case ST:
radioScaleUnit.check(R.id.btnRadioST);
break;
}
switch(scaleUser.getGender()) {
case MALE:
radioGender.check(R.id.btnRadioMale);
break;
case FEMALE:
radioGender.check(R.id.btnRadioWoman);
break;
}
}
use of com.health.openscale.core.datatypes.ScaleUser in project openScale by oliexdev.
the class UserAddTest method verifyUserAdd.
@After
public void verifyUserAdd() {
ScaleUser user = OpenScale.getInstance(context).getSelectedScaleUser();
assertEquals("test", user.getUserName());
assertEquals(180, user.getBodyHeight());
assertEquals(80, user.getInitialWeight(), DELTA);
assertEquals(60, user.getGoalWeight(), DELTA);
Calendar birthday = Calendar.getInstance();
birthday.setTimeInMillis(0);
birthday.set(Calendar.YEAR, 1990);
birthday.set(Calendar.MONTH, Calendar.JANUARY);
birthday.set(Calendar.DAY_OF_MONTH, 19);
birthday.set(Calendar.HOUR_OF_DAY, 0);
assertEquals(birthday.getTime().getTime(), user.getBirthday().getTime());
Calendar goalDate = Calendar.getInstance();
goalDate.setTimeInMillis(0);
goalDate.set(Calendar.YEAR, 2018);
goalDate.set(Calendar.MONTH, Calendar.JANUARY);
goalDate.set(Calendar.DAY_OF_MONTH, 31);
goalDate.set(Calendar.HOUR_OF_DAY, 0);
assertEquals(goalDate.getTime().getTime(), user.getGoalDate().getTime());
}
use of com.health.openscale.core.datatypes.ScaleUser in project openScale by oliexdev.
the class OpenScale method migrateSQLtoRoom.
private void migrateSQLtoRoom() {
if (!context.getDatabasePath(ScaleUserDatabase.DATABASE_NAME).exists() || !context.getDatabasePath(ScaleDatabase.DATABASE_NAME).exists()) {
return;
}
ScaleDatabase scaleDB = new ScaleDatabase(context);
ScaleUserDatabase scaleUserDB = new ScaleUserDatabase(context);
List<ScaleUser> oldScaleUserList = scaleUserDB.getScaleUserList();
if (scaleDB.getReadableDatabase().getVersion() == 6 && userDAO.getAll().isEmpty() && !oldScaleUserList.isEmpty()) {
Toast.makeText(context, "Migrating old SQL database to new database format...", Toast.LENGTH_LONG).show();
userDAO.insertAll(oldScaleUserList);
for (ScaleUser user : oldScaleUserList) {
List<ScaleMeasurement> oldScaleMeasurementList = scaleDB.getScaleDataList(user.getId());
measurementDAO.insertAll(oldScaleMeasurementList);
}
Toast.makeText(context, "Finished migrating old SQL database to new database format", Toast.LENGTH_LONG).show();
}
scaleUserDB.close();
scaleDB.close();
}
Aggregations