Skip to content

Commit

Permalink
Show non avatar selected alert banner
Browse files Browse the repository at this point in the history
  • Loading branch information
hamorillo committed Nov 22, 2024
1 parent 7064aa5 commit 0bb7e96
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.ActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.StringRes
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.animateContentSize
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -51,6 +52,7 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import com.gravatar.extensions.defaultProfile
import com.gravatar.quickeditor.R
import com.gravatar.quickeditor.data.repository.EmailAvatars
import com.gravatar.quickeditor.ui.components.AlertBanner
import com.gravatar.quickeditor.ui.components.AvatarDeletionConfirmationDialog
import com.gravatar.quickeditor.ui.components.AvatarOption
import com.gravatar.quickeditor.ui.components.AvatarsSection
Expand Down Expand Up @@ -147,6 +149,11 @@ internal fun AvatarPicker(uiState: AvatarPickerUiState, onEvent: (AvatarPickerEv
var loadingSectionHeight by remember { mutableStateOf(DEFAULT_PAGE_HEIGHT) }
var storagePermissionRationaleDialogVisible by rememberSaveable { mutableStateOf(false) }
var avatarToDownload: Avatar? by remember { mutableStateOf(null) }
var nonSelectedAvatarAlertVisible by rememberSaveable { mutableStateOf(uiState.showNonSelectedAvatarAlert) }

LaunchedEffect(uiState.showNonSelectedAvatarAlert) {
nonSelectedAvatarAlertVisible = uiState.showNonSelectedAvatarAlert
}

val writeExternalStoragePermissionLauncher = rememberLauncherForActivityResult(
ActivityResultContracts.RequestPermission(),
Expand Down Expand Up @@ -197,6 +204,13 @@ internal fun AvatarPicker(uiState: AvatarPickerUiState, onEvent: (AvatarPickerEv
.fillMaxWidth()
.padding(bottom = 10.dp),
)
AnimatedVisibility(nonSelectedAvatarAlertVisible) {
AlertBanner(
message = stringResource(id = R.string.gravatar_qe_alert_banner_no_avatar_selected),
onClose = { nonSelectedAvatarAlertVisible = false },
modifier = Modifier.padding(start = 16.dp, end = 16.dp, bottom = 24.dp),
)
}
key(uiState.avatarUpdates) {
ProfileCard(
profile = uiState.profile,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ internal data class AvatarPickerUiState(
)
}

val showNonSelectedAvatarAlert: Boolean = if (emailAvatars != null) {
emailAvatars.selectedAvatarId == null
} else {
false
}

private fun EmailAvatars.mapToUiModel(): List<AvatarUi> {
return mutableListOf<AvatarUi>().apply {
uploadingAvatar?.let {
Expand Down

0 comments on commit 0bb7e96

Please sign in to comment.