Added FAB reply menu

pull/175/head
M66B 5 years ago
parent b6e1ab3097
commit a936ca5286

@ -891,20 +891,68 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
fabReply.setOnClickListener(new View.OnClickListener() { fabReply.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
boolean reply_hint = prefs.getBoolean("reply_hint", false); if (values.containsKey("expanded") && values.get("expanded").size() > 0) {
if (reply_hint) Bundle args = new Bundle();
onReply("reply"); args.putLong("id", values.get("expanded").get(0));
else
new AlertDialog.Builder(getContext()) new SimpleTask<Integer>() {
.setMessage(R.string.title_reply_hint) @Override
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { protected Integer onExecute(Context context, Bundle args) {
long id = args.getLong("id");
DB db = DB.getInstance(context);
EntityMessage message = db.message().getMessage(id);
if (message == null)
return null;
List<TupleIdentityEx> identities = db.identity().getComposableIdentities(message.account);
if (identities == null)
return null;
Address[] recipients = message.getAllRecipients(identities, message.account);
return recipients.length;
}
@Override
protected void onExecuted(Bundle args, Integer recipients) {
if (recipients == null)
return;
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(getContext(), getViewLifecycleOwner(), fabReply);
popupMenu.inflate(R.menu.popup_reply);
for (int i = 0; i < popupMenu.getMenu().size(); i++)
popupMenu.getMenu().getItem(i).setVisible(false);
popupMenu.getMenu().findItem(R.id.menu_reply_to_sender).setVisible(true);
popupMenu.getMenu().findItem(R.id.menu_reply_to_all).setVisible(recipients > 1);
popupMenu.getMenu().findItem(R.id.menu_forward).setVisible(true);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public boolean onMenuItemClick(MenuItem target) {
prefs.edit().putBoolean("reply_hint", true).apply(); switch (target.getItemId()) {
onReply("reply"); case R.id.menu_reply_to_sender:
onReply("reply");
return true;
case R.id.menu_reply_to_all:
onReply("reply_all");
return true;
case R.id.menu_forward:
onReply("forward");
return true;
default:
return false;
}
} }
}) });
.show(); popupMenu.show();
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(FragmentMessages.this, args, "messages:reply");
}
} }
}); });

Loading…
Cancel
Save