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:
parent
a690b537c2
commit
973ebd236c
23 changed files with 72 additions and 99 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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?) {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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) }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue