mirror of
https://github.com/M66B/FairEmail.git
synced 2025-12-30 09:31:11 +01:00
Added long press to set account/identity primary
This commit is contained in:
@@ -241,6 +241,8 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
|
||||
|
||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_enabled, 1, R.string.title_enabled)
|
||||
.setCheckable(true).setChecked(account.synchronize);
|
||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_primary, 2, R.string.title_primary)
|
||||
.setCheckable(true).setChecked(account.primary);
|
||||
|
||||
if (account.notify &&
|
||||
Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
@@ -248,11 +250,11 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
|
||||
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
NotificationChannel channel = nm.getNotificationChannel(channelId);
|
||||
if (channel != null)
|
||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_channel, 2, R.string.title_edit_channel);
|
||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_channel, 3, R.string.title_edit_channel);
|
||||
}
|
||||
|
||||
if (account.protocol == EntityAccount.TYPE_IMAP && settings)
|
||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_copy, 3, R.string.title_copy);
|
||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_copy, 4, R.string.title_copy);
|
||||
|
||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
@Override
|
||||
@@ -262,6 +264,10 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
|
||||
onActionSync(!item.isChecked());
|
||||
return true;
|
||||
|
||||
case R.string.title_primary:
|
||||
onActionPrimary(!item.isChecked());
|
||||
return true;
|
||||
|
||||
case R.string.title_edit_channel:
|
||||
onActionEditChannel();
|
||||
return true;
|
||||
@@ -308,6 +314,40 @@ public class AdapterAccount extends RecyclerView.Adapter<AdapterAccount.ViewHold
|
||||
}.execute(context, owner, args, "account:enable");
|
||||
}
|
||||
|
||||
private void onActionPrimary(boolean primary) {
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("id", account.id);
|
||||
args.putBoolean("primary", primary);
|
||||
|
||||
new SimpleTask<Void>() {
|
||||
@Override
|
||||
protected Void onExecute(Context context, Bundle args) {
|
||||
long id = args.getLong("id");
|
||||
boolean primary = args.getBoolean("primary");
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
try {
|
||||
db.beginTransaction();
|
||||
|
||||
if (primary)
|
||||
db.account().resetPrimary();
|
||||
db.account().setAccountPrimary(id, primary);
|
||||
|
||||
db.setTransactionSuccessful();
|
||||
} finally {
|
||||
db.endTransaction();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
|
||||
}
|
||||
}.execute(context, owner, args, "account:primary");
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.O)
|
||||
private void onActionEditChannel() {
|
||||
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
|
||||
|
||||
Reference in New Issue
Block a user