Merge pull request #5708 from k9mail/remove_AccountsLiveData
Remove AccountsLiveData
This commit is contained in:
commit
07569ba424
4 changed files with 8 additions and 50 deletions
|
@ -1,40 +0,0 @@
|
|||
package com.fsck.k9.ui.account
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import com.fsck.k9.Account
|
||||
import com.fsck.k9.AccountsChangeListener
|
||||
import com.fsck.k9.Preferences
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class AccountsLiveData(val preferences: Preferences) : LiveData<List<Account>>(), AccountsChangeListener {
|
||||
|
||||
private fun loadAccountsAsync() {
|
||||
GlobalScope.launch(Dispatchers.Main) {
|
||||
value = withContext(Dispatchers.IO) {
|
||||
loadAccounts()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAccountsChanged() {
|
||||
loadAccountsAsync()
|
||||
}
|
||||
|
||||
private fun loadAccounts(): List<Account> {
|
||||
return preferences.accounts
|
||||
}
|
||||
|
||||
override fun onActive() {
|
||||
super.onActive()
|
||||
preferences.addOnAccountsChangeListener(this)
|
||||
loadAccountsAsync()
|
||||
}
|
||||
|
||||
override fun onInactive() {
|
||||
super.onInactive()
|
||||
preferences.removeOnAccountsChangeListener(this)
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package com.fsck.k9.ui.settings
|
||||
|
||||
import com.fsck.k9.helper.NamedThreadFactory
|
||||
import com.fsck.k9.ui.account.AccountsLiveData
|
||||
import com.fsck.k9.ui.settings.account.AccountSettingsDataStoreFactory
|
||||
import com.fsck.k9.ui.settings.account.AccountSettingsViewModel
|
||||
import com.fsck.k9.ui.settings.export.SettingsExportViewModel
|
||||
|
@ -15,8 +14,7 @@ import org.koin.core.qualifier.named
|
|||
import org.koin.dsl.module
|
||||
|
||||
val settingsUiModule = module {
|
||||
factory { AccountsLiveData(get()) }
|
||||
viewModel { SettingsViewModel(accountManager = get(), accounts = get()) }
|
||||
viewModel { SettingsViewModel(accountManager = get()) }
|
||||
|
||||
factory { GeneralSettingsDataStore(jobManager = get(), themeManager = get(), appLanguageManager = get()) }
|
||||
single(named("SaveSettingsExecutorService")) {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package com.fsck.k9.ui.settings
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.asLiveData
|
||||
import com.fsck.k9.Account
|
||||
import com.fsck.k9.preferences.AccountManager
|
||||
import com.fsck.k9.ui.account.AccountsLiveData
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
@ -15,8 +15,8 @@ internal class SettingsViewModel(
|
|||
private val accountManager: AccountManager,
|
||||
private val coroutineScope: CoroutineScope = GlobalScope,
|
||||
private val coroutineDispatcher: CoroutineDispatcher = Dispatchers.IO,
|
||||
val accounts: AccountsLiveData
|
||||
) : ViewModel() {
|
||||
val accounts = accountManager.getAccountsFlow().asLiveData()
|
||||
|
||||
fun moveAccount(account: Account, newPosition: Int) {
|
||||
coroutineScope.launch(coroutineDispatcher) {
|
||||
|
|
|
@ -3,24 +3,24 @@ package com.fsck.k9.ui.settings.account
|
|||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.asLiveData
|
||||
import com.fsck.k9.Account
|
||||
import com.fsck.k9.Preferences
|
||||
import com.fsck.k9.mailstore.FolderRepository
|
||||
import com.fsck.k9.mailstore.FolderType
|
||||
import com.fsck.k9.mailstore.RemoteFolder
|
||||
import com.fsck.k9.mailstore.SpecialFolderSelectionStrategy
|
||||
import com.fsck.k9.ui.account.AccountsLiveData
|
||||
import com.fsck.k9.preferences.AccountManager
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
class AccountSettingsViewModel(
|
||||
private val preferences: Preferences,
|
||||
private val accountManager: AccountManager,
|
||||
private val folderRepository: FolderRepository,
|
||||
private val specialFolderSelectionStrategy: SpecialFolderSelectionStrategy
|
||||
) : ViewModel() {
|
||||
val accounts = AccountsLiveData(preferences)
|
||||
val accounts = accountManager.getAccountsFlow().asLiveData()
|
||||
private val accountLiveData = MutableLiveData<Account>()
|
||||
private val foldersLiveData = MutableLiveData<RemoteFolderInfo>()
|
||||
|
||||
|
@ -49,7 +49,7 @@ class AccountSettingsViewModel(
|
|||
}
|
||||
|
||||
private fun loadAccount(accountUuid: String): Account {
|
||||
return preferences.getAccount(accountUuid) ?: error("Account $accountUuid not found")
|
||||
return accountManager.getAccount(accountUuid) ?: error("Account $accountUuid not found")
|
||||
}
|
||||
|
||||
fun getFolders(account: Account): LiveData<RemoteFolderInfo> {
|
||||
|
|
Loading…
Reference in a new issue