Simplify color selection

This commit is contained in:
M66B
2019-09-29 14:45:00 +02:00
parent a685da21a9
commit 97bc466942
12 changed files with 160 additions and 224 deletions

View File

@@ -24,7 +24,6 @@ import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.GradientDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@@ -43,7 +42,6 @@ import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.RadioGroup;
import android.widget.ScrollView;
import android.widget.Spinner;
@@ -93,9 +91,7 @@ public class FragmentAccount extends FragmentBase {
private EditText etRealm;
private EditText etName;
private Button btnColor;
private View vwColor;
private ImageButton ibColorDefault;
private ButtonColor btnColor;
private TextView tvColorPro;
private Button btnAdvanced;
@@ -142,7 +138,6 @@ public class FragmentAccount extends FragmentBase {
private long copy = -1;
private int auth = MailService.AUTH_TYPE_PASSWORD;
private boolean saving = false;
private int color = Color.TRANSPARENT;
private static final int REQUEST_COLOR = 1;
private static final int REQUEST_SAVE = 2;
@@ -191,8 +186,6 @@ public class FragmentAccount extends FragmentBase {
etName = view.findViewById(R.id.etName);
btnColor = view.findViewById(R.id.btnColor);
vwColor = view.findViewById(R.id.vwColor);
ibColorDefault = view.findViewById(R.id.ibColorDefault);
tvColorPro = view.findViewById(R.id.tvColorPro);
btnAdvanced = view.findViewById(R.id.btnAdvanced);
@@ -307,24 +300,16 @@ public class FragmentAccount extends FragmentBase {
}
});
setColor(color);
btnColor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentDialogColor fragment = new FragmentDialogColor();
fragment.initialize(R.string.title_color, color, new Bundle(), getContext());
fragment.initialize(R.string.title_color, btnColor.getColor(), new Bundle(), getContext());
fragment.setTargetFragment(FragmentAccount.this, REQUEST_COLOR);
fragment.show(getFragmentManager(), "account:color");
}
});
ibColorDefault.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setColor(Color.TRANSPARENT);
}
});
Helper.linkPro(tvColorPro);
btnAdvanced.setOnClickListener(new View.OnClickListener() {
@@ -693,7 +678,7 @@ public class FragmentAccount extends FragmentBase {
args.putString("realm", etRealm.getText().toString());
args.putString("name", etName.getText().toString());
args.putInt("color", color);
args.putInt("color", btnColor.getColor());
args.putBoolean("synchronize", cbSynchronize.isChecked());
args.putBoolean("primary", cbPrimary.isChecked());
@@ -1129,7 +1114,6 @@ public class FragmentAccount extends FragmentBase {
outState.putString("fair:password", tilPassword.getEditText().getText().toString());
outState.putInt("fair:advanced", grpAdvanced.getVisibility());
outState.putInt("fair:auth", auth);
outState.putInt("fair:color", color);
super.onSaveInstanceState(outState);
}
@@ -1191,6 +1175,7 @@ public class FragmentAccount extends FragmentBase {
etRealm.setText(account == null ? null : account.realm);
etName.setText(account == null ? null : account.name);
btnColor.setColor(account == null ? null : account.color);
boolean pro = ActivityBilling.isPro(getContext());
cbNotify.setChecked(account != null && account.notify && pro);
@@ -1204,7 +1189,6 @@ public class FragmentAccount extends FragmentBase {
cbPartialFetch.setChecked(account == null ? true : account.partial_fetch);
auth = (account == null ? MailService.AUTH_TYPE_PASSWORD : account.auth_type);
color = (account == null || account.color == null ? Color.TRANSPARENT : account.color);
new SimpleTask<EntityAccount>() {
@Override
@@ -1231,7 +1215,6 @@ public class FragmentAccount extends FragmentBase {
tilPassword.getEditText().setText(savedInstanceState.getString("fair:password"));
grpAdvanced.setVisibility(savedInstanceState.getInt("fair:advanced"));
auth = savedInstanceState.getInt("fair:auth");
color = savedInstanceState.getInt("fair:color");
}
Helper.setViewsEnabled(view, true);
@@ -1241,7 +1224,6 @@ public class FragmentAccount extends FragmentBase {
tilPassword.setEnabled(false);
}
setColor(color);
cbPrimary.setEnabled(cbSynchronize.isChecked());
// Consider previous check/save/delete as cancelled
@@ -1329,7 +1311,7 @@ public class FragmentAccount extends FragmentBase {
if (resultCode == RESULT_OK && data != null) {
if (ActivityBilling.isPro(getContext())) {
Bundle args = data.getBundleExtra("args");
setColor(args.getInt("color"));
btnColor.setColor(args.getInt("color"));
} else
startActivity(new Intent(getContext(), ActivityBilling.class));
}
@@ -1356,15 +1338,6 @@ public class FragmentAccount extends FragmentBase {
}
}
private void setColor(int color) {
this.color = color;
GradientDrawable border = new GradientDrawable();
border.setColor(color);
border.setStroke(1, Helper.resolveColor(getContext(), R.attr.colorSeparator));
vwColor.setBackground(border);
}
private void onDelete() {
Bundle args = new Bundle();
args.putLong("id", id);