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

fix: Bugs with navigation and UI improvements on EditProfile #87

Merged
merged 3 commits into from
Jan 29, 2025
Merged
Changes from 1 commit
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 @@ -18,6 +18,7 @@ import android.provider.MediaStore
import android.view.Gravity
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.activity.OnBackPressedCallback
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.background
import androidx.compose.foundation.border
Expand All @@ -43,6 +44,7 @@ import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Card
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material.ContentAlpha
import androidx.compose.material.Divider
import androidx.compose.material.ExperimentalMaterialApi
Expand Down Expand Up @@ -163,6 +165,17 @@ class EditProfileFragment : Fragment() {
}
}

private val onBackPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
if (viewModel.profileDataChanged) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This code is very close to lambda in EditProfileScreen

onBackClick = {
    if (it) {
        viewModel.setShowLeaveDialog(true)
    } else {
        viewModel.setShowLeaveDialog(false)
        requireActivity().supportFragmentManager.popBackStackImmediate()
    }
},

maybe we can create a separate method from this?

viewModel.setShowLeaveDialog(true)
} else {
viewModel.setShowLeaveDialog(false)
requireActivity().supportFragmentManager.popBackStackImmediate()
}
}
}

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
Expand Down Expand Up @@ -241,6 +254,16 @@ class EditProfileFragment : Fragment() {
}
}

override fun onResume() {
super.onResume()
activity?.onBackPressedDispatcher?.addCallback(onBackPressedCallback)
}

override fun onPause() {
onBackPressedCallback.remove()
super.onPause()
}

@Suppress("DEPRECATION")
private fun cropImage(uri: Uri): Uri {
val matrix = Matrix()
Expand Down Expand Up @@ -360,7 +383,7 @@ private fun EditProfileScreen(
mutableStateMapOf(
Pair(
YEAR_OF_BIRTH,
if (uiState.account.yearOfBirth != null) uiState.account.yearOfBirth.toString() else ""
if (uiState.account.yearOfBirth != null) uiState.account.yearOfBirth.toString() else null
),
Pair(LANGUAGE, uiState.account.languageProficiencies),
Pair(COUNTRY, uiState.account.country),
Expand Down Expand Up @@ -598,7 +621,7 @@ private fun EditProfileScreen(
) {
Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.BottomCenter
contentAlignment = Alignment.Center
) {
Column(
Modifier
Expand Down Expand Up @@ -777,6 +800,13 @@ private fun EditProfileScreen(
)
Spacer(Modifier.height(52.dp))
}
if (uiState.isUpdating) {
CircularProgressIndicator(
modifier = Modifier
.size(42.dp),
color = MaterialTheme.appColors.primary,
)
}
if (openWarningMessageDialog) {
LimitedProfileDialog(
modifier = popUpModifier
Expand Down Expand Up @@ -1003,7 +1033,7 @@ private fun SelectableField(
unfocusedBorderColor = MaterialTheme.appColors.textFieldBorder,
cursorColor = MaterialTheme.appColors.textFieldText,
disabledBorderColor = MaterialTheme.appColors.textFieldBorder,
disabledTextColor = MaterialTheme.appColors.textFieldHint,
disabledTextColor = MaterialTheme.appColors.textPrimary,
disabledPlaceholderColor = MaterialTheme.appColors.textFieldHint
)
}
Expand Down
Loading