Added long press account to edit account color

pull/215/head
M66B 7 months ago
parent b417e28fd1
commit c744fc9904

@ -90,10 +90,11 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
static final int REQUEST_SELECT_IDENTITY = 8; static final int REQUEST_SELECT_IDENTITY = 8;
static final int REQUEST_EDIT_SIGNATURE = 9; static final int REQUEST_EDIT_SIGNATURE = 9;
static final int REQUEST_CHANGE_PASSWORD = 10; static final int REQUEST_CHANGE_PASSWORD = 10;
static final int REQUEST_DELETE_ACCOUNT = 11; static final int REQUEST_EDIT_ACCOUNT_COLOR = 11;
static final int REQUEST_IMPORT_PROVIDERS = 12; static final int REQUEST_DELETE_ACCOUNT = 12;
static final int REQUEST_GRAPH_CONTACTS = 13; static final int REQUEST_IMPORT_PROVIDERS = 13;
static final int REQUEST_GRAPH_CONTACTS_OAUTH = 14; static final int REQUEST_GRAPH_CONTACTS = 14;
static final int REQUEST_GRAPH_CONTACTS_OAUTH = 15;
static final int REQUEST_DEBUG_INFO = 7000; static final int REQUEST_DEBUG_INFO = 7000;
static final int PI_CONNECTION = 1; static final int PI_CONNECTION = 1;

@ -494,6 +494,8 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
} }
popupMenu.getMenu().add(Menu.NONE, R.string.title_primary, order++, R.string.title_primary) popupMenu.getMenu().add(Menu.NONE, R.string.title_primary, order++, R.string.title_primary)
.setCheckable(true).setChecked(account.primary); .setCheckable(true).setChecked(account.primary);
if (parentFragment instanceof FragmentAccounts)
popupMenu.getMenu().add(Menu.NONE, R.string.title_color, order++, R.string.title_color);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String channelId = EntityAccount.getNotificationChannelId(account.id); String channelId = EntityAccount.getNotificationChannelId(account.id);
@ -536,6 +538,9 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
} else if (itemId == R.string.title_primary) { } else if (itemId == R.string.title_primary) {
onActionPrimary(!item.isChecked()); onActionPrimary(!item.isChecked());
return true; return true;
} else if (itemId == R.string.title_color) {
onActionEditColor();
return true;
} else if (itemId == R.string.title_create_channel) { } else if (itemId == R.string.title_create_channel) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
onActionCreateChannel(); onActionCreateChannel();
@ -676,6 +681,19 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
}.execute(context, owner, args, "account:primary"); }.execute(context, owner, args, "account:primary");
} }
private void onActionEditColor() {
Bundle args = new Bundle();
args.putLong("id", account.id);
args.putInt("color", account.color == null ? Color.TRANSPARENT : account.color);
args.putString("title", context.getString(R.string.title_color));
args.putBoolean("reset", true);
FragmentDialogColor fragment = new FragmentDialogColor();
fragment.setArguments(args);
fragment.setTargetFragment(parentFragment, ActivitySetup.REQUEST_EDIT_ACCOUNT_COLOR);
fragment.show(parentFragment.getParentFragmentManager(), "edit:color");
}
@TargetApi(Build.VERSION_CODES.O) @TargetApi(Build.VERSION_CODES.O)
private void onActionCreateChannel() { private void onActionCreateChannel() {
if (!ActivityBilling.isPro(context)) { if (!ActivityBilling.isPro(context)) {

@ -488,6 +488,10 @@ public class FragmentAccounts extends FragmentBase {
try { try {
switch (requestCode) { switch (requestCode) {
case ActivitySetup.REQUEST_EDIT_ACCOUNT_COLOR:
if (resultCode == RESULT_OK && data != null)
onEditAccountColor(data.getBundleExtra("args"));
break;
case ActivitySetup.REQUEST_DELETE_ACCOUNT: case ActivitySetup.REQUEST_DELETE_ACCOUNT:
if (resultCode == RESULT_OK && data != null) if (resultCode == RESULT_OK && data != null)
onDeleteAccount(data.getBundleExtra("args")); onDeleteAccount(data.getBundleExtra("args"));
@ -506,6 +510,33 @@ public class FragmentAccounts extends FragmentBase {
} }
} }
private void onEditAccountColor(Bundle args) {
if (!ActivityBilling.isPro(getContext())) {
startActivity(new Intent(getContext(), ActivityBilling.class));
return;
}
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id");
Integer color = args.getInt("color");
if (color == Color.TRANSPARENT)
color = null;
DB db = DB.getInstance(context);
db.account().setAccountColor(id, color);
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(this, args, "edit:color");
}
private void onDeleteAccount(Bundle args) { private void onDeleteAccount(Bundle args) {
long account = args.getLong("account"); long account = args.getLong("account");
String name = args.getString("name"); String name = args.getString("name");

Loading…
Cancel
Save