mirror of
https://github.com/thunderbird/thunderbird-android.git
synced 2024-09-20 12:12:15 +02:00
Add getAccounts to AccountManager and replace usage
This commit is contained in:
parent
e2e583ef41
commit
4d2a07e9a7
@ -45,7 +45,7 @@ object Core : EarlyInit {
|
|||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun setServicesEnabled(context: Context) {
|
fun setServicesEnabled(context: Context) {
|
||||||
val appContext = context.applicationContext
|
val appContext = context.applicationContext
|
||||||
val acctLength = Preferences.getPreferences().accounts.size
|
val acctLength = Preferences.getPreferences().getAccounts().size
|
||||||
val enable = acctLength > 0
|
val enable = acctLength > 0
|
||||||
|
|
||||||
setServicesEnabled(appContext, enable)
|
setServicesEnabled(appContext, enable)
|
||||||
@ -82,7 +82,7 @@ object Core : EarlyInit {
|
|||||||
|
|
||||||
private fun restoreNotifications() {
|
private fun restoreNotifications() {
|
||||||
appCoroutineScope.launch(Dispatchers.IO) {
|
appCoroutineScope.launch(Dispatchers.IO) {
|
||||||
val accounts = preferences.accounts
|
val accounts = preferences.getAccounts()
|
||||||
notificationController.restoreNewMailNotifications(accounts)
|
notificationController.restoreNewMailNotifications(accounts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,8 +98,7 @@ class Preferences internal constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val accounts: List<Account>
|
override fun getAccounts(): List<Account> {
|
||||||
get() {
|
|
||||||
synchronized(accountLock) {
|
synchronized(accountLock) {
|
||||||
if (accountsMap == null) {
|
if (accountsMap == null) {
|
||||||
loadAccounts()
|
loadAccounts()
|
||||||
@ -110,7 +109,7 @@ class Preferences internal constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val completeAccounts: List<Account>
|
private val completeAccounts: List<Account>
|
||||||
get() = accounts.filter { it.isFinishedSetup }
|
get() = getAccounts().filter { it.isFinishedSetup }
|
||||||
|
|
||||||
override fun getAccount(accountUuid: String): Account? {
|
override fun getAccount(accountUuid: String): Account? {
|
||||||
synchronized(accountLock) {
|
synchronized(accountLock) {
|
||||||
@ -203,7 +202,7 @@ class Preferences internal constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val defaultAccount: Account?
|
val defaultAccount: Account?
|
||||||
get() = accounts.firstOrNull()
|
get() = getAccounts().firstOrNull()
|
||||||
|
|
||||||
override fun saveAccount(account: Account) {
|
override fun saveAccount(account: Account) {
|
||||||
ensureAssignedAccountNumber(account)
|
ensureAssignedAccountNumber(account)
|
||||||
@ -236,7 +235,7 @@ class Preferences internal constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun generateAccountNumber(): Int {
|
fun generateAccountNumber(): Int {
|
||||||
val accountNumbers = accounts.map { it.accountNumber }
|
val accountNumbers = getAccounts().map { it.accountNumber }
|
||||||
return findNewAccountNumber(accountNumbers)
|
return findNewAccountNumber(accountNumbers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ internal class NotificationOperations(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun clearUnifiedInboxNotifications() {
|
private fun clearUnifiedInboxNotifications() {
|
||||||
for (account in preferences.accounts) {
|
for (account in preferences.getAccounts()) {
|
||||||
val messageStore = messageStoreManager.getMessageStore(account)
|
val messageStore = messageStoreManager.getMessageStore(account)
|
||||||
|
|
||||||
val folderIds = messageStore.getFolders(excludeLocalOnly = true) { folderDetails ->
|
val folderIds = messageStore.getFolders(excludeLocalOnly = true) { folderDetails ->
|
||||||
@ -46,7 +46,7 @@ internal class NotificationOperations(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun clearAllNotifications() {
|
private fun clearAllNotifications() {
|
||||||
for (account in preferences.accounts) {
|
for (account in preferences.getAccounts()) {
|
||||||
notificationController.clearNewMailNotifications(account, clearNewMessageState = false)
|
notificationController.clearNewMailNotifications(account, clearNewMessageState = false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ class PushController internal constructor(
|
|||||||
Timber.v("PushController.disablePush()")
|
Timber.v("PushController.disablePush()")
|
||||||
|
|
||||||
coroutineScope.launch(coroutineDispatcher) {
|
coroutineScope.launch(coroutineDispatcher) {
|
||||||
for (account in preferences.accounts) {
|
for (account in preferences.getAccounts()) {
|
||||||
account.folderPushMode = FolderMode.NONE
|
account.folderPushMode = FolderMode.NONE
|
||||||
preferences.saveAccount(account)
|
preferences.saveAccount(account)
|
||||||
}
|
}
|
||||||
@ -191,18 +191,22 @@ class PushController internal constructor(
|
|||||||
realPushAccounts.isEmpty() -> {
|
realPushAccounts.isEmpty() -> {
|
||||||
stopServices()
|
stopServices()
|
||||||
}
|
}
|
||||||
|
|
||||||
backgroundSyncDisabledViaSystem -> {
|
backgroundSyncDisabledViaSystem -> {
|
||||||
setPushNotificationState(WAIT_BACKGROUND_SYNC)
|
setPushNotificationState(WAIT_BACKGROUND_SYNC)
|
||||||
startServices()
|
startServices()
|
||||||
}
|
}
|
||||||
|
|
||||||
networkNotAvailable -> {
|
networkNotAvailable -> {
|
||||||
setPushNotificationState(WAIT_NETWORK)
|
setPushNotificationState(WAIT_NETWORK)
|
||||||
startServices()
|
startServices()
|
||||||
}
|
}
|
||||||
|
|
||||||
arePushersActive -> {
|
arePushersActive -> {
|
||||||
setPushNotificationState(LISTENING)
|
setPushNotificationState(LISTENING)
|
||||||
startServices()
|
startServices()
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
stopServices()
|
stopServices()
|
||||||
}
|
}
|
||||||
@ -210,7 +214,7 @@ class PushController internal constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getPushAccounts(): List<Account> {
|
private fun getPushAccounts(): List<Account> {
|
||||||
return preferences.accounts.filter { account ->
|
return preferences.getAccounts().filter { account ->
|
||||||
account.folderPushMode != FolderMode.NONE && backendManager.getBackend(account).isPushCapable
|
account.folderPushMode != FolderMode.NONE && backendManager.getBackend(account).isPushCapable
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ class K9JobManager(
|
|||||||
private fun scheduleMailSync() {
|
private fun scheduleMailSync() {
|
||||||
cancelAllMailSyncJobs()
|
cancelAllMailSyncJobs()
|
||||||
|
|
||||||
preferences.accounts.forEach { account ->
|
preferences.getAccounts().forEach { account ->
|
||||||
mailSyncWorkerManager.scheduleMailSync(account)
|
mailSyncWorkerManager.scheduleMailSync(account)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ class NotificationChannelManager(
|
|||||||
backgroundExecutor.execute {
|
backgroundExecutor.execute {
|
||||||
addGeneralChannels()
|
addGeneralChannels()
|
||||||
|
|
||||||
val accounts = preferences.accounts
|
val accounts = preferences.getAccounts()
|
||||||
|
|
||||||
removeChannelsForNonExistingOrChangedAccounts(notificationManager, accounts)
|
removeChannelsForNonExistingOrChangedAccounts(notificationManager, accounts)
|
||||||
addChannelsForAccounts(notificationManager, accounts)
|
addChannelsForAccounts(notificationManager, accounts)
|
||||||
|
@ -6,6 +6,7 @@ import com.fsck.k9.AccountsChangeListener
|
|||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
interface AccountManager {
|
interface AccountManager {
|
||||||
|
fun getAccounts(): List<Account>
|
||||||
fun getAccountsFlow(): Flow<List<Account>>
|
fun getAccountsFlow(): Flow<List<Account>>
|
||||||
fun getAccount(accountUuid: String): Account?
|
fun getAccount(accountUuid: String): Account?
|
||||||
fun getAccountFlow(accountUuid: String): Flow<Account>
|
fun getAccountFlow(accountUuid: String): Flow<Account>
|
||||||
|
@ -19,7 +19,7 @@ val LocalSearch.isSingleFolder: Boolean
|
|||||||
|
|
||||||
@JvmName("getAccountsFromLocalSearch")
|
@JvmName("getAccountsFromLocalSearch")
|
||||||
fun LocalSearch.getAccounts(preferences: Preferences): List<Account> {
|
fun LocalSearch.getAccounts(preferences: Preferences): List<Account> {
|
||||||
val accounts = preferences.accounts
|
val accounts = preferences.getAccounts()
|
||||||
return if (searchAllAccounts()) {
|
return if (searchAllAccounts()) {
|
||||||
accounts
|
accounts
|
||||||
} else {
|
} else {
|
||||||
|
@ -9,7 +9,7 @@ class AccountColorPicker(
|
|||||||
private val resources: Resources,
|
private val resources: Resources,
|
||||||
) {
|
) {
|
||||||
fun pickColor(): Int {
|
fun pickColor(): Int {
|
||||||
val accounts = preferences.accounts
|
val accounts = preferences.getAccounts()
|
||||||
val usedAccountColors = accounts.map { it.chipColor }.toSet()
|
val usedAccountColors = accounts.map { it.chipColor }.toSet()
|
||||||
val accountColors = resources.getIntArray(R.array.account_colors).toList()
|
val accountColors = resources.getIntArray(R.array.account_colors).toList()
|
||||||
|
|
||||||
|
@ -11,6 +11,8 @@ class FakeAccountManager(
|
|||||||
private val isFailureOnSave: Boolean = false,
|
private val isFailureOnSave: Boolean = false,
|
||||||
) : AccountManager {
|
) : AccountManager {
|
||||||
|
|
||||||
|
override fun getAccounts(): List<Account> = accounts.values.toList()
|
||||||
|
|
||||||
override fun getAccountsFlow(): Flow<List<Account>> {
|
override fun getAccountsFlow(): Flow<List<Account>> {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,7 @@ open class MessageList :
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val accounts = preferences.accounts
|
val accounts = preferences.getAccounts()
|
||||||
deleteIncompleteAccounts(accounts)
|
deleteIncompleteAccounts(accounts)
|
||||||
val hasAccountSetup = accounts.any { it.isFinishedSetup }
|
val hasAccountSetup = accounts.any { it.isFinishedSetup }
|
||||||
if (!hasAccountSetup) {
|
if (!hasAccountSetup) {
|
||||||
@ -332,9 +332,11 @@ open class MessageList :
|
|||||||
DisplayMode.MESSAGE_LIST -> {
|
DisplayMode.MESSAGE_LIST -> {
|
||||||
showMessageList()
|
showMessageList()
|
||||||
}
|
}
|
||||||
|
|
||||||
DisplayMode.MESSAGE_VIEW -> {
|
DisplayMode.MESSAGE_VIEW -> {
|
||||||
showMessageView()
|
showMessageView()
|
||||||
}
|
}
|
||||||
|
|
||||||
DisplayMode.SPLIT_VIEW -> {
|
DisplayMode.SPLIT_VIEW -> {
|
||||||
val messageListFragment = checkNotNull(this.messageListFragment)
|
val messageListFragment = checkNotNull(this.messageListFragment)
|
||||||
|
|
||||||
@ -712,6 +714,7 @@ open class MessageList :
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyEvent.KEYCODE_VOLUME_DOWN -> {
|
KeyEvent.KEYCODE_VOLUME_DOWN -> {
|
||||||
if (messageViewContainerFragment != null && displayMode != DisplayMode.MESSAGE_LIST &&
|
if (messageViewContainerFragment != null && displayMode != DisplayMode.MESSAGE_LIST &&
|
||||||
K9.isUseVolumeKeysForNavigation
|
K9.isUseVolumeKeysForNavigation
|
||||||
@ -720,10 +723,12 @@ open class MessageList :
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyEvent.KEYCODE_DEL -> {
|
KeyEvent.KEYCODE_DEL -> {
|
||||||
onDeleteHotKey()
|
onDeleteHotKey()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyEvent.KEYCODE_DPAD_LEFT -> {
|
KeyEvent.KEYCODE_DPAD_LEFT -> {
|
||||||
return if (messageViewContainerFragment != null && displayMode == DisplayMode.MESSAGE_VIEW) {
|
return if (messageViewContainerFragment != null && displayMode == DisplayMode.MESSAGE_VIEW) {
|
||||||
showPreviousMessage()
|
showPreviousMessage()
|
||||||
@ -731,6 +736,7 @@ open class MessageList :
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
KeyEvent.KEYCODE_DPAD_RIGHT -> {
|
KeyEvent.KEYCODE_DPAD_RIGHT -> {
|
||||||
return if (messageViewContainerFragment != null && displayMode == DisplayMode.MESSAGE_VIEW) {
|
return if (messageViewContainerFragment != null && displayMode == DisplayMode.MESSAGE_VIEW) {
|
||||||
showNextMessage()
|
showNextMessage()
|
||||||
@ -745,22 +751,27 @@ open class MessageList :
|
|||||||
messageListFragment!!.onCompose()
|
messageListFragment!!.onCompose()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
'o' -> {
|
'o' -> {
|
||||||
messageListFragment!!.onCycleSort()
|
messageListFragment!!.onCycleSort()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
'i' -> {
|
'i' -> {
|
||||||
messageListFragment!!.onReverseSort()
|
messageListFragment!!.onReverseSort()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
'd' -> {
|
'd' -> {
|
||||||
onDeleteHotKey()
|
onDeleteHotKey()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
's' -> {
|
's' -> {
|
||||||
messageListFragment!!.toggleMessageSelect()
|
messageListFragment!!.toggleMessageSelect()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
'g' -> {
|
'g' -> {
|
||||||
if (displayMode == DisplayMode.MESSAGE_LIST) {
|
if (displayMode == DisplayMode.MESSAGE_LIST) {
|
||||||
messageListFragment!!.onToggleFlagged()
|
messageListFragment!!.onToggleFlagged()
|
||||||
@ -769,6 +780,7 @@ open class MessageList :
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
'm' -> {
|
'm' -> {
|
||||||
if (displayMode == DisplayMode.MESSAGE_LIST) {
|
if (displayMode == DisplayMode.MESSAGE_LIST) {
|
||||||
messageListFragment!!.onMove()
|
messageListFragment!!.onMove()
|
||||||
@ -777,6 +789,7 @@ open class MessageList :
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
'v' -> {
|
'v' -> {
|
||||||
if (displayMode == DisplayMode.MESSAGE_LIST) {
|
if (displayMode == DisplayMode.MESSAGE_LIST) {
|
||||||
messageListFragment!!.onArchive()
|
messageListFragment!!.onArchive()
|
||||||
@ -785,6 +798,7 @@ open class MessageList :
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
'y' -> {
|
'y' -> {
|
||||||
if (displayMode == DisplayMode.MESSAGE_LIST) {
|
if (displayMode == DisplayMode.MESSAGE_LIST) {
|
||||||
messageListFragment!!.onCopy()
|
messageListFragment!!.onCopy()
|
||||||
@ -793,6 +807,7 @@ open class MessageList :
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
'z' -> {
|
'z' -> {
|
||||||
if (displayMode == DisplayMode.MESSAGE_LIST) {
|
if (displayMode == DisplayMode.MESSAGE_LIST) {
|
||||||
messageListFragment!!.onToggleRead()
|
messageListFragment!!.onToggleRead()
|
||||||
@ -801,30 +816,35 @@ open class MessageList :
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
'f' -> {
|
'f' -> {
|
||||||
if (messageViewContainerFragment != null) {
|
if (messageViewContainerFragment != null) {
|
||||||
messageViewContainerFragment!!.onForward()
|
messageViewContainerFragment!!.onForward()
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
'a' -> {
|
'a' -> {
|
||||||
if (messageViewContainerFragment != null) {
|
if (messageViewContainerFragment != null) {
|
||||||
messageViewContainerFragment!!.onReplyAll()
|
messageViewContainerFragment!!.onReplyAll()
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
'r' -> {
|
'r' -> {
|
||||||
if (messageViewContainerFragment != null) {
|
if (messageViewContainerFragment != null) {
|
||||||
messageViewContainerFragment!!.onReply()
|
messageViewContainerFragment!!.onReply()
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
'j', 'p' -> {
|
'j', 'p' -> {
|
||||||
if (messageViewContainerFragment != null) {
|
if (messageViewContainerFragment != null) {
|
||||||
showPreviousMessage()
|
showPreviousMessage()
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
'n', 'k' -> {
|
'n', 'k' -> {
|
||||||
if (messageViewContainerFragment != null) {
|
if (messageViewContainerFragment != null) {
|
||||||
showNextMessage()
|
showNextMessage()
|
||||||
|
@ -460,7 +460,7 @@ class MessageListFragment :
|
|||||||
}
|
}
|
||||||
|
|
||||||
val subtitle = account.let { account ->
|
val subtitle = account.let { account ->
|
||||||
if (account == null || isUnifiedInbox || preferences.accounts.size == 1) {
|
if (account == null || isUnifiedInbox || preferences.getAccounts().size == 1) {
|
||||||
null
|
null
|
||||||
} else {
|
} else {
|
||||||
account.displayName
|
account.displayName
|
||||||
|
@ -58,7 +58,7 @@ class SettingsExportViewModel(
|
|||||||
uiModelLiveData.value = uiModel
|
uiModelLiveData.value = uiModel
|
||||||
|
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
val accounts = withContext(Dispatchers.IO) { preferences.accounts }
|
val accounts = withContext(Dispatchers.IO) { preferences.getAccounts() }
|
||||||
|
|
||||||
accountsMap = accounts.map { it.accountNumber to it.uuid }.toMap()
|
accountsMap = accounts.map { it.accountNumber to it.uuid }.toMap()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user