@@ -35,6 +35,8 @@ import kotlinx.android.synthetic.main.fragment_edit_profile.view.lastName
35
35
import kotlinx.android.synthetic.main.fragment_edit_profile.view.profilePhoto
36
36
import kotlinx.android.synthetic.main.fragment_edit_profile.view.progressBar
37
37
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
38
40
import org.fossasia.openevent.general.CircleTransform
39
41
import org.fossasia.openevent.general.MainActivity
40
42
import org.fossasia.openevent.general.R
@@ -52,6 +54,7 @@ import java.io.FileOutputStream
52
54
import java.io.IOException
53
55
import java.io.FileNotFoundException
54
56
import org.fossasia.openevent.general.utils.Utils.setToolbar
57
+ import org.fossasia.openevent.general.utils.setRequired
55
58
import org.jetbrains.anko.design.snackbar
56
59
57
60
class EditProfileFragment : Fragment (), ComplexBackPressFragment {
@@ -122,8 +125,12 @@ class EditProfileFragment : Fragment(), ComplexBackPressFragment {
122
125
123
126
rootView.updateButton.setOnClickListener {
124
127
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
+ }
127
134
}
128
135
129
136
editProfileViewModel.message
@@ -140,6 +147,9 @@ class EditProfileFragment : Fragment(), ComplexBackPressFragment {
140
147
showEditPhotoDialog()
141
148
}
142
149
150
+ rootView.firstNameLayout.setRequired()
151
+ rootView.lastNameLayout.setRequired()
152
+
143
153
return rootView
144
154
}
145
155
@@ -166,6 +176,19 @@ class EditProfileFragment : Fragment(), ComplexBackPressFragment {
166
176
}
167
177
}
168
178
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
+
169
192
private fun loadUserUI (user : User ) {
170
193
userFirstName = user.firstName.nullToEmpty()
171
194
userLastName = user.lastName.nullToEmpty()
0 commit comments