diff --git a/app/src/main/java/com/github/se/assocify/model/CurrentUser.kt b/app/src/main/java/com/github/se/assocify/model/CurrentUser.kt index 6e157340d..10098bfe4 100644 --- a/app/src/main/java/com/github/se/assocify/model/CurrentUser.kt +++ b/app/src/main/java/com/github/se/assocify/model/CurrentUser.kt @@ -7,9 +7,10 @@ import kotlinx.coroutines.flow.StateFlow object CurrentUser { var userUid: String? = null var associationUid: String? = null - private var _associationLogo : StateFlow = MutableStateFlow(null) + private var _associationLogo: StateFlow = MutableStateFlow(null) val associationLogo: StateFlow = _associationLogo - fun setAssociationLogo(uri: Uri?) { - (_associationLogo as MutableStateFlow).value = uri - } + + fun setAssociationLogo(uri: Uri?) { + (_associationLogo as MutableStateFlow).value = uri + } } diff --git a/app/src/main/java/com/github/se/assocify/model/database/AssociationAPI.kt b/app/src/main/java/com/github/se/assocify/model/database/AssociationAPI.kt index 9e83ab473..503478772 100644 --- a/app/src/main/java/com/github/se/assocify/model/database/AssociationAPI.kt +++ b/app/src/main/java/com/github/se/assocify/model/database/AssociationAPI.kt @@ -27,11 +27,11 @@ import kotlinx.serialization.json.JsonObject class AssociationAPI(private val db: SupabaseClient, cachePath: Path) : SupabaseApi() { private var associationCache = mapOf() private val imageCacher = ImageCacher(60 * 60_000, cachePath, db.storage["association"]) - private var currentAssociationCache : String? = null + private var currentAssociationCache: String? = null init { updateCache({}, {}) // Try and fill the cache as quickly as possible - currentAssociationCache = CurrentUser.associationUid + currentAssociationCache = CurrentUser.associationUid } /** @@ -45,7 +45,7 @@ class AssociationAPI(private val db: SupabaseClient, cachePath: Path) : Supabase val assoc = db.from("association").select().decodeList() associationCache = assoc.associateBy { it.uid!! }.mapValues { it.value.toAssociation() } memberCache = null - currentAssociationCache = CurrentUser.associationUid + currentAssociationCache = CurrentUser.associationUid onSuccess(associationCache) } } @@ -443,11 +443,11 @@ class AssociationAPI(private val db: SupabaseClient, cachePath: Path) : Supabase * @param onFailure called on failure */ fun getLogo(associationId: String, onSuccess: (Uri) -> Unit, onFailure: (Exception) -> Unit) { - Log.d("image", "getLogo from association $associationId") - if (associationId != currentAssociationCache) { - currentAssociationCache = associationId - imageCacher.fetchImage(associationId, {onSuccess(Uri.fromFile(it.toFile())) }, onFailure) - } + Log.d("image", "getLogo from association $associationId") + if (associationId != currentAssociationCache) { + currentAssociationCache = associationId + imageCacher.fetchImage(associationId, { onSuccess(Uri.fromFile(it.toFile())) }, onFailure) + } } @Serializable diff --git a/app/src/main/java/com/github/se/assocify/ui/composables/MainTopBar.kt b/app/src/main/java/com/github/se/assocify/ui/composables/MainTopBar.kt index d1c07744f..9cd4c1d5d 100644 --- a/app/src/main/java/com/github/se/assocify/ui/composables/MainTopBar.kt +++ b/app/src/main/java/com/github/se/assocify/ui/composables/MainTopBar.kt @@ -60,8 +60,8 @@ fun MainTopBar( // Page state var currentPage by remember { mutableIntStateOf(page) } - val associationLogoUri = CurrentUser.associationLogo.collectAsState() - val associationLogoUriValue = associationLogoUri.value + val associationLogoUri = CurrentUser.associationLogo.collectAsState() + val associationLogoUriValue = associationLogoUri.value if (currentPage != page) { currentPage = page @@ -78,7 +78,7 @@ fun MainTopBar( onClick = { /*TODO On assoc account click */}) { // profile picture if (associationLogoUriValue != null) { - Log.d("image", "CurrentUser.associationLogo: ${associationLogoUriValue}") + Log.d("image", "CurrentUser.associationLogo: ${associationLogoUriValue}") AsyncImage( modifier = Modifier.size(80.dp) @@ -89,7 +89,7 @@ fun MainTopBar( contentDescription = "profile picture", contentScale = ContentScale.Crop) } else { - Log.d("image", "CurrentUser.associationLogo: ${associationLogoUriValue}") + Log.d("image", "CurrentUser.associationLogo: ${associationLogoUriValue}") Icon( modifier = Modifier.fillMaxSize(), imageVector = Icons.Outlined.AccountCircle, diff --git a/app/src/main/java/com/github/se/assocify/ui/screens/profile/ProfileViewModel.kt b/app/src/main/java/com/github/se/assocify/ui/screens/profile/ProfileViewModel.kt index 7e8bbac53..70bbf1aeb 100644 --- a/app/src/main/java/com/github/se/assocify/ui/screens/profile/ProfileViewModel.kt +++ b/app/src/main/java/com/github/se/assocify/ui/screens/profile/ProfileViewModel.kt @@ -190,10 +190,10 @@ class ProfileViewModel( } val oldAssociationUid = CurrentUser.associationUid CurrentUser.associationUid = association.uid - assoAPI.getLogo( - CurrentUser.associationUid!!, - { uri -> CurrentUser.setAssociationLogo(uri) }, - { CurrentUser.setAssociationLogo(null) }) + assoAPI.getLogo( + CurrentUser.associationUid!!, + { uri -> CurrentUser.setAssociationLogo(uri) }, + { CurrentUser.setAssociationLogo(null) }) userAPI.getCurrentUserRole( { role -> _uiState.value = _uiState.value.copy(selectedAssociation = association) @@ -204,7 +204,6 @@ class ProfileViewModel( CurrentUser.associationUid = oldAssociationUid snackbarSystem.showSnackbar("Couldn't switch association") }) - } /** diff --git a/app/src/main/java/com/github/se/assocify/ui/screens/treasury/TreasuryGraph.kt b/app/src/main/java/com/github/se/assocify/ui/screens/treasury/TreasuryGraph.kt index ed6969bea..8c2656a38 100644 --- a/app/src/main/java/com/github/se/assocify/ui/screens/treasury/TreasuryGraph.kt +++ b/app/src/main/java/com/github/se/assocify/ui/screens/treasury/TreasuryGraph.kt @@ -39,8 +39,7 @@ fun NavGraphBuilder.treasuryGraph( balanceAPI, budgetAPI, userAPI, - associationAPI - ) + associationAPI) } TreasuryScreen(navigationActions, treasuryViewModel) } diff --git a/app/src/main/java/com/github/se/assocify/ui/screens/treasury/TreasuryScreen.kt b/app/src/main/java/com/github/se/assocify/ui/screens/treasury/TreasuryScreen.kt index ecfb5d6d2..fafa87423 100644 --- a/app/src/main/java/com/github/se/assocify/ui/screens/treasury/TreasuryScreen.kt +++ b/app/src/main/java/com/github/se/assocify/ui/screens/treasury/TreasuryScreen.kt @@ -21,7 +21,6 @@ import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag import androidx.compose.ui.unit.dp -import com.github.se.assocify.model.CurrentUser import com.github.se.assocify.model.entities.RoleType import com.github.se.assocify.navigation.Destination import com.github.se.assocify.navigation.MAIN_TABS_LIST @@ -100,9 +99,7 @@ fun TreasuryScreen(navActions: NavigationActions, treasuryViewModel: TreasuryVie snackbar = { snackbarData -> Snackbar(snackbarData = snackbarData) }) }, contentWindowInsets = WindowInsets(20.dp, 0.dp, 20.dp, 0.dp)) { innerPadding -> - Column(modifier = Modifier - .padding(innerPadding) - .fillMaxSize()) { + Column(modifier = Modifier.padding(innerPadding).fillMaxSize()) { if (receiptState.userCurrentRole.type != RoleType.TREASURY && receiptState.userCurrentRole.type != RoleType.PRESIDENCY) { ReceiptListScreen(viewModel = receiptListViewModel) diff --git a/app/src/main/java/com/github/se/assocify/ui/screens/treasury/TreasuryViewModel.kt b/app/src/main/java/com/github/se/assocify/ui/screens/treasury/TreasuryViewModel.kt index 358f92eba..b287c6fc3 100644 --- a/app/src/main/java/com/github/se/assocify/ui/screens/treasury/TreasuryViewModel.kt +++ b/app/src/main/java/com/github/se/assocify/ui/screens/treasury/TreasuryViewModel.kt @@ -1,9 +1,7 @@ package com.github.se.assocify.ui.screens.treasury -import android.net.Uri import android.util.Log import androidx.compose.material3.SnackbarHostState -import androidx.compose.runtime.collectAsState import com.github.se.assocify.model.CurrentUser import com.github.se.assocify.model.database.AccountingCategoryAPI import com.github.se.assocify.model.database.AccountingSubCategoryAPI @@ -29,15 +27,16 @@ class TreasuryViewModel( userAPI: UserAPI, associationAPI: AssociationAPI ) { - init { - Log.d("image", "getting logo in View model at init") - associationAPI.getLogo(CurrentUser.associationUid!!, - {uri -> - Log.d("image", "uri is $uri") - CurrentUser.setAssociationLogo(uri) }, - {CurrentUser.setAssociationLogo(null)} - ) - } + init { + Log.d("image", "getting logo in View model at init") + associationAPI.getLogo( + CurrentUser.associationUid!!, + { uri -> + Log.d("image", "uri is $uri") + CurrentUser.setAssociationLogo(uri) + }, + { CurrentUser.setAssociationLogo(null) }) + } // ViewModel states private val _uiState: MutableStateFlow = MutableStateFlow(TreasuryUIState()) val uiState: StateFlow = _uiState