Added reply ... menu

pull/152/head
M66B 6 years ago
parent 7873712479
commit 782c786169

@ -1189,7 +1189,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
new SimpleTask<Void>() { new SimpleTask<Void>() {
@Override @Override
protected Void onExecute(Context context, Bundle args) throws Throwable { protected Void onExecute(Context context, Bundle args) {
long id = args.getLong("id"); long id = args.getLong("id");
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
@ -1197,7 +1197,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.beginTransaction(); db.beginTransaction();
EntityMessage msg = db.message().getMessage(id); EntityMessage msg = db.message().getMessage(id);
if (message != null) if (msg != null)
for (EntityAttachment attachment : db.attachment().getAttachments(message.id)) for (EntityAttachment attachment : db.attachment().getAttachments(message.id))
if (attachment.progress == null && !attachment.available) { if (attachment.progress == null && !attachment.available) {
db.attachment().setProgress(attachment.id, 0); db.attachment().setProgress(attachment.id, 0);
@ -1649,7 +1649,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
onActionArchive(data); onActionArchive(data);
return true; return true;
case R.id.action_reply: case R.id.action_reply:
onActionReply(data, false); onActionReplyMenu(data);
return true; return true;
default: default:
return false; return false;
@ -1698,73 +1698,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}.execute(context, owner, args, "message:forward"); }.execute(context, owner, args, "message:forward");
} }
private void onMenuAnswer(final ActionData data) {
new SimpleTask<List<EntityAnswer>>() {
@Override
protected List<EntityAnswer> onExecute(Context context, Bundle args) {
return DB.getInstance(context).answer().getAnswers();
}
@Override
protected void onExecuted(Bundle args, List<EntityAnswer> answers) {
if (answers == null || answers.size() == 0) {
Snackbar snackbar = Snackbar.make(
itemView,
context.getString(R.string.title_no_answers),
Snackbar.LENGTH_LONG);
snackbar.setAction(R.string.title_fix, new View.OnClickListener() {
@Override
public void onClick(View v) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(new Intent(ActivityView.ACTION_EDIT_ANSWERS));
}
});
snackbar.show();
} else {
final Collator collator = Collator.getInstance(Locale.getDefault());
collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc
Collections.sort(answers, new Comparator<EntityAnswer>() {
@Override
public int compare(EntityAnswer a1, EntityAnswer a2) {
return collator.compare(a1.name, a2.name);
}
});
View anchor = bnvActions.findViewById(R.id.action_more);
PopupMenu popupMenu = new PopupMenu(context, anchor);
int order = 0;
for (EntityAnswer answer : answers)
popupMenu.getMenu().add(Menu.NONE, answer.id.intValue(), order++, answer.name);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem target) {
if (Helper.isPro(context))
context.startActivity(new Intent(context, ActivityCompose.class)
.putExtra("action", "reply")
.putExtra("reference", data.message.id)
.putExtra("answer", (long) target.getItemId()));
else {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(new Intent(ActivityView.ACTION_SHOW_PRO));
}
return true;
}
});
popupMenu.show();
}
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(context, owner, ex);
}
}.execute(context, owner, new Bundle(), "message:answer");
}
private void onMenuUnseen(final ActionData data) { private void onMenuUnseen(final ActionData data) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", data.message.id); args.putLong("id", data.message.id);
@ -2230,9 +2163,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
popupMenu.getMenu().findItem(R.id.menu_forward).setEnabled(data.message.content); popupMenu.getMenu().findItem(R.id.menu_forward).setEnabled(data.message.content);
popupMenu.getMenu().findItem(R.id.menu_reply_all).setEnabled(data.message.content);
popupMenu.getMenu().findItem(R.id.menu_answer).setEnabled(data.message.content);
popupMenu.getMenu().findItem(R.id.menu_unseen).setEnabled(data.message.uid != null); popupMenu.getMenu().findItem(R.id.menu_unseen).setEnabled(data.message.uid != null);
popupMenu.getMenu().findItem(R.id.menu_delete).setVisible(debug); popupMenu.getMenu().findItem(R.id.menu_delete).setVisible(debug);
@ -2264,12 +2194,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
case R.id.menu_forward: case R.id.menu_forward:
onMenuForward(data); onMenuForward(data);
return true; return true;
case R.id.menu_reply_all:
onActionReply(data, true);
return true;
case R.id.menu_answer:
onMenuAnswer(data);
return true;
case R.id.menu_unseen: case R.id.menu_unseen:
onMenuUnseen(data); onMenuUnseen(data);
return true; return true;
@ -2487,7 +2411,34 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
properties.move(data.message.id, EntityFolder.ARCHIVE, true); properties.move(data.message.id, EntityFolder.ARCHIVE, true);
} }
private void onActionReply(final ActionData data, final boolean all) { private void onActionReplyMenu(final ActionData data) {
View anchor = bnvActions.findViewById(R.id.action_reply);
PopupMenu popupMenu = new PopupMenu(context, anchor);
popupMenu.inflate(R.menu.menu_reply);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem target) {
switch (target.getItemId()) {
case R.id.menu_reply_to_sender:
onMenuReply(data, false);
return true;
case R.id.menu_reply_to_all:
onMenuReply(data, true);
return true;
case R.id.menu_reply_template:
onMenuAnswer(data);
return true;
default:
return false;
}
}
});
popupMenu.show();
}
private void onMenuReply(final ActionData data, final boolean all) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", data.message.id); args.putLong("id", data.message.id);
@ -2529,6 +2480,73 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}.execute(context, owner, args, "message:reply"); }.execute(context, owner, args, "message:reply");
} }
private void onMenuAnswer(final ActionData data) {
new SimpleTask<List<EntityAnswer>>() {
@Override
protected List<EntityAnswer> onExecute(Context context, Bundle args) {
return DB.getInstance(context).answer().getAnswers();
}
@Override
protected void onExecuted(Bundle args, List<EntityAnswer> answers) {
if (answers == null || answers.size() == 0) {
Snackbar snackbar = Snackbar.make(
itemView,
context.getString(R.string.title_no_answers),
Snackbar.LENGTH_LONG);
snackbar.setAction(R.string.title_fix, new View.OnClickListener() {
@Override
public void onClick(View v) {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(new Intent(ActivityView.ACTION_EDIT_ANSWERS));
}
});
snackbar.show();
} else {
final Collator collator = Collator.getInstance(Locale.getDefault());
collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc
Collections.sort(answers, new Comparator<EntityAnswer>() {
@Override
public int compare(EntityAnswer a1, EntityAnswer a2) {
return collator.compare(a1.name, a2.name);
}
});
View anchor = bnvActions.findViewById(R.id.action_reply);
PopupMenu popupMenu = new PopupMenu(context, anchor);
int order = 0;
for (EntityAnswer answer : answers)
popupMenu.getMenu().add(Menu.NONE, answer.id.intValue(), order++, answer.name);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem target) {
if (Helper.isPro(context))
context.startActivity(new Intent(context, ActivityCompose.class)
.putExtra("action", "reply")
.putExtra("reference", data.message.id)
.putExtra("answer", (long) target.getItemId()));
else {
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
lbm.sendBroadcast(new Intent(ActivityView.ACTION_SHOW_PRO));
}
return true;
}
});
popupMenu.show();
}
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(context, owner, ex);
}
}.execute(context, owner, new Bundle(), "message:answer");
}
ItemDetailsLookup.ItemDetails<Long> getItemDetails(@NonNull MotionEvent motionEvent) { ItemDetailsLookup.ItemDetails<Long> getItemDetails(@NonNull MotionEvent motionEvent) {
return new ItemDetailsMessage(this); return new ItemDetailsMessage(this);
} }

@ -4,14 +4,6 @@
android:id="@+id/menu_forward" android:id="@+id/menu_forward"
android:title="@string/title_forward" /> android:title="@string/title_forward" />
<item
android:id="@+id/menu_reply_all"
android:title="@string/title_reply_all" />
<item
android:id="@+id/menu_answer"
android:title="@string/title_answer_reply" />
<item <item
android:id="@+id/menu_unseen" android:id="@+id/menu_unseen"
android:title="@string/title_unseen" /> android:title="@string/title_unseen" />

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_reply_to_sender"
android:title="@string/title_reply_to_sender" />
<item
android:id="@+id/menu_reply_to_all"
android:title="@string/title_reply_to_all" />
<item
android:id="@+id/menu_reply_template"
android:title="@string/title_reply_template" />
</menu>

@ -316,7 +316,6 @@
<string name="title_flag">Add star</string> <string name="title_flag">Add star</string>
<string name="title_unflag">Remove star</string> <string name="title_unflag">Remove star</string>
<string name="title_forward">Forward</string> <string name="title_forward">Forward</string>
<string name="title_reply_all">Reply to all</string>
<string name="title_create_rule">Create rule &#8230;</string> <string name="title_create_rule">Create rule &#8230;</string>
<string name="title_share">Share</string> <string name="title_share">Share</string>
<string name="title_show_headers">Show headers</string> <string name="title_show_headers">Show headers</string>
@ -338,6 +337,9 @@
<string name="title_snooze">Snooze &#8230;</string> <string name="title_snooze">Snooze &#8230;</string>
<string name="title_archive">Archive</string> <string name="title_archive">Archive</string>
<string name="title_reply">Reply</string> <string name="title_reply">Reply</string>
<string name="title_reply_to_sender">Sender</string>
<string name="title_reply_to_all">All</string>
<string name="title_reply_template">Template</string>
<string name="title_moving">Moving to %1$s</string> <string name="title_moving">Moving to %1$s</string>
<string name="title_open_with">Open with</string> <string name="title_open_with">Open with</string>

Loading…
Cancel
Save