Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix constraining width of recipient token views #8734

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.fsck.k9.ui.compose

import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.view.ViewGroup
import com.fsck.k9.ui.R

/**
* Custom layout for recipient tokens.
*
* Note: This layout is tightly coupled to recipient_token_item.xml
*/
class RecipientTokenLayout(context: Context, attrs: AttributeSet?) : ViewGroup(context, attrs) {
private lateinit var background: View
private lateinit var contactPicture: View
private lateinit var recipientName: View
private lateinit var cryptoStatus: View

override fun onFinishInflate() {
super.onFinishInflate()
background = findViewById(R.id.background)
contactPicture = findViewById(R.id.contact_photo)
recipientName = findViewById(android.R.id.text1)
cryptoStatus = findViewById(R.id.crypto_status_container)
}

// Return an appropriate baseline so the view is properly aligned with user-entered text in RecipientSelectView
override fun getBaseline(): Int {
return recipientName.top + recipientName.baseline
}

override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
recipientName.measure(widthMeasureSpec, heightMeasureSpec)
cryptoStatus.measure(widthMeasureSpec, heightMeasureSpec)

val height = recipientName.measuredHeight.coerceAtLeast(minimumHeight)

val contactPictureWidth = height
val fixedWidthComponent = contactPictureWidth + cryptoStatus.measuredWidth
val desiredWidth = fixedWidthComponent + recipientName.measuredWidth

if (MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.UNSPECIFIED) {
setMeasuredDimension(desiredWidth, height)
} else {
// Re-measure recipient name view with final width constraint
val width = desiredWidth.coerceAtMost(MeasureSpec.getSize(widthMeasureSpec))
val recipientNameWidth = width - fixedWidthComponent
val recipientNameWidthMeasureSpec = MeasureSpec.makeMeasureSpec(recipientNameWidth, MeasureSpec.AT_MOST)
recipientName.measure(recipientNameWidthMeasureSpec, heightMeasureSpec)

setMeasuredDimension(width, height)
}
}

override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
val contactPictureSize = height
background.layout(contactPictureSize / 2, 0, width, height)
contactPicture.layout(0, 0, contactPictureSize, contactPictureSize)

val recipientNameHeight = recipientName.measuredHeight
val recipientNameTop = (height - recipientNameHeight) / 2
recipientName.layout(
contactPictureSize,
recipientNameTop,
contactPictureSize + recipientName.measuredWidth,
recipientNameTop + recipientNameHeight,
)

cryptoStatus.layout(width - cryptoStatus.measuredWidth, 0, width, cryptoStatus.measuredHeight)
}
}
109 changes: 44 additions & 65 deletions legacy/ui/legacy/src/main/res/layout/recipient_token_item.xml
Original file line number Diff line number Diff line change
@@ -1,102 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<com.fsck.k9.ui.compose.RecipientTokenConstraintLayout
<com.fsck.k9.ui.compose.RecipientTokenLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="32dp"
>

<View
android:id="@+id/background"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="?attr/contactTokenBackgroundColor"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/background_position_helper"
app:layout_constraintTop_toTopOf="parent"
/>

<com.fsck.k9.ui.compose.RecipientCircleImageView
android:id="@+id/contact_photo"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_height="match_parent"
android:contentDescription="@null"
android:minHeight="32dp"
app:layout_constraintBottom_toBottomOf="@android:id/text1"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@android:id/text1"
tools:src="@drawable/ic_account_circle"
/>

<View
android:id="@+id/background_position_helper"
android:layout_width="0dp"
android:layout_height="0dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@+id/contact_photo"
app:layout_constraintEnd_toEndOf="@+id/contact_photo"
app:layout_constraintStart_toStartOf="@+id/contact_photo"
app:layout_constraintTop_toTopOf="@+id/contact_photo"
/>

<com.google.android.material.textview.MaterialTextView
android:id="@android:id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:ellipsize="end"
android:maxLines="1"
android:paddingTop="4dp"
android:paddingStart="0dp"
android:paddingEnd="14dp"
android:paddingBottom="4dp"
android:padding="4sp"
android:textAppearance="?attr/textAppearanceBodyMedium"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="@+id/contact_photo"
app:layout_constraintTop_toTopOf="parent"
tools:text="Jane Doe"
/>

<ImageView
android:id="@+id/contact_crypto_status_icon"
<FrameLayout
android:id="@+id/crypto_status_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@null"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_status_corner"
app:tint="?openpgp_black"
tools:visibility="gone"
/>
>

<ImageView
android:id="@+id/contact_crypto_status_icon_enabled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@null"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_status_corner"
app:tint="?openpgp_green"
tools:visibility="gone"
/>
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/contact_crypto_status_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:contentDescription="@null"
android:visibility="gone"
app:srcCompat="@drawable/ic_status_corner"
app:tint="?openpgp_black"
tools:visibility="visible"
/>

<ImageView
android:id="@+id/contact_crypto_status_icon_error"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@null"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_status_corner"
app:tint="?openpgp_red"
tools:visibility="gone"
/>
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/contact_crypto_status_icon_enabled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:contentDescription="@null"
android:visibility="gone"
app:srcCompat="@drawable/ic_status_corner"
app:tint="?openpgp_green"
tools:visibility="gone"
/>

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/contact_crypto_status_icon_error"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:contentDescription="@null"
android:visibility="gone"
app:srcCompat="@drawable/ic_status_corner"
app:tint="?openpgp_red"
tools:visibility="gone"
/>

</FrameLayout>

</com.fsck.k9.ui.compose.RecipientTokenConstraintLayout>
</com.fsck.k9.ui.compose.RecipientTokenLayout>
8 changes: 8 additions & 0 deletions legacy/ui/legacy/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
<item name="messageListRegularItemBackgroundColor">?android:attr/windowBackground</item>
<item name="messageListReadItemBackgroundColor">?attr/messageListRegularItemBackgroundColor</item>
<item name="messageListUnreadItemBackgroundColor">?attr/messageListRegularItemBackgroundColor</item>
<item name="contactTokenBackgroundColor">#ccc</item>
<item name="openpgp_black">#000</item>
<item name="openpgp_orange">#FF8800</item>
<item name="openpgp_red">#CC0000</item>
<item name="openpgp_green">#669900</item>
<item name="openpgp_blue">#336699</item>
<item name="openpgp_grey">#bbb</item>
<item name="openpgp_dark_grey">#888</item>
</style>

</resources>
Loading
Loading