Merge branch 'simple_sub_system' into 'master'
Add a simple toggle for debugging purposes See merge request ti/2023-2024/s4/mobile-security/students/joren-schipman/pokesearch!4
This commit is contained in:
		@@ -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(
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user