Add a simple toggle for debugging purposes

This commit is contained in:
Joren 2024-04-30 12:06:25 +02:00
parent 8690ed006e
commit 09f9b2c5cf
Signed by untrusted user who does not match committer: Joren
GPG Key ID: 280E33DFBC0F1B55
2 changed files with 14 additions and 2 deletions

View File

@ -1,5 +1,6 @@
package com.ti.mobpo.ui.screens package com.ti.mobpo.ui.screens
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
@ -28,6 +29,11 @@ fun FavoritesScreen(viewModel: FavouritesViewModel) {
@Composable @Composable
fun Favorites(favoritesViewModel: FavouritesViewModel) { fun Favorites(favoritesViewModel: FavouritesViewModel) {
// Function to toggle debug mode
val toggleDebugMode: () -> Unit = {
favoritesViewModel.toggleDebugMode()
}
LaunchedEffect(Unit) { LaunchedEffect(Unit) {
favoritesViewModel.loadFavourites() favoritesViewModel.loadFavourites()
} }
@ -43,11 +49,9 @@ fun Favorites(favoritesViewModel: FavouritesViewModel) {
) { ) {
Spacer(modifier = Modifier.height(16.dp)) Spacer(modifier = Modifier.height(16.dp))
// Show AlertDialog if access check failed
if (favoritesViewModel.accessCheckFailed.value) { if (favoritesViewModel.accessCheckFailed.value) {
AlertDialog( AlertDialog(
onDismissRequest = { onDismissRequest = {
// Dismiss the dialog
favoritesViewModel.accessCheckFailed.value = false favoritesViewModel.accessCheckFailed.value = false
}, },
title = { title = {
@ -68,6 +72,11 @@ fun Favorites(favoritesViewModel: FavouritesViewModel) {
) )
} }
Text(
text = "Toggle Debug Mode",
modifier = Modifier.clickable { toggleDebugMode() }
)
favorites?.let { favoritesList -> favorites?.let { favoritesList ->
if (favoritesList.isNotEmpty()) { if (favoritesList.isNotEmpty()) {
LazyVerticalGrid( LazyVerticalGrid(

View File

@ -28,6 +28,9 @@ class FavouritesViewModel(private val favouritesRepository: FavouritesRepository
val pokemonDetails: StateFlow<List<PokemonDetails>?> = _pokemonDetails.asStateFlow() val pokemonDetails: StateFlow<List<PokemonDetails>?> = _pokemonDetails.asStateFlow()
val accessCheckFailed: MutableState<Boolean> = mutableStateOf(false) val accessCheckFailed: MutableState<Boolean> = mutableStateOf(false)
fun toggleDebugMode() {
featureManager.setPaidFeatureEnabled(!featureManager.hasAccessToPaidFeature())
}
fun loadFavourites() { fun loadFavourites() {
// featureManager.setPaidFeatureEnabled(false) enable and disable acccess // featureManager.setPaidFeatureEnabled(false) enable and disable acccess
// Ugly workaround to make sure all the favourites are loaded before displaying them // Ugly workaround to make sure all the favourites are loaded before displaying them