diff options
Diffstat (limited to 'src/main/java/de/pixart/messenger/ui/ConversationFragment.java')
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/ConversationFragment.java | 148 |
1 files changed, 72 insertions, 76 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index a0f4bf894..f1df07e0b 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -32,6 +32,7 @@ import android.support.v7.view.menu.MenuBuilder; import android.support.v7.view.menu.MenuPopupHelper; import android.support.v7.widget.PopupMenu; import android.text.Editable; +import android.text.TextUtils; import android.util.Log; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; @@ -117,7 +118,6 @@ import de.pixart.messenger.utils.UIHelper; import de.pixart.messenger.xmpp.XmppConnection; import de.pixart.messenger.xmpp.chatstate.ChatState; import de.pixart.messenger.xmpp.jingle.JingleConnection; -import in.championswimmer.sfg.lib.SimpleFingerGestures; import rocks.xmpp.addr.Jid; import static de.pixart.messenger.ui.XmppActivity.EXTRA_ACCOUNT; @@ -180,7 +180,6 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke }; private boolean reInitRequiredOnStart = true; private MediaPreviewAdapter mediaPreviewAdapter; - private SimpleFingerGestures gesturesDetector = new SimpleFingerGestures(); private OnClickListener clickToMuc = new OnClickListener() { @Override @@ -625,7 +624,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke final boolean hideVoice = p.getBoolean("show_record_voice_btn", activity.getResources().getBoolean(R.bool.show_record_voice_btn)); PopupMenu popup = new PopupMenu(activity, v); popup.inflate(R.menu.choose_attachment); - Menu menu = popup.getMenu(); + final Menu menu = popup.getMenu(); ConversationMenuConfigurator.configureQuickShareAttachmentMenu(conversation, menu, hideVoice); popup.setOnMenuItemClickListener(attachmentItem -> { switch (attachmentItem.getItemId()) { @@ -658,7 +657,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke hideUnreadMessagesCount(); } else { binding.scrollToBottomButton.setEnabled(true); - binding.scrollToBottomButton.setVisibility(View.VISIBLE); + binding.scrollToBottomButton.show(); if (lastMessageUuid == null) { lastMessageUuid = conversation.getLatestMessage().getUuid(); } @@ -887,11 +886,15 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke commitAttachments(); return; } - final String body = binding.textinput.getText().toString(); + final Editable text = this.binding.textinput.getText(); + final String body = text == null ? "" : text.toString(); final Conversation conversation = this.conversation; if (body.length() == 0 || conversation == null) { return; } + if (conversation.getNextEncryption() == Message.ENCRYPTION_AXOLOTL && trustKeysIfNeeded(REQUEST_TRUST_KEYS_TEXT)) { + return; + } final Message message; if (conversation.getCorrectingMessage() == null) { message = new Message(conversation, body, conversation.getNextEncryption()); @@ -916,11 +919,6 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke case Message.ENCRYPTION_PGP: sendPgpMessage(message); break; - case Message.ENCRYPTION_AXOLOTL: - if (!trustKeysIfNeeded(REQUEST_TRUST_KEYS_TEXT)) { - sendMessage(message); - } - break; default: sendMessage(message); } @@ -989,9 +987,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke private void handlePositiveActivityResult(int requestCode, final Intent data) { switch (requestCode) { case REQUEST_TRUST_KEYS_TEXT: - final String body = binding.textinput.getText().toString(); - Message message = new Message(conversation, body, conversation.getNextEncryption()); - sendMessage(message); + sendMessage(); break; case REQUEST_TRUST_KEYS_ATTACHMENTS: commitAttachments(); @@ -1139,13 +1135,21 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke if (conversation.getMode() == Conversation.MODE_MULTI) { menuInviteContact.setVisible(true); menuArchiveChat.setTitle(R.string.action_end_conversation_muc); - menuGroupDetails.setVisible(true); - menuContactDetails.setVisible(false); } else { menuInviteContact.setVisible(false); menuArchiveChat.setTitle(R.string.action_end_conversation); + } + if (getFragmentManager().findFragmentById(R.id.secondary_fragment) != null) { + if (conversation.getMode() == Conversation.MODE_MULTI) { + menuGroupDetails.setVisible(true); + menuContactDetails.setVisible(false); + } else { + menuGroupDetails.setVisible(false); + menuContactDetails.setVisible(true); + } + } else { menuGroupDetails.setVisible(false); - menuContactDetails.setVisible(true); + menuContactDetails.setVisible(false); } menuNeedHelp.setVisible(true); menuSearchUpdates.setVisible(false); @@ -1360,20 +1364,21 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke || m.isGeoUri() || m.isXmppUri() || m.treatAsDownloadable() - || (t != null && t instanceof HttpDownloadConnection)) { + || t instanceof HttpDownloadConnection) { copyUrl.setVisible(true); } if (m.isFileOrImage() && deleted && m.hasFileOnRemoteHost()) { downloadFile.setVisible(true); downloadFile.setTitle(activity.getString(R.string.download_x_file, UIHelper.getFileDescriptionString(activity, m))); } - boolean waitingOfferedSending = m.getStatus() == Message.STATUS_WAITING + final boolean waitingOfferedSending = m.getStatus() == Message.STATUS_WAITING || m.getStatus() == Message.STATUS_UNSEND || m.getStatus() == Message.STATUS_OFFERED; - if ((t != null && !deleted) || waitingOfferedSending && m.needsUploading()) { + final boolean cancelable = (t != null && !deleted) || waitingOfferedSending && m.needsUploading(); + if (cancelable) { cancelTransmission.setVisible(true); } - if (m.isFileOrImage() && !deleted) { + if (m.isFileOrImage() && !deleted && !cancelable) { String path = m.getRelativeFilePath(); Log.d(Config.LOGTAG, "Path = " + path); if (path == null || !path.startsWith("/") || path.contains(FileBackend.getConversationsDirectory("null"))) { @@ -1381,7 +1386,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke deleteFile.setTitle(activity.getString(R.string.delete_x_file, UIHelper.getFileDescriptionString(activity, m))); } } - if (m.getStatus() == Message.STATUS_SEND_FAILED && m.getErrorMessage() != null) { + if (m.getStatus() == Message.STATUS_SEND_FAILED && m.getErrorMessage() != null && !Message.ERROR_MESSAGE_CANCELLED.equals(m.getErrorMessage())) { showErrorMessage.setVisible(true); } } @@ -1716,7 +1721,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } builder.setView(dialogView); builder.setNegativeButton(getString(R.string.cancel), null); - builder.setPositiveButton(getString(R.string.delete_messages), (dialog, which) -> { + builder.setPositiveButton(getString(R.string.confirm), (dialog, which) -> { this.activity.xmppConnectionService.clearConversationHistory(conversation); if (endConversationCheckBox.isChecked()) { this.activity.xmppConnectionService.archiveConversation(conversation); @@ -1879,12 +1884,19 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke refresh(); } - private void deleteFile(Message message) { - if (activity.xmppConnectionService.getFileBackend().deleteFile(message)) { - message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED)); - activity.onConversationsListItemUpdated(); - refresh(); - } + private void deleteFile(final Message message) { + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setNegativeButton(R.string.cancel, null); + builder.setTitle(R.string.delete_file_dialog); + builder.setMessage(R.string.delete_file_dialog_msg); + builder.setPositiveButton(R.string.confirm, (dialog, which) -> { + if (activity.xmppConnectionService.getFileBackend().deleteFile(message)) { + message.setTransferable(new TransferablePlaceholder(Transferable.STATUS_DELETED)); + activity.onConversationsListItemUpdated(); + refresh(); + } + }); + builder.create().show(); } public void resendMessage(final Message message) { @@ -1951,7 +1963,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke if (transferable != null) { transferable.cancel(); } else if (message.getStatus() != Message.STATUS_RECEIVED) { - activity.xmppConnectionService.markMessage(message, Message.STATUS_SEND_FAILED); + activity.xmppConnectionService.markMessage(message, Message.STATUS_SEND_FAILED, Message.ERROR_MESSAGE_CANCELLED); } } @@ -2207,48 +2219,6 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke this.binding.messagesView.post(this::fireReadEvent); //TODO if we only do this when this fragment is running on main it won't *bing* in tablet layout which might be unnecessary since we can *see* it activity.xmppConnectionService.getNotificationService().setOpenConversation(this.conversation); - - // todo temporarly disable swipe gestures - /* - gesturesDetector.setOnFingerGestureListener(new SimpleFingerGestures.OnFingerGestureListener() { - @Override - public boolean onSwipeUp(int fingers, long gestureDuration, double gestureDistance) { - return false; - } - - @Override - public boolean onSwipeDown(int fingers, long gestureDuration, double gestureDistance) { - return false; - } - - @Override - public boolean onSwipeLeft(int fingers, long gestureDuration, double gestureDistance) { - return false; - } - - @Override - public boolean onSwipeRight(int fingers, long gestureDuration, double gestureDistance) { - activity.onBackPressed(); - return false; - } - - @Override - public boolean onPinch(int fingers, long gestureDuration, double gestureDistance) { - return false; - } - - @Override - public boolean onUnpinch(int fingers, long gestureDuration, double gestureDistance) { - return false; - } - - @Override - public boolean onDoubleTap(int fingers) { - return false; - } - }); - this.binding.messagesView.setOnTouchListener(gesturesDetector); - */ return true; } @@ -2262,7 +2232,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke return; } this.binding.scrollToBottomButton.setEnabled(false); - this.binding.scrollToBottomButton.setVisibility(View.GONE); + this.binding.scrollToBottomButton.hide(); this.binding.unreadCountCustomView.setVisibility(View.GONE); } @@ -2282,9 +2252,11 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke final String nick = extras.getString(ConversationsActivity.EXTRA_NICK); final boolean asQuote = extras.getBoolean(ConversationsActivity.EXTRA_AS_QUOTE); 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); if (uris != null && uris.size() > 0) { - mediaPreviewAdapter.addMediaPreviews(Attachment.of(getActivity(), uris)); + final List<Uri> cleanedUris = cleanUris(new ArrayList<>(uris)); + mediaPreviewAdapter.addMediaPreviews(Attachment.of(getActivity(), cleanedUris)); toggleInputMethod(); return; } @@ -2307,7 +2279,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke if (text != null && asQuote) { quoteText(text); } else { - appendText(text); + appendText(text, doNotAppend); } } final Message message = downloadUuid == null ? null : conversation.findMessageWithFileAndUuid(downloadUuid); @@ -2329,6 +2301,18 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } } + private List<Uri> cleanUris(List<Uri> uris) { + Iterator<Uri> iterator = uris.iterator(); + while (iterator.hasNext()) { + final Uri uri = iterator.next(); + if (FileBackend.weOwnFile(getActivity(), uri)) { + iterator.remove(); + Toast.makeText(getActivity(), R.string.security_violation_not_attaching_file, Toast.LENGTH_SHORT).show(); + } + } + return uris; + } + private boolean showBlockSubmenu(View view) { final Jid jid = conversation.getJid(); if (jid.getLocal() == null) { @@ -2386,6 +2370,13 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke showSnackbar(R.string.remote_server_not_found, R.string.leave, leaveMuc); } break; + case REMOTE_SERVER_TIMEOUT: + if (conversation.receivedMessagesCount() > 0) { + showSnackbar(R.string.remote_server_timeout, R.string.try_again, joinMuc); + } else { + showSnackbar(R.string.remote_server_timeout, R.string.leave, leaveMuc); + } + break; case PASSWORD_REQUIRED: showSnackbar(R.string.conference_requires_password, R.string.enter_password, enterPassword); break; @@ -2832,11 +2823,16 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke }); } - public void appendText(String text) { + public void appendText(String text, final boolean doNotAppend) { if (text == null) { return; } - String previous = this.binding.textinput.getText().toString(); + final Editable editable = this.binding.textinput.getText(); + String previous = editable == null ? "" : editable.toString(); + if (doNotAppend && !TextUtils.isEmpty(previous)) { + Toast.makeText(getActivity(), R.string.already_drafting_message, Toast.LENGTH_LONG).show(); + return; + } if (UIHelper.isLastLineQuote(previous)) { text = '\n' + text; } else if (previous.length() != 0 && !Character.isWhitespace(previous.charAt(previous.length() - 1))) { |