Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Injuries #371

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ kotlin {
dependencies {
implementation(kotlin("test"))
implementation(libs.mockk)
implementation(libs.kotlinx.coroutines.test)
}
}

Expand Down Expand Up @@ -153,6 +154,11 @@ kotlin {

implementation(libs.korau)
implementation(libs.pdfbox)
implementation("dev.gitlive:firebase-java-sdk") {
version {
strictly("0.4.7")
}
}
}
}

Expand Down Expand Up @@ -206,6 +212,7 @@ buildkonfig {
Properties()
}

buildConfigField(STRING, "authEmulatorUrl", properties.getOrDefault("dev.authEmulatorUrl", "").toString())
buildConfigField(STRING, "functionsEmulatorUrl", properties.getOrDefault("dev.functionsEmulatorUrl", "").toString())
buildConfigField(STRING, "firestoreEmulatorUrl", properties.getOrDefault("dev.firestoreEmulatorUrl", "").toString())
buildConfigField(STRING, "versionName", System.getenv("SUPPLY_VERSION_NAME") ?: "dev")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import cafe.adriel.voyager.core.screen.Screen
import cz.frantisekmasa.wfrp_master.common.Str
import cz.frantisekmasa.wfrp_master.common.core.ui.cards.CardTitle
import cz.frantisekmasa.wfrp_master.common.core.ui.cards.StickyHeader
import cz.frantisekmasa.wfrp_master.common.core.ui.menu.WithContextMenu
import cz.frantisekmasa.wfrp_master.common.core.ui.navigation.LocalNavigationTransaction
import cz.frantisekmasa.wfrp_master.common.core.ui.primitives.CompactEmptyUI
import cz.frantisekmasa.wfrp_master.common.core.ui.primitives.ContextMenu
import dev.icerock.moko.resources.compose.stringResource
import kotlinx.collections.immutable.ImmutableList

Expand All @@ -25,10 +27,21 @@ fun <T> LazyListScope.characterItemsCard(
items: ImmutableList<T>,
actions: (@Composable () -> Unit)? = null,
newItemScreen: () -> Screen,
detailScreen: (T) -> Screen,
contextMenuItems: @Composable (T) -> List<ContextMenu.Item> = { emptyList() },
leadingDivider: Boolean = false,
onRemove: (T) -> Unit,
noItems: @Composable () -> Unit = {
CompactEmptyUI(stringResource(Str.common_ui_messages_no_items))
},
item: @Composable (T) -> Unit,
) {
stickyHeader(key = "$key-header") {
StickyHeader {
if (leadingDivider) {
Divider()
}

CardTitle(
title(),
actions = {
Expand All @@ -49,7 +62,7 @@ fun <T> LazyListScope.characterItemsCard(
if (items.isEmpty()) {
item(key = "$key-empty-ui") {
if (items.isEmpty()) {
CompactEmptyUI(stringResource(Str.common_ui_messages_no_items))
noItems()
}
}
}
Expand All @@ -60,7 +73,18 @@ fun <T> LazyListScope.characterItemsCard(
Divider()
}

item(it)
val navigation = LocalNavigationTransaction.current
WithContextMenu(
items =
contextMenuItems(it) +
ContextMenu.Item(
stringResource(Str.common_ui_button_remove),
onClick = { onRemove(it) },
),
onClick = { navigation.navigate(detailScreen(it)) },
) {
item(it)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import cz.frantisekmasa.wfrp_master.common.character.CharacterItemDetailScreen
import cz.frantisekmasa.wfrp_master.common.character.wellBeing.diseases.DiseaseSpecification
import cz.frantisekmasa.wfrp_master.common.character.wellBeing.diseases.DiseaseSpecificationForm
import cz.frantisekmasa.wfrp_master.common.compendium.disease.CompendiumDiseaseDetailScreen
import cz.frantisekmasa.wfrp_master.common.core.domain.character.diseases.Countdown
import cz.frantisekmasa.wfrp_master.common.core.domain.character.Countdown
import cz.frantisekmasa.wfrp_master.common.core.domain.character.diseases.Disease
import cz.frantisekmasa.wfrp_master.common.core.domain.identifiers.CharacterId
import cz.frantisekmasa.wfrp_master.common.core.domain.localizedName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.text.input.KeyboardType
import com.halilibo.richtext.commonmark.Markdown
import com.halilibo.richtext.ui.material.RichText
import cz.frantisekmasa.wfrp_master.common.core.domain.character.diseases.Countdown
import cz.frantisekmasa.wfrp_master.common.core.domain.character.Countdown
import cz.frantisekmasa.wfrp_master.common.core.ui.forms.InputValue
import cz.frantisekmasa.wfrp_master.common.core.ui.forms.SelectBox
import cz.frantisekmasa.wfrp_master.common.core.ui.forms.TextInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import androidx.compose.runtime.saveable.rememberSaveable
import com.benasher44.uuid.Uuid
import com.benasher44.uuid.uuid4
import cz.frantisekmasa.wfrp_master.common.Str
import cz.frantisekmasa.wfrp_master.common.core.domain.character.diseases.Countdown
import cz.frantisekmasa.wfrp_master.common.core.domain.character.Countdown
import cz.frantisekmasa.wfrp_master.common.core.domain.character.diseases.Disease
import cz.frantisekmasa.wfrp_master.common.core.ui.forms.FormDialog
import cz.frantisekmasa.wfrp_master.common.core.ui.forms.HydratedFormData
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
package cz.frantisekmasa.wfrp_master.common.character.skills

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.material.Divider
import androidx.compose.material.DropdownMenuItem
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.ListItem
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material.icons.rounded.Add
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -25,18 +20,14 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import com.benasher44.uuid.Uuid
import cz.frantisekmasa.wfrp_master.common.Str
import cz.frantisekmasa.wfrp_master.common.character.characterItemsCard
import cz.frantisekmasa.wfrp_master.common.character.skills.add.AddSkillScreen
import cz.frantisekmasa.wfrp_master.common.character.skills.addBasic.AddBasicSkillsScreen
import cz.frantisekmasa.wfrp_master.common.core.domain.identifiers.CharacterId
import cz.frantisekmasa.wfrp_master.common.core.shared.Resources
import cz.frantisekmasa.wfrp_master.common.core.ui.cards.CardTitle
import cz.frantisekmasa.wfrp_master.common.core.ui.cards.StickyHeader
import cz.frantisekmasa.wfrp_master.common.core.ui.menu.DropdownMenu
import cz.frantisekmasa.wfrp_master.common.core.ui.menu.WithContextMenu
import cz.frantisekmasa.wfrp_master.common.core.ui.navigation.LocalNavigationTransaction
import cz.frantisekmasa.wfrp_master.common.core.ui.primitives.ContextMenu
import cz.frantisekmasa.wfrp_master.common.core.ui.primitives.EmptyUI
import cz.frantisekmasa.wfrp_master.common.core.ui.primitives.Spacing
import dev.icerock.moko.resources.compose.stringResource
import kotlinx.collections.immutable.ImmutableList

Expand All @@ -45,114 +36,66 @@ internal fun LazyListScope.skillsCard(
skills: ImmutableList<SkillDataItem>,
onRemove: (SkillDataItem) -> Unit,
) {
stickyHeader(key = "skills-header") {
StickyHeader {
CardTitle(
stringResource(Str.skills_title_skills),
actions = {
var contextMenuExpanded by remember { mutableStateOf(false) }
val navigation = LocalNavigationTransaction.current

IconButton(
onClick = { navigation.navigate(AddSkillScreen(characterId)) },
) {
Icon(Icons.Rounded.Add, stringResource(Str.skills_title_add))
}

IconButton(onClick = { contextMenuExpanded = true }) {
Icon(
Icons.Filled.MoreVert,
stringResource(Str.common_ui_label_open_context_menu),
)
}

DropdownMenu(
expanded = contextMenuExpanded,
onDismissRequest = { contextMenuExpanded = false },
) {
DropdownMenuItem(
onClick = {
contextMenuExpanded = false
navigation.navigate(AddBasicSkillsScreen(characterId))
},
) {
Text(stringResource(Str.skills_button_import_basic_skills))
}
}
},
characterItemsCard(
title = { stringResource(Str.skills_title_skills) },
key = "skills",
id = SkillDataItem::id,
items = skills,
newItemScreen = { AddSkillScreen(characterId) },
noItems = {
EmptyUI(
text = stringResource(Str.skills_messages_character_has_no_skills),
icon = Resources.Drawable.Skill,
size = EmptyUI.Size.Small,
)
}
}
},
actions = {
var contextMenuExpanded by remember { mutableStateOf(false) }
val navigation = LocalNavigationTransaction.current

if (skills.isEmpty()) {
item(key = "skills-empty-ui") {
if (skills.isEmpty()) {
EmptyUI(
text = stringResource(Str.skills_messages_character_has_no_skills),
icon = Resources.Drawable.Skill,
size = EmptyUI.Size.Small,
IconButton(onClick = { contextMenuExpanded = true }) {
Icon(
Icons.Filled.MoreVert,
stringResource(Str.common_ui_label_open_context_menu),
)
}
}
}

itemsIndexed(skills, key = { _, it -> "skill" to it.id }) { index, skill ->
val navigation = LocalNavigationTransaction.current

SkillItem(
skill,
onClick = {
navigation.navigate(
CharacterSkillDetailScreen(
characterId,
skill.id,
),
)
},
onRemove = { onRemove(skill) },
showDivider = index != 0,
)
}
DropdownMenu(
expanded = contextMenuExpanded,
onDismissRequest = { contextMenuExpanded = false },
) {
DropdownMenuItem(
onClick = {
contextMenuExpanded = false
navigation.navigate(AddBasicSkillsScreen(characterId))
},
) {
Text(stringResource(Str.skills_button_import_basic_skills))
}
}
},
detailScreen = { skill -> CharacterSkillDetailScreen(characterId, skill.id) },
onRemove = onRemove,
item = { skill -> SkillItem(skill) },
)
}

@Composable
private fun SkillItem(
skill: SkillDataItem,
onClick: () -> Unit,
onRemove: () -> Unit,
showDivider: Boolean,
) {
Column(Modifier.padding(horizontal = Spacing.large)) {
if (showDivider) {
Divider()
}

WithContextMenu(
items =
listOf(
ContextMenu.Item(
stringResource(Str.common_ui_button_remove),
onClick = { onRemove() },
),
),
onClick = onClick,
) {
ListItem(
text = {
Text(
skill.name,
fontWeight =
if (skill.advances > 0) {
FontWeight.SemiBold
} else {
FontWeight.Normal
},
)
},
trailing = { TestNumber(skill.testNumber) },
private fun SkillItem(skill: SkillDataItem) {
ListItem(
text = {
Text(
skill.name,
fontWeight =
if (skill.advances > 0) {
FontWeight.SemiBold
} else {
FontWeight.Normal
},
)
}
}
},
trailing = { TestNumber(skill.testNumber) },
)
}

@Composable
Expand Down
Loading
Loading