Skip to content

Commit

Permalink
use the correct paddings for status info and follow notifications (#4958
Browse files Browse the repository at this point in the history
)

On my device the status info was just slighty misaligned, so I
investigated. Turns out the dp values were correct, but the
`Utils.dpToPx` method calculates with the exact density of the device,
whereas everything else uses the density buckets Android defines. And on
some devices that makes a visible difference. Did a little refactor and
now everything should always be aligned correctly.

And in `item_follow` the padding was just different from other
notification items.
  • Loading branch information
connyduck authored Feb 28, 2025
1 parent b9cdb02 commit ba4f57e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package com.keylesspalace.tusky.components.notifications

import android.view.View
import at.connyduck.sparkbutton.helpers.Utils
import com.keylesspalace.tusky.R
import com.keylesspalace.tusky.adapter.StatusViewHolder
import com.keylesspalace.tusky.entity.Notification
Expand Down Expand Up @@ -57,16 +56,16 @@ internal class StatusViewHolder(
if (payloads.isNotEmpty()) {
return
}

val res = itemView.resources
if (viewData.type == Notification.Type.Poll) {
statusInfo.setText(if (accountId == viewData.account.id) R.string.poll_ended_created else R.string.poll_ended_voted)
statusInfo.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.ic_poll_24dp, 0, 0, 0)
statusInfo.setCompoundDrawablePadding(Utils.dpToPx(statusInfo.context, 10))
statusInfo.setPaddingRelative(Utils.dpToPx(statusInfo.context, 28), 0, 0, 0)
statusInfo.setCompoundDrawablePadding(res.getDimensionPixelSize(R.dimen.status_info_drawable_padding_large))
statusInfo.setPadding(res.getDimensionPixelSize(R.dimen.status_info_padding_large), 0, 0, 0)
statusInfo.show()
} else if (viewData.type == Notification.Type.Mention) {
statusInfo.setCompoundDrawablePadding(Utils.dpToPx(statusInfo.context, 6))
statusInfo.setPaddingRelative(Utils.dpToPx(statusInfo.context, 38), 0, 0, 0)
statusInfo.setCompoundDrawablePadding(res.getDimensionPixelSize(R.dimen.status_info_drawable_padding_small))
statusInfo.setPaddingRelative(res.getDimensionPixelSize(R.dimen.status_info_padding_small), 0, 0, 0)
statusInfo.show()
if (viewData.statusViewData.status.inReplyToAccountId == accountId) {
statusInfo.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.ic_reply_18dp, 0, 0, 0)
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/item_follow.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:paddingStart="14dp"
android:paddingEnd="14dp"
android:paddingBottom="8dp">

<TextView
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/item_status.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
android:layout_marginStart="14dp"
android:layout_marginTop="@dimen/status_reblogged_bar_padding_top"
android:layout_marginEnd="14dp"
android:drawablePadding="6dp"
android:drawablePadding="@dimen/status_info_drawable_padding_small"
android:gravity="start"
android:importantForAccessibility="no"
android:paddingStart="38dp"
android:paddingStart="@dimen/status_info_padding_small"
android:textColor="?android:textColorTertiary"
android:textSize="?attr/status_text_medium"
app:drawableStartCompat="@drawable/ic_reblog_18dp"
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,12 @@

<dimen name="bottomAppBarHeight">64dp</dimen>

<!-- padding + drawablePadding + drawable size must be 62dp to align with the 14dp padding and the 48dp avatar -->
<!-- paddings for when the status info has a large (24dp) icon -->
<dimen name="status_info_drawable_padding_large">10dp</dimen>
<dimen name="status_info_padding_large">28dp</dimen>
<!-- paddings for when the status info has a small (18dp) icon -->
<dimen name="status_info_drawable_padding_small">6dp</dimen>
<dimen name="status_info_padding_small">38dp</dimen>

</resources>

0 comments on commit ba4f57e

Please sign in to comment.