Search in sources :

Example 66 with ScaleUser

use of com.health.openscale.core.datatypes.ScaleUser in project openScale by oliexdev.

the class UserMeasurementView method getInputView.

@Override
protected View getInputView() {
    Spinner spinScaleUer = new Spinner(getContext());
    ArrayAdapter<String> spinScaleUserAdapter = new ArrayAdapter<>(getContext(), R.layout.support_simple_spinner_dropdown_item, new ArrayList<>());
    spinScaleUer.setAdapter(spinScaleUserAdapter);
    int spinPos = 0;
    for (ScaleUser scaleUser : openScale.getScaleUserList()) {
        spinScaleUserAdapter.add(scaleUser.getUserName());
        if (scaleUser.getId() == userId) {
            spinPos = spinScaleUserAdapter.getCount() - 1;
        }
    }
    spinScaleUer.setSelection(spinPos);
    return spinScaleUer;
}
Also used : Spinner(android.widget.Spinner) ScaleUser(com.health.openscale.core.datatypes.ScaleUser) ArrayAdapter(android.widget.ArrayAdapter)

Example 67 with ScaleUser

use of com.health.openscale.core.datatypes.ScaleUser in project openScale by oliexdev.

the class UserSettingsFragment method saveUserData.

private boolean saveUserData() {
    try {
        if (validateInput()) {
            OpenScale openScale = OpenScale.getInstance();
            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;
            switch(radioMeasurementUnit.getCheckedRadioButtonId()) {
                case R.id.btnRadioCM:
                    measure_unit = Converters.MeasureUnit.CM;
                    break;
                case R.id.btnRadioINCH:
                    measure_unit = Converters.MeasureUnit.INCH;
                    break;
            }
            Converters.WeightUnit scale_unit = Converters.WeightUnit.KG;
            switch(radioScaleUnit.getCheckedRadioButtonId()) {
                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(radioGender.getCheckedRadioButtonId()) {
                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(Converters.toCentimeter(body_height, measure_unit));
            scaleUser.setScaleUnit(scale_unit);
            scaleUser.setMeasureUnit(measure_unit);
            scaleUser.setActivityLevel(Converters.fromActivityLevelInt(spinnerActivityLevel.getSelectedItemPosition()));
            scaleUser.setLeftAmputationLevel(Converters.fromAmputationLevelInt(spinnerLeftAmputationLevel.getSelectedItemPosition()));
            scaleUser.setRightAmputationLevel(Converters.fromAmputationLevelInt(spinnerRightAmputationLevel.getSelectedItemPosition()));
            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);
            switch(mode) {
                case ADD:
                    int id = openScale.addScaleUser(scaleUser);
                    scaleUser.setId(id);
                    break;
                case EDIT:
                    scaleUser.setId(UserSettingsFragmentArgs.fromBundle(getArguments()).getUserId());
                    openScale.updateScaleUser(scaleUser);
                    break;
            }
            openScale.selectScaleUser(scaleUser.getId());
            return true;
        }
    } catch (NumberFormatException ex) {
        Toast.makeText(context, getResources().getString(R.string.error_value_range) + "(" + ex.getMessage() + ")", Toast.LENGTH_SHORT).show();
    }
    return false;
}
Also used : ScaleUser(com.health.openscale.core.datatypes.ScaleUser) Converters(com.health.openscale.core.utils.Converters) OpenScale(com.health.openscale.core.OpenScale)

Example 68 with ScaleUser

use of com.health.openscale.core.datatypes.ScaleUser in project openScale by oliexdev.

the class UserSettingsFragment method editMode.

private void editMode() {
    int id = UserSettingsFragmentArgs.fromBundle(getArguments()).getUserId();
    OpenScale openScale = OpenScale.getInstance();
    ScaleUser scaleUser = openScale.getScaleUser(id);
    birthday = scaleUser.getBirthday();
    goal_date = scaleUser.getGoalDate();
    txtUserName.setText(scaleUser.getUserName());
    txtBodyHeight.setText(Float.toString(Math.round(Converters.fromCentimeter(scaleUser.getBodyHeight(), scaleUser.getMeasureUnit()) * 100.0f) / 100.0f));
    txtBodyHeight.setHint(getResources().getString(R.string.info_enter_value_in) + " " + scaleUser.getMeasureUnit().toString());
    txtBirthday.setText(dateFormat.format(birthday));
    txtGoalDate.setText(dateFormat.format(goal_date));
    txtInitialWeight.setText(Float.toString(Math.round(Converters.fromKilogram(scaleUser.getInitialWeight(), scaleUser.getScaleUnit()) * 100.0f) / 100.0f));
    txtGoalWeight.setText(Float.toString(Math.round(Converters.fromKilogram(scaleUser.getGoalWeight(), scaleUser.getScaleUnit()) * 100.0f) / 100.0f));
    txtInitialWeight.setHint(getResources().getString(R.string.info_enter_value_in) + " " + scaleUser.getScaleUnit().toString());
    txtGoalWeight.setHint(getResources().getString(R.string.info_enter_value_in) + " " + scaleUser.getScaleUnit().toString());
    switch(scaleUser.getMeasureUnit()) {
        case CM:
            radioMeasurementUnit.check(R.id.btnRadioCM);
            break;
        case INCH:
            radioMeasurementUnit.check(R.id.btnRadioINCH);
            break;
    }
    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;
    }
    assistedWeighing.setChecked(scaleUser.isAssistedWeighing());
    spinnerActivityLevel.setSelection(scaleUser.getActivityLevel().toInt());
    spinnerLeftAmputationLevel.setSelection(scaleUser.getLeftAmputationLevel().toInt());
    spinnerRightAmputationLevel.setSelection(scaleUser.getRightAmputationLevel().toInt());
}
Also used : ScaleUser(com.health.openscale.core.datatypes.ScaleUser) OpenScale(com.health.openscale.core.OpenScale)

Example 69 with ScaleUser

use of com.health.openscale.core.datatypes.ScaleUser in project openScale by oliexdev.

the class UserIntroSlide method updateTableUsers.

private void updateTableUsers() {
    tblUsers.removeAllViews();
    tblUsers.setStretchAllColumns(true);
    List<ScaleUser> scaleUserList = OpenScale.getInstance().getScaleUserList();
    TableRow header = new TableRow(getContext());
    TextView headerUsername = new TextView(getContext());
    headerUsername.setText(R.string.label_user_name);
    headerUsername.setGravity(Gravity.CENTER_HORIZONTAL);
    headerUsername.setTypeface(null, Typeface.BOLD);
    header.addView(headerUsername);
    TextView headAge = new TextView(getContext());
    headAge.setText(R.string.label_age);
    headAge.setGravity(Gravity.CENTER_HORIZONTAL);
    headAge.setTypeface(null, Typeface.BOLD);
    header.addView(headAge);
    TextView headerGender = new TextView(getContext());
    headerGender.setText(R.string.label_gender);
    headerGender.setGravity(Gravity.CENTER_HORIZONTAL);
    headerGender.setTypeface(null, Typeface.BOLD);
    header.addView(headerGender);
    tblUsers.addView(header);
    if (!scaleUserList.isEmpty()) {
        TableRow row = new TableRow(getContext());
        for (ScaleUser scaleUser : scaleUserList) {
            row = new TableRow(getContext());
            TextView txtUsername = new TextView(getContext());
            txtUsername.setText(scaleUser.getUserName());
            txtUsername.setGravity(Gravity.CENTER_HORIZONTAL);
            row.addView(txtUsername);
            TextView txtAge = new TextView(getContext());
            txtAge.setText(Integer.toString(scaleUser.getAge()));
            txtAge.setGravity(Gravity.CENTER_HORIZONTAL);
            row.addView(txtAge);
            TextView txtGender = new TextView(getContext());
            txtGender.setText((scaleUser.getGender().isMale()) ? getString(R.string.label_male) : getString(R.string.label_female));
            txtGender.setGravity(Gravity.CENTER_HORIZONTAL);
            row.addView(txtGender);
            row.setGravity(Gravity.CENTER_HORIZONTAL);
            tblUsers.addView(row);
        }
    } else {
        TableRow row = new TableRow(getContext());
        TextView txtEmpty = new TextView(getContext());
        txtEmpty.setText("[" + getContext().getString(R.string.label_empty) + "]");
        txtEmpty.setGravity(Gravity.CENTER_HORIZONTAL);
        row.addView(txtEmpty);
        row.setGravity(Gravity.CENTER_HORIZONTAL);
        tblUsers.addView(row);
    }
}
Also used : ScaleUser(com.health.openscale.core.datatypes.ScaleUser) TableRow(android.widget.TableRow) TextView(android.widget.TextView)

Aggregations

ScaleUser (com.health.openscale.core.datatypes.ScaleUser)69 ScaleMeasurement (com.health.openscale.core.datatypes.ScaleMeasurement)23 Date (java.util.Date)21 Calendar (java.util.Calendar)9 OpenScale (com.health.openscale.core.OpenScale)8 ParseException (java.text.ParseException)6 Converters (com.health.openscale.core.utils.Converters)5 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)4 Intent (android.content.Intent)3 SharedPreferences (android.content.SharedPreferences)3 SimpleDateFormat (java.text.SimpleDateFormat)3 AlertDialog (android.app.AlertDialog)2 Context (android.content.Context)2 DialogInterface (android.content.DialogInterface)2 Uri (android.net.Uri)2 ArrayAdapter (android.widget.ArrayAdapter)2 Spinner (android.widget.Spinner)2 TableRow (android.widget.TableRow)2 TextView (android.widget.TextView)2