Added account color to long press menu

pull/199/head
M66B 4 years ago
parent b6c30f7e00
commit 5be1b53250

@ -324,6 +324,7 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
.setCheckable(true).setChecked(account.synchronize); .setCheckable(true).setChecked(account.synchronize);
popupMenu.getMenu().add(Menu.NONE, R.string.title_primary, 2, R.string.title_primary) popupMenu.getMenu().add(Menu.NONE, R.string.title_primary, 2, R.string.title_primary)
.setCheckable(true).setChecked(account.primary); .setCheckable(true).setChecked(account.primary);
popupMenu.getMenu().add(Menu.NONE, R.string.title_color, 3, R.string.title_color);
if (account.notify && if (account.notify &&
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@ -331,14 +332,14 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel channel = nm.getNotificationChannel(channelId); NotificationChannel channel = nm.getNotificationChannel(channelId);
if (channel != null) if (channel != null)
popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_channel, 3, R.string.title_edit_channel); popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_channel, 4, R.string.title_edit_channel);
} }
if (account.protocol == EntityAccount.TYPE_IMAP && settings) if (account.protocol == EntityAccount.TYPE_IMAP && settings)
popupMenu.getMenu().add(Menu.NONE, R.string.title_copy, 4, R.string.title_copy); popupMenu.getMenu().add(Menu.NONE, R.string.title_copy, 5, R.string.title_copy);
if (debug) if (debug)
popupMenu.getMenu().add(Menu.NONE, R.string.title_reset, 5, R.string.title_reset); popupMenu.getMenu().add(Menu.NONE, R.string.title_reset, 6, R.string.title_reset);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override @Override
@ -350,6 +351,8 @@ 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) {
onActionColor();
} else if (itemId == R.string.title_edit_channel) { } else if (itemId == R.string.title_edit_channel) {
onActionEditChannel(); onActionEditChannel();
return true; return true;
@ -437,6 +440,19 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
}.execute(context, owner, args, "account:primary"); }.execute(context, owner, args, "account:primary");
} }
private void onActionColor() {
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, FragmentAccounts.REQUEST_ACCOUNT_COLOR);
fragment.show(parentFragment.getParentFragmentManager(), "account:color");
}
@TargetApi(Build.VERSION_CODES.O) @TargetApi(Build.VERSION_CODES.O)
private void onActionEditChannel() { private void onActionEditChannel() {
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS) Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)

@ -136,6 +136,9 @@ public interface DaoAccount {
@Query("UPDATE account SET `primary` = :primary WHERE id = :id AND NOT (`primary` IS :primary)") @Query("UPDATE account SET `primary` = :primary WHERE id = :id AND NOT (`primary` IS :primary)")
int setAccountPrimary(long id, boolean primary); int setAccountPrimary(long id, boolean primary);
@Query("UPDATE account SET color = :color WHERE id = :id AND NOT (color IS :color)")
int setAccountColor(long id, Integer color);
@Query("UPDATE account SET thread = :thread WHERE id = :id AND NOT (thread IS :thread)") @Query("UPDATE account SET thread = :thread WHERE id = :id AND NOT (thread IS :thread)")
int setAccountThread(long id, Long thread); int setAccountThread(long id, Long thread);

@ -55,6 +55,7 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import static android.app.Activity.RESULT_OK;
import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_PASSWORD; import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_PASSWORD;
public class FragmentAccounts extends FragmentBase { public class FragmentAccounts extends FragmentBase {
@ -76,6 +77,7 @@ public class FragmentAccounts extends FragmentBase {
private AdapterAccount adapter; private AdapterAccount adapter;
private static final int REQUEST_IMPORT_OAUTH = 1; private static final int REQUEST_IMPORT_OAUTH = 1;
static final int REQUEST_ACCOUNT_COLOR = 2;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
@ -336,6 +338,25 @@ public class FragmentAccounts extends FragmentBase {
ToastEx.makeText(getContext(), R.string.title_executing, Toast.LENGTH_LONG).show(); ToastEx.makeText(getContext(), R.string.title_executing, Toast.LENGTH_LONG).show();
} }
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
try {
switch (requestCode) {
case REQUEST_ACCOUNT_COLOR:
if (resultCode == RESULT_OK && data != null) {
if (ActivityBilling.isPro(getContext()))
onAccountColor(data.getBundleExtra("args"));
else
startActivity(new Intent(getContext(), ActivityBilling.class));
}
break;
}
} catch (Throwable ex) {
Log.e(ex);
}
}
@Override @Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults); super.onRequestPermissionsResult(requestCode, permissions, grantResults);
@ -345,6 +366,29 @@ public class FragmentAccounts extends FragmentBase {
ServiceSynchronize.reload(getContext(), null, false, "Permissions regranted"); ServiceSynchronize.reload(getContext(), null, false, "Permissions regranted");
} }
private void onAccountColor(Bundle args) {
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) throws Throwable {
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, "account:color");
}
private void onSwipeRefresh() { private void onSwipeRefresh() {
Bundle args = new Bundle(); Bundle args = new Bundle();

Loading…
Cancel
Save