From d3981b8f12c396aab23149c9d0f04f0b78277be7 Mon Sep 17 00:00:00 2001 From: hasibprince Date: Tue, 21 Feb 2023 22:38:29 +0600 Subject: [PATCH 1/3] initial caching thorough datastore --- app/ui/legacy/build.gradle | 4 ++ .../com/fsck/k9/ui/messagelist/EmailCache.kt | 70 +++++++++++++++++++ .../com/fsck/k9/ui/messagelist/KoinModule.kt | 10 ++- .../k9/ui/messagelist/MessageListLiveData.kt | 9 ++- .../messagelist/MessageListLiveDataFactory.kt | 5 +- gradle/libs.versions.toml | 4 ++ 6 files changed, 97 insertions(+), 5 deletions(-) create mode 100644 app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/EmailCache.kt diff --git a/app/ui/legacy/build.gradle b/app/ui/legacy/build.gradle index 2e4f957a75..36ef6c0a2e 100644 --- a/app/ui/legacy/build.gradle +++ b/app/ui/legacy/build.gradle @@ -42,6 +42,10 @@ dependencies { implementation libs.fastadapter.extensions.drag implementation libs.fastadapter.extensions.utils implementation libs.circleimageview + implementation libs.moshi + implementation libs.moshi.kotlin + implementation libs.gson + implementation libs.androidx.datastore api libs.appauth implementation libs.commons.io diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/EmailCache.kt b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/EmailCache.kt new file mode 100644 index 0000000000..19b84dcfef --- /dev/null +++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/EmailCache.kt @@ -0,0 +1,70 @@ +package com.fsck.k9.ui.messagelist + +import android.content.Context +import androidx.datastore.preferences.core.edit +import androidx.datastore.preferences.core.stringPreferencesKey +import androidx.datastore.preferences.preferencesDataStore +import com.google.gson.Gson +import com.google.gson.TypeAdapter +import com.google.gson.reflect.TypeToken +import com.google.gson.stream.JsonReader +import com.google.gson.stream.JsonToken +import com.google.gson.stream.JsonWriter +import com.squareup.moshi.Moshi +import java.io.IOException +import kotlinx.coroutines.flow.firstOrNull +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.runBlocking +import timber.log.Timber + +class EmailCache constructor(private val context: Context, private val moshi: Moshi, private val gson: Gson) { + companion object { + private const val preferenceDataStoreName = "emailCache" + private val Context.emailCacheDataStore by preferencesDataStore(preferenceDataStoreName) + } + + private val MAIL_LIST_KEY = stringPreferencesKey("mail_list") + + suspend fun saveLatestMails(mailList: List) { +// val type = Types.newParameterizedType(List::class.java, MessageListItem::class.java) +// val adapter = moshi.adapter>(type) +// val mailListJson = adapter.toJson(mailList) + val listType = object : TypeToken>() {}.type + val mailListJson = gson.toJson(mailList, listType) + context.emailCacheDataStore.edit { + it[MAIL_LIST_KEY] = mailListJson + } + } + + suspend fun getCachedMails(): List? { + return runBlocking { + val listType = object : TypeToken>() {}.type + val mailListJson = context.emailCacheDataStore.data.map { it[MAIL_LIST_KEY] }.firstOrNull() + Timber.d("email data: $mailListJson") + gson.fromJson(mailListJson, listType) + } + } +} + +internal class CharSequenceTypeAdapter : TypeAdapter() { + @Throws(IOException::class) + override fun write(out: JsonWriter, value: CharSequence?) { + if (value == null) { + out.nullValue() + } else { + // Assumes that value complies with CharSequence.toString() contract + out.value(value.toString()) + } + } + + @Throws(IOException::class) + override fun read(`in`: JsonReader): CharSequence? { + return if (`in`.peek() === JsonToken.NULL) { + // Skip the JSON null + `in`.skipValue() + null + } else { + `in`.nextString() + } + } +} diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/KoinModule.kt b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/KoinModule.kt index 487fcea1c5..33d728f71f 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/KoinModule.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/KoinModule.kt @@ -1,5 +1,10 @@ package com.fsck.k9.ui.messagelist +import com.google.gson.Gson +import com.google.gson.GsonBuilder +import com.squareup.moshi.Moshi +import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory +import org.koin.android.ext.koin.androidContext import org.koin.androidx.viewmodel.dsl.viewModel import org.koin.dsl.module @@ -14,8 +19,11 @@ val messageListUiModule = module { messageHelper = get() ) } + single { Moshi.Builder().add(KotlinJsonAdapterFactory()) .build() } + single { GsonBuilder().registerTypeAdapter(CharSequence::class.java, CharSequenceTypeAdapter()).create() } + single { EmailCache(androidContext(), get(), get()) } factory { - MessageListLiveDataFactory(messageListLoader = get(), preferences = get(), messageListRepository = get()) + MessageListLiveDataFactory(messageListLoader = get(), preferences = get(), messageListRepository = get(), emailCache = get()) } single { SortTypeToastProvider() } } diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLiveData.kt b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLiveData.kt index bf757521d2..0b1e0eedb2 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLiveData.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLiveData.kt @@ -15,7 +15,8 @@ class MessageListLiveData( private val preferences: Preferences, private val messageListRepository: MessageListRepository, private val coroutineScope: CoroutineScope, - val config: MessageListConfig + val config: MessageListConfig, + val emailCache: EmailCache ) : LiveData() { private val messageListChangedListener = MessageListChangedListener { @@ -24,10 +25,14 @@ class MessageListLiveData( private fun loadMessageListAsync() { coroutineScope.launch(Dispatchers.Main) { + emailCache.getCachedMails()?.let { + value = MessageListInfo(it, true) + } val messageList = withContext(Dispatchers.IO) { messageListLoader.getMessageList(config) } - value = messageList +// value = messageList + emailCache.saveLatestMails(messageList.messageListItems) } } diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLiveDataFactory.kt b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLiveDataFactory.kt index af995910f1..236f679c11 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLiveDataFactory.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLiveDataFactory.kt @@ -7,9 +7,10 @@ import kotlinx.coroutines.CoroutineScope class MessageListLiveDataFactory( private val messageListLoader: MessageListLoader, private val preferences: Preferences, - private val messageListRepository: MessageListRepository + private val messageListRepository: MessageListRepository, + private val emailCache: EmailCache ) { fun create(coroutineScope: CoroutineScope, config: MessageListConfig): MessageListLiveData { - return MessageListLiveData(messageListLoader, preferences, messageListRepository, coroutineScope, config) + return MessageListLiveData(messageListLoader, preferences, messageListRepository, coroutineScope, config, emailCache) } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 123d4e8720..c2c24ab364 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -29,6 +29,7 @@ okhttp = "4.10.0" glide = "4.14.2" moshi = "1.14.0" mockito = "5.0.0" +datastore = "1.0.0" [plugins] android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" } @@ -70,6 +71,7 @@ androidx-preference = { module = "androidx.preference:preference", version.ref = androidx-swiperefreshlayout = "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0" androidx-test-core = "androidx.test:core:1.5.0" android-material = "com.google.android.material:material:1.7.0" +androidx-datastore = { module = "androidx.datastore:datastore-preferences", version.ref = "datastore" } fastadapter = { module = "com.mikepenz:fastadapter", version.ref = "fastAdapter" } fastadapter-extensions-drag = { module = "com.mikepenz:fastadapter-extensions-drag", version.ref = "fastAdapter" } fastadapter-extensions-utils = { module = "com.mikepenz:fastadapter-extensions-utils", version.ref = "fastAdapter" } @@ -79,7 +81,9 @@ preferencex-datetimepicker = { module = "com.takisoft.preferencex:preferencex-da preferencex-colorpicker = { module = "com.takisoft.preferencex:preferencex-colorpicker", version.ref = "preferencesFix" } okio = "com.squareup.okio:okio:3.3.0" moshi = { module = "com.squareup.moshi:moshi", version.ref = "moshi" } +moshi-kotlin = { module = "com.squareup.moshi:moshi-kotlin", version.ref = "moshi" } moshi-kotlin-codegen = { module = "com.squareup.moshi:moshi-kotlin-codegen", version.ref = "moshi" } +gson = "com.google.code.gson:gson:2.8.9" timber = "com.jakewharton.timber:timber:5.0.1" koin-core = { module = "io.insert-koin:koin-core", version.ref = "koinCore" } koin-android = { module = "io.insert-koin:koin-android", version.ref = "koinAndroid" } -- GitLab From 669e962d993246ec831091f2fde07384cfc74776 Mon Sep 17 00:00:00 2001 From: hasibprince Date: Thu, 23 Feb 2023 11:53:29 +0600 Subject: [PATCH 2/3] initially app shows mail from cache --- .../com/fsck/k9/ui/messagelist/EmailCache.kt | 52 ++++++++++++++++--- .../k9/ui/messagelist/MessageListFragment.kt | 7 +++ .../k9/ui/messagelist/MessageListLiveData.kt | 5 +- 3 files changed, 55 insertions(+), 9 deletions(-) diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/EmailCache.kt b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/EmailCache.kt index 19b84dcfef..27289fbdc8 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/EmailCache.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/EmailCache.kt @@ -4,6 +4,9 @@ import android.content.Context import androidx.datastore.preferences.core.edit import androidx.datastore.preferences.core.stringPreferencesKey import androidx.datastore.preferences.preferencesDataStore +import com.fsck.k9.Account +import com.fsck.k9.controller.MessageReference +import com.fsck.k9.search.getAccounts import com.google.gson.Gson import com.google.gson.TypeAdapter import com.google.gson.reflect.TypeToken @@ -24,24 +27,59 @@ class EmailCache constructor(private val context: Context, private val moshi: Mo } private val MAIL_LIST_KEY = stringPreferencesKey("mail_list") + private var isCacheShown = false + + suspend fun getCachedMails(accountList: List? = null): List? { + if (isCacheShown) { + return null + } + return runBlocking { + fetchCachedMail() + } + } + + private suspend fun fetchCachedMail(): List? { + val listType = object : TypeToken>() {}.type + val mailListJson = context.emailCacheDataStore.data.map { it[MAIL_LIST_KEY] }.firstOrNull() + Timber.d("email data: $mailListJson") + return gson.fromJson(mailListJson, listType) + } suspend fun saveLatestMails(mailList: List) { // val type = Types.newParameterizedType(List::class.java, MessageListItem::class.java) // val adapter = moshi.adapter>(type) // val mailListJson = adapter.toJson(mailList) + if (isCacheShown) return + isCacheShown = true + val cachedMailsWithLatest = getLatestMails(mailList) + val listType = object : TypeToken>() {}.type - val mailListJson = gson.toJson(mailList, listType) + val mailListJson = gson.toJson(cachedMailsWithLatest, listType) context.emailCacheDataStore.edit { it[MAIL_LIST_KEY] = mailListJson } } - suspend fun getCachedMails(): List? { - return runBlocking { - val listType = object : TypeToken>() {}.type - val mailListJson = context.emailCacheDataStore.data.map { it[MAIL_LIST_KEY] }.firstOrNull() - Timber.d("email data: $mailListJson") - gson.fromJson(mailListJson, listType) + private suspend fun getLatestMails(mailList: List): MutableList { + var cachedMailsWithLatest = mutableListOf() + cachedMailsWithLatest.addAll(mailList) + fetchCachedMail()?.let { + cachedMailsWithLatest.addAll(it) + } + cachedMailsWithLatest.sortedByDescending { it.messageDate } + val lastIndex = if (cachedMailsWithLatest.size < 40) cachedMailsWithLatest.size else 39 + cachedMailsWithLatest = cachedMailsWithLatest.subList(0, lastIndex) + return cachedMailsWithLatest + } + + suspend fun deleteMail(messages: List) { + isCacheShown = false + val cachedMessages = fetchCachedMail()?.toMutableList() + cachedMessages?.let { + messages.forEach { messageRef -> + cachedMessages.removeIf { it.messageUid == messageRef.uid } + saveLatestMails(cachedMessages) + } } } } diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListFragment.kt b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListFragment.kt index 9f5261fdf1..1979715e58 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListFragment.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListFragment.kt @@ -22,6 +22,7 @@ import androidx.core.view.setPadding import androidx.fragment.app.Fragment import androidx.recyclerview.widget.DefaultItemAnimator import androidx.lifecycle.Observer +import androidx.lifecycle.lifecycleScope import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView.OnScrollListener import androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_IDLE @@ -64,6 +65,8 @@ import com.google.android.material.floatingactionbutton.ExtendedFloatingActionBu import com.google.android.material.snackbar.BaseTransientBottomBar.BaseCallback import com.google.android.material.snackbar.Snackbar import java.util.concurrent.Future +import kotlinx.coroutines.coroutineScope +import kotlinx.coroutines.launch import net.jcip.annotations.GuardedBy import org.koin.android.ext.android.inject import org.koin.androidx.viewmodel.ext.android.sharedViewModel @@ -88,6 +91,7 @@ class MessageListFragment : private val messagingController: MessagingController by inject() private val preferences: Preferences by inject() private val clock: Clock by inject() + private val emailCache: EmailCache by inject() private val handler = MessageListHandler(this) private val activityListener = MessageListActivityListener() @@ -805,6 +809,9 @@ class MessageListFragment : } private fun onDeleteConfirmed(messages: List) { + lifecycleScope.launch { + emailCache.deleteMail(messages) + } if (showingThreadedList) { messagingController.deleteThreads(messages) } else { diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLiveData.kt b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLiveData.kt index 0b1e0eedb2..9829932e20 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLiveData.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLiveData.kt @@ -5,6 +5,7 @@ import com.fsck.k9.Preferences import com.fsck.k9.mailstore.MessageListChangedListener import com.fsck.k9.mailstore.MessageListRepository import com.fsck.k9.search.getAccountUuids +import com.fsck.k9.search.getAccounts import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -25,13 +26,13 @@ class MessageListLiveData( private fun loadMessageListAsync() { coroutineScope.launch(Dispatchers.Main) { - emailCache.getCachedMails()?.let { + emailCache.getCachedMails(config.search.getAccounts(preferences))?.let { value = MessageListInfo(it, true) } val messageList = withContext(Dispatchers.IO) { messageListLoader.getMessageList(config) } -// value = messageList + value = messageList emailCache.saveLatestMails(messageList.messageListItems) } } -- GitLab From 15577ff9772f5973f6e65396a53b9f06f8042a55 Mon Sep 17 00:00:00 2001 From: hasibprince Date: Tue, 14 Mar 2023 13:21:43 +0600 Subject: [PATCH 3/3] refactor: EmailCache --- .../com/fsck/k9/ui/messagelist/EmailCache.kt | 84 +++++++++++-------- .../com/fsck/k9/ui/messagelist/KoinModule.kt | 5 +- .../k9/ui/messagelist/MessageListLiveData.kt | 3 +- 3 files changed, 53 insertions(+), 39 deletions(-) diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/EmailCache.kt b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/EmailCache.kt index 27289fbdc8..f1ff13198c 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/EmailCache.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/EmailCache.kt @@ -1,3 +1,19 @@ +/* + * Copyright MURENA SAS 2023 + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + package com.fsck.k9.ui.messagelist import android.content.Context @@ -6,22 +22,21 @@ import androidx.datastore.preferences.core.stringPreferencesKey import androidx.datastore.preferences.preferencesDataStore import com.fsck.k9.Account import com.fsck.k9.controller.MessageReference -import com.fsck.k9.search.getAccounts import com.google.gson.Gson import com.google.gson.TypeAdapter import com.google.gson.reflect.TypeToken import com.google.gson.stream.JsonReader import com.google.gson.stream.JsonToken import com.google.gson.stream.JsonWriter -import com.squareup.moshi.Moshi import java.io.IOException import kotlinx.coroutines.flow.firstOrNull import kotlinx.coroutines.flow.map import kotlinx.coroutines.runBlocking import timber.log.Timber -class EmailCache constructor(private val context: Context, private val moshi: Moshi, private val gson: Gson) { +class EmailCache constructor(private val context: Context, private val gson: Gson) { companion object { + private const val MAX_CACHE_SIZE = 20 private const val preferenceDataStoreName = "emailCache" private val Context.emailCacheDataStore by preferencesDataStore(preferenceDataStoreName) } @@ -29,27 +44,19 @@ class EmailCache constructor(private val context: Context, private val moshi: Mo private val MAIL_LIST_KEY = stringPreferencesKey("mail_list") private var isCacheShown = false - suspend fun getCachedMails(accountList: List? = null): List? { + suspend fun getCachedMails(): List? { if (isCacheShown) { return null } + return runBlocking { fetchCachedMail() } } - private suspend fun fetchCachedMail(): List? { - val listType = object : TypeToken>() {}.type - val mailListJson = context.emailCacheDataStore.data.map { it[MAIL_LIST_KEY] }.firstOrNull() - Timber.d("email data: $mailListJson") - return gson.fromJson(mailListJson, listType) - } - suspend fun saveLatestMails(mailList: List) { -// val type = Types.newParameterizedType(List::class.java, MessageListItem::class.java) -// val adapter = moshi.adapter>(type) -// val mailListJson = adapter.toJson(mailList) if (isCacheShown) return + isCacheShown = true val cachedMailsWithLatest = getLatestMails(mailList) @@ -58,18 +65,7 @@ class EmailCache constructor(private val context: Context, private val moshi: Mo context.emailCacheDataStore.edit { it[MAIL_LIST_KEY] = mailListJson } - } - - private suspend fun getLatestMails(mailList: List): MutableList { - var cachedMailsWithLatest = mutableListOf() - cachedMailsWithLatest.addAll(mailList) - fetchCachedMail()?.let { - cachedMailsWithLatest.addAll(it) - } - cachedMailsWithLatest.sortedByDescending { it.messageDate } - val lastIndex = if (cachedMailsWithLatest.size < 40) cachedMailsWithLatest.size else 39 - cachedMailsWithLatest = cachedMailsWithLatest.subList(0, lastIndex) - return cachedMailsWithLatest + Timber.d("Saved latest mails in the cache") } suspend fun deleteMail(messages: List) { @@ -82,27 +78,45 @@ class EmailCache constructor(private val context: Context, private val moshi: Mo } } } + + private suspend fun fetchCachedMail(): List? { + val listType = object : TypeToken>() {}.type + val mailListJson = context.emailCacheDataStore.data.map { it[MAIL_LIST_KEY] }.firstOrNull() + Timber.d("Cached email data: $mailListJson") + return gson.fromJson(mailListJson, listType) + } + + private suspend fun getLatestMails(mailList: List): MutableList { + var cachedMailsWithLatest = mutableListOf() + cachedMailsWithLatest.addAll(mailList) + fetchCachedMail()?.let { + cachedMailsWithLatest.addAll(it) + } + + cachedMailsWithLatest.sortedByDescending { it.messageDate } + val lastIndex = if (cachedMailsWithLatest.size < MAX_CACHE_SIZE) cachedMailsWithLatest.size else MAX_CACHE_SIZE + cachedMailsWithLatest = cachedMailsWithLatest.subList(0, lastIndex) + return cachedMailsWithLatest + } } internal class CharSequenceTypeAdapter : TypeAdapter() { @Throws(IOException::class) - override fun write(out: JsonWriter, value: CharSequence?) { + override fun write(writer: JsonWriter, value: CharSequence?) { if (value == null) { - out.nullValue() + writer.nullValue() } else { - // Assumes that value complies with CharSequence.toString() contract - out.value(value.toString()) + writer.value(value.toString()) } } @Throws(IOException::class) - override fun read(`in`: JsonReader): CharSequence? { - return if (`in`.peek() === JsonToken.NULL) { - // Skip the JSON null - `in`.skipValue() + override fun read(reader: JsonReader): CharSequence? { + return if (reader.peek() === JsonToken.NULL) { + reader.skipValue() null } else { - `in`.nextString() + reader.nextString() } } } diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/KoinModule.kt b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/KoinModule.kt index 33d728f71f..95ffa93e13 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/KoinModule.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/KoinModule.kt @@ -1,6 +1,5 @@ package com.fsck.k9.ui.messagelist -import com.google.gson.Gson import com.google.gson.GsonBuilder import com.squareup.moshi.Moshi import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory @@ -20,8 +19,8 @@ val messageListUiModule = module { ) } single { Moshi.Builder().add(KotlinJsonAdapterFactory()) .build() } - single { GsonBuilder().registerTypeAdapter(CharSequence::class.java, CharSequenceTypeAdapter()).create() } - single { EmailCache(androidContext(), get(), get()) } + single { GsonBuilder().registerTypeAdapter(CharSequence::class.java, CharSequenceTypeAdapter()).create() } + single { EmailCache(androidContext(), get()) } factory { MessageListLiveDataFactory(messageListLoader = get(), preferences = get(), messageListRepository = get(), emailCache = get()) } diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLiveData.kt b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLiveData.kt index 9829932e20..e8e517a5be 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLiveData.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLiveData.kt @@ -26,9 +26,10 @@ class MessageListLiveData( private fun loadMessageListAsync() { coroutineScope.launch(Dispatchers.Main) { - emailCache.getCachedMails(config.search.getAccounts(preferences))?.let { + emailCache.getCachedMails()?.let { value = MessageListInfo(it, true) } + val messageList = withContext(Dispatchers.IO) { messageListLoader.getMessageList(config) } -- GitLab