Skip to content

Commit

Permalink
Merge pull request #141 from fmasa/char-counter
Browse files Browse the repository at this point in the history
Visible Character count + increased max Trapping description length
  • Loading branch information
fmasa authored Jul 27, 2023
2 parents adba433 + d752bbe commit e4e02c2
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ fun CharacterBasicInfoForm(
label = strings.labelNote,
value = data.note,
multiLine = true,
maxLength = Character.NOTE_MAX_LENGTH,
validate = validate,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ data class InventoryItem(

companion object {
const val NAME_MAX_LENGTH = 50
const val DESCRIPTION_MAX_LENGTH = 200
const val DESCRIPTION_MAX_LENGTH = 1000
}

// TODO: Add support for Trappings compendium
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package cz.frantisekmasa.wfrp_master.common.core.ui.forms
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
Expand Down Expand Up @@ -167,13 +169,26 @@ private fun TextInput(
}
}

if (helperText != null && helperText.isNotBlank()) {
if (maxLength < Int.MAX_VALUE || helperText.isNullOrBlank()) {
CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.medium) {
Text(helperText, style = MaterialTheme.typography.body2)
Row {
if (!helperText.isNullOrBlank()) {
Text(helperText, style = MaterialTheme.typography.body2)
}

Spacer(Modifier.weight(1f))

if (maxLength < Int.MAX_VALUE) {
Text(
"${value.length} / $maxLength",
style = MaterialTheme.typography.overline,
)
}
}
}
}

if (errorMessage != null && errorMessage.isNotBlank()) {
if (!errorMessage.isNullOrBlank()) {
ErrorMessage(errorMessage)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ fun Theme(content: @Composable () -> Unit) {
colors = if (darkMode) Theme.darkColors() else Theme.lightColors(),
typography = MaterialTheme.typography.copy(
caption = MaterialTheme.typography.caption.copy(fontSize = 14.sp),
overline = MaterialTheme.typography.overline.copy(
fontSize = 12.sp,
letterSpacing = 0.25.sp,
)
),
) {
SystemBarsChangingEffect()
Expand Down
2 changes: 1 addition & 1 deletion firebase/firestore.rules
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ service cloud.firestore {
return ["id", "name", "description", "quantity", "encumbrance", "trappingType", "containerId"].hasAll(item.keys())
&& item.id is string && item.id == itemId && isValidUuid(item.id)
&& item.name is string && isNotBlank(item.name) && item.name.size() <= 50
&& item.description is string && item.description.size() <= 200
&& item.description is string && item.description.size() <= 1000
&& item.quantity is int && item.quantity > 0
&& (! ("encumbrance" in item) || (item.encumbrance is number && item.encumbrance >= 0))
&& (! ("trappingType" in item) || item.trappingType == null || item.trappingType is map)
Expand Down
2 changes: 1 addition & 1 deletion firebase/tests/Inventory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class Inventory extends CharacterSubCollectionSuite {
{name: " \t\r"},

// Description too long
{description: "a".repeat(201)},
{description: "a".repeat(1001)},

// Zero quantity
{quantity: 0},
Expand Down

0 comments on commit e4e02c2

Please sign in to comment.