mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-18 11:49:01 +00:00
properly clear data when logging out
This commit is contained in:
parent
24aeaab80a
commit
c6957adae9
6 changed files with 22 additions and 7 deletions
|
|
@ -106,4 +106,11 @@ class TaskLocalRepository @Inject constructor() {
|
|||
TaskType.REWARD.value to (tasks[TaskType.REWARD]?.value?.size ?: 0),
|
||||
)
|
||||
}
|
||||
|
||||
fun clearData() {
|
||||
tasks.values.forEach {
|
||||
it.value = null
|
||||
}
|
||||
taskCountHelperValue.value = 0
|
||||
}
|
||||
}
|
||||
|
|
@ -78,4 +78,5 @@ class TaskRepository @Inject constructor(
|
|||
|
||||
fun getTaskCounts() = localRepository.getTaskCounts()
|
||||
fun getActiveTaskCounts() = localRepository.getActiveTaskCounts()
|
||||
fun clearData() = localRepository.clearData()
|
||||
}
|
||||
|
|
@ -3,18 +3,19 @@ package com.habitrpg.wearos.habitica.data.repositories
|
|||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.asFlow
|
||||
import com.habitrpg.wearos.habitica.models.user.User
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class UserLocalRepository @Inject constructor() {
|
||||
private val user = MutableLiveData<User>()
|
||||
fun getUser(): Flow<User> {
|
||||
return user.asFlow()
|
||||
}
|
||||
private val user = MutableLiveData<User?>()
|
||||
fun getUser() = user.asFlow()
|
||||
|
||||
fun saveUser(user: User) {
|
||||
this.user.value = user
|
||||
}
|
||||
|
||||
fun clearData() {
|
||||
user.value = null
|
||||
}
|
||||
}
|
||||
|
|
@ -39,4 +39,8 @@ class UserRepository @Inject constructor(
|
|||
suspend fun runCron() {
|
||||
apiClient.runCron()
|
||||
}
|
||||
|
||||
fun clearData() {
|
||||
localRepository.clearData()
|
||||
}
|
||||
}
|
||||
|
|
@ -126,8 +126,8 @@ class LoginViewModel @Inject constructor(userRepository: UserRepository,
|
|||
saveTokens(userAuthResponse.apiToken, userAuthResponse.id)
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
val user = userRepository.retrieveUser()
|
||||
taskRepository.retrieveTasks(user?.tasksOrder)
|
||||
val user = userRepository.retrieveUser(true)
|
||||
taskRepository.retrieveTasks(user?.tasksOrder, true)
|
||||
onLoginCompleted()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@ class SettingsViewModel @Inject constructor(userRepository: UserRepository,
|
|||
clear()
|
||||
}
|
||||
apiClient.updateAuthenticationCredentials(null, null)
|
||||
userRepository.clearData()
|
||||
taskRepository.clearData()
|
||||
}
|
||||
|
||||
fun resyncData() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue