Don't load 'hasMoreMessages' data in main thread
This commit is contained in:
parent
20e239f68e
commit
caa7b6d797
6 changed files with 34 additions and 22 deletions
|
@ -23,7 +23,7 @@ public class FolderInfoHolder {
|
|||
this.serverId = localFolder.getServerId();
|
||||
this.lastChecked = localFolder.getLastUpdate();
|
||||
this.displayName = getDisplayName(account, localFolder);
|
||||
setMoreMessagesFromFolder(localFolder);
|
||||
moreMessages = localFolder.hasMoreMessages();
|
||||
}
|
||||
|
||||
private String getDisplayName(Account account, LocalFolder localFolder) {
|
||||
|
@ -37,10 +37,6 @@ public class FolderInfoHolder {
|
|||
return folderNameFormatter.displayName(folder);
|
||||
}
|
||||
|
||||
public void setMoreMessagesFromFolder(LocalFolder folder) {
|
||||
moreMessages = folder.hasMoreMessages();
|
||||
}
|
||||
|
||||
public static FolderType getFolderType(Account account, String serverId) {
|
||||
if (serverId.equals(account.getInboxFolder())) {
|
||||
return FolderType.INBOX;
|
||||
|
|
|
@ -67,6 +67,7 @@ import com.fsck.k9.ui.folders.FolderNameFormatterFactory;
|
|||
import com.fsck.k9.ui.messagelist.MessageListAppearance;
|
||||
import com.fsck.k9.ui.messagelist.MessageListConfig;
|
||||
import com.fsck.k9.ui.messagelist.MessageListFragmentDiContainer;
|
||||
import com.fsck.k9.ui.messagelist.MessageListInfo;
|
||||
import com.fsck.k9.ui.messagelist.MessageListItem;
|
||||
import com.fsck.k9.ui.messagelist.MessageListViewModel;
|
||||
|
||||
|
@ -191,7 +192,6 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
|
|||
if (currentFolder != null && currentFolder.serverId.equals(folder)) {
|
||||
currentFolder.loading = loading;
|
||||
}
|
||||
updateMoreMessagesOfCurrentFolder();
|
||||
updateFooterView();
|
||||
}
|
||||
|
||||
|
@ -2375,7 +2375,8 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
|
|||
return fragmentListener.startSearch(account, folderServerId);
|
||||
}
|
||||
|
||||
public void setMessageList(List<MessageListItem> messageListItems) {
|
||||
public void setMessageList(MessageListInfo messageListInfo) {
|
||||
List<MessageListItem> messageListItems = messageListInfo.getMessageListItems();
|
||||
if (isThreadDisplay && messageListItems.isEmpty()) {
|
||||
handler.goBack();
|
||||
return;
|
||||
|
@ -2417,16 +2418,10 @@ public class MessageListFragment extends Fragment implements OnItemClickListener
|
|||
}
|
||||
|
||||
fragmentListener.updateMenu();
|
||||
}
|
||||
|
||||
private void updateMoreMessagesOfCurrentFolder() {
|
||||
if (folderServerId != null) {
|
||||
try {
|
||||
LocalFolder folder = MlfUtils.getOpenFolder(folderServerId, account);
|
||||
currentFolder.setMoreMessagesFromFolder(folder);
|
||||
} catch (MessagingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
currentFolder.moreMessages = messageListInfo.getHasMoreMessages();
|
||||
updateFooterView();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,6 @@ val messageListUiModule = module {
|
|||
viewModel { MessageListViewModel(get()) }
|
||||
factory { DefaultFolderProvider() }
|
||||
factory { MessageListExtractor(get(), get()) }
|
||||
factory { MessageListLoader(get(), get(), get()) }
|
||||
factory { MessageListLoader(get(), get(), get(), get()) }
|
||||
factory { MessageListLiveDataFactory(get(), get(), get()) }
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ class MessageListLiveData(
|
|||
private val contentResolver: ContentResolver,
|
||||
private val coroutineScope: CoroutineScope,
|
||||
val config: MessageListConfig
|
||||
) : LiveData<List<MessageListItem>>() {
|
||||
) : LiveData<MessageListInfo>() {
|
||||
|
||||
private val contentObserver = object : ContentObserver(Handler()) {
|
||||
override fun onChange(selfChange: Boolean) {
|
||||
|
|
|
@ -18,6 +18,7 @@ import com.fsck.k9.fragment.MessageListFragmentComparators.SenderComparator
|
|||
import com.fsck.k9.fragment.MessageListFragmentComparators.SubjectComparator
|
||||
import com.fsck.k9.fragment.MessageListFragmentComparators.UnreadComparator
|
||||
import com.fsck.k9.helper.MergeCursorWithUniqueId
|
||||
import com.fsck.k9.mailstore.LocalStoreProvider
|
||||
import com.fsck.k9.provider.EmailProvider
|
||||
import com.fsck.k9.provider.EmailProvider.SpecialColumns
|
||||
import com.fsck.k9.search.LocalSearch
|
||||
|
@ -30,11 +31,13 @@ import java.util.Comparator
|
|||
class MessageListLoader(
|
||||
private val preferences: Preferences,
|
||||
private val contentResolver: ContentResolver,
|
||||
private val localStoreProvider: LocalStoreProvider,
|
||||
private val messageListExtractor: MessageListExtractor
|
||||
) {
|
||||
|
||||
fun getMessageList(config: MessageListConfig): List<MessageListItem> {
|
||||
val cursors = config.search.getAccounts(preferences)
|
||||
fun getMessageList(config: MessageListConfig): MessageListInfo {
|
||||
val accounts = config.search.getAccounts(preferences)
|
||||
val cursors = accounts
|
||||
.mapNotNull { loadMessageListForAccount(it, config) }
|
||||
.toTypedArray()
|
||||
|
||||
|
@ -48,13 +51,16 @@ class MessageListLoader(
|
|||
uniqueIdColumn = MLFProjectionInfo.ID_COLUMN
|
||||
}
|
||||
|
||||
return cursor.use {
|
||||
val messageListItems = cursor.use {
|
||||
messageListExtractor.extractMessageList(
|
||||
cursor,
|
||||
uniqueIdColumn,
|
||||
threadCountIncluded = config.showingThreadedList
|
||||
)
|
||||
}
|
||||
val hasMoreMessages = loadHasMoreMessages(accounts, config.search.folderServerIds)
|
||||
|
||||
return MessageListInfo(messageListItems, hasMoreMessages)
|
||||
}
|
||||
|
||||
private fun loadMessageListForAccount(account: Account, config: MessageListConfig): Cursor? {
|
||||
|
@ -166,6 +172,19 @@ class MessageListLoader(
|
|||
return ComparatorChain(chain)
|
||||
}
|
||||
|
||||
private fun loadHasMoreMessages(accounts: List<Account>, folderServerIds: List<String>): Boolean {
|
||||
return if (accounts.size == 1 && folderServerIds.size == 1) {
|
||||
val account = accounts[0]
|
||||
val folderServerId = folderServerIds[0]
|
||||
val localStore = localStoreProvider.getInstance(account)
|
||||
val localFolder = localStore.getFolder(folderServerId)
|
||||
localFolder.open()
|
||||
localFolder.hasMoreMessages()
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val SORT_COMPARATORS = mapOf(
|
||||
SortType.SORT_ATTACHMENT to AttachmentComparator(),
|
||||
|
@ -178,3 +197,5 @@ class MessageListLoader(
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
data class MessageListInfo(val messageListItems: List<MessageListItem>, val hasMoreMessages: Boolean)
|
||||
|
|
|
@ -7,9 +7,9 @@ import androidx.lifecycle.viewModelScope
|
|||
|
||||
class MessageListViewModel(private val messageListLiveDataFactory: MessageListLiveDataFactory) : ViewModel() {
|
||||
private var currentMessageListLiveData: MessageListLiveData? = null
|
||||
private val messageListLiveData = MediatorLiveData<List<MessageListItem>>()
|
||||
private val messageListLiveData = MediatorLiveData<MessageListInfo>()
|
||||
|
||||
fun getMessageListLiveData(): LiveData<List<MessageListItem>> {
|
||||
fun getMessageListLiveData(): LiveData<MessageListInfo> {
|
||||
return messageListLiveData
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue