Skip to content

Commit

Permalink
Fix text field name (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
YoussefHachicha authored Oct 26, 2023
1 parent dae016d commit dee40b8
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 37 deletions.
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/kotlinScripting.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import app.deckbox.common.compose.PlatformBackHandler
Expand All @@ -68,19 +69,17 @@ import kotlinx.coroutines.launch
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun CardBuilder(
name: String,
name: TextFieldValue,
title: @Composable () -> AnnotatedString,
floatingActionButton: @Composable (isScrolled: Boolean) -> Unit,
bottomSheetContent: @Composable ColumnScope.() -> Unit,

onNavClick: () -> Unit,
onAddClick: () -> Unit,
onCardClick: (Stacked<Card>) -> Unit,
onAddCardClick: (Stacked<Card>) -> Unit,
onRemoveCardClick: (Stacked<Card>) -> Unit,
onTipClick: (CardUiModel.Tip) -> Unit,
onNameChange: (String) -> Unit,

onNameChange: (TextFieldValue) -> Unit,
cardsState: LoadState<out ImmutableList<CardUiModel>>,
modifier: Modifier = Modifier,
isValid: Boolean = true,
Expand Down Expand Up @@ -130,6 +129,7 @@ fun CardBuilder(
indication = null,
onClick = {
isEditing = false
focusManager.clearFocus()
},
),
scaffoldState = scaffoldState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
Expand All @@ -34,17 +30,16 @@ import app.deckbox.core.model.SuperType
import com.moriatsushi.insetsx.navigationBars
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf

@OptIn(ExperimentalFoundationApi::class)
@Composable
internal fun ColumnScope.BuilderBottomSheet(
name: String,
name: TextFieldValue,
isValid: Boolean,
legalities: Legalities,
cardsState: LoadState<out ImmutableList<CardUiModel>>,
focusRequester: FocusRequester,
cardsState: LoadState<out ImmutableList<CardUiModel>>,
onHeaderClick: () -> Unit,
onNameChange: (String) -> Unit,
onNameChange: (TextFieldValue) -> Unit,
content: @Composable ColumnScope.() -> Unit,
) {
val cards = cardsState.dataOrNull ?: persistentListOf()
Expand All @@ -64,17 +59,13 @@ internal fun ColumnScope.BuilderBottomSheet(
.focusGroup()
.verticalScroll(rememberScrollState()),
) {
var nameValue by remember(name) {
mutableStateOf(TextFieldValue(name))
}
BuilderTextField(
icon = { Icon(Icons.Rounded.ShortText, contentDescription = null) },
) {
TextField(
value = nameValue,
value = name,
onValueChange = { value ->
nameValue = value
onNameChange(value.text)
onNameChange(value)
},
placeholder = {
Text("Name")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.unit.dp
import app.deckbox.common.compose.icons.rounded.AddCard
import app.deckbox.common.compose.overlays.showBottomSheetScreen
Expand All @@ -26,7 +31,6 @@ import app.deckbox.features.boosterpacks.ui.builder.BoosterPackBuilderUiEvent.Ad
import app.deckbox.features.boosterpacks.ui.builder.BoosterPackBuilderUiEvent.AddToDeck
import app.deckbox.features.boosterpacks.ui.builder.BoosterPackBuilderUiEvent.CardClick
import app.deckbox.features.boosterpacks.ui.builder.BoosterPackBuilderUiEvent.DecrementCard
import app.deckbox.features.boosterpacks.ui.builder.BoosterPackBuilderUiEvent.EditName
import app.deckbox.features.boosterpacks.ui.builder.BoosterPackBuilderUiEvent.IncrementCard
import app.deckbox.features.boosterpacks.ui.builder.BoosterPackBuilderUiEvent.NavigateBack
import app.deckbox.features.boosterpacks.ui.builder.BoosterPackBuilderUiEvent.NewDeck
Expand All @@ -45,14 +49,20 @@ fun BoosterPackBuilder(
val coroutineScope = rememberCoroutineScope()
val overlayHost = LocalOverlayHost.current
val eventSink = state.eventSink

val boosterPack = state.session.boosterPackOrNull()
val boosterPackName = boosterPack?.name ?: ""

var boosterPackName by remember(state.session.boosterPackOrNull() != null) {
mutableStateOf(TextFieldValue(state.session.boosterPackOrNull()?.name ?: ""))
}

CardBuilder(
name = boosterPackName,
onNameChange = { value ->
boosterPackName = value
eventSink(BoosterPackBuilderUiEvent.EditName(value.text))
},
title = {
if (boosterPackName.isBlank()) {
if (boosterPackName.text.isBlank()) {
AnnotatedString(
LocalStrings.current.boosterPackPickerTitle,
SpanStyle(
Expand All @@ -61,7 +71,7 @@ fun BoosterPackBuilder(
),
)
} else {
AnnotatedString(boosterPackName)
AnnotatedString(boosterPackName.text)
}
},
floatingActionButton = { isScrolled ->
Expand Down Expand Up @@ -96,11 +106,10 @@ fun BoosterPackBuilder(
CardUiModel.Tip.Energy -> eventSink(AddCards(SuperType.ENERGY))
}
},
onNameChange = { newName -> eventSink(EditName(newName)) },
cardsState = state.cards,
legalities = boosterPack?.legalities ?: Legalities(standard = Legality.LEGAL),
modifier = modifier,
columns = 4,
cardSpacing = 8.dp,
modifier = modifier,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ internal fun ColumnScope.BoosterPackBottomSheet(
state: BoosterPackBuilderUiState,
) {
Divider()

PackPrices(
prices = state.price.dataOrNull ?: PackPriceState(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.input.TextFieldValue
import app.deckbox.common.compose.icons.rounded.AddCard
import app.deckbox.common.compose.overlays.showBottomSheetScreen
import app.deckbox.common.compose.widgets.builder.CardBuilder
Expand All @@ -26,7 +31,6 @@ import app.deckbox.ui.decks.builder.DeckBuilderUiEvent.AddBoosterPack
import app.deckbox.ui.decks.builder.DeckBuilderUiEvent.AddCards
import app.deckbox.ui.decks.builder.DeckBuilderUiEvent.CardClick
import app.deckbox.ui.decks.builder.DeckBuilderUiEvent.DecrementCard
import app.deckbox.ui.decks.builder.DeckBuilderUiEvent.EditName
import app.deckbox.ui.decks.builder.DeckBuilderUiEvent.IncrementCard
import app.deckbox.ui.decks.builder.DeckBuilderUiEvent.NavigateBack
import app.deckbox.ui.decks.builder.DeckBuilderUiEvent.NewBoosterPack
Expand All @@ -45,15 +49,19 @@ fun DeckBuilder(
val coroutineScope = rememberCoroutineScope()
val overlayHost = LocalOverlayHost.current
val eventSink = state.eventSink

val deck = state.session.deckOrNull()
val deckName = deck?.name ?: ""
val validation = state.validation.dataOrNull ?: DeckValidation()

var deckName by remember(state.session.deckOrNull() != null) {
mutableStateOf(TextFieldValue(state.session.deckOrNull()?.name ?: ""))
}
CardBuilder(
name = deckName,
onNameChange = { value ->
deckName = value
eventSink(DeckBuilderUiEvent.EditName(value.text))
},
title = {
if (deckName.isBlank()) {
if (deckName.text.isBlank()) {
AnnotatedString(
LocalStrings.current.deckTitleNoName,
SpanStyle(
Expand All @@ -62,7 +70,7 @@ fun DeckBuilder(
),
)
} else {
AnnotatedString(deckName)
AnnotatedString(deckName.text)
}
},
floatingActionButton = { isScrolled ->
Expand Down Expand Up @@ -96,12 +104,9 @@ fun DeckBuilder(
CardUiModel.Tip.Energy -> eventSink(AddCards(SuperType.ENERGY))
}
},
onNameChange = { newName -> eventSink(EditName(newName)) },

cardsState = state.cards,
modifier = modifier,

isValid = validation.isValid && !validation.isEmpty,
legalities = deck?.legalities ?: Legalities(standard = Legality.LEGAL),
modifier = modifier,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.ColumnScope
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.ErrorOutline
import androidx.compose.material.icons.rounded.Subject
Expand All @@ -21,6 +22,8 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.unit.dp
import app.deckbox.common.compose.widgets.builder.composables.BuilderTextField
Expand Down Expand Up @@ -54,6 +57,10 @@ internal fun ColumnScope.DeckBuilderBottomSheet(
Text("Description")
},
minLines = 3,
keyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.Text,
imeAction = ImeAction.Done,
),
modifier = Modifier.fillMaxWidth(),
)
}
Expand Down

0 comments on commit dee40b8

Please sign in to comment.