Skip to content

Commit 9428b5e

Browse files
anhanh11001nikit19
authored andcommitted
Summary: Fix empty input username (#2112)
Details: - Fix app crash on going to EditProfileFragment - Add error and check on username emptyness Fixes: #2107
1 parent d9896b6 commit 9428b5e

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

app/src/main/java/org/fossasia/openevent/general/auth/EditProfileFragment.kt

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ import kotlinx.android.synthetic.main.fragment_edit_profile.view.lastName
3535
import kotlinx.android.synthetic.main.fragment_edit_profile.view.profilePhoto
3636
import kotlinx.android.synthetic.main.fragment_edit_profile.view.progressBar
3737
import kotlinx.android.synthetic.main.fragment_edit_profile.view.profilePhotoFab
38+
import kotlinx.android.synthetic.main.fragment_edit_profile.view.firstNameLayout
39+
import kotlinx.android.synthetic.main.fragment_edit_profile.view.lastNameLayout
3840
import org.fossasia.openevent.general.CircleTransform
3941
import org.fossasia.openevent.general.MainActivity
4042
import org.fossasia.openevent.general.R
@@ -52,6 +54,7 @@ import java.io.FileOutputStream
5254
import java.io.IOException
5355
import java.io.FileNotFoundException
5456
import org.fossasia.openevent.general.utils.Utils.setToolbar
57+
import org.fossasia.openevent.general.utils.setRequired
5558
import org.jetbrains.anko.design.snackbar
5659

5760
class EditProfileFragment : Fragment(), ComplexBackPressFragment {
@@ -122,8 +125,12 @@ class EditProfileFragment : Fragment(), ComplexBackPressFragment {
122125

123126
rootView.updateButton.setOnClickListener {
124127
hideSoftKeyboard(context, rootView)
125-
editProfileViewModel.updateProfile(rootView.firstName.text.toString(),
126-
rootView.lastName.text.toString(), rootView.details.text.toString())
128+
if (isValidUsername()) {
129+
editProfileViewModel.updateProfile(rootView.firstName.text.toString(),
130+
rootView.lastName.text.toString(), rootView.details.text.toString())
131+
} else {
132+
rootView.snackbar(getString(R.string.fill_required_fields_message))
133+
}
127134
}
128135

129136
editProfileViewModel.message
@@ -140,6 +147,9 @@ class EditProfileFragment : Fragment(), ComplexBackPressFragment {
140147
showEditPhotoDialog()
141148
}
142149

150+
rootView.firstNameLayout.setRequired()
151+
rootView.lastNameLayout.setRequired()
152+
143153
return rootView
144154
}
145155

@@ -166,6 +176,19 @@ class EditProfileFragment : Fragment(), ComplexBackPressFragment {
166176
}
167177
}
168178

179+
private fun isValidUsername(): Boolean {
180+
var valid = true
181+
if (rootView.firstName.text.isNullOrBlank()) {
182+
rootView.firstName.error = getString(R.string.empty_field_error_message)
183+
valid = false
184+
}
185+
if (rootView.lastName.text.isNullOrBlank()) {
186+
rootView.lastName.error = getString(R.string.empty_field_error_message)
187+
valid = false
188+
}
189+
return valid
190+
}
191+
169192
private fun loadUserUI(user: User) {
170193
userFirstName = user.firstName.nullToEmpty()
171194
userLastName = user.lastName.nullToEmpty()

app/src/main/res/layout/fragment_edit_profile.xml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,31 +53,33 @@
5353
android:weightSum="2">
5454

5555
<com.google.android.material.textfield.TextInputLayout
56+
android:id="@+id/firstNameLayout"
5657
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
5758
android:layout_width="@dimen/layout_margin_none"
5859
android:layout_height="wrap_content"
59-
android:layout_weight="1">
60+
android:layout_weight="1"
61+
android:hint="@string/first_name">
6062

6163
<com.google.android.material.textfield.TextInputEditText
6264
android:id="@+id/firstName"
6365
android:layout_width="match_parent"
6466
android:layout_height="wrap_content"
65-
android:hint="@string/first_name"
6667
android:inputType="textPersonName|textCapWords" />
6768
</com.google.android.material.textfield.TextInputLayout>
6869

6970
<com.google.android.material.textfield.TextInputLayout
71+
android:id="@+id/lastNameLayout"
7072
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
7173
android:layout_width="@dimen/layout_margin_none"
7274
android:layout_height="wrap_content"
73-
android:layout_marginLeft="@dimen/layout_margin_small"
74-
android:layout_weight="1">
75+
android:layout_marginStart="@dimen/layout_margin_small"
76+
android:layout_weight="1"
77+
android:hint="@string/last_name">
7578

7679
<com.google.android.material.textfield.TextInputEditText
7780
android:id="@+id/lastName"
7881
android:layout_width="match_parent"
7982
android:layout_height="wrap_content"
80-
android:hint="@string/last_name"
8183
android:inputType="textPersonName|textCapWords" />
8284
</com.google.android.material.textfield.TextInputLayout>
8385

app/src/main/res/navigation/navigation_graph.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@
492492
<argument
493493
android:name="croppedImage"
494494
app:argType="string"
495-
android:defaultValue="''"/>
495+
android:defaultValue=""/>
496496
</fragment>
497497
<fragment
498498
android:id="@+id/cropImageFragment"

0 commit comments

Comments
 (0)