add "Resend" to message menu

the UI does not check before selection if a message can be resent,
this is subject to change and not worth the effort.
instead, just an error is shown.

for the ID_NEVER_SHOW_AS_ACTION_* - this is a bit ugly,
however, the few alternatives i tried were even more uglier,
Java and Array-primitives are just not great.
as it is not changed often, it is probably not worth the effort to dive deeper.
This commit is contained in:
B. Petersen
2022-04-23 15:00:55 +02:00
committed by bjoern
parent f047f1382e
commit ad042a73ab
4 changed files with 26 additions and 1 deletions
+4
View File
@@ -39,6 +39,10 @@
android:id="@+id/menu_context_reply_privately"
app:showAsAction="never" />
<item android:title="@string/resend"
android:id="@+id/menu_resend"
app:showAsAction="never" />
<!-- The `showAsAction` behaviors are managed by
ConversationAdaptiveActionsToolbar. The `app:showAsAction`
values set here don't actually make a difference.-->
+2
View File
@@ -31,6 +31,8 @@
<string name="back">Back</string>
<string name="close">Close</string>
<string name="forward">Forward</string>
<!-- "Resend" means "Sending the selected message(s) again to the same chat". The string is used in a menu and should be as short as possible. Resending may be needed after failures or to repost old messages to new members. -->
<string name="resend">Resend</string>
<!-- In the meaning of "To archive", "Put a chat to the archive". This string does not mean "The Archive". -->
<string name="archive">Archive</string>
<!-- In the meaning of "To unarchive", "Remove a chat from the archive", opposite of the previous string -->
@@ -466,6 +466,20 @@ public class ConversationFragment extends MessageSelectorFragment
}
}
private void handleResendMessage(final Set<DcMsg> dcMsgsSet) {
int[] ids = DcMsg.msgSetToIds(dcMsgsSet);
if (dcContext.resendMsgs(ids)) {
actionMode.finish();
Toast.makeText(getContext(), R.string.sending, Toast.LENGTH_SHORT).show();
} else {
new AlertDialog.Builder(getContext())
.setMessage(dcContext.getLastError())
.setCancelable(false)
.setPositiveButton(android.R.string.ok, null)
.show();
}
}
private void reloadList() {
reloadList(false);
}
@@ -924,6 +938,9 @@ public class ConversationFragment extends MessageSelectorFragment
case R.id.menu_context_reply_privately:
handleReplyMessagePrivately(getSelectedMessageRecord(getListAdapter().getSelectedItems()));
return true;
case R.id.menu_resend:
handleResendMessage(getListAdapter().getSelectedItems());
return true;
}
return false;
@@ -25,6 +25,7 @@ public class ConversationAdaptiveActionsToolbar extends Toolbar {
private static final int ID_NEVER_SHOW_AS_ACTION_1 = R.id.menu_context_reply_privately;
private static final int ID_NEVER_SHOW_AS_ACTION_2 = R.id.menu_context_save_attachment;
private static final int ID_NEVER_SHOW_AS_ACTION_3 = R.id.menu_resend;
private static final int ID_ALWAYS_SHOW_AS_ACTION = R.id.menu_context_forward;
private int maxShown;
@@ -79,7 +80,8 @@ public class ConversationAdaptiveActionsToolbar extends Toolbar {
MenuItem item = menu.getItem(i);
boolean neverShowAsAction = item.getItemId() == ID_NEVER_SHOW_AS_ACTION_1
|| item.getItemId() == ID_NEVER_SHOW_AS_ACTION_2;
|| item.getItemId() == ID_NEVER_SHOW_AS_ACTION_2
|| item.getItemId() == ID_NEVER_SHOW_AS_ACTION_3;
boolean alwaysShowAsAction = item.getItemId() == ID_ALWAYS_SHOW_AS_ACTION;
if (alwaysShowAsAction) continue;