From faf8b42acc47302e7fa285628a2900eaea2c34b2 Mon Sep 17 00:00:00 2001 From: cketti Date: Wed, 8 Feb 2023 15:35:47 +0100 Subject: [PATCH] Display folder name in message details screen --- .../k9/ui/messagedetails/FolderNameItem.kt | 34 ++++++++++++++ .../fsck/k9/ui/messagedetails/KoinModule.kt | 4 +- .../messagedetails/MessageDetailsFragment.kt | 15 +++++++ .../k9/ui/messagedetails/MessageDetailsUi.kt | 9 +++- .../messagedetails/MessageDetailsViewModel.kt | 19 +++++++- .../message_details_folder_name_item.xml | 44 +++++++++++++++++++ .../main/res/values/message_details_ids.xml | 1 + 7 files changed, 122 insertions(+), 4 deletions(-) create mode 100644 app/ui/legacy/src/main/java/com/fsck/k9/ui/messagedetails/FolderNameItem.kt create mode 100644 app/ui/legacy/src/main/res/layout/message_details_folder_name_item.xml diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagedetails/FolderNameItem.kt b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagedetails/FolderNameItem.kt new file mode 100644 index 000000000..054344df9 --- /dev/null +++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagedetails/FolderNameItem.kt @@ -0,0 +1,34 @@ +package com.fsck.k9.ui.messagedetails + +import android.view.View +import android.widget.ImageView +import android.widget.TextView +import androidx.annotation.DrawableRes +import com.fsck.k9.ui.R +import com.mikepenz.fastadapter.FastAdapter +import com.mikepenz.fastadapter.items.AbstractItem + +internal class FolderNameItem( + val displayName: String, + @DrawableRes val iconResourceId: Int +) : AbstractItem() { + override val type: Int = R.id.message_details_folder_name + override val layoutRes = R.layout.message_details_folder_name_item + + override fun getViewHolder(v: View) = ViewHolder(v) + + class ViewHolder(view: View) : FastAdapter.ViewHolder(view) { + private val folderIcon: ImageView = view.findViewById(R.id.folder_icon) + private val folderName = view.findViewById(R.id.folder_name) + + override fun bindView(item: FolderNameItem, payloads: List) { + folderName.text = item.displayName + folderIcon.setImageResource(item.iconResourceId) + } + + override fun unbindView(item: FolderNameItem) { + folderName.text = null + folderIcon.setImageDrawable(null) + } + } +} diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagedetails/KoinModule.kt b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagedetails/KoinModule.kt index 04adce291..afa9f2f4a 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagedetails/KoinModule.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagedetails/KoinModule.kt @@ -8,11 +8,13 @@ val messageDetailsUiModule = module { MessageDetailsViewModel( resources = get(), messageRepository = get(), + folderRepository = get(), contactSettingsProvider = get(), contacts = get(), clipboardManager = get(), accountManager = get(), - participantFormatter = get() + participantFormatter = get(), + folderNameFormatter = get() ) } factory { ContactSettingsProvider() } diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagedetails/MessageDetailsFragment.kt b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagedetails/MessageDetailsFragment.kt index fcf95ef6a..97b308918 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagedetails/MessageDetailsFragment.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagedetails/MessageDetailsFragment.kt @@ -23,6 +23,7 @@ import com.fsck.k9.controller.MessageReference import com.fsck.k9.mail.Address import com.fsck.k9.mailstore.CryptoResultAnnotation import com.fsck.k9.ui.R +import com.fsck.k9.ui.folders.FolderIconProvider import com.fsck.k9.ui.observe import com.fsck.k9.ui.withArguments import com.mikepenz.fastadapter.FastAdapter @@ -31,12 +32,14 @@ import com.mikepenz.fastadapter.adapters.ItemAdapter import com.mikepenz.fastadapter.listeners.ClickEventHook import org.koin.android.ext.android.inject import org.koin.androidx.viewmodel.ext.android.viewModel +import org.koin.core.parameter.parametersOf class MessageDetailsFragment : ToolbarBottomSheetDialogFragment() { private val viewModel: MessageDetailsViewModel by viewModel() private val addToContactsLauncher: AddToContactsLauncher by inject() private val showContactLauncher: ShowContactLauncher by inject() private val contactPictureLoader: ContactPictureLoader by inject() + private val folderIconProvider: FolderIconProvider by inject { parametersOf(requireContext().theme) } private lateinit var messageReference: MessageReference @@ -129,6 +132,10 @@ class MessageDetailsFragment : ToolbarBottomSheetDialogFragment() { addParticipants(details.to, R.string.message_details_to_section_title, showContactPicture) addParticipants(details.cc, R.string.message_details_cc_section_title, showContactPicture) addParticipants(details.bcc, R.string.message_details_bcc_section_title, showContactPicture) + + if (details.folder != null) { + addFolderName(details.folder) + } } val adapter = FastAdapter.with(itemAdapter).apply { @@ -157,6 +164,14 @@ class MessageDetailsFragment : ToolbarBottomSheetDialogFragment() { } } + private fun ItemAdapter.addFolderName(folder: FolderInfoUi) { + val folderNameItem = FolderNameItem( + displayName = folder.displayName, + iconResourceId = folderIconProvider.getFolderIcon(folder.type) + ) + add(folderNameItem) + } + private val cryptoStatusClickEventHook = object : ClickEventHook() { override fun onBind(viewHolder: RecyclerView.ViewHolder): View? { return if (viewHolder is CryptoStatusItem.ViewHolder) { diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagedetails/MessageDetailsUi.kt b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagedetails/MessageDetailsUi.kt index 8ae50e383..d07369f53 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagedetails/MessageDetailsUi.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagedetails/MessageDetailsUi.kt @@ -2,6 +2,7 @@ package com.fsck.k9.ui.messagedetails import android.net.Uri import com.fsck.k9.mail.Address +import com.fsck.k9.mailstore.FolderType import com.fsck.k9.view.MessageCryptoDisplayStatus data class MessageDetailsUi( @@ -12,7 +13,8 @@ data class MessageDetailsUi( val replyTo: List, val to: List, val cc: List, - val bcc: List + val bcc: List, + val folder: FolderInfoUi? ) data class CryptoDetails( @@ -31,3 +33,8 @@ data class Participant( val address: Address get() = Address(emailAddress, displayName?.toString()) } + +data class FolderInfoUi( + val displayName: String, + val type: FolderType +) diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagedetails/MessageDetailsViewModel.kt b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagedetails/MessageDetailsViewModel.kt index 81ff3f0d3..c3348e0f8 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagedetails/MessageDetailsViewModel.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/ui/messagedetails/MessageDetailsViewModel.kt @@ -10,10 +10,13 @@ import com.fsck.k9.helper.ClipboardManager import com.fsck.k9.helper.Contacts import com.fsck.k9.mail.Address import com.fsck.k9.mailstore.CryptoResultAnnotation +import com.fsck.k9.mailstore.Folder +import com.fsck.k9.mailstore.FolderRepository import com.fsck.k9.mailstore.MessageDate import com.fsck.k9.mailstore.MessageRepository import com.fsck.k9.preferences.AccountManager import com.fsck.k9.ui.R +import com.fsck.k9.ui.folders.FolderNameFormatter import com.fsck.k9.view.MessageCryptoDisplayStatus import java.text.DateFormat import java.util.Locale @@ -27,11 +30,13 @@ import kotlinx.coroutines.launch internal class MessageDetailsViewModel( private val resources: Resources, private val messageRepository: MessageRepository, + private val folderRepository: FolderRepository, private val contactSettingsProvider: ContactSettingsProvider, private val contacts: Contacts, private val clipboardManager: ClipboardManager, private val accountManager: AccountManager, - private val participantFormatter: MessageDetailsParticipantFormatter + private val participantFormatter: MessageDetailsParticipantFormatter, + private val folderNameFormatter: FolderNameFormatter ) : ViewModel() { private val dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.MEDIUM, Locale.getDefault()) private val uiState = MutableStateFlow(MessageDetailsState.Loading) @@ -46,6 +51,8 @@ internal class MessageDetailsViewModel( val account = accountManager.getAccount(messageReference.accountUuid) ?: error("Account not found") val messageDetails = messageRepository.getMessageDetails(messageReference) + val folder = folderRepository.getFolder(account, folderId = messageReference.folderId) + val senderList = messageDetails.sender?.let { listOf(it) } ?: emptyList() val messageDetailsUi = MessageDetailsUi( date = buildDisplayDate(messageDetails.date), @@ -55,7 +62,8 @@ internal class MessageDetailsViewModel( replyTo = messageDetails.replyTo.toParticipants(account), to = messageDetails.to.toParticipants(account), cc = messageDetails.cc.toParticipants(account), - bcc = messageDetails.bcc.toParticipants(account) + bcc = messageDetails.bcc.toParticipants(account), + folder = folder?.toFolderInfo() ) MessageDetailsState.DataLoaded( @@ -100,6 +108,13 @@ internal class MessageDetailsViewModel( } } + private fun Folder.toFolderInfo(): FolderInfoUi { + return FolderInfoUi( + displayName = folderNameFormatter.displayName(this), + type = this.type + ) + } + fun onCryptoStatusClicked() { val cryptoResult = cryptoResult ?: return val cryptoStatus = MessageCryptoDisplayStatus.fromResultAnnotation(cryptoResult) diff --git a/app/ui/legacy/src/main/res/layout/message_details_folder_name_item.xml b/app/ui/legacy/src/main/res/layout/message_details_folder_name_item.xml new file mode 100644 index 000000000..5026de554 --- /dev/null +++ b/app/ui/legacy/src/main/res/layout/message_details_folder_name_item.xml @@ -0,0 +1,44 @@ + + + + + + + + + + diff --git a/app/ui/legacy/src/main/res/values/message_details_ids.xml b/app/ui/legacy/src/main/res/values/message_details_ids.xml index aab6b828f..bc2f6e35f 100644 --- a/app/ui/legacy/src/main/res/values/message_details_ids.xml +++ b/app/ui/legacy/src/main/res/values/message_details_ids.xml @@ -4,5 +4,6 @@ +