Skip to content

Commit

Permalink
Added maze screen seed copy, updated google-services.json #15
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomanaia committed Dec 25, 2022
1 parent 63e33a2 commit 99da2d7
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 34 deletions.
13 changes: 13 additions & 0 deletions core/src/main/res/values-pt/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,17 @@
<string name="sign_in">Login</string>
<string name="show_login_card">Mostrar o cartão de login</string>
<string name="show_login_card_at_home_screen">Mostrar o cartão de login na página inicial</string>
<string name="more_options">More options</string>
<string name="open_drawer">Abrir navegação</string>
<string name="copy_maze_seed">Copiar seed labirinto</string>
<string name="restart_maze">Recomeçar labirinto</string>
<string name="generate_maze">Gerar labirinto</string>
<string name="random_maze">Labirinto aleatório</string>
<string name="generate_maze_with_random_items">Gerar labirinto com perguntas aleatórias, todos os modos de jogo serão incluidos.</string>
<string name="custom_maze">Labirinto customizado</string>
<string name="generate_maze_with_custom_options">Gerar labirinto com opções personalizadas</string>
<string name="expand_custom_options">Expandir opções de personalização</string>
<string name="custom_maze_multi_choice_warning">"Quando usa uma seed personalizada, as perguntas de múltipla escolha não serão geradas aleatoriamente por essa seed. "</string>
<string name="generate">Gerar</string>
<string name="seed">Seed</string>
</resources>
13 changes: 13 additions & 0 deletions core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<resources>
<string name="quick_quiz">Quick Quiz</string>
<string name="back">Back</string>
<string name="more_options">More options</string>
<string name="saved_questions">Saved questions</string>
<string name="wordle">Wordle</string>
<string name="wordle_infinite">Wordle infinite</string>
Expand Down Expand Up @@ -125,4 +126,16 @@
<string name="easy">Easy</string>
<string name="medium">Medium</string>
<string name="hard">Hard</string>
<string name="open_drawer">Open drawer</string>
<string name="copy_maze_seed">Copy maze seed</string>
<string name="restart_maze">Restart maze</string>
<string name="generate_maze">Generate maze</string>
<string name="random_maze">Random maze</string>
<string name="generate_maze_with_random_items">Generate maze with random questions, all game modes will be included.</string>
<string name="custom_maze">Custom maze</string>
<string name="generate_maze_with_custom_options">Generate maze with custom options</string>
<string name="expand_custom_options">Expand custom options</string>
<string name="custom_maze_multi_choice_warning">When using custom seed, multi choice questions will not be random generated by this seed.</string>
<string name="generate">Generate</string>
<string name="seed">Seed</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -67,36 +67,43 @@ class GenerateMazeQuizWorker @AssistedInject constructor(
val allMazeItemsAsync = gameModes.map { mode ->
when (mode) {
GameModes.MULTI_CHOICE -> generateMultiChoiceMazeItems(
mazeSeed = seed,
questionSize = questionSizePerMode,
multiChoiceQuizType = MultiChoiceQuizType.NORMAL,
random = random
)
GameModes.LOGO -> generateMultiChoiceMazeItems(
mazeSeed = seed,
questionSize = questionSizePerMode,
multiChoiceQuizType = MultiChoiceQuizType.LOGO,
random = random
)
GameModes.FLAG -> generateMultiChoiceMazeItems(
mazeSeed = seed,
questionSize = questionSizePerMode,
multiChoiceQuizType = MultiChoiceQuizType.FLAG,
random = random
)
GameModes.WORDLE -> generateWordleMazeItems(
mazeSeed = seed,
questionSize = questionSizePerMode,
wordleQuizType = WordleQuizType.TEXT,
random = random
)
GameModes.GUESS_NUMBER -> generateWordleMazeItems(
mazeSeed = seed,
questionSize = questionSizePerMode,
wordleQuizType = WordleQuizType.NUMBER,
random = random
)
GameModes.GUESS_MATH_FORMULA -> generateWordleMazeItems(
mazeSeed = seed,
questionSize = questionSizePerMode,
wordleQuizType = WordleQuizType.MATH_FORMULA,
random = random
)
GameModes.GUESS_MATH_SOLUTION -> generateMultiChoiceMazeItems(
mazeSeed = seed,
questionSize = questionSizePerMode,
multiChoiceQuizType = MultiChoiceQuizType.GUESS_MATH_SOLUTION,
random = random
Expand Down Expand Up @@ -132,10 +139,11 @@ class GenerateMazeQuizWorker @AssistedInject constructor(
}

private suspend fun generateMultiChoiceMazeItems(
mazeSeed: Int,
questionSize: Int,
multiChoiceQuizType: MultiChoiceQuizType,
difficulty: QuestionDifficulty = QuestionDifficulty.Easy,
random: Random = Random,
random: Random = Random
): List<MazeQuiz.MazeItem> {
val questions = when (multiChoiceQuizType) {
MultiChoiceQuizType.NORMAL -> multiChoiceQuestionRepository.getRandomQuestions(
Expand All @@ -158,13 +166,15 @@ class GenerateMazeQuizWorker @AssistedInject constructor(

return questions.map { question ->
MazeQuiz.MazeItem.MultiChoice(
mazeSeed = mazeSeed,
question = question,
difficulty = difficulty
)
}
}

private suspend fun generateWordleMazeItems(
mazeSeed: Int,
questionSize: Int,
wordleQuizType: WordleQuizType,
difficulty: QuestionDifficulty = QuestionDifficulty.Easy,
Expand All @@ -187,6 +197,7 @@ class GenerateMazeQuizWorker @AssistedInject constructor(
}
).map { word ->
MazeQuiz.MazeItem.Wordle(
mazeSeed = mazeSeed,
word = word,
wordleQuizType = wordleQuizType,
difficulty = difficulty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import com.infinitepower.newquiz.core.ui.home_card.components.HomeCardItemConten
import com.infinitepower.newquiz.core.ui.home_card.model.HomeCardItem
import com.infinitepower.newquiz.core.util.ui.nav_drawer.NavDrawerUtil
import com.infinitepower.newquiz.math_quiz.list.data.getMathQuizListCardItemData
import com.ramcosta.composedestinations.annotation.DeepLink
import com.infinitepower.newquiz.core.R as CoreR
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
Expand Down Expand Up @@ -68,7 +67,7 @@ private fun MathQuizListScreenImpl(
IconButton(onClick = openDrawer) {
Icon(
imageVector = Icons.Rounded.Menu,
contentDescription = "Open drawer"
contentDescription = stringResource(id = CoreR.string.open_drawer)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.ArrowBack
import androidx.compose.material.icons.rounded.ContentCopy
import androidx.compose.material.icons.rounded.MoreVert
import androidx.compose.material.icons.rounded.RestartAlt
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
Expand All @@ -17,9 +21,13 @@ import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.ExperimentalLifecycleComposeApi
import androidx.lifecycle.compose.collectAsStateWithLifecycle
Expand All @@ -29,7 +37,6 @@ import com.infinitepower.newquiz.core.theme.NewQuizTheme
import com.infinitepower.newquiz.core.theme.spacing
import com.infinitepower.newquiz.maze_quiz.components.GenerateMazeComponent
import com.infinitepower.newquiz.maze_quiz.components.MazeComponent
import com.infinitepower.newquiz.model.math_quiz.MathFormula
import com.infinitepower.newquiz.model.maze.MazeQuiz
import com.infinitepower.newquiz.model.maze.MazeQuiz.MazeItem
import com.infinitepower.newquiz.model.question.QuestionDifficulty
Expand Down Expand Up @@ -76,8 +83,12 @@ private fun MazeScreenImpl(
) {
val spaceMedium = MaterialTheme.spacing.medium

val clipboardManager = LocalClipboardManager.current

val formulas = uiState.mathMaze.items

var moreOptionsExpanded by remember { mutableStateOf(false) }

Scaffold(
topBar = {
TopAppBar(
Expand All @@ -93,11 +104,45 @@ private fun MazeScreenImpl(
}
},
actions = {
if (!uiState.isMazeEmpty) {
IconButton(onClick = { uiEvent(MazeScreenUiEvent.RestartMaze) }) {
Icon(
imageVector = Icons.Rounded.RestartAlt,
contentDescription = "Restart"
IconButton(onClick = { moreOptionsExpanded = true }) {
Icon(
imageVector = Icons.Rounded.MoreVert,
contentDescription = stringResource(id = CoreR.string.more_options)
)
}
DropdownMenu(
expanded = moreOptionsExpanded,
onDismissRequest = { moreOptionsExpanded = false }
) {
if (formulas.isNotEmpty()) {
DropdownMenuItem(
text = { Text(stringResource(id = CoreR.string.copy_maze_seed)) },
onClick = {
val mazeSeed = uiState.mazeSeed
if (mazeSeed != null) {
clipboardManager.setText(AnnotatedString(mazeSeed.toString()))
}
moreOptionsExpanded = false
},
leadingIcon = {
Icon(
imageVector = Icons.Rounded.ContentCopy,
contentDescription = stringResource(id = CoreR.string.copy_maze_seed)
)
}
)
DropdownMenuItem(
text = { Text(stringResource(id = CoreR.string.restart_maze)) },
onClick = {
uiEvent(MazeScreenUiEvent.RestartMaze)
moreOptionsExpanded = false
},
leadingIcon = {
Icon(
imageVector = Icons.Rounded.RestartAlt,
contentDescription = stringResource(id = CoreR.string.restart_maze)
)
}
)
}
}
Expand Down Expand Up @@ -143,15 +188,17 @@ fun MazeScreenPreview() {
word = "1+1=2",
difficulty = QuestionDifficulty.Easy,
played = true,
wordleQuizType = WordleQuizType.MATH_FORMULA
wordleQuizType = WordleQuizType.MATH_FORMULA,
mazeSeed = 0
)
}

val otherItems = List(20) {
MazeItem.Wordle(
word = "1+1=2",
difficulty = QuestionDifficulty.Easy,
wordleQuizType = WordleQuizType.MATH_FORMULA
wordleQuizType = WordleQuizType.MATH_FORMULA,
mazeSeed = 0
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ data class MazeScreenUiState(
) {
val isMazeEmpty: Boolean
get() = mathMaze.items.isEmpty()

val mazeSeed: Int?
get() = mathMaze.items.firstOrNull()?.mazeSeed
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ 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.unit.dp
import com.infinitepower.newquiz.core.R as CoreR
import com.infinitepower.newquiz.core.common.annotation.compose.PreviewNightLight
import com.infinitepower.newquiz.core.theme.NewQuizTheme
import com.infinitepower.newquiz.core.theme.spacing
Expand All @@ -38,7 +40,7 @@ internal fun GenerateMazeComponent(
) {
item {
Text(
text = "Generate Maze",
text = stringResource(id = CoreR.string.generate_maze),
style = MaterialTheme.typography.displaySmall
)
}
Expand All @@ -47,7 +49,7 @@ internal fun GenerateMazeComponent(
Spacer(modifier = Modifier.height(spaceExtraLarge))
GenerateMazeCard(
onClick = {
onGenerateClick(null, null) // empty list means all game modes selected
onGenerateClick(null, null) // null list means all game modes selected
}
)
Spacer(modifier = Modifier.height(spaceMedium))
Expand Down Expand Up @@ -80,12 +82,12 @@ private fun GenerateMazeCard(
.padding(spaceMedium)
) {
Text(
text = "Random Maze",
text = stringResource(id = CoreR.string.random_maze),
style = MaterialTheme.typography.headlineMedium
)
Spacer(modifier = Modifier.height(spaceSmall))
Text(
text = "Generate maze with random questions, all game modes will be included.",
text = stringResource(id = CoreR.string.generate_maze_with_random_items),
style = MaterialTheme.typography.titleMedium
)
}
Expand Down
Loading

0 comments on commit 99da2d7

Please sign in to comment.