1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-23 00:33:09 +02:00

validate only if the data is enabled

This commit is contained in:
OliE
2016-12-21 12:45:39 +01:00
parent e2500b9a07
commit 68bbbb4098

View File

@@ -215,66 +215,67 @@ public class DataEntryActivity extends Activity {
private boolean validateInput() private boolean validateInput()
{ {
boolean validate = true; boolean validate = true;
if( txtWeight.getText().toString().length() == 0 )
{
txtWeight.setError(getResources().getString(R.string.error_weight_value_required));
validate = false;
} else if(!isInRange(txtWeight.getText().toString(), 300))
{
txtWeight.setError(getResources().getString(R.string.error_value_range_0_300));
validate = false;
}
if( txtFat.getText().toString().length() == 0 )
{
txtFat.setError(getResources().getString(R.string.error_fat_value_required));
validate = false;
} else if(!isInRange(txtFat.getText().toString(), 100))
{
txtFat.setError(getResources().getString(R.string.error_value_range_0_100));
validate = false;
}
if( txtWater.getText().toString().length() == 0 )
{
txtWater.setError(getResources().getString(R.string.error_water_value_required));
validate = false;
} else if(!isInRange(txtWater.getText().toString(), 100))
{
txtWater.setError(getResources().getString(R.string.error_value_range_0_100));
validate = false;
}
if( txtMuscle.getText().toString().length() == 0 )
{
txtMuscle.setError(getResources().getString(R.string.error_muscle_value_required));
validate = false;
} else if(!isInRange(txtMuscle.getText().toString(), 100))
{
txtMuscle.setError(getResources().getString(R.string.error_value_range_0_100));
validate = false;
}
if( txtWaist.getText().toString().length() == 0 ) SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
{
txtWaist.setError(getResources().getString(R.string.error_waist_value_required)); if (prefs.getBoolean("weightEnable", true)) {
validate = false; if (txtWeight.getText().toString().length() == 0) {
} else if(!isInRange(txtWaist.getText().toString(), 300)) txtWeight.setError(getResources().getString(R.string.error_weight_value_required));
{ validate = false;
txtWaist.setError(getResources().getString(R.string.error_value_range_0_300)); } else if (!isInRange(txtWeight.getText().toString(), 300)) {
validate = false; txtWeight.setError(getResources().getString(R.string.error_value_range_0_300));
validate = false;
}
} }
if( txtHip.getText().toString().length() == 0 ) if (prefs.getBoolean("fatEnable", true)) {
{ if (txtFat.getText().toString().length() == 0) {
txtHip.setError(getResources().getString(R.string.error_hip_value_required)); txtFat.setError(getResources().getString(R.string.error_fat_value_required));
validate = false; validate = false;
} else if(!isInRange(txtHip.getText().toString(), 300)) } else if (!isInRange(txtFat.getText().toString(), 100)) {
{ txtFat.setError(getResources().getString(R.string.error_value_range_0_100));
txtHip.setError(getResources().getString(R.string.error_value_range_0_300)); validate = false;
validate = false; }
}
if (prefs.getBoolean("waterEnable", true)) {
if (txtWater.getText().toString().length() == 0) {
txtWater.setError(getResources().getString(R.string.error_water_value_required));
validate = false;
} else if (!isInRange(txtWater.getText().toString(), 100)) {
txtWater.setError(getResources().getString(R.string.error_value_range_0_100));
validate = false;
}
}
if (prefs.getBoolean("muscleEnable", true)) {
if (txtMuscle.getText().toString().length() == 0) {
txtMuscle.setError(getResources().getString(R.string.error_muscle_value_required));
validate = false;
} else if (!isInRange(txtMuscle.getText().toString(), 100)) {
txtMuscle.setError(getResources().getString(R.string.error_value_range_0_100));
validate = false;
}
}
if (prefs.getBoolean("waistEnable", true)) {
if (txtWaist.getText().toString().length() == 0) {
txtWaist.setError(getResources().getString(R.string.error_waist_value_required));
validate = false;
} else if (!isInRange(txtWaist.getText().toString(), 300)) {
txtWaist.setError(getResources().getString(R.string.error_value_range_0_300));
validate = false;
}
}
if (prefs.getBoolean("hipEnable", true)) {
if (txtHip.getText().toString().length() == 0) {
txtHip.setError(getResources().getString(R.string.error_hip_value_required));
validate = false;
} else if (!isInRange(txtHip.getText().toString(), 300)) {
txtHip.setError(getResources().getString(R.string.error_value_range_0_300));
validate = false;
}
} }
return validate; return validate;