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

Improve maze #63

Merged
merged 9 commits into from
Jan 6, 2024
Merged
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
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ dependencies {
implementation(projects.core.userServices)
implementation(projects.core.userServices.ui)
implementation(projects.feature.settings)
implementation(projects.feature.maze)
implementation(projects.model)
implementation(projects.multiChoiceQuiz)
implementation(projects.wordle)
implementation(projects.data)
implementation(projects.domain)
implementation(projects.mazeQuiz)
implementation(projects.comparisonQuiz)
implementation(projects.dailyChallenge)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.infinitepower.newquiz.core.remote_config.RemoteConfig
import com.infinitepower.newquiz.core.user_services.ui.profile.destinations.ProfileScreenDestination
import com.infinitepower.newquiz.daily_challenge.destinations.DailyChallengeScreenDestination
import com.infinitepower.newquiz.feature.settings.destinations.SettingsScreenDestination
import com.infinitepower.newquiz.maze_quiz.destinations.MazeScreenDestination
import com.infinitepower.newquiz.feature.maze.destinations.MazeScreenDestination
import com.infinitepower.newquiz.multi_choice_quiz.destinations.MultiChoiceQuizListScreenDestination
import com.infinitepower.newquiz.multi_choice_quiz.destinations.MultiChoiceQuizResultsScreenDestination
import com.infinitepower.newquiz.multi_choice_quiz.destinations.MultiChoiceQuizScreenDestination
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.infinitepower.newquiz.core.remote_config.RemoteConfig
import com.infinitepower.newquiz.core.remote_config.RemoteConfigValue
import com.infinitepower.newquiz.core.remote_config.get
import com.infinitepower.newquiz.daily_challenge.DailyChallengeScreenNavigator
import com.infinitepower.newquiz.maze_quiz.MazeScreenNavigator
import com.infinitepower.newquiz.feature.maze.MazeScreenNavigator
import com.infinitepower.newquiz.model.comparison_quiz.ComparisonMode
import com.infinitepower.newquiz.model.comparison_quiz.ComparisonQuizCategory
import com.infinitepower.newquiz.model.maze.MazeQuiz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import com.infinitepower.newquiz.core.navigation.ScreenType
import com.infinitepower.newquiz.core.user_services.ui.profile.destinations.ProfileScreenDestination
import com.infinitepower.newquiz.daily_challenge.destinations.DailyChallengeScreenDestination
import com.infinitepower.newquiz.feature.settings.destinations.SettingsScreenDestination
import com.infinitepower.newquiz.maze_quiz.destinations.MazeScreenDestination
import com.infinitepower.newquiz.feature.maze.destinations.MazeScreenDestination
import com.infinitepower.newquiz.multi_choice_quiz.destinations.MultiChoiceQuizListScreenDestination
import com.infinitepower.newquiz.wordle.destinations.WordleListScreenDestination
import com.ramcosta.composedestinations.spec.DestinationSpec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ object SettingsCommon {
object WordleAnimationsEnabled : PreferenceRequest<Boolean>(booleanPreferencesKey("wordle_animations_enabled"), true)
object MultiChoiceAnimationsEnabled : PreferenceRequest<Boolean>(booleanPreferencesKey("multi_choice_animations_enabled"), true)

object MazeAutoScrollToCurrentItem : PreferenceRequest<Boolean>(booleanPreferencesKey("mazeAutoScrollToCurrentItem"), true)

/**
* The translation settings.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Check
import androidx.compose.material.icons.rounded.Wifi
import androidx.compose.material.icons.rounded.WifiOff
import androidx.compose.material3.Icon
Expand All @@ -21,10 +22,10 @@ import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.tooling.preview.PreviewLightDark
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
import com.infinitepower.newquiz.core.R
import androidx.compose.ui.tooling.preview.PreviewLightDark
import com.infinitepower.newquiz.core.common.compose.preview.BooleanPreviewParameterProvider
import com.infinitepower.newquiz.core.theme.NewQuizTheme
import com.infinitepower.newquiz.core.theme.spacing
Expand All @@ -36,16 +37,12 @@ import com.infinitepower.newquiz.core.theme.spacing
* @param modifier The modifier to be applied to the component.
* @param requireConnection Whether the category requires an internet connection or not.
* @param showTextByDefault Whether the text should be shown by default.
* @param color The color of the badge.
* @param shape The shape of the badge.
*/
@Composable
internal fun CategoryConnectionInfoBadge(
modifier: Modifier = Modifier,
requireConnection: Boolean = true,
showTextByDefault: Boolean = false,
color: Color = MaterialTheme.colorScheme.tertiaryContainer,
shape: Shape = MaterialTheme.shapes.medium,
) {
val (showText, setShowText) = remember {
mutableStateOf(showTextByDefault)
Expand All @@ -59,10 +56,8 @@ internal fun CategoryConnectionInfoBadge(
}
)

Surface(
CategoryBadge(
modifier = modifier,
color = color,
shape = shape,
onClick = { setShowText(!showText) }
) {
Row(
Expand All @@ -84,7 +79,10 @@ internal fun CategoryConnectionInfoBadge(
},
contentDescription = null
)
AnimatedVisibility(visible = showText) {
AnimatedVisibility(
visible = showText,
label = "Connection info text"
) {
Text(
text = description,
style = MaterialTheme.typography.bodySmall
Expand All @@ -94,6 +92,44 @@ internal fun CategoryConnectionInfoBadge(
}
}

/**
* A badge that indicates that the category is checked.
*/
@Composable
internal fun CategoryCheckedBadge(
modifier: Modifier = Modifier,
onClick: () -> Unit
) {
CategoryBadge(
modifier = modifier,
color = MaterialTheme.colorScheme.primary,
onClick = onClick
) {
Icon(
imageVector = Icons.Rounded.Check,
contentDescription = null,
modifier = Modifier.padding(MaterialTheme.spacing.default)
)
}
}

@Composable
private fun CategoryBadge(
modifier: Modifier = Modifier,
color: Color = MaterialTheme.colorScheme.tertiaryContainer,
shape: Shape = MaterialTheme.shapes.medium,
onClick: () -> Unit = {},
badgeContent: @Composable () -> Unit
) {
Surface(
modifier = modifier,
color = color,
shape = shape,
onClick = onClick,
content = badgeContent
)
}

@Composable
@PreviewLightDark
private fun CategoryConnectionInfoBadgePreview(
Expand All @@ -108,3 +144,16 @@ private fun CategoryConnectionInfoBadgePreview(
}
}
}

@Composable
@PreviewLightDark
private fun CategoryCheckedBadgePreview() {
NewQuizTheme {
Surface {
CategoryCheckedBadge(
modifier = Modifier.padding(16.dp),
onClick = {}
)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.infinitepower.newquiz.core.ui.components.category

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
Expand All @@ -16,6 +19,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
Expand All @@ -36,23 +40,31 @@ fun CategoryComponent(
imageUrl: Any,
requireInternetConnection: Boolean = false,
showConnectionInfo: ShowCategoryConnectionInfo = ShowCategoryConnectionInfo.NONE,
checked: Boolean = false,
enabled: Boolean = true,
textStyle: TextStyle = MaterialTheme.typography.headlineLarge,
onClick: () -> Unit = {}
shape: Shape = MaterialTheme.shapes.large,
onClick: () -> Unit = {},
onCheckClick: () -> Unit = {}
) {
val shapeMedium = MaterialTheme.shapes.large

val containerOverlayColor = if (isSystemInDarkTheme()) {
MaterialTheme.colorScheme.primaryContainer.copy(alpha = 0.5f)
MaterialTheme.colorScheme.primaryContainer
} else {
MaterialTheme.colorScheme.primary.copy(alpha = 0.5f)
}
MaterialTheme.colorScheme.primary
}.copy(alpha = if (checked) 0.6f else 0.5f)

Surface(
modifier = modifier.alpha(if (enabled) 1f else DISABLED_ALPHA),
shape = shapeMedium,
modifier = modifier
.height(120.dp)
.alpha(if (enabled) 1f else DISABLED_ALPHA),
shape = shape,
onClick = onClick,
enabled = enabled
enabled = enabled,
border = if (checked) {
BorderStroke(2.dp, MaterialTheme.colorScheme.primary)
} else {
null
}
) {
AsyncImage(
model = imageUrl,
Expand All @@ -74,13 +86,25 @@ fun CategoryComponent(
color = Color.White,
textAlign = TextAlign.Center
)
if (showConnectionInfo.shouldShowBadge(requireInternetConnection)) {
CategoryConnectionInfoBadge(
modifier = Modifier
.padding(MaterialTheme.spacing.default)
.align(Alignment.TopEnd),
requireConnection = requireInternetConnection
)

Row(
modifier = Modifier
.padding(MaterialTheme.spacing.default)
.align(Alignment.TopEnd),
) {
if (showConnectionInfo.shouldShowBadge(requireInternetConnection)) {
CategoryConnectionInfoBadge(
requireConnection = requireInternetConnection
)
}
AnimatedVisibility(
visible = checked,
label = "Checked badge"
) {
CategoryCheckedBadge(
onClick = onCheckClick
)
}
}
}
}
Expand All @@ -96,8 +120,10 @@ private fun CategoryPreview() {
imageUrl = "",
modifier = Modifier
.padding(16.dp)
.height(200.dp)
.fillMaxWidth()
.fillMaxWidth(),
requireInternetConnection = true,
showConnectionInfo = ShowCategoryConnectionInfo.BOTH,
checked = true
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.infinitepower.newquiz.core.ui.components.icon.button

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.ArrowBack
import androidx.compose.material.icons.automirrored.rounded.ArrowBack
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.runtime.Composable
Expand All @@ -19,7 +19,7 @@ fun BackIconButton(
modifier = modifier
) {
Icon(
imageVector = Icons.Rounded.ArrowBack,
imageVector = Icons.AutoMirrored.Rounded.ArrowBack,
contentDescription = stringResource(id = R.string.back)
)
}
Expand Down
1 change: 1 addition & 0 deletions core/src/main/res/values-pt/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,5 @@
<string name="wordle_settings_summary">Modo difícil, Linguagem do questionário, Dicas de palavras</string>
<string name="translation_settings_summary">Idioma de tradução</string>
<string name="about_and_help_settings_summary">Versão, Contacto, Licenças de código aberto</string>
<string name="select_only_offline">Seleciona apenas Offline</string>
</resources>
1 change: 1 addition & 0 deletions core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,5 @@
<string name="wordle_settings_summary">Hard mode, Quiz language, Letter hints</string>
<string name="translation_settings_summary">Translation language</string>
<string name="about_and_help_settings_summary">Version, Contact, Open source licences</string>
<string name="select_only_offline">Select only Offline</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.infinitepower.newquiz.core.database.model.toEntity
import com.infinitepower.newquiz.core.database.model.toMazeQuizItem
import com.infinitepower.newquiz.domain.repository.maze.MazeQuizRepository
import com.infinitepower.newquiz.model.maze.MazeQuiz
import kotlinx.collections.immutable.toPersistentList
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import javax.inject.Inject
Expand All @@ -18,7 +19,7 @@ class MazeQuizRepositoryImpl @Inject constructor(
override fun getSavedMazeQuizFlow(): Flow<MazeQuiz> = mazeQuizDao
.getAllMazeItemsFlow()
.map { entities -> entities.map(MazeQuizItemEntity::toMazeQuizItem) }
.map { mazeItems -> MazeQuiz(items = mazeItems) }
.map { mazeItems -> MazeQuiz(items = mazeItems.toPersistentList()) }

override suspend fun countAllItems(): Int = mazeQuizDao.countAllItems()

Expand Down
Loading