Skip to content

fix: empty input username #2112

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

Merged
merged 1 commit into from
Jul 13, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import kotlinx.android.synthetic.main.fragment_edit_profile.view.lastName
import kotlinx.android.synthetic.main.fragment_edit_profile.view.profilePhoto
import kotlinx.android.synthetic.main.fragment_edit_profile.view.progressBar
import kotlinx.android.synthetic.main.fragment_edit_profile.view.profilePhotoFab
import kotlinx.android.synthetic.main.fragment_edit_profile.view.firstNameLayout
import kotlinx.android.synthetic.main.fragment_edit_profile.view.lastNameLayout
import org.fossasia.openevent.general.CircleTransform
import org.fossasia.openevent.general.MainActivity
import org.fossasia.openevent.general.R
Expand All @@ -52,6 +54,7 @@ import java.io.FileOutputStream
import java.io.IOException
import java.io.FileNotFoundException
import org.fossasia.openevent.general.utils.Utils.setToolbar
import org.fossasia.openevent.general.utils.setRequired
import org.jetbrains.anko.design.snackbar

class EditProfileFragment : Fragment(), ComplexBackPressFragment {
Expand Down Expand Up @@ -122,8 +125,12 @@ class EditProfileFragment : Fragment(), ComplexBackPressFragment {

rootView.updateButton.setOnClickListener {
hideSoftKeyboard(context, rootView)
editProfileViewModel.updateProfile(rootView.firstName.text.toString(),
rootView.lastName.text.toString(), rootView.details.text.toString())
if (isValidUsername()) {
editProfileViewModel.updateProfile(rootView.firstName.text.toString(),
rootView.lastName.text.toString(), rootView.details.text.toString())
} else {
rootView.snackbar(getString(R.string.fill_required_fields_message))
}
}

editProfileViewModel.message
Expand All @@ -140,6 +147,9 @@ class EditProfileFragment : Fragment(), ComplexBackPressFragment {
showEditPhotoDialog()
}

rootView.firstNameLayout.setRequired()
rootView.lastNameLayout.setRequired()

return rootView
}

Expand All @@ -166,6 +176,19 @@ class EditProfileFragment : Fragment(), ComplexBackPressFragment {
}
}

private fun isValidUsername(): Boolean {
var valid = true
if (rootView.firstName.text.isNullOrBlank()) {
rootView.firstName.error = getString(R.string.empty_field_error_message)
valid = false
}
if (rootView.lastName.text.isNullOrBlank()) {
rootView.lastName.error = getString(R.string.empty_field_error_message)
valid = false
}
return valid
}

private fun loadUserUI(user: User) {
userFirstName = user.firstName.nullToEmpty()
userLastName = user.lastName.nullToEmpty()
Expand Down
12 changes: 7 additions & 5 deletions app/src/main/res/layout/fragment_edit_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,31 +53,33 @@
android:weightSum="2">

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/firstNameLayout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_width="@dimen/layout_margin_none"
android:layout_height="wrap_content"
android:layout_weight="1">
android:layout_weight="1"
android:hint="@string/first_name">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/firstName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/first_name"
android:inputType="textPersonName|textCapWords" />
</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.textfield.TextInputLayout
android:id="@+id/lastNameLayout"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_width="@dimen/layout_margin_none"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/layout_margin_small"
android:layout_weight="1">
android:layout_marginStart="@dimen/layout_margin_small"
android:layout_weight="1"
android:hint="@string/last_name">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/lastName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/last_name"
android:inputType="textPersonName|textCapWords" />
</com.google.android.material.textfield.TextInputLayout>

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/navigation/navigation_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@
<argument
android:name="croppedImage"
app:argType="string"
android:defaultValue="''"/>
android:defaultValue=""/>
</fragment>
<fragment
android:id="@+id/cropImageFragment"
Expand Down