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.actionButtonBookmark.setInactiveImage(R.drawable.ic_round_bookmark_border_24);
holder.binding.actionButtonBoost.setActiveImage(R.drawable.ic_round_repeat_active_24); holder.binding.actionButtonBoost.setActiveImage(R.drawable.ic_round_repeat_active_24);
holder.binding.actionButtonBoost.setInactiveImage(R.drawable.ic_round_repeat_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); applyColor(context, holder);
if (status.pinned) { 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_bot, theme_icons_color);
Helper.changeDrawableColor(context, R.drawable.ic_round_reply_24, theme_icons_color); Helper.changeDrawableColor(context, R.drawable.ic_round_reply_24, theme_icons_color);
Helper.changeDrawableColor(context, holder.binding.actionButtonTranslate, 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); holder.binding.replyCount.setTextColor(theme_icons_color);
} }
if (theme_statuses_color != -1) { if (theme_statuses_color != -1) {

View file

@ -7,10 +7,10 @@ import android.animation.ObjectAnimator;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.PorterDuff;
import android.os.Build; import android.os.Build;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.Gravity; import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.animation.AccelerateDecelerateInterpolator; import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.DecelerateInterpolator; import android.view.animation.DecelerateInterpolator;
@ -55,21 +55,24 @@ public class SparkButton extends FrameLayout implements View.OnClickListener {
private float animationSpeed = 1; private float animationSpeed = 1;
private boolean isChecked = false; private boolean isChecked = false;
private AnimatorSet animatorSet; private AnimatorSet animatorSet;
private SparkEventListener listener; private final Context context;
SparkButton(Context context) { SparkButton(Context context) {
super(context); super(context);
this.context = context;
} }
public SparkButton(Context context, AttributeSet attrs) { public SparkButton(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
initFromXML(attrs); initFromXML(attrs);
this.context = context;
init(); init();
} }
public SparkButton(Context context, AttributeSet attrs, int defStyleAttr) { public SparkButton(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr); super(context, attrs, defStyleAttr);
initFromXML(attrs); initFromXML(attrs);
this.context = context;
init(); init();
} }
@ -77,6 +80,7 @@ public class SparkButton extends FrameLayout implements View.OnClickListener {
public SparkButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { public SparkButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes); super(context, attrs, defStyleAttr, defStyleRes);
initFromXML(attrs); initFromXML(attrs);
this.context = context;
init(); init();
} }
@ -221,6 +225,24 @@ public class SparkButton extends FrameLayout implements View.OnClickListener {
return isChecked; 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) * 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) { public void setChecked(boolean flag) {
isChecked = flag; isChecked = flag;
imageView.setImageResource(isChecked ? imageResourceIdActive : imageResourceIdInactive); imageView.setImageResource(isChecked ? imageResourceIdActive : imageResourceIdInactive);
imageView.setColorFilter(isChecked ? activeImageTint : inActiveImageTint, PorterDuff.Mode.SRC_ATOP);
} }
public void setInactiveImage(int inactiveResource) { public void setInactiveImage(int inactiveResource) {
@ -241,59 +264,29 @@ public class SparkButton extends FrameLayout implements View.OnClickListener {
imageView.setImageResource(isChecked ? imageResourceIdActive : imageResourceIdInactive); imageView.setImageResource(isChecked ? imageResourceIdActive : imageResourceIdInactive);
} }
@Override @Override
public void onClick(View v) { public void onClick(View v) {
boolean shouldPlayAnimation = listener == null || listener.onEvent(this, isChecked); if (imageResourceIdInactive != INVALID_RESOURCE_ID) {
isChecked = !isChecked;
if (shouldPlayAnimation) { imageView.setImageResource(isChecked ? imageResourceIdActive : imageResourceIdInactive);
if (imageResourceIdInactive != INVALID_RESOURCE_ID) {
isChecked = !isChecked;
imageView.setImageResource(isChecked ? imageResourceIdActive : imageResourceIdInactive); if (animatorSet != null) {
animatorSet.cancel();
if (animatorSet != null) {
animatorSet.cancel();
}
if (isChecked) {
sparkAnimationView.setVisibility(VISIBLE);
playAnimation();
} else {
sparkAnimationView.setVisibility(INVISIBLE);
}
} else {
playAnimation();
} }
if (isChecked) {
sparkAnimationView.setVisibility(VISIBLE);
playAnimation();
} else {
sparkAnimationView.setVisibility(INVISIBLE);
}
} else {
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) { private int getColor(int id) {
return ContextCompat.getColor(getContext(), id); return ContextCompat.getColor(getContext(), id);
} }
@ -310,4 +303,6 @@ public class SparkButton extends FrameLayout implements View.OnClickListener {
// recycle typedArray // recycle typedArray
a.recycle(); a.recycle();
} }
} }