Skip to content

Commit

Permalink
Merge pull request #7 from kaszabimre/core-domain
Browse files Browse the repository at this point in the history
chore: add core and domain modules
  • Loading branch information
kaszabimre authored Oct 5, 2024
2 parents aa7c0f7 + 613e693 commit 8b115ba
Show file tree
Hide file tree
Showing 29 changed files with 333 additions and 187 deletions.
3 changes: 2 additions & 1 deletion composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ kotlin {
baseName = "ComposeApp"
}
}

sourceSets {
androidMain.dependencies {
implementation(compose.preview)
implementation(libs.androidx.activity.compose)
}
commonMain.dependencies {
implementation(project(":modules:core"))
implementation(project(":modules:domain"))
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material3)
Expand Down
2 changes: 1 addition & 1 deletion composeApp/src/commonMain/kotlin/widget/AbilityItemView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fun AbilityItemView(ability: PlayerAbility) {
Text(
text = ability.label,
style = AppTheme.typography.body.large.copy(fontWeight = FontWeight.Bold),
color = AppTheme.colorScheme.onBackground
color = AppTheme.colors.yellow.light2
)
}
}
172 changes: 18 additions & 154 deletions composeApp/src/commonMain/kotlin/widget/PlayerDetailView.kt
Original file line number Diff line number Diff line change
@@ -1,46 +1,25 @@
package widget

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
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.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.CheckCircle
import androidx.compose.material.icons.filled.Menu
import androidx.compose.material.icons.filled.Star
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import coil3.compose.AsyncImage
import eaplayers.composeapp.generated.resources.Res
import eaplayers.composeapp.generated.resources.abilities
import eaplayers.composeapp.generated.resources.height
import eaplayers.composeapp.generated.resources.nationality
import eaplayers.composeapp.generated.resources.player_image_desc
import eaplayers.composeapp.generated.resources.player_rank
import eaplayers.composeapp.generated.resources.position
import eaplayers.composeapp.generated.resources.rating
import eaplayers.composeapp.generated.resources.team
import eaplayers.composeapp.generated.resources.team_mates
import io.imrekaszab.eaplayers.domain.model.Player
import org.jetbrains.compose.resources.stringResource
import theme.AppTheme
Expand Down Expand Up @@ -79,28 +58,6 @@ fun PlayerDetailView(
}
}

@Composable
fun PlayerImage(player: Player) {
Box(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = AppTheme.dimens.margin.default)
.aspectRatio(1f)
.clip(AppTheme.shapes.default.roundedDefault)
.background(AppTheme.colorScheme.surface)
) {
AsyncImage(
model = player.shieldUrl,
contentDescription = stringResource(
Res.string.player_image_desc,
player.firstName,
player.lastName
),
modifier = Modifier.fillMaxSize()
)
}
}

@Composable
fun PlayerInfoSection(player: Player) {
Column(
Expand All @@ -110,7 +67,8 @@ fun PlayerInfoSection(player: Player) {
Text(
text = "${player.firstName} ${player.lastName}",
style = AppTheme.typography.heading.large,
color = AppTheme.colorScheme.onBackground
color = AppTheme.colorScheme.onBackground,
textAlign = TextAlign.Center
)
Text(
text = stringResource(Res.string.player_rank, player.rank),
Expand All @@ -133,122 +91,28 @@ fun PlayerInfoSection(player: Player) {
}
}

@Composable
fun PlayerStatsRow(player: Player) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
) {
PlayerStatItem(
icon = Icons.Default.Star,
stat = player.overallRating.toString(),
label = stringResource(Res.string.rating)
)
PlayerStatItem(
icon = Icons.Default.Menu,
stat = player.position.shortLabel,
label = stringResource(Res.string.position)
)
PlayerStatItem(
icon = Icons.Default.CheckCircle,
stat = "${player.height} cm",
label = stringResource(Res.string.height)
)
}
}

@Composable
fun AbilitiesSection(player: Player) {
if (player.playerAbilities.isNotEmpty()) {
Text(
text = stringResource(Res.string.abilities),
style = AppTheme.typography.heading.medium,
color = AppTheme.colorScheme.onBackground
)
Spacer(modifier = Modifier.height(AppTheme.dimens.margin.tiny))

player.playerAbilities.forEach { ability ->
AbilityItemView(ability)
}
}
}

@Composable
fun TeamMatesSection(player: Player, onTeamMateSelected: (Player) -> Unit) {
Text(
text = stringResource(Res.string.team_mates),
style = AppTheme.typography.heading.medium,
color = AppTheme.colorScheme.onBackground
)
Spacer(modifier = Modifier.height(AppTheme.dimens.margin.tiny))

Box(
modifier = Modifier
.fillMaxWidth()
.height(AppTheme.dimens.playerDetailView.boxSize)
) {
LazyVerticalGrid(
columns = GridCells.Adaptive(minSize = AppTheme.dimens.playerDetailView.gridMinSize)
) {
items(
player.teamMates.filter { it.id != player.id }
.sortedByDescending { it.overallRating }
) { mate ->
TeamMateCard(mate = mate, onTeamMateSelected = onTeamMateSelected)
}
}
}
}

@Composable
fun TeamMateCard(mate: Player, onTeamMateSelected: (Player) -> Unit) {
Column(
modifier = Modifier
.padding(AppTheme.dimens.margin.tiny)
.width(AppTheme.dimens.playerDetailView.cardWidth)
.clickable { onTeamMateSelected(mate) },
horizontalAlignment = Alignment.CenterHorizontally
) {
AsyncImage(
modifier = Modifier
.size(AppTheme.dimens.playerDetailView.imageSize)
.clip(AppTheme.shapes.default.circle),
model = mate.avatarUrl,
contentDescription = mate.lastName
)
Spacer(modifier = Modifier.height(AppTheme.dimens.margin.tiny))
Text(
text = mate.commonName ?: "${mate.firstName}. ${mate.lastName.first()}",
textAlign = TextAlign.Center,
style = AppTheme.typography.body.small.copy(fontWeight = FontWeight.Bold),
color = AppTheme.colorScheme.onSurface
)
Text(
text = mate.position.shortLabel,
style = AppTheme.typography.body.small,
color = AppTheme.colorScheme.onSurface
)
}
}

@Composable
fun PlayerStatRow(statItems: List<PlayerStat>) {
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceEvenly
.clip(AppTheme.shapes.default.roundedDefault)
.background(
color = AppTheme.colors.blue.default,
shape = AppTheme.shapes.default.roundedDefault
)
.padding(AppTheme.dimens.margin.default)
) {
statItems.forEach { statItem ->
PlayerStatItem(
imageUrl = statItem.imageUrl,
stat = statItem.stat,
label = statItem.label
if (player.playerAbilities.isNotEmpty()) {
Text(
text = stringResource(Res.string.abilities),
style = AppTheme.typography.heading.medium,
color = AppTheme.colors.yellow.default
)
Spacer(modifier = Modifier.height(AppTheme.dimens.margin.tiny))

player.playerAbilities.forEach { ability ->
AbilityItemView(ability)
}
}
}
}

data class PlayerStat(
val imageUrl: String,
val stat: String,
val label: String
)
39 changes: 39 additions & 0 deletions composeApp/src/commonMain/kotlin/widget/PlayerImage.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package widget

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import coil3.compose.AsyncImage
import eaplayers.composeapp.generated.resources.Res
import eaplayers.composeapp.generated.resources.player_image_desc
import io.imrekaszab.eaplayers.domain.model.Player
import org.jetbrains.compose.resources.stringResource
import theme.AppTheme

@Composable
fun PlayerImage(player: Player) {
Box(
modifier = Modifier
.fillMaxWidth()
.padding(vertical = AppTheme.dimens.margin.default)
.aspectRatio(1f)
.clip(AppTheme.shapes.default.roundedDefault)
.background(AppTheme.colorScheme.surface)
) {
AsyncImage(
model = player.shieldUrl,
contentDescription = stringResource(
Res.string.player_image_desc,
player.firstName,
player.lastName
),
modifier = Modifier.fillMaxSize()
)
}
}
4 changes: 2 additions & 2 deletions composeApp/src/commonMain/kotlin/widget/PlayerStatItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ fun PlayerStatItem(imageUrl: String, stat: String, label: String) {
Text(
text = stat,
style = AppTheme.typography.body.large,
color = AppTheme.colorScheme.onSurface
color = AppTheme.colors.yellow.default
)
Text(
text = label,
style = AppTheme.typography.body.small,
color = AppTheme.colorScheme.onSurfaceVariant
color = AppTheme.colors.yellow.light1
)
}
}
Expand Down
76 changes: 76 additions & 0 deletions composeApp/src/commonMain/kotlin/widget/PlayerStatRow.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package widget

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.KeyboardArrowUp
import androidx.compose.material.icons.filled.Menu
import androidx.compose.material.icons.filled.Star
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import eaplayers.composeapp.generated.resources.Res
import eaplayers.composeapp.generated.resources.height
import eaplayers.composeapp.generated.resources.position
import eaplayers.composeapp.generated.resources.rating
import io.imrekaszab.eaplayers.domain.model.Player
import org.jetbrains.compose.resources.stringResource
import theme.AppTheme

@Composable
fun PlayerStatsRow(player: Player) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = AppTheme.dimens.margin.default),
horizontalArrangement = Arrangement.SpaceBetween
) {
PlayerStatItem(
icon = Icons.Default.Star,
stat = player.overallRating.toString(),
label = stringResource(Res.string.rating)
)
PlayerStatItem(
icon = Icons.Default.Menu,
stat = player.position.shortLabel,
label = stringResource(Res.string.position)
)
PlayerStatItem(
icon = Icons.Default.KeyboardArrowUp,
stat = "${player.height} cm",
label = stringResource(Res.string.height)
)
}
}

@Composable
fun PlayerStatRow(statItems: List<PlayerStat>) {
Row(
modifier = Modifier
.fillMaxWidth()
.clip(AppTheme.shapes.default.roundedDefault)
.background(
color = AppTheme.colors.blue.default,
shape = AppTheme.shapes.default.roundedDefault
)
.padding(AppTheme.dimens.margin.default),
horizontalArrangement = Arrangement.SpaceEvenly
) {
statItems.forEach { statItem ->
PlayerStatItem(
imageUrl = statItem.imageUrl,
stat = statItem.stat,
label = statItem.label
)
}
}
}

data class PlayerStat(
val imageUrl: String,
val stat: String,
val label: String
)
Loading

0 comments on commit 8b115ba

Please sign in to comment.