small fixes

This commit is contained in:
Phillip Thelen 2023-05-11 16:19:11 +02:00
parent 4b9ba6c3f9
commit 9e0bbcd501
3 changed files with 11 additions and 9 deletions

View file

@ -427,7 +427,7 @@ class AccountPreferenceFragment :
}) {
lifecycleScope.launchCatching {
val user = userRepository.updateLoginName(it ?: "")
if (user == null) {
if (user == null || user.username != it) {
userRepository.retrieveUser(false, forced = true)
}
}

View file

@ -1,6 +1,5 @@
package com.habitrpg.android.habitica.ui.viewmodels
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.LiveData
import androidx.lifecycle.asLiveData
import com.habitrpg.android.habitica.data.SocialRepository
@ -18,10 +17,12 @@ import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.lastOrNull
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import javax.inject.Inject
class MainUserViewModel @Inject constructor(private val authenticationHandler : AuthenticationHandler, val userRepository: UserRepository, val socialRepository: SocialRepository) {
val formattedUsername: CharSequence?
@ -48,16 +49,17 @@ class MainUserViewModel @Inject constructor(private val authenticationHandler :
)
@OptIn(ExperimentalCoroutinesApi::class)
var currentTeamPlanGroup = currentTeamPlan
.map { it?.id }
.distinctUntilChanged { old, new -> old == new }
.filterNotNull()
.distinctUntilChanged { old, new ->
old.id == new.id }
.flatMapLatest { socialRepository.getGroup(it.id) }
.flatMapLatest { socialRepository.getGroup(it) }
@OptIn(ExperimentalCoroutinesApi::class)
var currentTeamPlanMembers: LiveData<List<Member>> = currentTeamPlan
.distinctUntilChanged { old, new -> old?.id == new?.id }
.map { it?.id }
.distinctUntilChanged { old, new -> old == new }
.filterNotNull()
.flatMapLatest { socialRepository.getGroupMembers(it.id) }
.distinctUntilChanged()
.flatMapLatest { socialRepository.getGroupMembers(it) }
.distinctUntilChanged { old, new -> old.size == new.size && !old.mapIndexed { index, member -> member.id == new[index].id }.contains(false) }
.onEach {
if (it.isEmpty()) {
currentTeamPlan.lastOrNull()?.let { plan ->

View file

@ -1,2 +1,2 @@
NAME=4.2
CODE=6041
CODE=6051