Only show account chip in message view when showing it in the message list

This commit is contained in:
cketti 2022-09-20 11:24:22 +02:00
parent c3c6c25d88
commit 2368973784
6 changed files with 48 additions and 13 deletions

View file

@ -139,6 +139,9 @@ open class MessageList :
private var viewSwitcher: ViewSwitcher? = null
private lateinit var recentChangesSnackbar: Snackbar
private val isShowAccountChip: Boolean
get() = messageListFragment?.isShowAccountChip ?: true
public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -1018,7 +1021,7 @@ open class MessageList :
if (draftsFolderId != null && folderId == draftsFolderId) {
MessageActions.actionEditDraft(this, messageReference)
} else {
val fragment = MessageViewContainerFragment.newInstance(messageReference)
val fragment = MessageViewContainerFragment.newInstance(messageReference, isShowAccountChip)
supportFragmentManager.commitNow {
replace(R.id.message_view_container, fragment, FRAGMENT_TAG_MESSAGE_VIEW_CONTAINER)
}

View file

@ -143,6 +143,9 @@ class MessageListFragment :
invalidateMenu()
}
val isShowAccountChip: Boolean
get() = !isSingleAccountMode
override fun onAttach(context: Context) {
super.onAttach(context)
@ -475,7 +478,7 @@ class MessageListFragment :
showContactPicture = K9.isShowContactPicture,
showingThreadedList = showingThreadedList,
backGroundAsReadIndicator = K9.isUseBackgroundAsUnreadIndicator,
showAccountChip = !isSingleAccountMode
showAccountChip = isShowAccountChip
)
private fun getFolderInfoHolder(folderId: Long, account: Account): FolderInfoHolder {

View file

@ -55,6 +55,8 @@ public class MessageTopView extends LinearLayout {
private boolean isShowingProgress;
private boolean showPicturesButtonClicked;
private boolean showAccountChip;
private MessageCryptoPresenter messageCryptoPresenter;
@ -84,6 +86,10 @@ public class MessageTopView extends LinearLayout {
hideHeaderView();
}
public void setShowAccountChip(boolean showAccountChip) {
this.showAccountChip = showAccountChip;
}
private void setShowPicturesButtonListener() {
showPicturesButton.setOnClickListener(new OnClickListener() {
@Override
@ -208,7 +214,7 @@ public class MessageTopView extends LinearLayout {
}
public void setHeaders(Message message, Account account, boolean showStar) {
mHeaderContainer.populate(message, account, showStar);
mHeaderContainer.populate(message, account, showStar, showAccountChip);
mHeaderContainer.setVisibility(View.VISIBLE);
}

View file

@ -29,6 +29,8 @@ class MessageViewContainerFragment : Fragment() {
setMenuVisibility(value)
}
private var showAccountChip: Boolean = true
lateinit var messageReference: MessageReference
private set
@ -72,7 +74,9 @@ class MessageViewContainerFragment : Fragment() {
lastDirection = savedInstanceState.getSerializable(STATE_LAST_DIRECTION) as Direction?
}
adapter = MessageViewContainerAdapter(this)
showAccountChip = arguments?.getBoolean(ARG_SHOW_ACCOUNT_CHIP) ?: showAccountChip
adapter = MessageViewContainerAdapter(this, showAccountChip)
}
override fun onAttach(context: Context) {
@ -234,7 +238,11 @@ class MessageViewContainerFragment : Fragment() {
findMessageViewFragment().onPendingIntentResult(requestCode, resultCode, data)
}
private class MessageViewContainerAdapter(fragment: Fragment) : FragmentStateAdapter(fragment) {
private class MessageViewContainerAdapter(
fragment: Fragment,
private val showAccountChip: Boolean
) : FragmentStateAdapter(fragment) {
var messageList: List<MessageListItem> = emptyList()
set(value) {
val diffResult = DiffUtil.calculateDiff(
@ -262,7 +270,7 @@ class MessageViewContainerFragment : Fragment() {
check(position in messageList.indices)
val messageReference = messageList[position].messageReference
return MessageViewFragment.newInstance(messageReference)
return MessageViewFragment.newInstance(messageReference, showAccountChip)
}
fun getMessageReference(position: Int): MessageReference {
@ -305,13 +313,15 @@ class MessageViewContainerFragment : Fragment() {
companion object {
private const val ARG_REFERENCE = "reference"
private const val ARG_SHOW_ACCOUNT_CHIP = "showAccountChip"
private const val STATE_MESSAGE_REFERENCE = "messageReference"
private const val STATE_LAST_DIRECTION = "lastDirection"
fun newInstance(reference: MessageReference): MessageViewContainerFragment {
fun newInstance(reference: MessageReference, showAccountChip: Boolean): MessageViewContainerFragment {
return MessageViewContainerFragment().withArguments(
ARG_REFERENCE to reference.toIdentityString()
ARG_REFERENCE to reference.toIdentityString(),
ARG_SHOW_ACCOUNT_CHIP to showAccountChip
)
}
}

View file

@ -86,6 +86,7 @@ class MessageViewFragment :
private lateinit var account: Account
lateinit var messageReference: MessageReference
private var showAccountChip: Boolean = true
private var currentAttachmentViewInfo: AttachmentViewInfo? = null
private var isDeleteMenuItemDisabled: Boolean = false
@ -109,6 +110,9 @@ class MessageViewFragment :
messageReference = MessageReference.parse(arguments?.getString(ARG_REFERENCE))
?: error("Invalid argument '$ARG_REFERENCE'")
showAccountChip = arguments?.getBoolean(ARG_SHOW_ACCOUNT_CHIP)
?: error("Missing argument: '$ARG_SHOW_ACCOUNT_CHIP'")
if (savedInstanceState != null) {
wasMessageMarkedAsOpened = savedInstanceState.getBoolean(STATE_WAS_MESSAGE_MARKED_AS_OPENED)
}
@ -136,6 +140,8 @@ class MessageViewFragment :
}
private fun initializeMessageTopView(messageTopView: MessageTopView) {
messageTopView.setShowAccountChip(showAccountChip)
messageTopView.setAttachmentCallback(this)
messageTopView.setMessageCryptoPresenter(messageCryptoPresenter)
@ -940,6 +946,7 @@ class MessageViewFragment :
const val PROGRESS_THRESHOLD_MILLIS = 500 * 1000
private const val ARG_REFERENCE = "reference"
private const val ARG_SHOW_ACCOUNT_CHIP = "showAccountChip"
private const val STATE_WAS_MESSAGE_MARKED_AS_OPENED = "wasMessageMarkedAsOpened"
@ -947,9 +954,10 @@ class MessageViewFragment :
private const val ACTIVITY_CHOOSE_FOLDER_COPY = 2
private const val REQUEST_CODE_CREATE_DOCUMENT = 3
fun newInstance(reference: MessageReference): MessageViewFragment {
fun newInstance(reference: MessageReference, showAccountChip: Boolean): MessageViewFragment {
return MessageViewFragment().withArguments(
ARG_REFERENCE to reference.toIdentityString()
ARG_REFERENCE to reference.toIdentityString(),
ARG_SHOW_ACCOUNT_CHIP to showAccountChip
)
}
}

View file

@ -128,9 +128,14 @@ public class MessageHeader extends LinearLayout implements OnClickListener, OnLo
starView.setOnClickListener(listener);
}
public void populate(final Message message, final Account account, boolean showStar) {
accountChip.setText(account.getDisplayName());
accountChip.setChipBackgroundColor(ColorStateList.valueOf(account.getChipColor()));
public void populate(final Message message, final Account account, boolean showStar, boolean showAccountChip) {
if (showAccountChip) {
accountChip.setVisibility(View.VISIBLE);
accountChip.setText(account.getDisplayName());
accountChip.setChipBackgroundColor(ColorStateList.valueOf(account.getChipColor()));
} else {
accountChip.setVisibility(View.GONE);
}
Address fromAddress = null;
Address[] fromAddresses = message.getFrom();