Skip to content

feat: Add user details under editing section #1930

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
Jun 8, 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 @@ -22,6 +22,7 @@ import com.squareup.picasso.Picasso
import kotlinx.android.synthetic.main.fragment_edit_profile.view.editProfileCoordinatorLayout
import kotlinx.android.synthetic.main.fragment_edit_profile.view.updateButton
import kotlinx.android.synthetic.main.fragment_edit_profile.view.firstName
import kotlinx.android.synthetic.main.fragment_edit_profile.view.details
import com.squareup.picasso.MemoryPolicy
import kotlinx.android.synthetic.main.fragment_edit_profile.view.lastName
import kotlinx.android.synthetic.main.fragment_edit_profile.view.profilePhoto
Expand Down Expand Up @@ -58,6 +59,7 @@ class EditProfileFragment : Fragment(), ComplexBackPressFragment {

private lateinit var userFirstName: String
private lateinit var userLastName: String
private lateinit var userDetails: String

override fun onCreateView(
inflater: LayoutInflater,
Expand All @@ -71,13 +73,17 @@ class EditProfileFragment : Fragment(), ComplexBackPressFragment {
.observe(viewLifecycleOwner, Observer {
userFirstName = it.firstName.nullToEmpty()
userLastName = it.lastName.nullToEmpty()
userDetails = it.details.nullToEmpty()
val imageUrl = it.avatarUrl.nullToEmpty()
if (rootView.firstName.text.isNullOrBlank()) {
rootView.firstName.setText(userFirstName)
}
if (rootView.lastName.text.isNullOrBlank()) {
rootView.lastName.setText(userLastName)
}
if (rootView.details.text.isNullOrBlank()) {
rootView.details.setText(userDetails)
}
if (imageUrl.isNotEmpty() && !editProfileViewModel.avatarUpdated) {
val drawable = requireDrawable(requireContext(), R.drawable.ic_account_circle_grey)
Picasso.get()
Expand Down Expand Up @@ -115,7 +121,7 @@ class EditProfileFragment : Fragment(), ComplexBackPressFragment {
rootView.updateButton.setOnClickListener {
hideSoftKeyboard(context, rootView)
editProfileViewModel.updateProfile(rootView.firstName.text.toString(),
rootView.lastName.text.toString())
rootView.lastName.text.toString(), rootView.details.text.toString())
}

editProfileViewModel.message
Expand Down Expand Up @@ -245,7 +251,7 @@ class EditProfileFragment : Fragment(), ComplexBackPressFragment {
override fun handleBackPress() {
val thisActivity = activity
if (!editProfileViewModel.avatarUpdated && rootView.lastName.text.toString() == userLastName &&
rootView.firstName.text.toString() == userFirstName) {
rootView.firstName.text.toString() == userFirstName && rootView.details.text.toString() == userDetails) {
if (thisActivity is MainActivity) thisActivity.onSuperBackPressed()
} else {
hideSoftKeyboard(context, rootView)
Expand All @@ -256,7 +262,7 @@ class EditProfileFragment : Fragment(), ComplexBackPressFragment {
}
dialog.setPositiveButton(getString(R.string.save)) { _, _ ->
editProfileViewModel.updateProfile(rootView.firstName.text.toString(),
rootView.lastName.text.toString())
rootView.lastName.text.toString(), rootView.details.text.toString())
}
dialog.create().show()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class EditProfileViewModel(
* @param firstName updated firstName
* @param lastName updated lastName
*/
fun updateProfile(firstName: String, lastName: String) {
fun updateProfile(firstName: String, lastName: String, details: String) {
if (encodedImage.isNullOrEmpty()) {
updateUser(null, firstName, lastName)
updateUser(null, firstName, lastName, details)
return
}
compositeDisposable += authService.uploadImage(UploadImage(encodedImage))
Expand All @@ -50,7 +50,7 @@ class EditProfileViewModel(
mutableProgress.value = false
}
.subscribe({
updateUser(it.url, firstName, lastName)
updateUser(it.url, firstName, lastName, details)
mutableMessage.value = resource.getString(R.string.image_upload_success_message)
Timber.d("Image uploaded ${it.url}")
}) {
Expand All @@ -59,7 +59,7 @@ class EditProfileViewModel(
}
}

private fun updateUser(url: String?, firstName: String, lastName: String) {
private fun updateUser(url: String?, firstName: String, lastName: String, details: String) {
val id = authHolder.getId()
if (firstName.isEmpty() || lastName.isEmpty()) {
mutableMessage.value = resource.getString(R.string.provide_name_message)
Expand All @@ -70,7 +70,8 @@ class EditProfileViewModel(
id = id,
firstName = firstName,
lastName = lastName,
avatarUrl = url
avatarUrl = url,
details = details
), id
)
.withDefaultSchedulers()
Expand Down
16 changes: 15 additions & 1 deletion app/src/main/res/layout/fragment_edit_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
android:layout_marginTop="@dimen/layout_margin_large"
android:baselineAligned="false"
android:orientation="horizontal"
android:paddingBottom="@dimen/padding_large"
android:paddingBottom="@dimen/padding_medium"
android:weightSum="2">

<com.google.android.material.textfield.TextInputLayout
Expand Down Expand Up @@ -78,6 +78,20 @@

</LinearLayout>

<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/padding_large"
android:hint="@string/details_of_the_user">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text" />
</com.google.android.material.textfield.TextInputLayout>

<Button
android:id="@+id/updateButton"
android:layout_width="match_parent"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<string name="confirm_password">Confirm Password</string>
<string name="first_name_optional">First Name (Optional)</string>
<string name="last_name_optional">Last Name (Optional)</string>
<string name="details_of_the_user">Details of the user</string>
<string name="welcome_back">Welcome back!</string>
<string name="update">Update</string>
<string name="profile_photo">Profile Photo</string>
Expand Down