Skip to content

Commit

Permalink
- Compose to 1.6.0-rc01 (#2)
Browse files Browse the repository at this point in the history
- Update to Compose 1.6.0-rc01
- Add string resources
  • Loading branch information
andremion authored Feb 16, 2024
1 parent 3b16cb2 commit 5e0a8f9
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 78 deletions.
20 changes: 18 additions & 2 deletions androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
/*
* Copyright 2024. André Luiz Oliveira Rêgo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
alias(libs.plugins.kotlinAndroid)
alias(libs.plugins.jetbrainsCompose)
alias(libs.plugins.androidApplication)
alias(libs.plugins.jetbrainsCompose)
}

android {
Expand All @@ -13,7 +29,7 @@ android {
minSdk = libs.versions.android.minSdk.get().toInt()
targetSdk = libs.versions.android.targetSdk.get().toInt()
versionCode = 3
versionName = "1.0.0"
versionName = "0.1.0"
vectorDrawables {
useSupportLibrary = true
}
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[versions]
agp = "8.2.2"
kotlin = "1.9.21"
kotlin = "1.9.22"
kotlinx-coroutines = "1.7.3"
kotlinx-datetime = "0.5.0"
android-minSdk = "26"
android-compileSdk = "34"
android-targetSdk = "34"
androidx-activityCompose = "1.8.2"
jetbrains-compose = "1.5.11"
jetbrains-compose = "1.6.0-rc01"
koin = "3.5.3"
koin-compose = "1.1.2"
precompose = "1.5.10"
Expand Down
4 changes: 2 additions & 2 deletions iosApp/iosApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.0;
MARKETING_VERSION = 0.1.0;
OTHER_LDFLAGS = (
"$(inherited)",
"-framework",
Expand Down Expand Up @@ -367,7 +367,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0.0;
MARKETING_VERSION = 0.1.0;
OTHER_LDFLAGS = (
"$(inherited)",
"-framework",
Expand Down
3 changes: 2 additions & 1 deletion shared/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
alias(libs.plugins.kotlinMultiplatform)
alias(libs.plugins.jetbrainsCompose)
alias(libs.plugins.androidLibrary)
alias(libs.plugins.jetbrainsCompose)
}

kotlin {
Expand All @@ -28,6 +28,7 @@ kotlin {
commonMain.dependencies {
implementation(compose.material3)
implementation(compose.materialIconsExtended)
implementation(compose.components.resources)

implementation(libs.kotlinx.coroutines)
implementation(libs.kotlinx.datetime)
Expand Down
12 changes: 12 additions & 0 deletions shared/src/commonMain/composeResources/values-pt/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<resources>
<string name="game_hint_button">Dica</string>
<string name="game_goal_button">Objetivo</string>
<string name="game_replay_button">Replay</string>
<string name="game_resume_button">Resumir contador</string>
<string name="game_pause_button">Pausar contador</string>
<string name="game_stats_timer_label">Contador</string>
<string name="game_moves_away_message">O objetivo está a %1$d movimentos de distância</string>
<string name="game_dialog_dismiss_button">OK</string>
<string name="game_dialog_goal_title">O objetivo é alcançar este estado</string>
<string name="game_dialog_congratulations_title">Parabéns!!! 🎉🥳</string>
</resources>
13 changes: 13 additions & 0 deletions shared/src/commonMain/composeResources/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<resources>
<string name="game_title" translatable="false">Sliding Puzzle Game</string>
<string name="game_hint_button">Hint</string>
<string name="game_goal_button">Goal</string>
<string name="game_replay_button">Replay</string>
<string name="game_resume_button">Resume timer</string>
<string name="game_pause_button">Pause timer</string>
<string name="game_stats_timer_label">Timer</string>
<string name="game_moves_away_message">The goal is %1$d moves away</string>
<string name="game_dialog_dismiss_button">OK</string>
<string name="game_dialog_goal_title">The goal is to reach this state</string>
<string name="game_dialog_congratulations_title">Congratulations!!! 🎉🥳</string>
</resources>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

@file:OptIn(ExperimentalResourceApi::class)

package io.github.andremion.slidingpuzzle.ui.game

import androidx.compose.foundation.layout.Arrangement
Expand Down Expand Up @@ -41,11 +43,14 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.PlainTooltipBox
import androidx.compose.material3.PlainTooltip
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.material3.TooltipBox
import androidx.compose.material3.TooltipDefaults
import androidx.compose.material3.rememberTooltipState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
Expand All @@ -59,6 +64,9 @@ import io.github.andremion.slidingpuzzle.presentation.game.GameViewModel
import io.github.andremion.slidingpuzzle.ui.animation.FadeAnimatedVisibility
import moe.tlaster.precompose.flow.collectAsStateWithLifecycle
import moe.tlaster.precompose.koin.koinViewModel
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.stringResource
import slidingpuzzle.shared.generated.resources.Res

@Composable
fun GameScreen() {
Expand All @@ -82,7 +90,7 @@ private fun ScreenContent(
Scaffold(
topBar = {
CenterAlignedTopAppBar(
title = { Text(text = "Sliding Puzzle Game") },
title = { Text(text = stringResource(Res.string.game_title)) },
)
},
bottomBar = {
Expand Down Expand Up @@ -167,78 +175,73 @@ private fun BottomBar(
BottomAppBar(
actions = {
PlainTooltipBox(
tooltip = { Text(text = "Hint") }
tooltip = { Text(text = stringResource(Res.string.game_hint_button)) },
) {
IconButton(
modifier = Modifier.tooltipAnchor(),
onClick = { onUiEvent(GameUiEvent.HintClick) }
) {
Icon(
imageVector = Icons.Outlined.Lightbulb,
contentDescription = "Hint"
contentDescription = stringResource(Res.string.game_hint_button)
)
}
}
PlainTooltipBox(
tooltip = { Text(text = "Goal") }
tooltip = { Text(text = stringResource(Res.string.game_goal_button)) }
) {
IconButton(
modifier = Modifier.tooltipAnchor(),
onClick = { onUiEvent(GameUiEvent.GoalClick) }
) {
Icon(
imageVector = Icons.Outlined.Flag,
contentDescription = "Goal"
contentDescription = stringResource(Res.string.game_goal_button)
)
}
}
PlainTooltipBox(
tooltip = { Text(text = "Replay") }
tooltip = { Text(text = stringResource(Res.string.game_replay_button)) }
) {
IconButton(
modifier = Modifier.tooltipAnchor(),
onClick = { onUiEvent(GameUiEvent.ReplayClick) }
) {
Icon(
imageVector = Icons.Rounded.Replay,
contentDescription = "Replay"
contentDescription = stringResource(Res.string.game_replay_button)
)
}
}
},
floatingActionButton = {
PlainTooltipBox(
tooltip = { Text(text = "Resume timer") }
tooltip = { Text(text = stringResource(Res.string.game_resume_button)) }
) {
FadeAnimatedVisibility(
isVisible = fab == GameUiState.Fab.Resume,
) {
FloatingActionButton(
modifier = Modifier.tooltipAnchor(),
elevation = FloatingActionButtonDefaults.bottomAppBarFabElevation(),
onClick = { onUiEvent(GameUiEvent.ResumeClick) }
) {
Icon(
imageVector = Icons.Rounded.PlayArrow,
contentDescription = "Resume timer"
contentDescription = stringResource(Res.string.game_resume_button)
)
}
}
}
PlainTooltipBox(
tooltip = { Text(text = "Pause timer") }
tooltip = { Text(text = stringResource(Res.string.game_pause_button)) }
) {
FadeAnimatedVisibility(
isVisible = fab == GameUiState.Fab.Pause,
) {
FloatingActionButton(
modifier = Modifier.tooltipAnchor(),
elevation = FloatingActionButtonDefaults.bottomAppBarFabElevation(),
onClick = { onUiEvent(GameUiEvent.PauseClick) }
) {
Icon(
imageVector = Icons.Rounded.Pause,
contentDescription = "Pause timer"
contentDescription = stringResource(Res.string.game_pause_button)
)
}
}
Expand All @@ -247,14 +250,28 @@ private fun BottomBar(
)
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun PlainTooltipBox(
tooltip: @Composable () -> Unit,
content: @Composable () -> Unit
) {
TooltipBox(
positionProvider = TooltipDefaults.rememberPlainTooltipPositionProvider(),
tooltip = { PlainTooltip { tooltip() } },
state = rememberTooltipState(),
content = content
)
}

@Composable
private fun GoalDialog(
board: GameUiState.Board,
onDismiss: () -> Unit
) {
AlertDialog(
title = {
Text(text = "This is your goal")
Text(text = stringResource(Res.string.game_dialog_goal_title))
},
text = {
Box(
Expand All @@ -276,7 +293,7 @@ private fun GoalDialog(
Button(
onClick = onDismiss
) {
Text(text = "Dismiss")
Text(text = stringResource(Res.string.game_dialog_dismiss_button))
}
},
)
Expand All @@ -290,7 +307,7 @@ private fun CongratulationsDialog(
) {
AlertDialog(
title = {
Text(text = "Congratulations!!! 🎉🥳")
Text(text = stringResource(Res.string.game_dialog_congratulations_title))
},
text = {
Column(
Expand All @@ -317,7 +334,7 @@ private fun CongratulationsDialog(
Button(
onClick = onDismiss
) {
Text(text = "Dismiss")
Text(text = stringResource(Res.string.game_dialog_dismiss_button))
}
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

@file:OptIn(ExperimentalResourceApi::class)

package io.github.andremion.slidingpuzzle.ui.game

import androidx.compose.animation.core.LinearEasing
Expand All @@ -34,13 +36,16 @@ import androidx.compose.material.icons.rounded.Numbers
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.VerticalDivider
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.unit.dp
import io.github.andremion.slidingpuzzle.ui.component.VerticalDivider
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.stringResource
import slidingpuzzle.shared.generated.resources.Res

@Composable
fun PuzzleStats(
Expand Down Expand Up @@ -115,7 +120,7 @@ private fun Timer(
) {
Icon(
imageVector = Icons.Outlined.Timer,
contentDescription = "Timer"
contentDescription = stringResource(Res.string.game_stats_timer_label)
)
Text(
text = timer,
Expand Down

0 comments on commit 5e0a8f9

Please sign in to comment.