@@ -3,7 +3,6 @@ package com.fsck.k9.ui.messagelist
33import android.app.SearchManager
44import android.content.Context
55import android.content.Intent
6- import android.os.Build
76import android.os.Bundle
87import android.os.SystemClock
98import android.view.LayoutInflater
@@ -38,7 +37,6 @@ import androidx.fragment.app.setFragmentResultListener
3837import androidx.lifecycle.Lifecycle
3938import androidx.lifecycle.Observer
4039import androidx.lifecycle.lifecycleScope
41- import androidx.lifecycle.repeatOnLifecycle
4240import androidx.recyclerview.widget.RecyclerView
4341import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
4442import app.k9mail.core.android.common.contact.ContactRepository
@@ -81,9 +79,7 @@ import kotlin.time.Clock
8179import kotlin.time.ExperimentalTime
8280import kotlinx.collections.immutable.persistentSetOf
8381import kotlinx.coroutines.Dispatchers
84- import kotlinx.coroutines.flow.Flow
8582import kotlinx.coroutines.flow.StateFlow
86- import kotlinx.coroutines.flow.collectLatest
8783import kotlinx.coroutines.flow.distinctUntilChanged
8884import kotlinx.coroutines.flow.drop
8985import kotlinx.coroutines.flow.launchIn
@@ -106,8 +102,8 @@ import net.thunderbird.core.featureflag.FeatureFlagProvider
106102import net.thunderbird.core.featureflag.FeatureFlagResult
107103import net.thunderbird.core.logging.Logger
108104import net.thunderbird.core.outcome.Outcome
109- import net.thunderbird.core.preference.GeneralSettings
110105import net.thunderbird.core.preference.GeneralSettingsManager
106+ import net.thunderbird.core.preference.display.visualSettings.message.list.DisplayMessageListSettings
111107import net.thunderbird.core.preference.interaction.InteractionSettings
112108import net.thunderbird.core.ui.theme.api.FeatureThemeProvider
113109import net.thunderbird.feature.account.AccountId
@@ -273,6 +269,8 @@ abstract class BaseMessageListFragment :
273269 private var messageListSwipeCallback: MessageListSwipeCallback ? = null
274270 private val interactionSettings: InteractionSettings
275271 get() = generalSettingsManager.getConfig().interaction
272+ private val messageListSettings: DisplayMessageListSettings
273+ get() = generalSettingsManager.getConfig().display.visualSettings.messageListSettings
276274
277275 /* *
278276 * Set this to `true` when the fragment should be considered active. When active, the fragment adds its actions to
@@ -287,8 +285,6 @@ abstract class BaseMessageListFragment :
287285 maybeHideFloatingActionButton()
288286 }
289287
290- private lateinit var messageListAppearance: MessageListAppearance
291-
292288 fun isSearchViewCollapsed (): Boolean {
293289 return searchView?.isIconified != false
294290 }
@@ -320,6 +316,12 @@ abstract class BaseMessageListFragment :
320316 return
321317 }
322318
319+ viewModel.getMessageListLiveData().observe(this ) { messageListInfo: MessageListInfo ->
320+ setMessageList(messageListInfo)
321+ }
322+
323+ adapter = createMessageListAdapter()
324+
323325 generalSettingsManager.getSettingsFlow()
324326 /* *
325327 * Skips the first emitted item from the settings flow,
@@ -349,18 +351,6 @@ abstract class BaseMessageListFragment :
349351 initialSearchViewIconified = savedInstanceState.getBoolean(STATE_SEARCH_VIEW_ICONIFIED , true )
350352 val messageReferenceString = savedInstanceState.getString(STATE_ACTIVE_MESSAGE )
351353 activeMessage = MessageReference .parse(messageReferenceString)
352-
353- messageListAppearance = requireNotNull(
354- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
355- savedInstanceState.getParcelable(STATE_MESSAGE_LIST_APPEARANCE , MessageListAppearance ::class .java)
356- } else {
357- @Suppress(" DEPRECATION" )
358- savedInstanceState.getParcelable(STATE_MESSAGE_LIST_APPEARANCE )
359- },
360- ) {
361- " Could not restore MessageListAppearance. Missing parcelable extra '$STATE_MESSAGE_LIST_APPEARANCE '. " +
362- " Extras: $savedInstanceState "
363- }
364354 }
365355
366356 private fun restoreSelectedMessages (savedInstanceState : Bundle ) {
@@ -414,7 +404,7 @@ abstract class BaseMessageListFragment :
414404 layoutInflater = layoutInflater,
415405 contactsPictureLoader = ContactPicture .getContactPictureLoader(),
416406 listItemListener = this ,
417- appearance = :: messageListAppearance,
407+ appearance = messageListAppearance,
418408 relativeDateTimeFormatter = RelativeDateTimeFormatter (requireContext(), clock),
419409 themeProvider = featureThemeProvider,
420410 featureFlagProvider = featureFlagProvider,
@@ -443,30 +433,7 @@ abstract class BaseMessageListFragment :
443433 }
444434 }
445435
446- private var pendingMessageListInfo: MessageListInfo ? = null
447-
448436 override fun onViewCreated (view : View , savedInstanceState : Bundle ? ) {
449- lifecycleScope.launch {
450- viewLifecycleOwner.repeatOnLifecycle(state = Lifecycle .State .CREATED ) {
451- fetchMessageListAppearance()
452- .distinctUntilChanged()
453- .collectLatest { appearance ->
454- messageListAppearance = appearance
455- if (recyclerView == null ) {
456- initializeRecyclerView(requireView())
457- }
458- }
459- }
460- }
461-
462- viewModel.getMessageListLiveData().observe(viewLifecycleOwner) { messageListInfo: MessageListInfo ->
463- if (::adapter.isInitialized) {
464- setMessageList(messageListInfo)
465- } else {
466- pendingMessageListInfo = messageListInfo
467- }
468- }
469-
470437 val menuHost: MenuHost = requireActivity()
471438
472439 menuHost.addMenuProvider(
@@ -499,17 +466,6 @@ abstract class BaseMessageListFragment :
499466 }
500467 }
501468
502- protected open suspend fun fetchMessageListAppearance (): Flow <MessageListAppearance > {
503- return generalSettingsManager
504- .getConfigFlow()
505- .map { config ->
506- if (showingThreadedList != config.display.inboxSettings.isThreadedViewEnabled) {
507- showingThreadedList = config.display.inboxSettings.isThreadedViewEnabled
508- }
509- createMessageListAppearance(config)
510- }
511- }
512-
513469 private fun initializeErrorLayout (view : View ) {
514470 val errorMessageView = view.findViewById<MaterialTextView >(R .id.message_list_error_message)
515471 errorMessageView.text = getString(error!! .errorText)
@@ -518,6 +474,7 @@ abstract class BaseMessageListFragment :
518474 private fun initializeMessageListLayout (view : View ) {
519475 initializeSwipeRefreshLayout(view)
520476 initializeFloatingActionButton(view)
477+ initializeRecyclerView(view)
521478 initializeRecentChangesSnackbar()
522479
523480 // This needs to be done before loading the message list below
@@ -602,12 +559,6 @@ abstract class BaseMessageListFragment :
602559 }
603560
604561 private fun initializeRecyclerView (view : View ) {
605- adapter = createMessageListAdapter()
606- pendingMessageListInfo?.let { messageListInfo ->
607- setMessageList(messageListInfo)
608- pendingMessageListInfo = null
609- }
610-
611562 val recyclerView = view.findViewById<RecyclerView >(R .id.message_list)
612563
613564 if (! isShowFloatingActionButton) {
@@ -908,25 +859,24 @@ abstract class BaseMessageListFragment :
908859 if (activeMessage != null ) {
909860 outState.putString(STATE_ACTIVE_MESSAGE , activeMessage!! .toIdentityString())
910861 }
911- outState.putParcelable(STATE_MESSAGE_LIST_APPEARANCE , messageListAppearance)
912862 }
913863
914- protected fun createMessageListAppearance (config : GeneralSettings ): MessageListAppearance {
915- val displaySettings = config.display
916- val inboxSettings = displaySettings.inboxSettings
917- val messageListSettings = displaySettings.visualSettings.messageListSettings
918- return MessageListAppearance (
864+ private val messageListAppearance: MessageListAppearance
865+ get() = MessageListAppearance (
919866 fontSizes = K9 .fontSizes,
920867 previewLines = messageListSettings.previewLines,
921- stars = ! isOutbox && displaySettings.inboxSettings.isShowMessageListStars,
922- senderAboveSubject = inboxSettings.isMessageListSenderAboveSubject,
868+ stars = ! isOutbox && generalSettingsManager.getConfig().display.inboxSettings.isShowMessageListStars,
869+ senderAboveSubject = generalSettingsManager
870+ .getConfig()
871+ .display
872+ .inboxSettings
873+ .isMessageListSenderAboveSubject,
923874 showContactPicture = messageListSettings.isShowContactPicture,
924875 showingThreadedList = showingThreadedList,
925876 backGroundAsReadIndicator = messageListSettings.isUseBackgroundAsUnreadIndicator,
926877 showAccountIndicator = isShowAccountIndicator,
927878 density = messageListSettings.uiDensity,
928879 )
929- }
930880
931881 private fun getFolderInfoHolder (account : LegacyAccount , folderId : Long ): FolderInfoHolder {
932882 val localStore = localStoreProvider.getInstanceByLegacyAccount(account)
@@ -2770,6 +2720,5 @@ abstract class BaseMessageListFragment :
27702720 protected const val STATE_REMOTE_SEARCH_PERFORMED = " remoteSearchPerformed"
27712721 protected const val STATE_SEARCH_VIEW_QUERY = " searchViewQuery"
27722722 protected const val STATE_SEARCH_VIEW_ICONIFIED = " searchViewIconified"
2773- protected const val STATE_MESSAGE_LIST_APPEARANCE = " messageListAppearance"
27742723 }
27752724}
0 commit comments