Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replacing the way error is shown from editText to editTextLayout #876

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions org.envirocar.app/res/layout/activity_signin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@
android:id="@+id/activity_signin_username_input_layout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_height="wrap_content"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the layout_height is changed to wrap_content because the layout needs to be big enough, to show the error.
more information: https://stackoverflow.com/a/44831214
see the below comments on this answer :)

android:layout_marginTop="40dp"
app:hintEnabled="false"
app:layout_constraintEnd_toEndOf="@id/activity_signin_guideline_right"
app:layout_constraintStart_toStartOf="@id/activity_signin_guideline_left"
app:layout_constraintTop_toBottomOf="@+id/textView6"
app:layout_constraintWidth_max="500dp">
app:layout_constraintWidth_max="500dp"
app:endIconMode="custom">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this to them which doesn't have any end icon so after making their height wrap_content, they all still have a similar height. As the height changes to wrap_content after an error is shown, via this they all have same height even before error shows.


<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/activity_signin_username_input"
Expand All @@ -91,14 +92,15 @@
android:id="@+id/activity_signin_password_input_layout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
app:hintEnabled="false"
app:layout_constraintEnd_toEndOf="@id/activity_signin_guideline_right"
app:layout_constraintStart_toStartOf="@id/activity_signin_guideline_left"
app:layout_constraintTop_toBottomOf="@+id/activity_signin_username_input_layout"
app:layout_constraintWidth_max="500dp"
app:endIconMode="password_toggle"
app:errorIconDrawable="@null"
app:endIconDrawable="@drawable/custom_password_eye"
app:endIconTint="@color/white_cario">

Expand Down
67 changes: 43 additions & 24 deletions org.envirocar.app/res/layout/activity_signup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,14 @@
android:id="@+id/activity_signup_username_input_layout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
app:hintEnabled="false"
app:layout_constraintEnd_toEndOf="@id/activity_signup_guideline_right"
app:layout_constraintStart_toStartOf="@id/activity_signup_guideline_left"
app:layout_constraintTop_toBottomOf="@+id/textView6"
app:layout_constraintWidth_max="500dp">
app:layout_constraintWidth_max="500dp"
app:endIconMode="custom">

<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/activity_signup_username_input"
Expand All @@ -78,7 +79,7 @@
android:layout_height="match_parent"
android:layout_below="@+id/activity_login_logo"
android:layout_centerHorizontal="true"
android:drawableLeft="@drawable/ic_action_user"
android:drawableStart="@drawable/ic_action_user"
android:hint="@string/username"
android:inputType="textPersonName" />

Expand All @@ -88,20 +89,21 @@
android:id="@+id/activity_signup_email_input_layout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
app:hintEnabled="false"
app:layout_constraintEnd_toEndOf="@id/activity_signup_guideline_right"
app:layout_constraintStart_toStartOf="@id/activity_signup_guideline_left"
app:layout_constraintTop_toBottomOf="@+id/activity_signup_username_input_layout"
app:layout_constraintWidth_max="500dp">
app:layout_constraintWidth_max="500dp"
app:endIconMode="custom">

<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/activity_signup_email_input"
style="@style/envirocar.login.edittext"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:drawableLeft="@drawable/ic_action_mail"
android:drawableStart="@drawable/ic_action_mail"
android:hint="@string/email"
android:inputType="textPersonName" />

Expand All @@ -111,7 +113,7 @@
android:id="@+id/activity_signup_password_1_layout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
app:hintEnabled="false"
app:layout_constraintEnd_toEndOf="@id/activity_signup_guideline_right"
Expand All @@ -120,7 +122,8 @@
app:layout_constraintWidth_max="500dp"
app:endIconMode="password_toggle"
app:endIconDrawable="@drawable/custom_password_eye"
app:endIconTint="@color/white_cario">
app:endIconTint="@color/white_cario"
app:errorIconDrawable="@null">


<androidx.appcompat.widget.AppCompatEditText
Expand All @@ -137,7 +140,7 @@
android:id="@+id/activity_signup_password_2_layout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
app:hintEnabled="false"
app:layout_constraintEnd_toEndOf="@id/activity_signup_guideline_right"
Expand Down Expand Up @@ -166,18 +169,26 @@
android:buttonTint="@color/white_cario"
app:layout_constraintStart_toStartOf="@id/activity_signup_guideline_left"
app:layout_constraintTop_toBottomOf="@+id/activity_signup_password_2_layout" />

<TextView
android:id="@+id/activity_signup_tou_text"
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/activity_signup_tou_text_layout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/signup_acknowledge_tou_text"
android:textColor="@color/white_cario"
android:textColorLink="@color/blue_light_cario"
app:layout_constraintBottom_toTopOf="@id/activity_signup_tou_checkbox"
app:layout_constraintEnd_toEndOf="@id/activity_signup_guideline_right"
app:layout_constraintStart_toEndOf="@id/activity_signup_tou_checkbox"
app:layout_constraintTop_toBottomOf="@+id/activity_signup_tou_checkbox" />
app:layout_constraintTop_toBottomOf="@+id/activity_signup_tou_checkbox"
app:layout_constraintWidth_max="500dp" >
<TextView
android:id="@+id/activity_signup_tou_text"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/signup_acknowledge_tou_text"
android:textColor="@color/white_cario"
android:textColorLink="@color/blue_light_cario" />

</com.google.android.material.textfield.TextInputLayout>

<CheckBox
android:id="@+id/activity_signup_ps_checkbox"
Expand All @@ -186,19 +197,27 @@
android:layout_marginTop="20dp"
android:buttonTint="@color/white_cario"
app:layout_constraintStart_toStartOf="@id/activity_signup_guideline_left"
app:layout_constraintTop_toBottomOf="@+id/activity_signup_tou_text" />
app:layout_constraintTop_toBottomOf="@+id/activity_signup_tou_text_layout" />

<TextView
android:id="@+id/activity_signup_ps_text"
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/activity_signup_ps_text_layout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/signup_acknowledge_ps_text"
android:textColor="@color/white_cario"
android:textColorLink="@color/blue_light_cario"
app:layout_constraintBottom_toTopOf="@+id/activity_signup_ps_checkbox"
app:layout_constraintEnd_toEndOf="@id/activity_signup_guideline_right"
app:layout_constraintStart_toEndOf="@id/activity_signup_ps_checkbox"
app:layout_constraintTop_toBottomOf="@+id/activity_signup_ps_checkbox" />
app:layout_constraintTop_toBottomOf="@+id/activity_signup_ps_checkbox"
app:layout_constraintWidth_max="500dp">
<TextView
android:id="@+id/activity_signup_ps_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/signup_acknowledge_ps_text"
android:textColor="@color/white_cario"
android:textColorLink="@color/blue_light_cario" />

</com.google.android.material.textfield.TextInputLayout>

<androidx.cardview.widget.CardView
android:id="@+id/activity_signup_register_button"
Expand All @@ -212,7 +231,7 @@
app:cardElevation="10dp"
app:layout_constraintEnd_toEndOf="@id/activity_signup_guideline_right"
app:layout_constraintStart_toStartOf="@id/activity_signup_guideline_left"
app:layout_constraintTop_toBottomOf="@+id/activity_signup_ps_text">
app:layout_constraintTop_toBottomOf="@+id/activity_signup_ps_text_layout">

<TextView
android:layout_width="wrap_content"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.google.android.material.textfield.TextInputLayout;
import com.jakewharton.rxbinding3.widget.RxTextView;

import org.envirocar.app.BaseApplicationComponent;
Expand Down Expand Up @@ -70,10 +71,16 @@ public class CarSelectionAttributesFragment extends BaseInjectorFragment {

@BindView(R.id.fragment_attributes_manufacturer_input)
protected AutoCompleteTextView manufactureEditText;
@BindView(R.id.fragment_attributes_manufacturer_input_layout)
protected TextInputLayout manufactureEditTextLayout;
@BindView(R.id.fragment_attributes_model_input)
protected AutoCompleteTextView modelEditText;
@BindView(R.id.fragment_attributes_model_input_layout)
protected TextInputLayout modelEditTextLayout;
@BindView(R.id.fragment_attributes_year_input)
protected AutoCompleteTextView yearEditText;
@BindView(R.id.fragment_attributes_year_input_layout)
protected TextInputLayout yearEditTextLayout;

@Inject
EnviroCarVehicleDB enviroCarVehicleDB;
Expand All @@ -85,7 +92,6 @@ public class CarSelectionAttributesFragment extends BaseInjectorFragment {
private CompositeDisposable disposable = new CompositeDisposable();
private static final int ERROR_DEBOUNCE_TIME = 750;
private List<Manufacturers> manufacturersList;
private static Drawable error;

CarSelectionAttributesFragment(List<Manufacturers> manufacturersList) {
this.manufacturersList = manufacturersList;
Expand All @@ -101,8 +107,6 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
fetchManufactureres();
initFocusChangedListener();
reactiveTexFieldCheck();
error = getResources().getDrawable(R.drawable.ic_error_red_24dp);
error.setBounds(-50, 0, 0, error.getIntrinsicHeight());
manufactureEditText.setOnItemClickListener((parent, view1, position, id) -> requestNextTextFieldFocus(manufactureEditText));
modelEditText.setOnItemClickListener((parent, view12, position, id) -> requestNextTextFieldFocus(modelEditText));
yearEditText.setOnItemClickListener((parent, view13, position, id) -> requestNextTextFieldFocus(yearEditText));
Expand All @@ -122,20 +126,20 @@ protected void injectDependencies(BaseApplicationComponent baseApplicationCompon

@OnTextChanged(value = R.id.fragment_attributes_manufacturer_input, callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
protected void onManufacturerChanged() {
manufactureEditText.setError(null);
manufactureEditTextLayout.setError(null);
modelEditText.setText("");
yearEditText.setText("");
}

@OnTextChanged(value = R.id.fragment_attributes_model_input, callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
protected void onModelChanged() {
modelEditText.setError(null);
modelEditTextLayout.setError(null);
yearEditText.setText("");
}

@OnTextChanged(value = R.id.fragment_attributes_year_input, callback = OnTextChanged.Callback.AFTER_TEXT_CHANGED)
protected void onYearChanged() {
yearEditText.setError(null);
yearEditTextLayout.setError(null);
}

@OnClick(R.id.fragment_car_search_button)
Expand All @@ -145,17 +149,17 @@ void searchButtonClick() {
String year = yearEditText.getText().toString().trim();
View focusView = null;
if (manufacturer.isEmpty()) {
manufactureEditText.setError(getString(R.string.car_selection_error_empty_input), error);
manufactureEditTextLayout.setError(getString(R.string.car_selection_error_empty_input));
focusView = manufactureEditText;
}

if (model.isEmpty()) {
modelEditText.setError(getString(R.string.car_selection_error_select_from_list), error);
modelEditTextLayout.setError(getString(R.string.car_selection_error_select_from_list));
focusView = modelEditText;
}

if (year.isEmpty()) {
yearEditText.setError(getString(R.string.car_selection_error_select_from_list), error);
yearEditTextLayout.setError(getString(R.string.car_selection_error_select_from_list));
focusView = yearEditText;
}

Expand Down Expand Up @@ -299,10 +303,10 @@ private void reactiveTexFieldCheck() {
}
}
if (flag == 0) {
manufactureEditText.setError(getString(R.string.car_selection_error_select_from_list), error);
manufactureEditTextLayout.setError(getString(R.string.car_selection_error_select_from_list));
manufactureEditText.requestFocus();
} else {
manufactureEditText.setError(null);
manufactureEditTextLayout.setError(null);
}
}));

Expand All @@ -323,10 +327,10 @@ private void reactiveTexFieldCheck() {
}

if (flag == 0) {
modelEditText.setError(getString(R.string.car_selection_error_select_from_list), error);
modelEditTextLayout.setError(getString(R.string.car_selection_error_select_from_list));
modelEditText.requestFocus();
} else {
modelEditText.setError(null);
modelEditTextLayout.setError(null);
}
} catch (Exception e) {
}
Expand All @@ -349,10 +353,10 @@ private void reactiveTexFieldCheck() {
}

if (flag == 0) {
yearEditText.setError(getString(R.string.car_selection_error_select_from_list), error);
yearEditTextLayout.setError(getString(R.string.car_selection_error_select_from_list));
yearEditText.requestFocus();
} else {
yearEditText.setError(null);
yearEditTextLayout.setError(null);
}
} catch (Exception e) {
}
Expand Down
Loading