Fix icon bug colors

This commit is contained in:
Thomas 2023-01-14 11:15:05 +01:00
parent f5b0eacfab
commit 3a8f037be5
2 changed files with 47 additions and 46 deletions

View File

@ -646,6 +646,9 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
holder.binding.actionButtonBookmark.setInactiveImage(R.drawable.ic_round_bookmark_border_24);
holder.binding.actionButtonBoost.setActiveImage(R.drawable.ic_round_repeat_active_24);
holder.binding.actionButtonBoost.setInactiveImage(R.drawable.ic_round_repeat_24);
holder.binding.actionButtonFavorite.setActiveImageTint(R.color.marked_icon);
holder.binding.actionButtonBoost.setActiveImageTint(R.color.boost_icon);
holder.binding.actionButtonBookmark.setActiveImageTint(R.color.marked_icon);
applyColor(context, holder);
if (status.pinned) {
@ -2324,6 +2327,9 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
Helper.changeDrawableColor(context, R.drawable.ic_bot, theme_icons_color);
Helper.changeDrawableColor(context, R.drawable.ic_round_reply_24, theme_icons_color);
Helper.changeDrawableColor(context, holder.binding.actionButtonTranslate, theme_icons_color);
holder.binding.actionButtonBoost.setInActiveImageTintColor(theme_icons_color);
holder.binding.actionButtonFavorite.setInActiveImageTintColor(theme_icons_color);
holder.binding.actionButtonBookmark.setInActiveImageTintColor(theme_icons_color);
holder.binding.replyCount.setTextColor(theme_icons_color);
}
if (theme_statuses_color != -1) {

View File

@ -7,10 +7,10 @@ import android.animation.ObjectAnimator;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.PorterDuff;
import android.os.Build;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
@ -55,21 +55,24 @@ public class SparkButton extends FrameLayout implements View.OnClickListener {
private float animationSpeed = 1;
private boolean isChecked = false;
private AnimatorSet animatorSet;
private SparkEventListener listener;
private final Context context;
SparkButton(Context context) {
super(context);
this.context = context;
}
public SparkButton(Context context, AttributeSet attrs) {
super(context, attrs);
initFromXML(attrs);
this.context = context;
init();
}
public SparkButton(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initFromXML(attrs);
this.context = context;
init();
}
@ -77,6 +80,7 @@ public class SparkButton extends FrameLayout implements View.OnClickListener {
public SparkButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
initFromXML(attrs);
this.context = context;
init();
}
@ -221,6 +225,24 @@ public class SparkButton extends FrameLayout implements View.OnClickListener {
return isChecked;
}
public void setInActiveImageTint(int inActiveImageTint) {
this.inActiveImageTint = getColor(inActiveImageTint);
}
public void setInActiveImageTintColor(int inActiveImageTint) {
this.inActiveImageTint = inActiveImageTint;
}
public void setActiveImageTint(int activeImageTint) {
this.activeImageTint = getColor(activeImageTint);
}
public void setActiveImageTintColor(int activeImageTint) {
this.activeImageTint = activeImageTint;
}
/**
* Change Button State (Works only if both active and disabled image resource is defined)
*
@ -229,6 +251,7 @@ public class SparkButton extends FrameLayout implements View.OnClickListener {
public void setChecked(boolean flag) {
isChecked = flag;
imageView.setImageResource(isChecked ? imageResourceIdActive : imageResourceIdInactive);
imageView.setColorFilter(isChecked ? activeImageTint : inActiveImageTint, PorterDuff.Mode.SRC_ATOP);
}
public void setInactiveImage(int inactiveResource) {
@ -241,11 +264,9 @@ public class SparkButton extends FrameLayout implements View.OnClickListener {
imageView.setImageResource(isChecked ? imageResourceIdActive : imageResourceIdInactive);
}
@Override
public void onClick(View v) {
boolean shouldPlayAnimation = listener == null || listener.onEvent(this, isChecked);
if (shouldPlayAnimation) {
if (imageResourceIdInactive != INVALID_RESOURCE_ID) {
isChecked = !isChecked;
@ -264,36 +285,8 @@ public class SparkButton extends FrameLayout implements View.OnClickListener {
playAnimation();
}
}
}
private void setOnTouchListener() {
setOnTouchListener((v, event) -> {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
imageView.animate().scaleX(0.8f).scaleY(0.8f).setDuration(150).setInterpolator(DECELERATE_INTERPOLATOR);
setPressed(true);
break;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
imageView.animate().scaleX(1).scaleY(1).setInterpolator(DECELERATE_INTERPOLATOR);
if (isPressed()) {
performClick();
setPressed(false);
}
break;
case MotionEvent.ACTION_CANCEL:
imageView.animate().scaleX(1).scaleY(1).setInterpolator(DECELERATE_INTERPOLATOR);
break;
}
return true;
});
}
private int getColor(int id) {
return ContextCompat.getColor(getContext(), id);
}
@ -310,4 +303,6 @@ public class SparkButton extends FrameLayout implements View.OnClickListener {
// recycle typedArray
a.recycle();
}
}