Skip to content

Commit

Permalink
chore: ktfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
zizouet committed Jun 2, 2024
1 parent e4331b6 commit af28f2a
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 38 deletions.
9 changes: 5 additions & 4 deletions app/src/main/java/com/github/se/assocify/model/CurrentUser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import kotlinx.coroutines.flow.StateFlow
object CurrentUser {
var userUid: String? = null
var associationUid: String? = null
private var _associationLogo : StateFlow<Uri?> = MutableStateFlow(null)
private var _associationLogo: StateFlow<Uri?> = MutableStateFlow(null)
val associationLogo: StateFlow<Uri?> = _associationLogo
fun setAssociationLogo(uri: Uri?) {
(_associationLogo as MutableStateFlow).value = uri
}

fun setAssociationLogo(uri: Uri?) {
(_associationLogo as MutableStateFlow).value = uri
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import kotlinx.serialization.json.JsonObject
class AssociationAPI(private val db: SupabaseClient, cachePath: Path) : SupabaseApi() {
private var associationCache = mapOf<String, Association>()
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
}

/**
Expand All @@ -45,7 +45,7 @@ class AssociationAPI(private val db: SupabaseClient, cachePath: Path) : Supabase
val assoc = db.from("association").select().decodeList<SupabaseAssociation>()
associationCache = assoc.associateBy { it.uid!! }.mapValues { it.value.toAssociation() }
memberCache = null
currentAssociationCache = CurrentUser.associationUid
currentAssociationCache = CurrentUser.associationUid
onSuccess(associationCache)
}
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -204,7 +204,6 @@ class ProfileViewModel(
CurrentUser.associationUid = oldAssociationUid
snackbarSystem.showSnackbar("Couldn't switch association")
})

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ fun NavGraphBuilder.treasuryGraph(
balanceAPI,
budgetAPI,
userAPI,
associationAPI
)
associationAPI)
}
TreasuryScreen(navigationActions, treasuryViewModel)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<TreasuryUIState> = MutableStateFlow(TreasuryUIState())
val uiState: StateFlow<TreasuryUIState> = _uiState
Expand Down

0 comments on commit af28f2a

Please sign in to comment.