Load all vector drawables with AppCompat for consistency (#4411)

Currently some vector drawables are loaded using the AppCompat library
and others are loaded using the framework.

This pull request uniformizes this to use AppCompat to load them all.

Other changes:
- Set all compound drawables using relative positioning, since all XML
layouts are also using relative positioning.
- Remove unnecessary layer list drawable used to center
`R.drawable.ic_play_indicator` icon and use
`ImageView.setForegroundGravity()` instead.
- Merge layers in toolbar icons `ic_arrow_back_with_background` and
`ic_more_with_background` into a single vector drawable. Note that the
AppCompat implementation of vector drawables is unable to load vector
drawables inside layer-list drawables, so this change also makes these
images compatible with older Android versions.

**Note**: technically, AppCompat will always delegate to the framework
to load vector drawables on API 24+ which is the current minSDK version
of the app. But at least this gives the option to lower the minSDK
version in the future.
This commit is contained in:
Christophe Beyls 2024-05-13 19:11:49 +02:00 committed by GitHub
parent a690b537c2
commit 973ebd236c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
23 changed files with 72 additions and 99 deletions

View File

@ -9,6 +9,7 @@ import android.graphics.drawable.Drawable;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.view.Gravity;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
@ -21,10 +22,10 @@ import android.widget.TextView;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.appcompat.widget.PopupMenu;
import androidx.appcompat.widget.TooltipCompat;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.content.ContextCompat;
import androidx.core.text.HtmlCompat;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
@ -535,7 +536,8 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
final Attachment.Type type = attachment.getType();
if (showingContent && (type == Attachment.Type.VIDEO || type == Attachment.Type.GIFV)) {
imageView.setForeground(ContextCompat.getDrawable(itemView.getContext(), R.drawable.play_indicator_overlay));
imageView.setForegroundGravity(Gravity.CENTER);
imageView.setForeground(AppCompatResources.getDrawable(itemView.getContext(), R.drawable.ic_play_indicator));
} else {
imageView.setForeground(null);
}
@ -611,7 +613,7 @@ public abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
// Set the icon next to the label.
int drawableId = getLabelIcon(attachments.get(0).getType());
mediaLabel.setCompoundDrawablesWithIntrinsicBounds(drawableId, 0, 0, 0);
mediaLabel.setCompoundDrawablesRelativeWithIntrinsicBounds(drawableId, 0, 0, 0);
setAttachmentClickListener(mediaLabel, listener, i, mediaDescriptions[i], false);
} else {

View File

@ -18,8 +18,8 @@ import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.content.res.AppCompatResources
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import com.google.android.material.datepicker.CalendarConstraints
import com.google.android.material.datepicker.DateValidatorPointForward
import com.google.android.material.datepicker.MaterialDatePicker
@ -89,10 +89,10 @@ class ComposeScheduleView
}
private fun setEditIcons() {
val icon = ContextCompat.getDrawable(context, R.drawable.ic_create_24dp) ?: return
val icon = AppCompatResources.getDrawable(context, R.drawable.ic_create_24dp) ?: return
val size = binding.scheduledDateTime.lineHeight
icon.setBounds(0, 0, size, size)
binding.scheduledDateTime.setCompoundDrawables(null, null, icon, null)
binding.scheduledDateTime.setCompoundDrawablesRelative(null, null, icon, null)
}
fun setResetOnClickListener(listener: OnClickListener?) {

View File

@ -27,7 +27,7 @@ import android.text.style.StyleSpan
import android.view.View
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.core.content.ContextCompat
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.text.toSpannable
import androidx.recyclerview.widget.RecyclerView
import at.connyduck.sparkbutton.helpers.Utils
@ -173,7 +173,7 @@ internal class StatusNotificationViewHolder(
@DrawableRes drawable: Int,
@ColorRes color: Int
): Drawable? {
val icon = ContextCompat.getDrawable(context, drawable)
val icon = AppCompatResources.getDrawable(context, drawable)
icon?.setTint(context.getColor(color))
return icon
}
@ -247,7 +247,7 @@ internal class StatusNotificationViewHolder(
format = context.getString(R.string.notification_favourite_format)
}
}
binding.notificationTopText.setCompoundDrawablesWithIntrinsicBounds(
binding.notificationTopText.setCompoundDrawablesRelativeWithIntrinsicBounds(
icon,
null,
null,

View File

@ -243,7 +243,7 @@ class StatusViewHelper(private val itemView: View) {
// Set the icon next to the label.
val drawableId = getLabelIcon(attachments[0].type)
mediaLabel.setCompoundDrawablesWithIntrinsicBounds(drawableId, 0, 0, 0)
mediaLabel.setCompoundDrawablesRelativeWithIntrinsicBounds(drawableId, 0, 0, 0)
mediaLabel.setOnClickListener { listener.onViewMedia(null, 0) }
}

View File

@ -1,5 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval" >
<solid android:color="@color/toolbar_icon_background" />
</shape>

View File

@ -1,11 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:autoMirrored="true"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#fff"
android:pathData="M20,11H7.83l5.59,-5.59L12,4l-8,8 8,8 1.41,-1.41L7.83,13H20v-2z" />
</vector>

View File

@ -1,12 +1,13 @@
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/background_circle" android:width="32dp" android:height="32dp"/>
<item android:drawable="@drawable/ic_arrow_back"
android:top="4dp"
android:bottom="4dp"
android:left="4dp"
android:right="4dp"/>
</layer-list>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:autoMirrored="true"
android:viewportWidth="32"
android:viewportHeight="32">
<path
android:fillColor="@color/toolbar_icon_background"
android:pathData="M16 0C7.152 0 0 7.152 0 16s7.152 16 16 16 16-7.152 16-16S24.848 0 16 0z" />
<path
android:fillColor="?attr/colorControlNormal"
android:pathData="M24 15H11.83l5.59-5.59L16 8l-8 8 8 8 1.41-1.41L11.83 17H24v-2z" />
</vector>

View File

@ -1,10 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#fff"
android:pathData="M12,8c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM12,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM12,16c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2z" />
</vector>

View File

@ -1,12 +1,12 @@
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/background_circle" android:width="32dp" android:height="32dp"/>
<item android:drawable="@drawable/ic_more"
android:top="4dp"
android:bottom="4dp"
android:left="4dp"
android:right="4dp"/>
</layer-list>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:viewportWidth="32"
android:viewportHeight="32">
<path
android:fillColor="@color/toolbar_icon_background"
android:pathData="M16 0C7.152 0 0 7.152 0 16s7.152 16 16 16 16-7.152 16-16S24.848 0 16 0z" />
<path
android:fillColor="?attr/colorControlNormal"
android:pathData="M16 12c1.1 0 2-0.9 2-2s-0.9-2-2-2-2 0.9-2 2 0.9 2 2 2zm0 2c-1.1 0-2 0.9-2 2s0.9 2 2 2 2-0.9 2-2-0.9-2-2-2zm0 6c-1.1 0-2 0.9-2 2s0.9 2 2 2 2-0.9 2-2-0.9-2-2-2z" />
</vector>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/ic_play_indicator"
android:gravity="center" />
</layer-list>

View File

@ -23,13 +23,13 @@
android:layout_width="0dp"
android:layout_height="0dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_check_24dp"
app:layout_constraintBottom_toBottomOf="@id/checkMark"
app:layout_constraintEnd_toEndOf="@id/checkMark"
app:layout_constraintHeight_default="percent"
app:layout_constraintHeight_percent="0.25"
app:layout_constraintStart_toStartOf="@id/checkMark"
app:layout_constraintTop_toTopOf="@id/checkMark"
app:layout_constraintHeight_default="percent"
app:srcCompat="@drawable/ic_check_24dp"
tools:ignore="ContentDescription" />
<TextView

View File

@ -46,8 +46,8 @@
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:contentDescription="@string/filter_addition_title"
android:src="@drawable/ic_plus_24dp"
app:layout_anchor="@id/filtersList"
app:layout_anchorGravity="bottom|end" />
app:layout_anchorGravity="bottom|end"
app:srcCompat="@drawable/ic_plus_24dp" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -29,7 +29,7 @@
android:layout_gravity="bottom|end"
android:layout_margin="16dp"
android:contentDescription="@string/action_add_tab"
android:src="@drawable/ic_plus_24dp" />
app:srcCompat="@drawable/ic_plus_24dp" />
<com.google.android.material.card.MaterialCardView
android:id="@+id/sheet"

View File

@ -23,8 +23,8 @@
android:layout_width="0dp"
android:layout_height="0dp"
android:scaleType="fitCenter"
android:src="@drawable/ic_check_24dp"
app:layout_constraintBottom_toBottomOf="@id/checkMark"
app:srcCompat="@drawable/ic_check_24dp"
app:layout_constraintEnd_toEndOf="@id/checkMark"
app:layout_constraintHeight_percent="0.3"
app:layout_constraintStart_toStartOf="@id/checkMark"

View File

@ -27,10 +27,10 @@
android:layout_height="24dp"
android:contentDescription="@null"
android:importantForAccessibility="no"
android:src="@drawable/bot_badge"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="@id/account_avatar"
app:layout_constraintEnd_toEndOf="@id/account_avatar"
app:srcCompat="@drawable/bot_badge"
tools:src="#000"
tools:visibility="visible" />

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
@ -21,12 +22,12 @@
<ImageButton
android:id="@+id/deleteButton"
style="@style/TuskyImageButton"
android:layout_marginStart="8dp"
android:layout_width="32dp"
android:layout_height="32dp"
android:contentDescription="@string/action_remove"
android:layout_gravity="bottom"
android:layout_marginStart="8dp"
android:layout_marginBottom="8dp"
android:src="@drawable/ic_clear_24dp" />
android:contentDescription="@string/action_remove"
app:srcCompat="@drawable/ic_clear_24dp" />
</LinearLayout>

View File

@ -26,9 +26,9 @@
android:layout_width="24dp"
android:layout_height="24dp"
android:contentDescription="@string/profile_badge_bot_text"
android:src="@drawable/bot_badge"
app:layout_constraintBottom_toBottomOf="@id/avatar"
app:layout_constraintEnd_toEndOf="@id/avatar" />
app:layout_constraintEnd_toEndOf="@id/avatar"
app:srcCompat="@drawable/bot_badge" />
<TextView
android:id="@+id/displayName"

View File

@ -23,9 +23,9 @@
android:layout_width="24dp"
android:layout_height="24dp"
android:contentDescription="@string/profile_badge_bot_text"
android:src="@drawable/bot_badge"
app:layout_constraintBottom_toBottomOf="@id/blocked_user_avatar"
app:layout_constraintEnd_toEndOf="@id/blocked_user_avatar" />
app:layout_constraintEnd_toEndOf="@id/blocked_user_avatar"
app:srcCompat="@drawable/bot_badge" />
<TextView
android:id="@+id/blocked_user_display_name"

View File

@ -42,9 +42,9 @@
android:layout_width="24dp"
android:layout_height="24dp"
android:contentDescription="@string/profile_badge_bot_text"
android:src="@drawable/bot_badge"
app:layout_constraintBottom_toBottomOf="@id/avatar"
app:layout_constraintEnd_toEndOf="@id/avatar" />
app:layout_constraintEnd_toEndOf="@id/avatar"
app:srcCompat="@drawable/bot_badge" />
<TextView
android:id="@+id/displayNameTextView"

View File

@ -28,34 +28,34 @@
<ImageButton
android:id="@+id/more_button"
android:visibility="gone"
style="@style/TuskyImageButton"
android:layout_width="32dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:background="?selectableItemBackgroundBorderless"
android:contentDescription="@string/action_more"
android:layout_marginLeft="8dp"
android:src="@drawable/ic_more_horiz_24dp" />
android:visibility="gone"
app:srcCompat="@drawable/ic_more_horiz_24dp" />
<ImageButton
android:id="@+id/add_button"
android:visibility="gone"
style="@style/TuskyImageButton"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginStart="8dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/action_add_to_list"
android:layout_marginLeft="8dp"
android:src="@drawable/ic_plus_24dp" />
android:visibility="gone"
app:srcCompat="@drawable/ic_plus_24dp" />
<ImageButton
android:id="@+id/remove_button"
android:visibility="gone"
style="@style/TuskyImageButton"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginStart="8dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/action_remove_from_list"
android:layout_marginLeft="8dp"
android:src="@drawable/ic_clear_24dp" />
android:visibility="gone"
app:srcCompat="@drawable/ic_clear_24dp" />
</LinearLayout>

View File

@ -24,9 +24,9 @@
android:layout_width="24dp"
android:layout_height="24dp"
android:contentDescription="@string/profile_badge_bot_text"
android:src="@drawable/bot_badge"
app:layout_constraintBottom_toBottomOf="@id/muted_user_avatar"
app:layout_constraintEnd_toEndOf="@id/muted_user_avatar" />
app:layout_constraintEnd_toEndOf="@id/muted_user_avatar"
app:srcCompat="@drawable/bot_badge" />
<TextView
android:id="@+id/muted_user_display_name"

View File

@ -18,11 +18,11 @@
android:layout_gravity="end"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:src="@drawable/ic_drag_indicator_24dp"
tools:ignore="ContentDescription"
app:layout_constraintBottom_toBottomOf="@id/textView"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="@id/textView"/>
app:srcCompat="@drawable/ic_drag_indicator_24dp"
tools:ignore="ContentDescription" />
<TextView
android:id="@+id/textView"
@ -52,9 +52,9 @@
android:layout_marginTop="4dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/action_delete"
android:src="@drawable/ic_clear_24dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_clear_24dp" />
<com.google.android.material.chip.ChipGroup
android:id="@+id/chipGroup"

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
@ -33,7 +34,7 @@
android:layout_marginTop="4dp"
android:contentDescription="@null"
android:scaleType="centerInside"
android:src="@drawable/errorphant_offline" />
tools:src="@drawable/errorphant_offline" />
<com.keylesspalace.tusky.view.ClickableSpanTextView
android:id="@+id/messageTextView"