Change message icons to direct drawable reference

This commit is contained in:
Wolf-Martell Montwé 2024-05-07 12:24:00 +02:00
parent 15682b7796
commit de43f5aff5
No known key found for this signature in database
GPG key ID: 6D45B21512ACBF72
8 changed files with 25 additions and 78 deletions

View file

@ -2,7 +2,6 @@ package com.fsck.k9.ui
import android.content.res.Resources.Theme
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.util.TypedValue
fun Theme.resolveColorAttribute(attrId: Int): Int {
@ -42,17 +41,6 @@ fun Theme.resolveColorAttribute(colorAttrId: Int, alphaFractionAttrId: Int, back
return Color.rgb(red.toInt(), green.toInt(), blue.toInt())
}
fun Theme.resolveDrawableAttribute(attrId: Int): Drawable {
val typedValue = TypedValue()
val found = resolveAttribute(attrId, typedValue, true)
if (!found) {
throw IllegalStateException("Couldn't resolve attribute ($attrId)")
}
return getDrawable(typedValue.resourceId)
}
fun Theme.getIntArray(attrId: Int): IntArray {
val typedValue = TypedValue()

View file

@ -33,7 +33,6 @@ import com.fsck.k9.mail.Address
import com.fsck.k9.ui.R
import com.fsck.k9.ui.helper.RelativeDateTimeFormatter
import com.fsck.k9.ui.resolveColorAttribute
import com.fsck.k9.ui.resolveDrawableAttribute
import kotlin.math.max
private const val FOOTER_ID = 1L
@ -51,9 +50,10 @@ class MessageListAdapter internal constructor(
private val relativeDateTimeFormatter: RelativeDateTimeFormatter,
) : RecyclerView.Adapter<MessageListViewHolder>() {
private val forwardedIcon: Drawable = theme.resolveDrawableAttribute(R.attr.messageListForwarded)
private val answeredIcon: Drawable = theme.resolveDrawableAttribute(R.attr.messageListAnswered)
private val forwardedAnsweredIcon: Drawable = theme.resolveDrawableAttribute(R.attr.messageListAnsweredForwarded)
private val forwardedIcon: Drawable = ResourcesCompat.getDrawable(res, R.drawable.ic_messagelist_forwarded, theme)!!
private val answeredIcon: Drawable = ResourcesCompat.getDrawable(res, R.drawable.ic_messagelist_answered, theme)!!
private val forwardedAnsweredIcon: Drawable = ResourcesCompat
.getDrawable(res, R.drawable.ic_messagelist_answered_forwarded, theme)!!
private val unreadTextColor: Int = theme.resolveColorAttribute(R.attr.messageListUnreadTextColor)
private val readTextColor: Int = theme.resolveColorAttribute(R.attr.messageListReadTextColor)
private val previewTextColor: Int = theme.resolveColorAttribute(R.attr.messageListPreviewTextColor)
@ -317,11 +317,13 @@ class MessageListAdapter internal constructor(
textViewMarginTop = compactTextViewMarginTop
lineSpacingMultiplier = compactLineSpacingMultiplier
}
UiDensity.Default -> {
verticalPadding = defaultVerticalPadding
textViewMarginTop = defaultTextViewMarginTop
lineSpacingMultiplier = defaultLineSpacingMultiplier
}
UiDensity.Relaxed -> {
verticalPadding = relaxedVerticalPadding
textViewMarginTop = relaxedTextViewMarginTop
@ -349,9 +351,11 @@ class MessageListAdapter internal constructor(
val messageListItem = getItem(position)
bindMessageViewHolder(holder as MessageViewHolder, messageListItem)
}
TYPE_FOOTER -> {
bindFooterViewHolder(holder as FooterViewHolder)
}
else -> {
error("Unsupported type: $viewType")
}

View file

@ -2,24 +2,24 @@ package com.fsck.k9.ui.messagelist
import android.content.res.Resources.Theme
import android.graphics.drawable.Drawable
import androidx.annotation.AttrRes
import androidx.annotation.DrawableRes
import androidx.core.content.res.ResourcesCompat
import com.fsck.k9.SwipeAction
import com.fsck.k9.ui.R
import com.fsck.k9.ui.resolveColorAttribute
import com.fsck.k9.ui.resolveDrawableAttribute
class SwipeResourceProvider(val theme: Theme) {
val iconTint = theme.resolveColorAttribute(R.attr.messageListSwipeIconTint)
private val selectIcon = theme.loadDrawable(R.attr.messageListSwipeSelectIcon)
private val markAsReadIcon = theme.loadDrawable(R.attr.messageListSwipeMarkAsReadIcon)
private val markAsUnreadIcon = theme.loadDrawable(R.attr.messageListSwipeMarkAsUnreadIcon)
private val addStarIcon = theme.loadDrawable(R.attr.messageListSwipeAddStarIcon)
private val removeStarIcon = theme.loadDrawable(R.attr.messageListSwipeRemoveStarIcon)
private val archiveIcon = theme.loadDrawable(R.attr.messageListSwipeArchiveIcon)
private val deleteIcon = theme.loadDrawable(R.attr.messageListSwipeDeleteIcon)
private val spamIcon = theme.loadDrawable(R.attr.messageListSwipeSpamIcon)
private val moveIcon = theme.loadDrawable(R.attr.messageListSwipeMoveIcon)
private val selectIcon = theme.loadDrawable(R.drawable.ic_check_circle)
private val markAsReadIcon = theme.loadDrawable(R.drawable.ic_opened_envelope)
private val markAsUnreadIcon = theme.loadDrawable(R.drawable.ic_mark_new)
private val addStarIcon = theme.loadDrawable(R.drawable.ic_star)
private val removeStarIcon = theme.loadDrawable(R.drawable.ic_star_outline)
private val archiveIcon = theme.loadDrawable(R.drawable.ic_archive)
private val deleteIcon = theme.loadDrawable(R.drawable.ic_trash_can)
private val spamIcon = theme.loadDrawable(R.drawable.ic_alert_octagon)
private val moveIcon = theme.loadDrawable(R.drawable.ic_move_to_folder)
private val noActionColor = theme.resolveColorAttribute(R.attr.messageListSwipeDisabledBackgroundColor)
private val selectColor = theme.resolveColorAttribute(R.attr.messageListSwipeSelectBackgroundColor)
@ -81,6 +81,6 @@ class SwipeResourceProvider(val theme: Theme) {
}
}
private fun Theme.loadDrawable(@AttrRes attributeId: Int): Drawable {
return resolveDrawableAttribute(attributeId).mutate()
private fun Theme.loadDrawable(@DrawableRes drawableResId: Int): Drawable {
return ResourcesCompat.getDrawable(resources, drawableResId, this)!!
}

View file

@ -63,7 +63,7 @@
android:paddingHorizontal="12dp"
app:layout_constraintEnd_toStartOf="@id/menu_overflow"
app:layout_constraintTop_toTopOf="@+id/menu_overflow"
app:srcCompat="?attr/messageDetailsAddContactIcon" />
app:srcCompat="@drawable/ic_person_add" />
<ImageView
android:id="@+id/menu_overflow"

View file

@ -78,7 +78,7 @@
android:layout_height="wrap_content"
app:layout_constraintStart_toEndOf="@+id/account_color_chip"
app:layout_constraintTop_toTopOf="@+id/top_guideline"
app:srcCompat="?attr/messageListAnswered" />
app:srcCompat="@drawable/ic_messagelist_answered" />
<TextView
android:id="@+id/subject"
@ -119,7 +119,7 @@
android:layout_marginEnd="4dp"
app:layout_constraintEnd_toStartOf="@+id/date"
app:layout_constraintTop_toTopOf="@+id/top_guideline"
app:srcCompat="?attr/messageListAttachment" />
app:srcCompat="@drawable/ic_messagelist_attachment" />
<TextView
android:id="@+id/date"

View file

@ -74,7 +74,7 @@
android:layout_marginBottom="8dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/locked_attach_unlock"
app:srcCompat="?attr/unencryptedAttachmentUnlock"
app:srcCompat="@drawable/ic_visibility"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/locked_name"

View file

@ -21,30 +21,16 @@
<attr name="messageListPreviewTextColor" format="reference|color"/>
<attr name="messageListDividerColor" format="reference|color"/>
<attr name="messageListStateIconTint" format="reference|color"/>
<attr name="messageListAttachment" format="reference"/>
<attr name="messageListAnswered" format="reference"/>
<attr name="messageListForwarded" format="reference"/>
<attr name="messageListAnsweredForwarded" format="reference"/>
<attr name="messageListSwipeIconTint" format="reference|color"/>
<attr name="messageListSwipeDisabledBackgroundColor" format="reference|color"/>
<attr name="messageListSwipeSelectIcon" format="reference"/>
<attr name="messageListSwipeSelectBackgroundColor" format="reference|color"/>
<attr name="messageListSwipeMarkAsReadIcon" format="reference"/>
<attr name="messageListSwipeMarkAsUnreadIcon" format="reference"/>
<attr name="messageListSwipeToggleReadBackgroundColor" format="reference|color"/>
<attr name="messageListSwipeAddStarIcon" format="reference"/>
<attr name="messageListSwipeRemoveStarIcon" format="reference"/>
<attr name="messageListSwipeToggleStarBackgroundColor" format="reference|color"/>
<attr name="messageListSwipeArchiveIcon" format="reference"/>
<attr name="messageListSwipeArchiveBackgroundColor" format="reference|color"/>
<attr name="messageListSwipeDeleteIcon" format="reference"/>
<attr name="messageListSwipeDeleteBackgroundColor" format="reference|color"/>
<attr name="messageListSwipeSpamIcon" format="reference"/>
<attr name="messageListSwipeSpamBackgroundColor" format="reference|color"/>
<attr name="messageListSwipeMoveIcon" format="reference"/>
<attr name="messageListSwipeMoveBackgroundColor" format="reference|color"/>
<attr name="messageStarColor" format="color"/>
<attr name="messageDetailsAddContactIcon" format="reference"/>
<attr name="messageDetailsDividerColor" format="reference|color"/>
<attr name="composerBackgroundColor" format="color"/>
<attr name="contactPictureFallbackDefaultBackgroundColor" format="reference|color"/>
@ -54,7 +40,6 @@
<attr name="tintColorBulletPointNeutral" format="reference|color"/>
<attr name="tintColorBulletPointNegative" format="reference|color"/>
<attr name="unencryptedAttachmentUnlock" format="reference|color" />
<attr name="openpgp_black" format="reference|color" />
<attr name="openpgp_orange" format="reference|color" />
<attr name="openpgp_red" format="reference|color" />

View file

@ -88,32 +88,18 @@
<item name="messageListPreviewTextColor">#ff444444</item>
<item name="messageListDividerColor">#ffcccccc</item>
<item name="messageListStateIconTint">#bbbbbb</item>
<item name="messageListAttachment">@drawable/ic_messagelist_attachment</item>
<item name="messageListAnswered">@drawable/ic_messagelist_answered</item>
<item name="messageListForwarded">@drawable/ic_messagelist_forwarded</item>
<item name="messageListAnsweredForwarded">@drawable/ic_messagelist_answered_forwarded</item>
<item name="messageListSwipeIconTint">#ffffff</item>
<item name="messageListSwipeDisabledBackgroundColor">@color/material_gray_200</item>
<item name="messageListSwipeSelectIcon">@drawable/ic_check_circle</item>
<item name="messageListSwipeSelectBackgroundColor">@color/material_blue_600</item>
<item name="messageListSwipeMarkAsReadIcon">@drawable/ic_opened_envelope</item>
<item name="messageListSwipeMarkAsUnreadIcon">@drawable/ic_mark_new</item>
<item name="messageListSwipeToggleReadBackgroundColor">@color/material_blue_600</item>
<item name="messageListSwipeAddStarIcon">@drawable/ic_star</item>
<item name="messageListSwipeRemoveStarIcon">@drawable/ic_star_outline</item>
<item name="messageListSwipeToggleStarBackgroundColor">@color/material_orange_600</item>
<item name="messageListSwipeArchiveIcon">@drawable/ic_archive</item>
<item name="messageListSwipeArchiveBackgroundColor">@color/material_green_600</item>
<item name="messageListSwipeDeleteIcon">@drawable/ic_trash_can</item>
<item name="messageListSwipeDeleteBackgroundColor">@color/material_red_600</item>
<item name="messageListSwipeSpamIcon">@drawable/ic_alert_octagon</item>
<item name="messageListSwipeSpamBackgroundColor">@color/material_red_700</item>
<item name="messageListSwipeMoveIcon">@drawable/ic_move_to_folder</item>
<item name="messageListSwipeMoveBackgroundColor">@color/material_purple_500</item>
<item name="messageStarColor">#fbbc04</item>
<item name="messageDetailsAddContactIcon">@drawable/ic_person_add</item>
<item name="messageDetailsDividerColor">#ffcccccc</item>
<item name="contactPictureFallbackDefaultBackgroundColor">#ffababab</item>
<item name="contactPictureFallbackBackgroundColors">@array/contact_picture_fallback_background_colors_light</item>
@ -123,7 +109,6 @@
<item name="tintColorBulletPointNegative">#dd2222</item>
<item name="tintColorBulletPointNeutral">#888</item>
<item name="unencryptedAttachmentUnlock">@drawable/ic_visibility</item>
<item name="openpgp_black">#000</item>
<item name="openpgp_orange">#FF8800</item>
<item name="openpgp_red">#CC0000</item>
@ -224,32 +209,18 @@
<item name="messageListPreviewTextColor">#ffaaaaaa</item>
<item name="messageListDividerColor">#ff333333</item>
<item name="messageListStateIconTint">#777777</item>
<item name="messageListAttachment">@drawable/ic_messagelist_attachment</item>
<item name="messageListAnswered">@drawable/ic_messagelist_answered</item>
<item name="messageListForwarded">@drawable/ic_messagelist_forwarded</item>
<item name="messageListAnsweredForwarded">@drawable/ic_messagelist_answered_forwarded</item>
<item name="messageListSwipeIconTint">#ffffff</item>
<item name="messageListSwipeDisabledBackgroundColor">@color/material_gray_900</item>
<item name="messageListSwipeSelectIcon">@drawable/ic_check_circle</item>
<item name="messageListSwipeSelectBackgroundColor">@color/material_blue_700</item>
<item name="messageListSwipeMarkAsReadIcon">@drawable/ic_opened_envelope</item>
<item name="messageListSwipeMarkAsUnreadIcon">@drawable/ic_mark_new</item>
<item name="messageListSwipeToggleReadBackgroundColor">@color/material_blue_700</item>
<item name="messageListSwipeAddStarIcon">@drawable/ic_star</item>
<item name="messageListSwipeRemoveStarIcon">@drawable/ic_star_outline</item>
<item name="messageListSwipeToggleStarBackgroundColor">@color/material_orange_700</item>
<item name="messageListSwipeArchiveIcon">@drawable/ic_archive</item>
<item name="messageListSwipeArchiveBackgroundColor">@color/material_green_700</item>
<item name="messageListSwipeDeleteIcon">@drawable/ic_trash_can</item>
<item name="messageListSwipeDeleteBackgroundColor">@color/material_red_700</item>
<item name="messageListSwipeSpamIcon">@drawable/ic_alert_octagon</item>
<item name="messageListSwipeSpamBackgroundColor">@color/material_red_800</item>
<item name="messageListSwipeMoveIcon">@drawable/ic_move_to_folder</item>
<item name="messageListSwipeMoveBackgroundColor">@color/material_purple_600</item>
<item name="messageStarColor">#fdd663</item>
<item name="messageDetailsAddContactIcon">@drawable/ic_person_add</item>
<item name="messageDetailsDividerColor">#ff555555</item>
<item name="contactTokenBackgroundColor">#313131</item>
<item name="contactPictureFallbackDefaultBackgroundColor">#ff606060</item>
@ -259,7 +230,6 @@
<item name="tintColorBulletPointNegative">#dd2222</item>
<item name="tintColorBulletPointNeutral">#bbb</item>
<item name="unencryptedAttachmentUnlock">@drawable/ic_visibility</item>
<item name="openpgp_black">#fff</item>
<item name="openpgp_orange">#ee7700</item>
<item name="openpgp_red">#CC0000</item>