Skip to content

Commit

Permalink
fix NPE in the BS
Browse files Browse the repository at this point in the history
  • Loading branch information
panasetskaya committed Nov 25, 2024
1 parent abf63e6 commit 2e4aae2
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ object ButtonDefaults {
Secondary,
SecondaryAlt,
Ghost,
Red
Red,
}

enum class ButtonSize {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ internal object RedStyleButtonTokens {
val HoverContentColor = ColorSchemeKeyTokens.TextWhite
val DisabledContainerColor = ColorSchemeKeyTokens.ButtonPrimaryDisabled
val DisabledContentColor = ColorSchemeKeyTokens.TextTertiary
val ActiveLoadingIndicatorColor = ColorSchemeKeyTokens.TextWhite //todo: check it in action
val ActiveLoadingIndicatorColor = ColorSchemeKeyTokens.TextWhite
val InactiveLoadingIndicatorColor = ColorSchemeKeyTokens.SignalRedText
val RedContentColor = ColorSchemeKeyTokens.SignalRedElement //should not be used ever
val RedContentColor = ColorSchemeKeyTokens.SignalRedElement // should not be used ever
}

internal object LargeSizeButtonTokens {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import com.hedvig.android.design.system.hedvig.HedvigButton
import com.hedvig.android.design.system.hedvig.HedvigErrorSection
import com.hedvig.android.design.system.hedvig.HedvigFullScreenCenterAlignedProgress
import com.hedvig.android.design.system.hedvig.HedvigPreview
import com.hedvig.android.design.system.hedvig.HedvigRedTextButton
import com.hedvig.android.design.system.hedvig.HedvigScaffold
import com.hedvig.android.design.system.hedvig.HedvigText
import com.hedvig.android.design.system.hedvig.HedvigTheme
Expand Down Expand Up @@ -125,8 +124,11 @@ private fun DeleteScreenContents(
Spacer(Modifier.height(16.dp))
Spacer(Modifier.weight(1f))
Spacer(Modifier.height(8.dp))
val buttonStyle = if (isButtonRed)
ButtonDefaults.ButtonStyle.Red else ButtonDefaults.ButtonStyle.Primary
val buttonStyle = if (isButtonRed) {
ButtonDefaults.ButtonStyle.Red
} else {
ButtonDefaults.ButtonStyle.Primary
}
HedvigButton(
text = buttonText,
onClick = onButtonClick,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ package com.hedvig.android.feature.editcoinsured.ui
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawing
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.windowInsetsBottomHeight
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
Expand All @@ -23,7 +23,6 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
Expand All @@ -50,15 +49,13 @@ import com.hedvig.android.design.system.hedvig.HedvigTextField
import com.hedvig.android.design.system.hedvig.HedvigTextFieldDefaults
import com.hedvig.android.design.system.hedvig.HedvigTheme
import com.hedvig.android.design.system.hedvig.HedvigToggle
import com.hedvig.android.design.system.hedvig.HorizontalItemsWithMaximumSpaceTaken
import com.hedvig.android.design.system.hedvig.NotificationDefaults
import com.hedvig.android.design.system.hedvig.RadioOption
import com.hedvig.android.design.system.hedvig.Surface
import com.hedvig.android.design.system.hedvig.ToggleDefaults.ToggleDefaultStyleSize.Small
import com.hedvig.android.design.system.hedvig.ToggleDefaults.ToggleStyle
import com.hedvig.android.design.system.hedvig.api.HedvigSelectableDates
import com.hedvig.android.design.system.hedvig.datepicker.HedvigDatePicker
import com.hedvig.android.design.system.hedvig.datepicker.HedvigDatePickerImmutableState
import com.hedvig.android.design.system.hedvig.datepicker.HedvigDatePickerState
import com.hedvig.android.design.system.hedvig.datepicker.HedvigDateTimeFormatterDefaults
import com.hedvig.android.design.system.hedvig.datepicker.getLocale
Expand Down Expand Up @@ -128,7 +125,9 @@ internal fun AddCoInsuredBottomSheetContent(
Spacer(Modifier.height(4.dp))
HedvigToggle(
turnedOn = bottomSheetState.showManualInput,
onClick = onManualInputSwitchChanged,
onClick = {
onManualInputSwitchChanged(it)
},
modifier = Modifier.fillMaxWidth(),
toggleStyle = ToggleStyle.Default(Small),
labelText = stringResource(id = R.string.CONTRACT_ADD_COINSURED_NO_SSN),
Expand Down Expand Up @@ -203,8 +202,7 @@ private fun SelectableHedvigCard(text: String, isSelected: Boolean, onClick: ()
chosenState = if (isSelected) ChosenState.Chosen else ChosenState.NotChosen,
onClick = onClick,
modifier = Modifier.fillMaxWidth(),
)
{
) {
HedvigText(
text = text,
)
Expand Down Expand Up @@ -233,9 +231,11 @@ private fun FetchFromSsnFields(
}
},
textFieldSize = HedvigTextFieldDefaults.TextFieldSize.Medium,
errorState = if (errorMessage != null) HedvigTextFieldDefaults.ErrorState.Error.WithMessage(errorMessage)
else HedvigTextFieldDefaults.ErrorState.NoError,

errorState = if (errorMessage != null) {
HedvigTextFieldDefaults.ErrorState.Error.WithMessage(errorMessage)
} else {
HedvigTextFieldDefaults.ErrorState.NoError
},
visualTransformation = PersonalNumberVisualTransformation(mask, maskColor),
keyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.Number,
Expand Down Expand Up @@ -323,42 +323,38 @@ private fun ManualInputFields(
modifier = Modifier.fillMaxWidth(),
)
Spacer(Modifier.height(4.dp))
HorizontalItemsWithMaximumSpaceTaken(

This comment has been minimized.

Copy link
@panasetskaya

panasetskaya Nov 25, 2024

Author Contributor

here

startSlot = {
HedvigTextField(
text = firstNameInput,
labelText = stringResource(id = R.string.CONTRACT_FIRST_NAME),
textFieldSize = HedvigTextFieldDefaults.TextFieldSize.Medium,
onValueChange = {
onFirstNameChanged(it)
firstNameInput = it
},

keyboardOptions = KeyboardOptions(
capitalization = KeyboardCapitalization.Words,
keyboardType = KeyboardType.Text,
),
modifier = Modifier.fillMaxWidth(),
)
},
endSlot = {
HedvigTextField(
text = lastNameInput,
textFieldSize = HedvigTextFieldDefaults.TextFieldSize.Medium,
labelText = stringResource(id = R.string.CONTRACT_LAST_NAME),
onValueChange = {
onLastNameChanged(it)
lastNameInput = it
},
keyboardOptions = KeyboardOptions(
capitalization = KeyboardCapitalization.Words,
keyboardType = KeyboardType.Text,
),
modifier = Modifier.fillMaxWidth(),
)
},
spaceBetween = 4.dp,
)
Row {
HedvigTextField(
text = firstNameInput,
labelText = stringResource(id = R.string.CONTRACT_FIRST_NAME),
textFieldSize = HedvigTextFieldDefaults.TextFieldSize.Medium,
onValueChange = {
onFirstNameChanged(it)
firstNameInput = it
},
keyboardOptions = KeyboardOptions(
capitalization = KeyboardCapitalization.Words,
keyboardType = KeyboardType.Text,
),
modifier = Modifier.weight(1f),
)
Spacer(Modifier.width(4.dp))
HedvigTextField(
text = lastNameInput,
textFieldSize = HedvigTextFieldDefaults.TextFieldSize.Medium,
labelText = stringResource(id = R.string.CONTRACT_LAST_NAME),
onValueChange = {
onLastNameChanged(it)
lastNameInput = it
},
keyboardOptions = KeyboardOptions(
capitalization = KeyboardCapitalization.Words,
keyboardType = KeyboardType.Text,
),
modifier = Modifier.weight(1f),
)
}

Spacer(Modifier.height(4.dp))
AnimatedVisibility(
Expand All @@ -369,18 +365,14 @@ private fun ManualInputFields(
HedvigNotificationCard(
message = errorMessage ?: "",
priority = NotificationDefaults.NotificationPriority.Attention,
modifier = Modifier.fillMaxWidth(),
)
}
}
}

@Composable
internal fun DatePickerWithDialog(
birthDate: LocalDate?,
onSave: (LocalDate) -> Unit,
modifier: Modifier = Modifier,
) {

internal fun DatePickerWithDialog(birthDate: LocalDate?, onSave: (LocalDate) -> Unit, modifier: Modifier = Modifier) {
val selectedDateMillis = birthDate?.atStartOfDayIn(TimeZone.UTC)?.toEpochMilliseconds()
?: Clock.System.now().toEpochMilliseconds()
val locale = getLocale()
Expand All @@ -396,13 +388,13 @@ internal fun DatePickerWithDialog(
initialDisplayedMonthMillis = selectedDateMillis,
selectableDates = object : HedvigSelectableDates {
override fun isSelectableDate(utcTimeMillis: Long): Boolean {
return utcTimeMillis <= Clock.System.now().toEpochMilliseconds() //todo: check here
return utcTimeMillis <= Clock.System.now().toEpochMilliseconds() // todo: check here
}

override fun isSelectableYear(year: Int): Boolean =
year <= Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault()).year
},
)
),
)
}
if (showDatePicker) {
Expand All @@ -417,40 +409,9 @@ internal fun DatePickerWithDialog(
onSave(date)
}
showDatePicker = false
}
},
)
}

// if (showDatePicker) {
// HedvigDatePicker (
// onDismissRequest = { showDatePicker = false },
// confirmButton = {
// TextButton(
// onClick = {
// showDatePicker = false
// selectedDate?.let {
// onSave(selectedDate)
// }
// },
// shape = HedvigTheme.shapes.medium,
// ) {
// Text(stringResource(R.string.general_save_button))
// }
// },
// dismissButton = {
// TextButton(
// onClick = {
// showDatePicker = false
// },
// shape = HedvigTheme.shapes.medium,
// ) {
// Text(stringResource(R.string.general_cancel_button))
// }
// },
// ) {
// HedvigDatePicker(datePickerState = datePickerState)
// }
// }
HedvigCard(
onClick = { showDatePicker = true },
modifier = modifier,
Expand Down Expand Up @@ -490,7 +451,6 @@ internal fun DatePickerWithDialog(
}
}


private fun AddBottomSheetState.SaveButtonLabel.stringRes() = when (this) {
AddBottomSheetState.SaveButtonLabel.FETCH_INFO -> R.string.CONTRACT_SSN_FETCH_INFO
AddBottomSheetState.SaveButtonLabel.ADD -> R.string.CONTRACT_ADD_COINSURED
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.hedvig.android.feature.editcoinsured.ui

import androidx.compose.foundation.layout.Column

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import com.hedvig.android.design.system.hedvig.HorizontalDivider
import com.hedvig.android.design.system.hedvig.datepicker.rememberHedvigBirthDateDateTimeFormatter

import com.hedvig.android.feature.editcoinsured.data.CoInsured
import hedvig.resources.R

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private fun EditCoInsuredScreen(

when (uiState) {
is EditCoInsuredState.Error -> {
ErrorDialog( //todo: dialog???
ErrorDialog( // todo: dialog???
title = stringResource(id = R.string.general_error),
message = uiState.message,
onDismiss = onDismissError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private fun EditCoInsuredScreen(

when (uiState) {
is EditCoInsuredState.Error -> {
ErrorDialog( //todo: check here, what is going on??
ErrorDialog( // todo: check here, what is going on??
title = stringResource(id = R.string.general_error),
message = uiState.message,
onDismiss = onDismissError,
Expand Down Expand Up @@ -222,7 +222,7 @@ private fun EditCoInsuredScreen(
onClick = onAddCoInsuredClicked,
enabled = true,
buttonStyle = ButtonDefaults.ButtonStyle.Secondary,
modifier = Modifier.padding(horizontal = 16.dp),
modifier = Modifier.padding(horizontal = 16.dp).fillMaxWidth(),
)
}

Expand All @@ -236,7 +236,7 @@ private fun EditCoInsuredScreen(
onClick = onCommitChanges,
enabled = true,
isLoading = uiState.listState.isCommittingUpdate,
modifier = Modifier.padding(horizontal = 16.dp),
modifier = Modifier.padding(horizontal = 16.dp).fillMaxWidth(),
)
}

Expand Down Expand Up @@ -286,7 +286,9 @@ private fun PriceInfo(priceInfo: EditCoInsuredState.Loaded.PriceInfo) {
style = LocalTextStyle.current.copy(textDecoration = TextDecoration.LineThrough),
)
Spacer(modifier = Modifier.width(8.dp))
HedvigText(text = stringResource(id = R.string.CHANGE_ADDRESS_PRICE_PER_MONTH_LABEL, priceInfo.newPrice.toString()))
HedvigText(
text = stringResource(id = R.string.CHANGE_ADDRESS_PRICE_PER_MONTH_LABEL, priceInfo.newPrice.toString()),
)
}
},
spaceBetween = 8.dp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import androidx.compose.foundation.layout.asPaddingValues
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeDrawing

import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand All @@ -23,7 +22,6 @@ import com.hedvig.android.design.system.hedvig.HedvigTheme
import com.hedvig.android.design.system.hedvig.Surface
import com.hedvig.android.design.system.hedvig.datepicker.getLocale
import com.hedvig.android.design.system.hedvig.datepicker.hedvigDateTimeFormatter

import kotlinx.datetime.LocalDate
import kotlinx.datetime.toJavaLocalDate

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ internal fun InsuredRow(
}

!allowEdit -> Icon(
imageVector = HedvigIcons.Close, //todo: check here
imageVector = HedvigIcons.Close, // todo: check here
contentDescription = "Remove",
modifier = Modifier.size(16.dp),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal fun RemoveCoInsuredBottomSheetContent(
onDismiss: () -> Unit,
onRemove: (CoInsured) -> Unit,
isLoading: Boolean,
errorMessage: String?, //todo: this one is not used?
errorMessage: String?, // todo: this one is not used?
coInsured: CoInsured,
) {
Column(
Expand All @@ -37,7 +37,8 @@ internal fun RemoveCoInsuredBottomSheetContent(
Spacer(Modifier.height(16.dp))
HedvigText(
stringResource(id = R.string.CONTRACT_REMOVE_COINSURED_CONFIRMATION),
textAlign = TextAlign.Center)
textAlign = TextAlign.Center,
)
Spacer(Modifier.height(24.dp))
HedvigButton(
text = stringResource(id = R.string.REMOVE_CONFIRMATION_BUTTON),
Expand Down

0 comments on commit 2e4aae2

Please sign in to comment.