diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 000000000..1a92dcbb5 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +DeckBox \ No newline at end of file diff --git a/.idea/kotlinScripting.xml b/.idea/kotlinScripting.xml index 424122b55..bafd01b0e 100644 --- a/.idea/kotlinScripting.xml +++ b/.idea/kotlinScripting.xml @@ -8,4 +8,4 @@ 2147483647 - \ No newline at end of file + diff --git a/common/compose/src/commonMain/kotlin/app/deckbox/common/compose/widgets/builder/CardBuilder.kt b/common/compose/src/commonMain/kotlin/app/deckbox/common/compose/widgets/builder/CardBuilder.kt index 249ba19f2..58f94b93a 100644 --- a/common/compose/src/commonMain/kotlin/app/deckbox/common/compose/widgets/builder/CardBuilder.kt +++ b/common/compose/src/commonMain/kotlin/app/deckbox/common/compose/widgets/builder/CardBuilder.kt @@ -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 @@ -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) -> Unit, onAddCardClick: (Stacked) -> Unit, onRemoveCardClick: (Stacked) -> Unit, onTipClick: (CardUiModel.Tip) -> Unit, - onNameChange: (String) -> Unit, - + onNameChange: (TextFieldValue) -> Unit, cardsState: LoadState>, modifier: Modifier = Modifier, isValid: Boolean = true, @@ -130,6 +129,7 @@ fun CardBuilder( indication = null, onClick = { isEditing = false + focusManager.clearFocus() }, ), scaffoldState = scaffoldState, diff --git a/common/compose/src/commonMain/kotlin/app/deckbox/common/compose/widgets/builder/composables/BuilderBottomSheet.kt b/common/compose/src/commonMain/kotlin/app/deckbox/common/compose/widgets/builder/composables/BuilderBottomSheet.kt index ab34133bb..cc714d918 100644 --- a/common/compose/src/commonMain/kotlin/app/deckbox/common/compose/widgets/builder/composables/BuilderBottomSheet.kt +++ b/common/compose/src/commonMain/kotlin/app/deckbox/common/compose/widgets/builder/composables/BuilderBottomSheet.kt @@ -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 @@ -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>, focusRequester: FocusRequester, + cardsState: LoadState>, onHeaderClick: () -> Unit, - onNameChange: (String) -> Unit, + onNameChange: (TextFieldValue) -> Unit, content: @Composable ColumnScope.() -> Unit, ) { val cards = cardsState.dataOrNull ?: persistentListOf() @@ -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") diff --git a/features/boosterpacks/ui/src/commonMain/kotlin/app/deckbox/features/boosterpacks/ui/builder/BoosterPackBuilder.kt b/features/boosterpacks/ui/src/commonMain/kotlin/app/deckbox/features/boosterpacks/ui/builder/BoosterPackBuilder.kt index 8a1d86500..9b40b058a 100644 --- a/features/boosterpacks/ui/src/commonMain/kotlin/app/deckbox/features/boosterpacks/ui/builder/BoosterPackBuilder.kt +++ b/features/boosterpacks/ui/src/commonMain/kotlin/app/deckbox/features/boosterpacks/ui/builder/BoosterPackBuilder.kt @@ -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 @@ -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 @@ -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( @@ -61,7 +71,7 @@ fun BoosterPackBuilder( ), ) } else { - AnnotatedString(boosterPackName) + AnnotatedString(boosterPackName.text) } }, floatingActionButton = { isScrolled -> @@ -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, ) } diff --git a/features/boosterpacks/ui/src/commonMain/kotlin/app/deckbox/features/boosterpacks/ui/builder/composables/BoosterPackBottomSheet.kt b/features/boosterpacks/ui/src/commonMain/kotlin/app/deckbox/features/boosterpacks/ui/builder/composables/BoosterPackBottomSheet.kt index d2989d4ef..5ed6f2588 100644 --- a/features/boosterpacks/ui/src/commonMain/kotlin/app/deckbox/features/boosterpacks/ui/builder/composables/BoosterPackBottomSheet.kt +++ b/features/boosterpacks/ui/src/commonMain/kotlin/app/deckbox/features/boosterpacks/ui/builder/composables/BoosterPackBottomSheet.kt @@ -15,7 +15,6 @@ internal fun ColumnScope.BoosterPackBottomSheet( state: BoosterPackBuilderUiState, ) { Divider() - PackPrices( prices = state.price.dataOrNull ?: PackPriceState(), ) diff --git a/features/decks/ui/src/commonMain/kotlin/app.deckbox.ui.decks/builder/DeckBuilder.kt b/features/decks/ui/src/commonMain/kotlin/app.deckbox.ui.decks/builder/DeckBuilder.kt index 4dc60181d..25fa19838 100644 --- a/features/decks/ui/src/commonMain/kotlin/app.deckbox.ui.decks/builder/DeckBuilder.kt +++ b/features/decks/ui/src/commonMain/kotlin/app.deckbox.ui.decks/builder/DeckBuilder.kt @@ -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 @@ -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 @@ -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( @@ -62,7 +70,7 @@ fun DeckBuilder( ), ) } else { - AnnotatedString(deckName) + AnnotatedString(deckName.text) } }, floatingActionButton = { isScrolled -> @@ -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, ) } diff --git a/features/decks/ui/src/commonMain/kotlin/app.deckbox.ui.decks/builder/composables/DeckBuilderBottomSheet.kt b/features/decks/ui/src/commonMain/kotlin/app.deckbox.ui.decks/builder/composables/DeckBuilderBottomSheet.kt index eb7efb4a6..b74d0915d 100644 --- a/features/decks/ui/src/commonMain/kotlin/app.deckbox.ui.decks/builder/composables/DeckBuilderBottomSheet.kt +++ b/features/decks/ui/src/commonMain/kotlin/app.deckbox.ui.decks/builder/composables/DeckBuilderBottomSheet.kt @@ -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 @@ -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 @@ -54,6 +57,10 @@ internal fun ColumnScope.DeckBuilderBottomSheet( Text("Description") }, minLines = 3, + keyboardOptions = KeyboardOptions( + keyboardType = KeyboardType.Text, + imeAction = ImeAction.Done, + ), modifier = Modifier.fillMaxWidth(), ) }