diff options
author | Christian Schneppe <christian@pix-art.de> | 2019-09-11 19:18:56 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2019-09-11 19:18:56 +0200 |
commit | 911b537f34eca7da671aa6da6409e03dcd514201 (patch) | |
tree | 26e66b55acd5126771424300828f421c45f7d1fb /src/main/java | |
parent | 41f36bd816b642c48473c5ba786c065bf81a549a (diff) |
include user into quote message
Diffstat (limited to 'src/main/java')
6 files changed, 52 insertions, 18 deletions
diff --git a/src/main/java/de/pixart/messenger/services/ExportBackupService.java b/src/main/java/de/pixart/messenger/services/ExportBackupService.java index 64595a961..8d4cd4f2d 100644 --- a/src/main/java/de/pixart/messenger/services/ExportBackupService.java +++ b/src/main/java/de/pixart/messenger/services/ExportBackupService.java @@ -445,6 +445,7 @@ public class ExportBackupService extends Service { case Message.STATUS_SEND: case Message.STATUS_SEND_RECEIVED: case Message.STATUS_SEND_DISPLAYED: + case Message.STATUS_SEND_FAILED: jid = accountJid.asBareJid().toString(); break; } diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index 8c7c313a7..9d2c7472b 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -1162,7 +1162,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke messageListAdapter = new MessageAdapter((XmppActivity) getActivity(), this.messageList); messageListAdapter.setOnContactPictureClicked(this); messageListAdapter.setOnContactPictureLongClicked(this); - messageListAdapter.setOnQuoteListener(this::quoteText); + messageListAdapter.setOnQuoteListener(text -> quoteText(text, conversation.getContact().getDisplayName())); binding.messagesView.setAdapter(messageListAdapter); registerForContextMenu(binding.messagesView); @@ -1184,9 +1184,14 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } } - private void quoteText(String text) { + private void quoteText(String text, String user) { if (binding.textinput.isEnabled()) { - binding.textinput.insertAsQuote(text); + String username = ""; + if (user != null && user.length() > 0) { + String res = "*" + user + "*"; + username = getString(R.string.x_has_written, res) + System.getProperty("line.separator"); + } + binding.textinput.insertAsQuote(username + text); binding.textinput.requestFocus(); InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); if (inputMethodManager != null) { @@ -1207,8 +1212,8 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke binding.recordVoiceButton.setImageResource(activity.getThemeResource(R.attr.ic_send_voice_offline, R.drawable.ic_send_voice_offline)); } - private void quoteMessage(Message message) { - quoteText(MessageUtils.prepareQuote(message)); + private void quoteMessage(Message message, String user) { + quoteText(MessageUtils.prepareQuote(message), user); } @Override @@ -1322,9 +1327,31 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke @Override public boolean onContextItemSelected(MenuItem item) { + String user; + try { + final Contact contact = selectedMessage.getContact(); + if (conversation.getMode() == Conversation.MODE_MULTI) { + if (contact != null) { + user = contact.getDisplayName(); + } else { + user = UIHelper.getDisplayedMucCounterpart(selectedMessage.getCounterpart()); + } + } else { + user = contact != null ? contact.getDisplayName() : null; + } + if (selectedMessage.getStatus() == Message.STATUS_SEND + || selectedMessage.getStatus() == Message.STATUS_SEND_FAILED + || selectedMessage.getStatus() == Message.STATUS_SEND_RECEIVED + || selectedMessage.getStatus() == Message.STATUS_SEND_DISPLAYED) { + user = getString(R.string.me); + } + } catch (Exception e) { + e.printStackTrace(); + user = null; + } switch (item.getItemId()) { case R.id.share_with: - ShareUtil.share(activity, selectedMessage); + ShareUtil.share(activity, selectedMessage, user); return true; case R.id.correct_message: correctMessage(selectedMessage); @@ -1336,7 +1363,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke ShareUtil.copyLinkToClipboard(activity, selectedMessage); return true; case R.id.quote_message: - quoteMessage(selectedMessage); + quoteMessage(selectedMessage, selectedMessage.getContact().getDisplayName()); return true; case R.id.send_again: resendMessage(selectedMessage); @@ -2244,6 +2271,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke final String text = extras.getString(Intent.EXTRA_TEXT); final String nick = extras.getString(ConversationsActivity.EXTRA_NICK); final boolean asQuote = extras.getBoolean(ConversationsActivity.EXTRA_AS_QUOTE); + final String user = extras.getString(ConversationsActivity.EXTRA_USER); final boolean pm = extras.getBoolean(ConversationsActivity.EXTRA_IS_PRIVATE_MESSAGE, false); final boolean doNotAppend = extras.getBoolean(ConversationsActivity.EXTRA_DO_NOT_APPEND, false); final List<Uri> uris = extractUris(extras); @@ -2278,7 +2306,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke toggleInputMethod(); return; } else if (text != null && asQuote) { - quoteText(text); + quoteText(text, user); } else { appendText(text, doNotAppend); } diff --git a/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java index 8270d4e1a..49e6d48ef 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java @@ -104,6 +104,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio public static final String EXTRA_DOWNLOAD_UUID = "de.pixart.messenger.download_uuid"; public static final String EXTRA_AS_QUOTE = "de.pixart.messenger.as_quote"; public static final String EXTRA_NICK = "nick"; + public static final String EXTRA_USER = "user"; public static final String EXTRA_IS_PRIVATE_MESSAGE = "pm"; public static final String EXTRA_DO_NOT_APPEND = "do_not_append"; public static final String ACTION_DESTROY_MUC = "de.pixart.messenger.DESTROY_MUC"; diff --git a/src/main/java/de/pixart/messenger/ui/SearchActivity.java b/src/main/java/de/pixart/messenger/ui/SearchActivity.java index e9ba1d426..b5d752522 100644 --- a/src/main/java/de/pixart/messenger/ui/SearchActivity.java +++ b/src/main/java/de/pixart/messenger/ui/SearchActivity.java @@ -149,13 +149,14 @@ public class SearchActivity extends XmppActivity implements TextWatcher, OnSearc @Override public boolean onContextItemSelected(MenuItem item) { final Message message = selectedMessageReference.get(); + final String user = selectedMessageReference.get().getContact().getDisplayName(); if (message != null) { switch (item.getItemId()) { case R.id.open_conversation: switchToConversation(wrap(message.getConversation())); break; case R.id.share_with: - ShareUtil.share(this, message); + ShareUtil.share(this, message, user); break; case R.id.copy_message: ShareUtil.copyToClipboard(this, message); @@ -164,7 +165,7 @@ public class SearchActivity extends XmppActivity implements TextWatcher, OnSearc ShareUtil.copyUrlToClipboard(this, message); break; case R.id.quote_message: - quote(message); + quote(message, user); break; } } @@ -180,8 +181,8 @@ public class SearchActivity extends XmppActivity implements TextWatcher, OnSearc super.onSaveInstanceState(bundle); } - private void quote(Message message) { - switchToConversationAndQuote(wrap(message.getConversation()), MessageUtils.prepareQuote(message)); + private void quote(Message message, String user) { + switchToConversationAndQuote(wrap(message.getConversation()), MessageUtils.prepareQuote(message), user); } private Conversation wrap(Conversational conversational) { diff --git a/src/main/java/de/pixart/messenger/ui/XmppActivity.java b/src/main/java/de/pixart/messenger/ui/XmppActivity.java index 9c7292515..06f350385 100644 --- a/src/main/java/de/pixart/messenger/ui/XmppActivity.java +++ b/src/main/java/de/pixart/messenger/ui/XmppActivity.java @@ -75,6 +75,7 @@ import de.pixart.messenger.databinding.DialogQuickeditBinding; import de.pixart.messenger.entities.Account; import de.pixart.messenger.entities.Contact; import de.pixart.messenger.entities.Conversation; +import de.pixart.messenger.entities.Conversational; import de.pixart.messenger.entities.Message; import de.pixart.messenger.entities.Presences; import de.pixart.messenger.services.AvatarService; @@ -470,8 +471,8 @@ public abstract class XmppActivity extends ActionBarActivity { switchToConversation(conversation, null); } - public void switchToConversationAndQuote(Conversation conversation, String text) { - switchToConversation(conversation, text, true, null, false, false); + public void switchToConversationAndQuote(Conversation conversation, String text, String user) { + switchToConversation(conversation, text, true, user, false, false); } public void switchToConversation(Conversation conversation, String text) { @@ -498,6 +499,7 @@ public abstract class XmppActivity extends ActionBarActivity { intent.putExtra(Intent.EXTRA_TEXT, text); if (asQuote) { intent.putExtra(ConversationsActivity.EXTRA_AS_QUOTE, true); + intent.putExtra(ConversationsActivity.EXTRA_ACCOUNT, nick); } } if (nick != null) { @@ -966,8 +968,8 @@ public abstract class XmppActivity extends ActionBarActivity { } if (!xmppConnectionService.multipleAccounts()) { Account mAccount = xmppConnectionService.getAccounts().get(0); - String user = Jid.of(mAccount.getJid()).getLocal(); - String domain = Jid.of(mAccount.getJid()).getDomain(); + String user = Jid.ofEscaped(mAccount.getJid()).getLocal(); + String domain = Jid.ofEscaped(mAccount.getJid()).getDomain(); String inviteURL = AdHocInviteUri(mAccount); if (inviteURL == null) { inviteURL = Config.inviteUserURL + user + "/" + domain; diff --git a/src/main/java/de/pixart/messenger/ui/util/ShareUtil.java b/src/main/java/de/pixart/messenger/ui/util/ShareUtil.java index 0b491e8ab..71cc5614a 100644 --- a/src/main/java/de/pixart/messenger/ui/util/ShareUtil.java +++ b/src/main/java/de/pixart/messenger/ui/util/ShareUtil.java @@ -47,17 +47,18 @@ import rocks.xmpp.addr.Jid; public class ShareUtil { - public static void share(XmppActivity activity, Message message) { + public static void share(XmppActivity activity, Message message, String user) { Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); if (message.isGeoUri()) { shareIntent.putExtra(Intent.EXTRA_TEXT, message.getBody()); shareIntent.setType("text/plain"); - shareIntent.putExtra(ConversationsActivity.EXTRA_AS_QUOTE, true); + shareIntent.putExtra(ConversationsActivity.EXTRA_AS_QUOTE, false); } else if (!message.isFileOrImage()) { shareIntent.putExtra(Intent.EXTRA_TEXT, message.getMergedBody().toString()); shareIntent.setType("text/plain"); shareIntent.putExtra(ConversationsActivity.EXTRA_AS_QUOTE, true); + shareIntent.putExtra(ConversationsActivity.EXTRA_USER, user); } else { final DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message); try { |