diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index f4b7d80..63f1f92 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -19,7 +19,7 @@ android:name=".MainActivity" android:exported="true" android:windowSoftInputMode="adjustResize" - android:theme="@style/Theme.Triqui"> + android:theme="@style/LaunchTheme"> diff --git a/app/src/main/java/dev/alejo/triqui/data/network/FirebaseService.kt b/app/src/main/java/dev/alejo/triqui/data/network/FirebaseService.kt index 7f9a60c..d2d2e68 100644 --- a/app/src/main/java/dev/alejo/triqui/data/network/FirebaseService.kt +++ b/app/src/main/java/dev/alejo/triqui/data/network/FirebaseService.kt @@ -1,5 +1,6 @@ package dev.alejo.triqui.data.network +import android.util.Log import com.google.firebase.database.DatabaseReference import com.google.firebase.database.snapshots import dev.alejo.triqui.data.network.model.GameData @@ -29,6 +30,7 @@ class FirebaseService @Inject constructor(private val databaseRef: DatabaseRefer } fun updateGame(gameData: GameData) { + Log.d("=======UPDATE->", gameData.toString()) if (gameData.gameId != null) { databaseRef.child(PATH).child(gameData.gameId).setValue(gameData) } diff --git a/app/src/main/java/dev/alejo/triqui/data/network/model/GameData.kt b/app/src/main/java/dev/alejo/triqui/data/network/model/GameData.kt index 0146136..27e8b7b 100644 --- a/app/src/main/java/dev/alejo/triqui/data/network/model/GameData.kt +++ b/app/src/main/java/dev/alejo/triqui/data/network/model/GameData.kt @@ -8,29 +8,32 @@ import java.util.Calendar data class GameData( val board: List? = null, val gameId: String? = null, - val player1: PlayerData? = null, - val player2: PlayerData? = null, + val mainPlayer: PlayerData? = null, + val secondPlayer: PlayerData? = null, val playerTurn: PlayerData? = null, - val player1PlayAgain: Boolean = false, - val player2PlayAgain: Boolean = false + val victories: GameVictories? = null, + val mainPlayerPlayAgain: Boolean = false, + val secondPlayerPlayAgain: Boolean = false ) fun GameData.toModel(): GameModel = GameModel( board = board?.map { playerId -> PlayerType.getPlayerTypeById(playerId) } ?: mutableListOf(), gameId = gameId.orEmpty(), - player1 = player1!!.toModel(), - player2 = player2?.toModel(), + mainPlayer = mainPlayer!!.toModel(), + secondPlayer = secondPlayer?.toModel(), playerTurn = playerTurn!!.toModel(), - player1PlayAgain = player1PlayAgain, - player2PlayAgain = player2PlayAgain + victories = victories ?: GameVictories(), + mainPlayerPlayAgain = mainPlayerPlayAgain, + secondPlayerPlayAgain = secondPlayerPlayAgain ) data class PlayerData( val userId: String? = Calendar.getInstance().timeInMillis.hashCode().toString(), val playerType: Int? = null ) +data class GameVictories(val mainPlayer: Int = 0, val secondPlayer: Int = 0, val draw: Int = 0) fun PlayerData.toModel(): PlayerModel = PlayerModel( id = userId!!, playerType = PlayerType.getPlayerTypeById(playerType) -) \ No newline at end of file +) diff --git a/app/src/main/java/dev/alejo/triqui/ui/game/GameScreen.kt b/app/src/main/java/dev/alejo/triqui/ui/game/GameScreen.kt index 80479ba..7e6e7de 100644 --- a/app/src/main/java/dev/alejo/triqui/ui/game/GameScreen.kt +++ b/app/src/main/java/dev/alejo/triqui/ui/game/GameScreen.kt @@ -2,7 +2,6 @@ package dev.alejo.triqui.ui.game import android.content.Context import android.content.Intent -import androidx.annotation.StringRes import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement @@ -11,7 +10,6 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer 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 @@ -34,11 +32,11 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.hilt.navigation.compose.hiltViewModel import dev.alejo.triqui.R +import dev.alejo.triqui.ui.game.components.GameResult +import dev.alejo.triqui.ui.game.components.GameVictories import dev.alejo.triqui.ui.home.components.TriquiButton -import dev.alejo.triqui.ui.home.components.TriquiOutlinedButton import dev.alejo.triqui.ui.model.GameModel import dev.alejo.triqui.ui.model.PlayerType -import dev.alejo.triqui.ui.theme.Black80 import dev.alejo.triqui.ui.theme.Blue40 import dev.alejo.triqui.ui.theme.GeneralRoundCorner import dev.alejo.triqui.ui.theme.Gold80 @@ -59,13 +57,19 @@ fun GameScreen( val game: GameModel? by gameViewModel.game.collectAsState() val winner: PlayerType? by gameViewModel.winner.collectAsState() + val playerType = game?.let { + if (it.isGameReady) { + gameViewModel.getPlayer() + } else { + PlayerType.Main + } + } ?: PlayerType.Main if (winner != null) { - val playerType = gameViewModel.getPlayer() - WinnerResult( + GameResult( game = game!!, winner = winner!!, - playerType = playerType!!, + playerType = playerType, onGoHome = { onGoHome() }, onPlayAgain = { gameViewModel.onPlayAgain() } ) @@ -73,6 +77,7 @@ fun GameScreen( val context = LocalContext.current Game( game = game, + playerType = playerType, shareGameId = { shareGameId(context, game?.gameId) } @@ -82,19 +87,6 @@ fun GameScreen( } } -@Composable -fun WaitingToPlayAgain(@StringRes msg: Int) { - Row( - modifier = Modifier.fillMaxWidth().padding(vertical = 16.dp), - horizontalArrangement = Arrangement.Center, - verticalAlignment = Alignment.CenterVertically - ) { - CircularProgressIndicator(modifier = Modifier.size(24.dp)) - Spacer(Modifier.width(8.dp)) - Text(text = stringResource(msg)) - } -} - private fun shareGameId(context: Context, gameId: String?) { val sendIntent: Intent = Intent().apply { action = Intent.ACTION_SEND @@ -107,69 +99,24 @@ private fun shareGameId(context: Context, gameId: String?) { } @Composable -fun WinnerResult( - game: GameModel, - winner: PlayerType, +fun Game( + game: GameModel?, playerType: PlayerType, - onGoHome: () -> Unit, - onPlayAgain: () -> Unit + shareGameId: () -> Unit, + onPressed: (Int) -> Unit ) { - Column( - Modifier.fillMaxSize(), - verticalArrangement = Arrangement.Center, - horizontalAlignment = Alignment.CenterHorizontally - ) { - val gameResult = if (winner == PlayerType.Empty) { - stringResource(R.string.draw) - } else { - if (winner == playerType) { - stringResource(R.string.you_won) - } else { - stringResource(R.string.you_lost) - } - } - Text( - modifier = Modifier.padding(16.dp), - text = gameResult, - fontSize = 28.sp, - color = Black80, - fontWeight = FontWeight.Bold - ) - - when { - (game.player1PlayAgain && (playerType == PlayerType.Main)) - || (game.player2PlayAgain && (playerType == PlayerType.Second)) -> { - WaitingToPlayAgain(R.string.waiting_for_your_opponent) - } - - (game.player1PlayAgain && (playerType == PlayerType.Second)) - || (game.player2PlayAgain && (playerType == PlayerType.Main)) -> { - WaitingToPlayAgain(R.string.opponent_wants_to_play_again) - } - } - - Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center) { - TriquiOutlinedButton(icon = R.drawable.ic_home, text = R.string.go_home) { - onGoHome() - } - Spacer(Modifier.width(16.dp)) - TriquiButton(icon = R.drawable.ic_restart, text = R.string.play_again) { - onPlayAgain() - } - } - } -} - -@Composable -fun Game(game: GameModel?, shareGameId: () -> Unit, onPressed: (Int) -> Unit) { if (game == null) return Column(Modifier.fillMaxSize(), horizontalAlignment = Alignment.CenterHorizontally) { Spacer(modifier = Modifier.weight(0.5f)) GameStatus(game) Spacer(modifier = Modifier.weight(1f)) + GameVictories(gameVictories = game.victories, playerType = playerType) + Spacer(modifier = Modifier.weight(1f)) Board(game) { position -> onPressed(position) } Spacer(modifier = Modifier.weight(1f)) - ShareGame { shareGameId() } + if (playerType == PlayerType.Main) { + ShareGame { shareGameId() } + } Spacer(modifier = Modifier.weight(0.5f)) } } diff --git a/app/src/main/java/dev/alejo/triqui/ui/game/GameViewModel.kt b/app/src/main/java/dev/alejo/triqui/ui/game/GameViewModel.kt index df4db16..5b4fac5 100644 --- a/app/src/main/java/dev/alejo/triqui/ui/game/GameViewModel.kt +++ b/app/src/main/java/dev/alejo/triqui/ui/game/GameViewModel.kt @@ -38,7 +38,7 @@ class GameViewModel @Inject constructor(private val firebaseService: FirebaseSer firebaseService.joinToGame(gameId).take(1).collect { game -> game?.let { val gameResult = it.copy( - player2 = PlayerModel( + secondPlayer = PlayerModel( id = playerId, playerType = PlayerType.Second ) @@ -55,15 +55,15 @@ class GameViewModel @Inject constructor(private val firebaseService: FirebaseSer viewModelScope.launch { firebaseService.joinToGame(gameId).collect { game -> val gameResult = game?.copy( - isGameReady = game.player2 != null, + isGameReady = game.secondPlayer != null, isMyTurn = isMyTurn(game.playerTurn) ) _game.value = gameResult gameResult?.let { - if (it.player1PlayAgain && it.player2PlayAgain) { - onRestartGame() + when { + (it.mainPlayerPlayAgain && it.secondPlayerPlayAgain) -> resetGameData() + (!it.mainPlayerPlayAgain && !it.secondPlayerPlayAgain) -> verifyWinner() } - verifyWinner() } } } @@ -97,14 +97,31 @@ class GameViewModel @Inject constructor(private val firebaseService: FirebaseSer if (boardData.size == 9) { when { isGameWon(board, PlayerType.Main) -> { + val mainVictories = _game.value!!.victories.mainPlayer + val victoriesUpdated = _game.value!!.victories.copy( + mainPlayer = mainVictories + 1 + ) + _game.value = _game.value!!.copy(victories = victoriesUpdated) _winner.value = PlayerType.Main } isGameWon(board, PlayerType.Second) -> { + val secondVictories = _game.value!!.victories.secondPlayer + val victoriesUpdated = _game.value!!.victories.copy( + secondPlayer = secondVictories + 1 + ) + _game.value = _game.value!!.copy(victories = victoriesUpdated) _winner.value = PlayerType.Second } - !boardIsNotComplete -> _winner.value = PlayerType.Empty + !boardIsNotComplete -> { + val drawVictories = _game.value!!.victories.draw + val victoriesUpdated = _game.value!!.victories.copy( + draw = drawVictories + 1 + ) + _game.value = _game.value!!.copy(victories = victoriesUpdated) + _winner.value = PlayerType.Empty + } } } } ?: return @@ -132,37 +149,37 @@ class GameViewModel @Inject constructor(private val firebaseService: FirebaseSer } fun getPlayer(): PlayerType? = when { - (game.value?.player1?.id == playerId) -> PlayerType.Main - (game.value?.player2?.id == playerId) -> PlayerType.Second + (game.value?.mainPlayer?.id == playerId) -> PlayerType.Main + (game.value?.secondPlayer?.id == playerId) -> PlayerType.Second else -> null } private fun getOpponentPlayer(): PlayerModel? { - return if (game.value?.player1?.id == playerId) game.value?.player2 else game.value?.player1 + return if (game.value?.mainPlayer?.id == playerId) game.value?.secondPlayer else game.value?.mainPlayer } fun onPlayAgain() { viewModelScope.launch { val gameUpdated = if (getPlayer() == PlayerType.Main) { - game.value!!.copy( - player1PlayAgain = true, + _game.value!!.copy( + mainPlayerPlayAgain = true, ) } else { - game.value!!.copy( - player2PlayAgain = true, + _game.value!!.copy( + secondPlayerPlayAgain = true, ) } firebaseService.updateGame(gameUpdated.toData()) } } - private fun onRestartGame() { + private fun resetGameData() { _winner.value = null val boardUpdated = _game.value!!.board.toMutableList().map { PlayerType.Empty } _game.value = _game.value!!.copy( board = boardUpdated, - player1PlayAgain = false, - player2PlayAgain = false + mainPlayerPlayAgain = false, + secondPlayerPlayAgain = false ) } diff --git a/app/src/main/java/dev/alejo/triqui/ui/game/components/GameResult.kt b/app/src/main/java/dev/alejo/triqui/ui/game/components/GameResult.kt new file mode 100644 index 0000000..a6f71b9 --- /dev/null +++ b/app/src/main/java/dev/alejo/triqui/ui/game/components/GameResult.kt @@ -0,0 +1,113 @@ +package dev.alejo.triqui.ui.game.components + +import androidx.annotation.StringRes +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +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.material3.CircularProgressIndicator +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import dev.alejo.triqui.R +import dev.alejo.triqui.ui.home.components.TriquiButton +import dev.alejo.triqui.ui.home.components.TriquiOutlinedButton +import dev.alejo.triqui.ui.model.GameModel +import dev.alejo.triqui.ui.model.PlayerType +import dev.alejo.triqui.ui.theme.Black80 + +@Composable +fun GameResult( + game: GameModel, + winner: PlayerType, + playerType: PlayerType, + onGoHome: () -> Unit, + onPlayAgain: () -> Unit +) { + Column( + Modifier.fillMaxSize(), + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally + ) { + VictoryResult(winner, playerType) + Spacer(modifier = Modifier.height(16.dp)) + GameVictories(gameVictories = game.victories, playerType = playerType) + Spacer(modifier = Modifier.height(16.dp)) + PlayAgainStatus(game, playerType) + GameOptions(onGoHome, onPlayAgain) + } +} + +@Composable +fun GameOptions(onGoHome: () -> Unit, onPlayAgain: () -> Unit) { + Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center) { + TriquiOutlinedButton(icon = R.drawable.ic_home, text = R.string.go_home) { + onGoHome() + } + Spacer(Modifier.width(16.dp)) + TriquiButton(icon = R.drawable.ic_restart, text = R.string.play_again) { + onPlayAgain() + } + } +} + +@Composable +fun PlayAgainStatus(game: GameModel, playerType: PlayerType) { + when { + (game.mainPlayerPlayAgain && (playerType == PlayerType.Main)) + || (game.secondPlayerPlayAgain && (playerType == PlayerType.Second)) -> { + WaitingToPlayAgain(R.string.waiting_for_your_opponent) + } + + (game.mainPlayerPlayAgain && (playerType == PlayerType.Second)) + || (game.secondPlayerPlayAgain && (playerType == PlayerType.Main)) -> { + WaitingToPlayAgain(R.string.opponent_wants_to_play_again) + } + } +} + +@Composable +private fun WaitingToPlayAgain(@StringRes msg: Int) { + Row( + modifier = Modifier + .fillMaxWidth() + .padding(vertical = 16.dp), + horizontalArrangement = Arrangement.Center, + verticalAlignment = Alignment.CenterVertically + ) { + CircularProgressIndicator(modifier = Modifier.size(24.dp)) + Spacer(Modifier.width(8.dp)) + Text(text = stringResource(msg)) + } +} + +@Composable +private fun VictoryResult(winner: PlayerType, playerType: PlayerType) { + val gameResult = if (winner == PlayerType.Empty) { + stringResource(R.string.draw) + } else { + if (winner == playerType) { + stringResource(R.string.you_won) + } else { + stringResource(R.string.you_lost) + } + } + Text( + modifier = Modifier.padding(16.dp), + text = gameResult, + fontSize = 28.sp, + color = Black80, + fontWeight = FontWeight.Bold + ) +} \ No newline at end of file diff --git a/app/src/main/java/dev/alejo/triqui/ui/game/components/GameVictories.kt b/app/src/main/java/dev/alejo/triqui/ui/game/components/GameVictories.kt new file mode 100644 index 0000000..1f02e79 --- /dev/null +++ b/app/src/main/java/dev/alejo/triqui/ui/game/components/GameVictories.kt @@ -0,0 +1,101 @@ +package dev.alejo.triqui.ui.game.components + +import androidx.annotation.StringRes +import androidx.compose.foundation.background +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.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.shape.RoundedCornerShape +import androidx.compose.material3.Divider +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.res.stringResource +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import dev.alejo.triqui.R +import dev.alejo.triqui.data.network.model.GameVictories +import dev.alejo.triqui.ui.model.PlayerType +import dev.alejo.triqui.ui.theme.Black80 +import dev.alejo.triqui.ui.theme.Gold40 +import dev.alejo.triqui.ui.theme.Gold80 +import dev.alejo.triqui.ui.theme.SmallRoundCorner +import dev.alejo.triqui.ui.theme.TransparentBlack80 +import dev.alejo.triqui.ui.theme.TransparentGold10 + +@Composable +fun GameVictories(gameVictories: GameVictories, playerType: PlayerType) { + if (playerType == PlayerType.Main) { + GameVictoriesBoard( + victories = gameVictories.mainPlayer, + draw = gameVictories.draw, + lost = gameVictories.secondPlayer + ) + } else { + GameVictoriesBoard( + victories = gameVictories.secondPlayer, + draw = gameVictories.draw, + lost = gameVictories.mainPlayer + ) + } +} + +@Composable +fun GameVictoriesBoard(victories: Int, draw: Int, lost: Int) { + Column(modifier = Modifier.padding(8.dp), horizontalAlignment = Alignment.CenterHorizontally) { + Text( + text = stringResource(id = R.string.results), + fontSize = 18.sp, + color = Black80 + ) + Row( + Modifier.fillMaxWidth(), + horizontalArrangement = Arrangement.Center, + verticalAlignment = Alignment.CenterVertically + ) { + VictoryItem(victories = victories.toString(), R.string.won) + VerticalDivider() + VictoryItem(victories = draw.toString(), R.string.draw) + VerticalDivider() + VictoryItem(victories = lost.toString(), R.string.lost) + } + } +} + +@Composable +fun VictoryItem(victories: String, @StringRes msg: Int) { + Column(horizontalAlignment = Alignment.CenterHorizontally) { + Box( + Modifier + .size(72.dp) + .padding(8.dp) + .clip(RoundedCornerShape(SmallRoundCorner)) + .background(TransparentGold10), + contentAlignment = Alignment.Center + ) { + Text(text = victories, fontSize = 26.sp, fontWeight = FontWeight.Bold, color = Gold80) + } + Text( + text = stringResource(id = msg), + color = Gold40 + ) + } +} + +@Composable +private fun VerticalDivider() { + Divider( + modifier = Modifier + .height(72.dp) + .width(1.dp), thickness = 1.dp, color = TransparentBlack80 + ) +} \ No newline at end of file diff --git a/app/src/main/java/dev/alejo/triqui/ui/home/HomeViewModel.kt b/app/src/main/java/dev/alejo/triqui/ui/home/HomeViewModel.kt index 729e608..31167f6 100644 --- a/app/src/main/java/dev/alejo/triqui/ui/home/HomeViewModel.kt +++ b/app/src/main/java/dev/alejo/triqui/ui/home/HomeViewModel.kt @@ -17,7 +17,7 @@ class HomeViewModel @Inject constructor( fun onCreateGame(navigateToGame: (String, String, Boolean) -> Unit) { val game = createNewGame() val gameId = firebaseService.createGame(game) - val userId = game.player1?.userId.orEmpty() + val userId = game.mainPlayer?.userId.orEmpty() val isOwner = true navigateToGame(gameId, userId, isOwner) } @@ -33,9 +33,9 @@ class HomeViewModel @Inject constructor( val currentPlayer = PlayerData(playerType = PlayerType.Main.id) return GameData( board = List(9) { 0 }, - player1 = currentPlayer, + mainPlayer = currentPlayer, playerTurn = currentPlayer, - player2 = null + secondPlayer = null ) } diff --git a/app/src/main/java/dev/alejo/triqui/ui/home/components/TriquiButton.kt b/app/src/main/java/dev/alejo/triqui/ui/home/components/TriquiButton.kt index b523844..12e33c6 100644 --- a/app/src/main/java/dev/alejo/triqui/ui/home/components/TriquiButton.kt +++ b/app/src/main/java/dev/alejo/triqui/ui/home/components/TriquiButton.kt @@ -2,10 +2,13 @@ package dev.alejo.triqui.ui.home.components import androidx.annotation.DrawableRes import androidx.annotation.StringRes +import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Row import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.Button +import androidx.compose.material3.ButtonColors +import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.Icon import androidx.compose.material3.OutlinedButton import androidx.compose.material3.Text @@ -14,8 +17,11 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource +import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +import dev.alejo.triqui.R import dev.alejo.triqui.ui.theme.GeneralRoundCorner +import dev.alejo.triqui.ui.theme.Gold40 @Composable fun TriquiButton( @@ -31,18 +37,7 @@ fun TriquiButton( onClick = { onClick() }, enabled = enabled ) { - Row( - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.spacedBy(8.dp) - ) { - Icon( - painter = painterResource(id = icon), - contentDescription = stringResource( - id = text - ) - ) - Text(text = stringResource(id = text)) - } + TriquiButtonContent(icon, text) } } @@ -57,20 +52,32 @@ fun TriquiOutlinedButton( OutlinedButton( modifier = modifier, shape = RoundedCornerShape(GeneralRoundCorner), + border = BorderStroke(width = 1.dp, color = Gold40), onClick = { onClick() }, enabled = enabled ) { - Row( - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.spacedBy(8.dp) - ) { - Icon( - painter = painterResource(id = icon), - contentDescription = stringResource( - id = text - ) + TriquiButtonContent(icon, text) + } +} + +@Composable +private fun TriquiButtonContent(@DrawableRes icon: Int, @StringRes text: Int) { + Row( + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(8.dp) + ) { + Icon( + painter = painterResource(id = icon), + contentDescription = stringResource( + id = text ) - Text(text = stringResource(id = text)) - } + ) + Text(text = stringResource(id = text)) } +} + +@Preview +@Composable +fun PreviewButton() { + TriquiOutlinedButton(icon = R.drawable.ic_join, text = R.string.draw) { } } \ No newline at end of file diff --git a/app/src/main/java/dev/alejo/triqui/ui/model/GameModel.kt b/app/src/main/java/dev/alejo/triqui/ui/model/GameModel.kt index 3102bc1..93e94e4 100644 --- a/app/src/main/java/dev/alejo/triqui/ui/model/GameModel.kt +++ b/app/src/main/java/dev/alejo/triqui/ui/model/GameModel.kt @@ -1,27 +1,30 @@ package dev.alejo.triqui.ui.model import dev.alejo.triqui.data.network.model.GameData +import dev.alejo.triqui.data.network.model.GameVictories import dev.alejo.triqui.data.network.model.PlayerData data class GameModel( val gameId: String, val board: List, - val player1: PlayerModel, - val player2: PlayerModel?, + val mainPlayer: PlayerModel, + val secondPlayer: PlayerModel?, val playerTurn: PlayerModel, val isGameReady: Boolean = false, val isMyTurn: Boolean = false, - val player1PlayAgain: Boolean = false, - val player2PlayAgain: Boolean = false + val victories: GameVictories, + val mainPlayerPlayAgain: Boolean = false, + val secondPlayerPlayAgain: Boolean = false ) { fun toData(): GameData = GameData( board = board.map { it.id }, gameId = gameId, - player1 = player1.toData(), - player2 = player2?.toData(), + mainPlayer = mainPlayer.toData(), + secondPlayer = secondPlayer?.toData(), playerTurn = playerTurn.toData(), - player1PlayAgain = player1PlayAgain, - player2PlayAgain = player2PlayAgain + victories = victories, + mainPlayerPlayAgain = mainPlayerPlayAgain, + secondPlayerPlayAgain = secondPlayerPlayAgain ) } diff --git a/app/src/main/java/dev/alejo/triqui/ui/theme/Shape.kt b/app/src/main/java/dev/alejo/triqui/ui/theme/Shape.kt index 86cbe08..c8dd860 100644 --- a/app/src/main/java/dev/alejo/triqui/ui/theme/Shape.kt +++ b/app/src/main/java/dev/alejo/triqui/ui/theme/Shape.kt @@ -2,4 +2,5 @@ package dev.alejo.triqui.ui.theme import androidx.compose.ui.unit.dp -val GeneralRoundCorner = 24.dp \ No newline at end of file +val GeneralRoundCorner = 24.dp +val SmallRoundCorner = 18.dp \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000..345888d --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000..b698387 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..aed5470 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/app/src/main/res/mipmap-hdpi/ic_launcher.webp deleted file mode 100644 index c209e78..0000000 Binary files a/app/src/main/res/mipmap-hdpi/ic_launcher.webp and /dev/null differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_background.png b/app/src/main/res/mipmap-hdpi/ic_launcher_background.png new file mode 100644 index 0000000..2fdcf28 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_background.png differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png b/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png new file mode 100644 index 0000000..0c49248 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_monochrome.png b/app/src/main/res/mipmap-hdpi/ic_launcher_monochrome.png new file mode 100644 index 0000000..0c49248 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_monochrome.png differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png new file mode 100644 index 0000000..0be8a81 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp deleted file mode 100644 index b2dfe3d..0000000 Binary files a/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp and /dev/null differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round_background.png b/app/src/main/res/mipmap-hdpi/ic_launcher_round_background.png new file mode 100644 index 0000000..2fdcf28 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_round_background.png differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round_foreground.png b/app/src/main/res/mipmap-hdpi/ic_launcher_round_foreground.png new file mode 100644 index 0000000..0c49248 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_round_foreground.png differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round_monochrome.png b/app/src/main/res/mipmap-hdpi/ic_launcher_round_monochrome.png new file mode 100644 index 0000000..0c49248 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_round_monochrome.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..801e81a Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/app/src/main/res/mipmap-mdpi/ic_launcher.webp deleted file mode 100644 index 4f0f1d6..0000000 Binary files a/app/src/main/res/mipmap-mdpi/ic_launcher.webp and /dev/null differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_background.png b/app/src/main/res/mipmap-mdpi/ic_launcher_background.png new file mode 100644 index 0000000..d49793e Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_background.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png b/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png new file mode 100644 index 0000000..e7663fd Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_monochrome.png b/app/src/main/res/mipmap-mdpi/ic_launcher_monochrome.png new file mode 100644 index 0000000..e7663fd Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_monochrome.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png new file mode 100644 index 0000000..a185f7c Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp deleted file mode 100644 index 62b611d..0000000 Binary files a/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp and /dev/null differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round_background.png b/app/src/main/res/mipmap-mdpi/ic_launcher_round_background.png new file mode 100644 index 0000000..d49793e Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_round_background.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round_foreground.png b/app/src/main/res/mipmap-mdpi/ic_launcher_round_foreground.png new file mode 100644 index 0000000..e7663fd Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_round_foreground.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round_monochrome.png b/app/src/main/res/mipmap-mdpi/ic_launcher_round_monochrome.png new file mode 100644 index 0000000..e7663fd Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_round_monochrome.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..1bb6bac Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xhdpi/ic_launcher.webp deleted file mode 100644 index 948a307..0000000 Binary files a/app/src/main/res/mipmap-xhdpi/ic_launcher.webp and /dev/null differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_background.png b/app/src/main/res/mipmap-xhdpi/ic_launcher_background.png new file mode 100644 index 0000000..ffb8a2b Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_background.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png b/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png new file mode 100644 index 0000000..d4749c8 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_monochrome.png b/app/src/main/res/mipmap-xhdpi/ic_launcher_monochrome.png new file mode 100644 index 0000000..d4749c8 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_monochrome.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png new file mode 100644 index 0000000..d28a4e2 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp deleted file mode 100644 index 1b9a695..0000000 Binary files a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp and /dev/null differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round_background.png b/app/src/main/res/mipmap-xhdpi/ic_launcher_round_background.png new file mode 100644 index 0000000..ffb8a2b Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_round_background.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round_foreground.png b/app/src/main/res/mipmap-xhdpi/ic_launcher_round_foreground.png new file mode 100644 index 0000000..d4749c8 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_round_foreground.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round_monochrome.png b/app/src/main/res/mipmap-xhdpi/ic_launcher_round_monochrome.png new file mode 100644 index 0000000..d4749c8 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_round_monochrome.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..12457c2 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp deleted file mode 100644 index 28d4b77..0000000 Binary files a/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp and /dev/null differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_background.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher_background.png new file mode 100644 index 0000000..78b58db Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_background.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png new file mode 100644 index 0000000..8720237 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_monochrome.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher_monochrome.png new file mode 100644 index 0000000..8720237 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_monochrome.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..13605ce Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp deleted file mode 100644 index 9287f50..0000000 Binary files a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp and /dev/null differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round_background.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round_background.png new file mode 100644 index 0000000..78b58db Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round_background.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round_foreground.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round_foreground.png new file mode 100644 index 0000000..8720237 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round_foreground.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round_monochrome.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round_monochrome.png new file mode 100644 index 0000000..8720237 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round_monochrome.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..88d1f20 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp deleted file mode 100644 index aa7d642..0000000 Binary files a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp and /dev/null differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_background.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_background.png new file mode 100644 index 0000000..806aca4 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_background.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png new file mode 100644 index 0000000..9e61302 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_monochrome.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_monochrome.png new file mode 100644 index 0000000..9e61302 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_monochrome.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..bba4ff6 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp deleted file mode 100644 index 9126ae3..0000000 Binary files a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp and /dev/null differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round_background.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round_background.png new file mode 100644 index 0000000..806aca4 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round_background.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round_foreground.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round_foreground.png new file mode 100644 index 0000000..9e61302 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round_foreground.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round_monochrome.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round_monochrome.png new file mode 100644 index 0000000..9e61302 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round_monochrome.png differ diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 29f1fa4..c51d592 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -13,6 +13,9 @@ You lost Play again Go home - Draw Your opponent wants to play again + Draw + Won + Lost + Results \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 79e4860..8b9ca03 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -1,7 +1,10 @@ - \ No newline at end of file