Replace keyword color button by color circle

pull/214/head
M66B 2 years ago
parent f68da4b313
commit 9d9b4e5d6d

@ -98,7 +98,7 @@ public class AdapterKeyword extends RecyclerView.Adapter<AdapterKeyword.ViewHold
private void bindTo(TupleKeyword keyword) { private void bindTo(TupleKeyword keyword) {
cbKeyword.setText(getTitle(keyword.name)); cbKeyword.setText(getTitle(keyword.name));
cbKeyword.setChecked(keyword.selected); cbKeyword.setChecked(keyword.selected);
btnColor.setColor(keyword.color); btnColor.setColor(keyword.color, true);
grpNotEdit.setVisibility(View.VISIBLE); grpNotEdit.setVisibility(View.VISIBLE);
grpEdit.setVisibility(View.GONE); grpEdit.setVisibility(View.GONE);
} }
@ -220,7 +220,7 @@ public class AdapterKeyword extends RecyclerView.Adapter<AdapterKeyword.ViewHold
} }
private void updateColor(TupleKeyword keyword, Integer color) { private void updateColor(TupleKeyword keyword, Integer color) {
btnColor.setColor(color); btnColor.setColor(color, true);
keyword.color = color; keyword.color = color;
String key = "kwcolor." + keyword.name; String key = "kwcolor." + keyword.name;

@ -21,7 +21,10 @@ package eu.faircode.email;
import android.content.Context; import android.content.Context;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.drawable.GradientDrawable; import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.util.AttributeSet; import android.util.AttributeSet;
@ -32,37 +35,56 @@ import androidx.core.graphics.ColorUtils;
public class ViewButtonColor extends AppCompatButton { public class ViewButtonColor extends AppCompatButton {
private int color = Color.TRANSPARENT; private int color = Color.TRANSPARENT;
private boolean circle = false;
private int colorSeparator;
public ViewButtonColor(Context context) { public ViewButtonColor(Context context) {
super(context); super(context);
init(context);
} }
public ViewButtonColor(Context context, AttributeSet attrs) { public ViewButtonColor(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
init(context);
} }
public ViewButtonColor(Context context, AttributeSet attrs, int defStyleAttr) { public ViewButtonColor(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr); super(context, attrs, defStyleAttr);
init(context);
}
private void init(Context context) {
this.colorSeparator = Helper.resolveColor(context, R.attr.colorSeparator);
} }
@Override @Override
public Parcelable onSaveInstanceState() { public Parcelable onSaveInstanceState() {
Parcelable superState = super.onSaveInstanceState(); Parcelable superState = super.onSaveInstanceState();
return new SavedState(superState, this.color); return new SavedState(superState, this.color, this.circle);
} }
@Override @Override
public void onRestoreInstanceState(Parcelable state) { public void onRestoreInstanceState(Parcelable state) {
SavedState savedState = (SavedState) state; SavedState savedState = (SavedState) state;
super.onRestoreInstanceState(savedState.getSuperState()); super.onRestoreInstanceState(savedState.getSuperState());
setColor(savedState.getColor()); setColor(savedState.getColor(), savedState.getCircle());
} }
void setColor(Integer color) { void setColor(Integer color) {
setColor(color, false);
}
void setColor(Integer color, boolean circle) {
if (color == null) if (color == null)
color = Color.TRANSPARENT; color = Color.TRANSPARENT;
this.color = color; this.color = color;
this.circle = circle;
if (circle) {
ShapeDrawable shape = new ShapeDrawable(new OvalShape());
shape.setColorFilter(color == Color.TRANSPARENT ? colorSeparator : color, PorterDuff.Mode.SRC_ATOP);
setBackground(shape);
} else {
GradientDrawable background = new GradientDrawable(); GradientDrawable background = new GradientDrawable();
background.setColor(color); background.setColor(color);
background.setStroke( background.setStroke(
@ -77,6 +99,7 @@ public class ViewButtonColor extends AppCompatButton {
setTextColor(lum < 0.5 ? Color.WHITE : Color.BLACK); setTextColor(lum < 0.5 ? Color.WHITE : Color.BLACK);
} }
} }
}
int getColor() { int getColor() {
return this.color; return this.color;
@ -84,25 +107,33 @@ public class ViewButtonColor extends AppCompatButton {
static class SavedState extends View.BaseSavedState { static class SavedState extends View.BaseSavedState {
private int color; private int color;
private boolean circle;
private SavedState(Parcelable superState, int color) { private SavedState(Parcelable superState, int color, boolean circle) {
super(superState); super(superState);
this.color = color; this.color = color;
this.circle = circle;
} }
private SavedState(Parcel in) { private SavedState(Parcel in) {
super(in); super(in);
color = in.readInt(); this.color = in.readInt();
this.circle = (in.readInt() != 0);
} }
public int getColor() { public int getColor() {
return this.color; return this.color;
} }
public boolean getCircle() {
return this.circle;
}
@Override @Override
public void writeToParcel(Parcel destination, int flags) { public void writeToParcel(Parcel destination, int flags) {
super.writeToParcel(destination, flags); super.writeToParcel(destination, flags);
destination.writeInt(color); destination.writeInt(color);
destination.writeInt(circle ? 1 : 0);
} }
public static final Parcelable.Creator<SavedState> CREATOR = new Creator<SavedState>() { public static final Parcelable.Creator<SavedState> CREATOR = new Creator<SavedState>() {

@ -68,11 +68,11 @@
<eu.faircode.email.ViewButtonColor <eu.faircode.email.ViewButtonColor
android:id="@+id/btnColor" android:id="@+id/btnColor"
style="?android:attr/buttonStyleSmall" style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content" android:layout_width="24dp"
android:layout_height="wrap_content" android:layout_height="24dp"
android:layout_marginStart="12dp" android:layout_marginStart="12dp"
android:layout_marginEnd="3dp"
android:paddingHorizontal="6dp" android:paddingHorizontal="6dp"
android:text="@string/title_select"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/ibSave" app:layout_constraintStart_toEndOf="@+id/ibSave"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />

Loading…
Cancel
Save