diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 47e2f5c3d3..d16548b63a 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -61,6 +61,7 @@ import android.provider.ContactsContract; import android.provider.Settings; import android.text.Html; import android.text.Spannable; +import android.text.SpannableString; import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.TextUtils; @@ -915,6 +916,7 @@ public class AdapterMessage extends RecyclerView.Adapter>() { + @Override + protected List onExecute(Context context, Bundle args) { + DB db = DB.getInstance(context); + return db.account().getSynchronizingAccounts(); + } + + @Override + protected void onExecuted(Bundle args, List accounts) { + if (accounts == null) + return; + + PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, owner, anchor); + + int order = 0; + for (EntityAccount account : accounts) { + String title = context.getString(R.string.title_move_to_account, account.name); + SpannableString ss = new SpannableString(title); + if (account.name != null && account.color != null) { + int i = title.indexOf(account.name); + int first = title.codePointAt(i); + int count = Character.charCount(first); + ss.setSpan(new ForegroundColorSpan(account.color), i, i + count, 0); + } + popupMenu.getMenu().add(Menu.NONE, R.string.title_move_to_account, order++, ss) + .setIntent(new Intent().putExtra("account", account.id)); + } + + popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + long account = item.getIntent().getLongExtra("account", -1); + long[] disabled = (message.account.equals(account) ? new long[]{account} : new long[]{}); + onActionMove(message, false, account, disabled); + return true; + } + }); + + popupMenu.show(); + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Log.unexpectedError(parentFragment.getParentFragmentManager(), ex); + } + }.execute(context, owner, args, "message:amove"); + } + private void onActionArchive(TupleMessageEx message) { properties.move(message.id, EntityFolder.ARCHIVE); }