Skip to content

Commit

Permalink
Add loading screen
Browse files Browse the repository at this point in the history
  • Loading branch information
anrouxel committed Feb 28, 2024
1 parent e642796 commit c1da3b0
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.medicapp.medicapp.ui.navigation

import android.content.Context
import android.content.SharedPreferences
import android.os.Build
import android.util.Log
import androidx.annotation.RequiresApi
Expand All @@ -14,6 +15,9 @@ import fr.medicapp.medicapp.ui.components.screen.Loading
import fr.medicapp.medicapp.ui.screen.user.UserEditAllergy
import fr.medicapp.medicapp.ui.screen.user.UserEditGeneralInformation
import fr.medicapp.medicapp.viewModel.SharedUserEditViewModel
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.callbackFlow
import java.util.concurrent.Flow

/**
* Cette fonction construit le graphe de navigation pour l'écran utilisateur.
Expand Down Expand Up @@ -68,10 +72,16 @@ fun NavGraphBuilder.userNavGraph(
LaunchedEffect(Unit) {
val sharedPreferences =
context.getSharedPreferences("medicapp", Context.MODE_PRIVATE)
snapshotFlow {
sharedPreferences.getBoolean("isDataDownloaded", false)
}.collect {
if (it) {
callbackFlow {
val listener = SharedPreferences.OnSharedPreferenceChangeListener { _, key ->
if (key == "isDataDownloaded") {
this.trySend(sharedPreferences.getBoolean(key, false)).isSuccess
}
}
sharedPreferences.registerOnSharedPreferenceChangeListener(listener)
awaitClose { sharedPreferences.unregisterOnSharedPreferenceChangeListener(listener) }
}.collect { isDataDownloaded ->
if (isDataDownloaded) {
Log.d("Guegueintervention", "ça change !!!!!!!")
navController.navigate(Graph.HOME) {
popUpTo(Graph.HOME) {
Expand Down

0 comments on commit c1da3b0

Please sign in to comment.