Merge pull request #6690 from thundernest/account_chip

Change appearance of account chip in message list
This commit is contained in:
cketti 2023-02-21 11:26:35 +01:00 committed by GitHub
commit bcae08ec10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 50 additions and 26 deletions

View file

@ -0,0 +1,38 @@
package com.fsck.k9.ui.messagelist
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.text.TextPaint
import android.util.AttributeSet
import android.util.TypedValue
import android.view.View
class AccountChip(context: Context, attrs: AttributeSet?) : View(context, attrs) {
private val textPaint = TextPaint().apply {
color = Color.BLUE
}
init {
setTextSizeSp(16)
}
fun setTextSizeSp(size: Int) {
val displayMetrics = context.resources.displayMetrics
textPaint.textSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, size.toFloat(), displayMetrics)
}
fun setColor(color: Int) {
textPaint.color = color
}
override fun onDraw(canvas: Canvas) {
val cornerRadius = width.toFloat() / 2
val baseLine = height - textPaint.fontMetrics.bottom
val chipTop = baseLine + textPaint.fontMetrics.ascent
val chipBottom = baseLine + cornerRadius
canvas.drawRoundRect(0f, chipTop, width.toFloat(), chipBottom, cornerRadius, cornerRadius, textPaint)
}
}

View file

@ -17,7 +17,6 @@ import android.view.View.OnLongClickListener
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.core.graphics.drawable.DrawableCompat
import androidx.core.view.isVisible
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
@ -263,6 +262,9 @@ class MessageListAdapter internal constructor(
holder.chip.isVisible = appearance.showAccountChip
appearance.fontSizes.setViewTextSize(holder.subject, subjectViewFontSize)
if (subjectViewFontSize != FontSizes.FONT_DEFAULT) {
holder.chip.setTextSizeSp(subjectViewFontSize)
}
appearance.fontSizes.setViewTextSize(holder.date, appearance.fontSizes.messageListDate)
@ -325,9 +327,7 @@ class MessageListAdapter internal constructor(
val subject = MlfUtils.buildSubject(subject, res.getString(R.string.general_no_subject), displayThreadCount)
if (appearance.showAccountChip) {
val accountChipDrawable = holder.chip.drawable.mutate()
DrawableCompat.setTint(accountChipDrawable, account.chipColor)
holder.chip.setImageDrawable(accountChipDrawable)
holder.chip.setColor(account.chipColor)
}
if (appearance.stars) {

View file

@ -16,7 +16,7 @@ class MessageViewHolder(view: View) : MessageListViewHolder(view) {
val subject: TextView = view.findViewById(R.id.subject)
val preview: TextView = view.findViewById(R.id.preview)
val date: TextView = view.findViewById(R.id.date)
val chip: ImageView = view.findViewById(R.id.account_color_chip)
val chip: AccountChip = view.findViewById(R.id.account_color_chip)
val threadCount: TextView = view.findViewById(R.id.thread_count)
val star: ImageView = view.findViewById(R.id.star)
val attachment: ImageView = view.findViewById(R.id.attachment)

View file

@ -1,10 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="4dp"
android:height="14dp"
android:viewportWidth="4"
android:viewportHeight="14">
<path
android:fillColor="#000000"
android:pathData="M 2 0 C 2 0, 4 0, 4 2 V 12 C 4 14 2 14 2 14 C 2 14 0 14 0 12 V 2 C 0 0 2 0 2 0 Z"
android:fillAlpha="1"/>
</vector>

View file

@ -55,24 +55,20 @@
app:layout_goneMarginEnd="16dp"
tools:text="Message preview" />
<ImageView
<com.fsck.k9.ui.messagelist.AccountChip
android:id="@+id/account_color_chip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@null"
android:paddingStart="0dp"
android:paddingEnd="4dp"
app:layout_constraintBottom_toBottomOf="@+id/subject"
app:layout_constraintStart_toEndOf="@+id/barrier_start"
android:layout_width="3dp"
android:layout_height="0dp"
android:layout_marginEnd="4dp"
app:layout_constraintTop_toTopOf="@+id/subject"
app:srcCompat="@drawable/ic_account_color"
tools:tint="#FF1976D2" />
app:layout_constraintBottom_toBottomOf="@+id/subject"
app:layout_constraintEnd_toEndOf="@+id/barrier_start" />
<ImageView
android:id="@+id/status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toEndOf="@+id/account_color_chip"
app:layout_constraintStart_toEndOf="@+id/barrier_start"
app:layout_constraintTop_toTopOf="@+id/top_guideline"
app:srcCompat="?attr/messageListAnswered"
tools:src="@drawable/ic_messagelist_answered" />