Rewrite ManageFoldersViewModel to use Flow

This commit is contained in:
cketti 2021-09-02 21:36:11 +02:00
parent 288486e247
commit ddda3f88df
2 changed files with 8 additions and 15 deletions

View file

@ -4,6 +4,6 @@ import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.dsl.module
val manageFoldersUiModule = module {
viewModel { ManageFoldersViewModel(foldersLiveDataFactory = get()) }
viewModel { ManageFoldersViewModel(folderRepository = get()) }
viewModel { FolderSettingsViewModel(preferences = get(), folderRepository = get(), messagingController = get()) }
}

View file

@ -1,21 +1,14 @@
package com.fsck.k9.ui.managefolders
import androidx.lifecycle.LiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.asLiveData
import com.fsck.k9.Account
import com.fsck.k9.ui.folders.FoldersLiveData
import com.fsck.k9.ui.folders.FoldersLiveDataFactory
import com.fsck.k9.mailstore.DisplayFolder
import com.fsck.k9.mailstore.FolderRepository
class ManageFoldersViewModel(private val foldersLiveDataFactory: FoldersLiveDataFactory) : ViewModel() {
private var foldersLiveData: FoldersLiveData? = null
fun getFolders(account: Account): FoldersLiveData {
val liveData = foldersLiveData
if (liveData != null && liveData.account.uuid == account.uuid) {
return liveData
}
return foldersLiveDataFactory.create(account).also {
foldersLiveData = it
}
class ManageFoldersViewModel(private val folderRepository: FolderRepository) : ViewModel() {
fun getFolders(account: Account): LiveData<List<DisplayFolder>> {
return folderRepository.getDisplayFoldersFlow(account).asLiveData()
}
}