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

Updated home list categories for the different game modes #49

Merged
merged 4 commits into from
Jun 16, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CommonNavGraphNavigator(
category: ComparisonQuizCategory,
mode: ComparisonMode
) {
navController.navigate(ComparisonQuizScreenDestination(category, mode))
navController.navigate(ComparisonQuizScreenDestination(category.toEntity(), mode))
}

override fun navigateToMultiChoiceQuiz(initialQuestions: ArrayList<MultiChoiceQuestion>) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/xml/remote_config_defaults.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</entry>
<entry>
<key>comparison_quiz_categories</key>
<value>[{"id":"country-population","title":"Country Population","description":"Compare population of each country","imageUrl":"https://firebasestorage.googleapis.com/v0/b/newquiz-app.appspot.com/o/Illustrations%2Fworld_population_illustration.png?alt=media&amp;token=db98d82c-7bbb-41bc-94a8-16771e0699aa","questionDescription":{"greater":"Which country has more population?","less":"Which country has less population?"},"formatType":"number","dataSourceAttribution":{"text":"Data from RESTCountries"}},{"id":"country-area","title":"Country Area","description":"Compare the area of each country (km²)","imageUrl":"https://firebasestorage.googleapis.com/v0/b/newquiz-app.appspot.com/o/Illustrations%2Fflags_illustration.png?alt=media&amp;token=ec6b2820-1d26-4352-9c54-201bd387ae94","questionDescription":{"greater":"Which country has more area?","less":"Which country has less area?"},"formatType":"number","helperValueSuffix":"km²","dataSourceAttribution":{"text":"Data from RESTCountries"}},{"id":"movie-popularity","title":"Movie Popularity","description":"Compare the populatiry of movies.","imageUrl":"https://firebasestorage.googleapis.com/v0/b/newquiz-app.appspot.com/o/Illustrations%2Fmovie_popularity_illustration.png?alt=media&amp;token=9e54b03f-391a-4cd9-9a04-e0a8f29d0b9f","questionDescription":{"greater":"Which movie is more popular?","less":"Which movie is less popular?"},"formatType":"number","dataSourceAttribution":{"text":"Powered by TMDB"}},{"id":"movie-release-date","title":"Movie Release Date","description":"Compare the release date of movies.","imageUrl":"https://firebasestorage.googleapis.com/v0/b/newquiz-app.appspot.com/o/Illustrations%2Fmovie_popularity_illustration.png?alt=media&amp;token=9e54b03f-391a-4cd9-9a04-e0a8f29d0b9f","questionDescription":{"greater":"Which movie is more recent?","less":"Which movie is less recent?"},"formatType":"date","dataSourceAttribution":{"text":"Powered by TMDB"}}]</value>
<value>[{"id":"country-population","name":"Country Population","description":"Compare population of each country","image":"https://firebasestorage.googleapis.com/v0/b/newquiz-app.appspot.com/o/Illustrations%2Fworld_population_illustration.png?alt=media&amp;token=db98d82c-7bbb-41bc-94a8-16771e0699aa","questionDescription":{"greater":"Which country has more population?","less":"Which country has less population?"},"formatType":"number","dataSourceAttribution":{"text":"Data from RESTCountries"}},{"id":"country-area","name":"Country Area","description":"Compare the area of each country (km²)","image":"https://firebasestorage.googleapis.com/v0/b/newquiz-app.appspot.com/o/Illustrations%2Fflags_illustration.png?alt=media&amp;token=ec6b2820-1d26-4352-9c54-201bd387ae94","questionDescription":{"greater":"Which country has more area?","less":"Which country has less area?"},"formatType":"number","helperValueSuffix":"km²","dataSourceAttribution":{"text":"Data from RESTCountries"}},{"id":"movie-popularity","name":"Movie Popularity","description":"Compare the populatiry of movies.","image":"https://firebasestorage.googleapis.com/v0/b/newquiz-app.appspot.com/o/Illustrations%2Fmovie_popularity_illustration.png?alt=media&amp;token=9e54b03f-391a-4cd9-9a04-e0a8f29d0b9f","questionDescription":{"greater":"Which movie is more popular?","less":"Which movie is less popular?"},"formatType":"number","dataSourceAttribution":{"text":"Powered by TMDB"}},{"id":"movie-release-date","name":"Movie Release Date","description":"Compare the release date of movies.","image":"https://firebasestorage.googleapis.com/v0/b/newquiz-app.appspot.com/o/Illustrations%2Fmovie_popularity_illustration.png?alt=media&amp;token=9e54b03f-391a-4cd9-9a04-e0a8f29d0b9f","questionDescription":{"greater":"Which movie is more recent?","less":"Which movie is less recent?"},"formatType":"date","dataSourceAttribution":{"text":"Powered by TMDB"}}]</value>
</entry>
<entry>
<key>comparison_quiz_skip_cost</key>
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/java/ProjectConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ object ProjectConfig {

const val targetSdk = 33

const val versionCode = 13
const val versionCode = 14

const val versionName = "1.5.3"
const val versionName = "1.6.0"

val javaVersionCompatibility = JavaVersion.VERSION_17

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ import com.infinitepower.newquiz.core.game.ComparisonQuizCore
import com.infinitepower.newquiz.core_test.compose.theme.NewQuizTestTheme
import com.infinitepower.newquiz.core_test.utils.setDeviceLocale
import com.infinitepower.newquiz.domain.repository.comparison_quiz.ComparisonQuizRepository
import com.infinitepower.newquiz.domain.repository.home.RecentCategoriesRepository
import com.infinitepower.newquiz.domain.repository.user.auth.AuthUserRepository
import com.infinitepower.newquiz.model.comparison_quiz.ComparisonMode
import com.infinitepower.newquiz.model.comparison_quiz.ComparisonQuizCategory
import com.infinitepower.newquiz.model.comparison_quiz.ComparisonQuizFormatType
import com.infinitepower.newquiz.model.comparison_quiz.ComparisonQuizItem
import com.infinitepower.newquiz.model.config.RemoteConfigApi
import com.infinitepower.newquiz.model.toUiText
import com.infinitepower.newquiz.online_services.domain.user.UserRepository
import com.ramcosta.composedestinations.navigation.EmptyDestinationsNavigator
import io.mockk.every
Expand All @@ -58,6 +60,7 @@ internal class ComparisonQuizScreenTest {
private val authUserRepository = mockk<AuthUserRepository>(relaxed = true)
private val userRepository = mockk<UserRepository>(relaxed = true)
private val remoteConfigApi = mockk<RemoteConfigApi>(relaxed = true)
private val recentCategoriesRepository = mockk<RecentCategoriesRepository>(relaxed = true)

private lateinit var comparisonQuizCore: ComparisonQuizCore

Expand All @@ -70,9 +73,9 @@ internal class ComparisonQuizScreenTest {
private val category by lazy {
ComparisonQuizCategory(
id = "numbers",
title = "Numbers",
name = "Numbers".toUiText(),
description = "Numbers description",
imageUrl = "",
image = "",
questionDescription = ComparisonQuizCategory.QuestionDescription(
greater = "Which number is greater?",
less = "Which number is lesser?",
Expand Down Expand Up @@ -132,13 +135,14 @@ internal class ComparisonQuizScreenTest {
savedStateHandle = SavedStateHandle(
mapOf(
ComparisonQuizListScreenNavArg::comparisonMode.name to comparisonMode,
ComparisonQuizListScreenNavArg::category.name to category
ComparisonQuizListScreenNavArg::category.name to category.toEntity()
)
),
comparisonQuizRepository = comparisonQuizRepository,
workManager = workManager,
authUserRepository = authUserRepository,
userRepository = userRepository
userRepository = userRepository,
recentCategoriesRepository = recentCategoriesRepository
)

composeTestRule.setContent {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
package com.infinitepower.newquiz.comparison_quiz.list

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
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.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.infinitepower.newquiz.comparison_quiz.destinations.ComparisonQuizScreenDestination
import com.infinitepower.newquiz.comparison_quiz.list.components.ComparisonModeComponents
import com.infinitepower.newquiz.core.common.annotation.compose.AllPreviewsNightLight
import com.infinitepower.newquiz.core.theme.NewQuizTheme
import com.infinitepower.newquiz.core.theme.spacing
import com.infinitepower.newquiz.core.ui.components.category.CategoryComponent
import com.infinitepower.newquiz.core.ui.components.rememberIsInternetAvailable
import com.infinitepower.newquiz.core.ui.home.HomeLazyColumn
import com.infinitepower.newquiz.core.ui.home.homeCategoriesItems
import com.infinitepower.newquiz.domain.repository.home.HomeCategories
import com.infinitepower.newquiz.model.comparison_quiz.ComparisonMode
import com.infinitepower.newquiz.model.comparison_quiz.ComparisonQuizCategory
import com.infinitepower.newquiz.model.comparison_quiz.ComparisonQuizFormatType
import com.infinitepower.newquiz.model.toUiText
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.infinitepower.newquiz.core.R as CoreR
Expand All @@ -45,7 +45,7 @@ fun ComparisonQuizListScreen(
onCategoryClick = { category ->
navigator.navigate(
ComparisonQuizScreenDestination(
category = category,
category = category.toEntity(),
comparisonMode = uiState.selectedMode
)
)
Expand All @@ -66,10 +66,9 @@ private fun ComparisonQuizListScreenImpl(

val isInternetAvailable = rememberIsInternetAvailable()

LazyColumn(
contentPadding = PaddingValues(spaceMedium),
verticalArrangement = Arrangement.spacedBy(spaceMedium)
) {
var seeAllCategories by remember { mutableStateOf(false) }

HomeLazyColumn {
item {
Column {
Text(
Expand All @@ -92,20 +91,14 @@ private fun ComparisonQuizListScreenImpl(
)
}

items(
items = uiState.categories,
key = { category -> category.id }
) { category ->
CategoryComponent(
modifier = Modifier
.fillMaxWidth()
.height(120.dp),
title = category.title,
imageUrl = category.imageUrl,
onClick = { onCategoryClick(category) },
enabled = isInternetAvailable
)
}
homeCategoriesItems(
seeAllCategories = seeAllCategories,
recentCategories = uiState.homeCategories.recentCategories,
otherCategories = uiState.homeCategories.otherCategories,
isInternetAvailable = isInternetAvailable,
onCategoryClick = onCategoryClick,
onSeeAllCategoriesClick = { seeAllCategories = !seeAllCategories }
)
}
}

Expand All @@ -116,18 +109,21 @@ private fun ComparisonQuizListScreenPreview() {
Surface {
ComparisonQuizListScreenImpl(
uiState = ComparisonQuizListScreenUiState(
categories = listOf(
ComparisonQuizCategory(
id = "test",
description = "Description",
title = "Title",
imageUrl = "",
questionDescription = ComparisonQuizCategory.QuestionDescription(
greater = "Greater",
less = "Less"
),
formatType = ComparisonQuizFormatType.Number
)
homeCategories = HomeCategories(
recentCategories = listOf(
ComparisonQuizCategory(
id = "test",
description = "Description",
name = "Title".toUiText(),
image = "",
questionDescription = ComparisonQuizCategory.QuestionDescription(
greater = "Greater",
less = "Less"
),
formatType = ComparisonQuizFormatType.Number
)
),
otherCategories = emptyList()
)
),
onCategoryClick = {},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.infinitepower.newquiz.comparison_quiz.list

import androidx.annotation.Keep
import com.infinitepower.newquiz.domain.repository.home.HomeCategories
import com.infinitepower.newquiz.domain.repository.home.emptyHomeCategories
import com.infinitepower.newquiz.model.comparison_quiz.ComparisonMode
import com.infinitepower.newquiz.model.comparison_quiz.ComparisonQuizCategory

@Keep
data class ComparisonQuizListScreenUiState(
val categories: List<ComparisonQuizCategory> = emptyList(),
val homeCategories: HomeCategories<ComparisonQuizCategory> = emptyHomeCategories(),
val selectedMode: ComparisonMode = ComparisonMode.GREATER
)
Original file line number Diff line number Diff line change
@@ -1,24 +1,48 @@
package com.infinitepower.newquiz.comparison_quiz.list

import androidx.lifecycle.ViewModel
import com.infinitepower.newquiz.domain.repository.comparison_quiz.ComparisonQuizRepository
import androidx.lifecycle.viewModelScope
import com.infinitepower.newquiz.core.network.NetworkStatus
import com.infinitepower.newquiz.core.network.NetworkStatusTracker
import com.infinitepower.newquiz.domain.repository.home.RecentCategoriesRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.update
import javax.inject.Inject

@HiltViewModel
@OptIn(ExperimentalCoroutinesApi::class)
class ComparisonQuizListScreenViewModel @Inject constructor(
private val comparisonQuizRepository: ComparisonQuizRepository
private val recentCategoriesRepository: RecentCategoriesRepository,
private val networkStatusTracker: NetworkStatusTracker
) : ViewModel() {
private val _uiState = MutableStateFlow(ComparisonQuizListScreenUiState())
val uiState = _uiState.asStateFlow()

init {
_uiState.update { currentState ->
currentState.copy(categories = comparisonQuizRepository.getCategories())
}
val networkStatus = networkStatusTracker
.networkStatus
.stateIn(
initialValue = NetworkStatus.Unknown,
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(5000)
)

networkStatus
.flatMapLatest { status ->
recentCategoriesRepository.getComparisonCategories(isInternetAvailable = status.isAvailable())
}.onEach { homeCategories ->
_uiState.update { currentState ->
currentState.copy(homeCategories = homeCategories)
}
}.launchIn(viewModelScope)
}

fun onEvent(event: ComparisonQuizListScreenUiEvent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,18 @@ import com.infinitepower.newquiz.core.ui.components.skip_question.SkipIconButton
import com.infinitepower.newquiz.core.ui.components.skip_question.SkipQuestionDialog
import com.infinitepower.newquiz.model.comparison_quiz.ComparisonMode
import com.infinitepower.newquiz.model.comparison_quiz.ComparisonQuizCategory
import com.infinitepower.newquiz.model.comparison_quiz.ComparisonQuizCategoryEntity
import com.infinitepower.newquiz.model.comparison_quiz.ComparisonQuizCurrentQuestion
import com.infinitepower.newquiz.model.comparison_quiz.ComparisonQuizFormatType
import com.infinitepower.newquiz.model.comparison_quiz.ComparisonQuizItem
import com.infinitepower.newquiz.model.toUiText
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.infinitepower.newquiz.core.R as CoreR

@Keep
data class ComparisonQuizListScreenNavArg(
val category: ComparisonQuizCategory,
val category: ComparisonQuizCategoryEntity,
val comparisonMode: ComparisonMode = ComparisonMode.GREATER
)

Expand All @@ -83,7 +85,7 @@ fun ComparisonQuizScreen(

navigator.navigate(
ComparisonQuizScreenDestination(
category = category,
category = category.toEntity(),
comparisonMode = comparisonMode
)
) {
Expand Down Expand Up @@ -423,9 +425,9 @@ private fun ComparisonQuizScreenPreview() {
),
gameDescription = "Which one is more popular?",
gameCategory = ComparisonQuizCategory(
title = "Social",
name = "Social".toUiText(),
description = "Social media",
imageUrl = "",
image = "",
id = "social",
questionDescription = ComparisonQuizCategory.QuestionDescription(
greater = "Which one is more popular?",
Expand Down
Loading