diff options
Diffstat (limited to 'src/main/java/de/pixart/messenger/ui')
5 files changed, 84 insertions, 20 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index 371bdb5e5..4207a1b5e 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -960,7 +960,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke message.setEdited(message.getUuid()); message.setUuid(UUID.randomUUID().toString()); } - switch (message.getConversation().getNextEncryption()) { + switch (conversation.getNextEncryption()) { case Message.ENCRYPTION_OTR: sendOtrMessage(message); break; @@ -1204,11 +1204,11 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke messageListAdapter.setOnContactPictureClicked(message -> { final boolean received = message.getStatus() <= Message.STATUS_RECEIVED; if (received) { - if (message.getConversation().getMode() == Conversation.MODE_MULTI) { + if (message.getConversation() instanceof Conversation && message.getConversation().getMode() == Conversation.MODE_MULTI) { Jid user = message.getCounterpart(); if (user != null && !user.isBareJid()) { - final MucOptions mucOptions = message.getConversation().getMucOptions(); - if (mucOptions.participating() || message.getConversation().getNextCounterpart() != null) { + final MucOptions mucOptions = ((Conversation) message.getConversation()).getMucOptions(); + if (mucOptions.participating() || ((Conversation) message.getConversation()).getNextCounterpart() != null) { if (!mucOptions.isUserInRoom(user)) { Toast.makeText(getActivity(), activity.getString(R.string.user_has_left_conference, user.getResource()), Toast.LENGTH_SHORT).show(); } @@ -1350,7 +1350,8 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } if (relevantForCorrection.getType() == Message.TYPE_TEXT && relevantForCorrection.isLastCorrectableMessage() - && (m.getConversation().getMucOptions().nonanonymous() || m.getConversation().getMode() == Conversation.MODE_SINGLE)) { + && m.getConversation() instanceof Conversation + && (((Conversation) m.getConversation()).getMucOptions().nonanonymous() || m.getConversation().getMode() == Conversation.MODE_SINGLE)) { correctMessage.setVisible(true); } if ((m.isFileOrImage() && !deleted && !receiving) || (m.getType() == Message.TYPE_TEXT && !m.treatAsDownloadable())) { @@ -1898,9 +1899,12 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke public void resendMessage(final Message message) { if (message != null && message.isFileOrImage()) { + if (!(message.getConversation() instanceof Conversation)) { + return; + } + final Conversation conversation = (Conversation) message.getConversation(); DownloadableFile file = activity.xmppConnectionService.getFileBackend().getFile(message); if (file.exists()) { - final Conversation conversation = message.getConversation(); final XmppConnection xmppConnection = conversation.getAccount().getXmppConnection(); if (!message.hasFileOnRemoteHost() && xmppConnection != null @@ -2797,7 +2801,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke protected void sendOtrMessage(final Message message) { final ConversationsActivity activity = (ConversationsActivity) getActivity(); final XmppConnectionService xmppService = activity.xmppConnectionService; - activity.selectPresence(message.getConversation(), + activity.selectPresence(conversation, () -> { message.setCounterpart(conversation.getNextCounterpart()); xmppService.sendMessage(message); diff --git a/src/main/java/de/pixart/messenger/ui/SearchActivity.java b/src/main/java/de/pixart/messenger/ui/SearchActivity.java index e65b2dd6c..2120cac3e 100644 --- a/src/main/java/de/pixart/messenger/ui/SearchActivity.java +++ b/src/main/java/de/pixart/messenger/ui/SearchActivity.java @@ -34,7 +34,6 @@ import android.os.Bundle; import android.support.v7.widget.Toolbar; import android.text.Editable; import android.text.TextWatcher; -import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.widget.EditText; @@ -42,18 +41,18 @@ import android.widget.EditText; import java.util.ArrayList; import java.util.List; -import de.pixart.messenger.Config; import de.pixart.messenger.R; import de.pixart.messenger.databinding.ActivitySearchBinding; import de.pixart.messenger.entities.Message; import de.pixart.messenger.ui.adapter.MessageAdapter; +import de.pixart.messenger.ui.interfaces.OnSearchResultsAvailable; import de.pixart.messenger.ui.util.Color; import de.pixart.messenger.ui.util.Drawable; import static de.pixart.messenger.ui.util.SoftKeyboardUtils.hideSoftKeyboard; import static de.pixart.messenger.ui.util.SoftKeyboardUtils.showKeyboard; -public class SearchActivity extends XmppActivity implements TextWatcher { +public class SearchActivity extends XmppActivity implements TextWatcher, OnSearchResultsAvailable { private final List<Message> messages = new ArrayList<>(); private ActivitySearchBinding binding; @@ -122,7 +121,24 @@ public class SearchActivity extends XmppActivity implements TextWatcher { @Override public void afterTextChanged(Editable s) { - Log.d(Config.LOGTAG, "searching for " + s); + String term = s.toString().trim(); + if (term.length() > 0) { + xmppConnectionService.search(s.toString().trim(), this); + } else { + this.messages.clear(); + messageListAdapter.notifyDataSetChanged(); + changeBackground(false, false); + } + } + + @Override + public void onSearchResultsAvailable(String term, List<Message> messages) { + this.messages.clear(); + this.messages.addAll(messages); + runOnUiThread(() -> { + messageListAdapter.notifyDataSetChanged(); + changeBackground(true, messages.size() > 0); + }); } }
\ No newline at end of file diff --git a/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java b/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java index f27b8b7aa..22cd2a677 100644 --- a/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java @@ -90,11 +90,12 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer } else { resId = R.string.shared_file_with_x; } - replaceToast(getString(resId, message.getConversation().getName())); + Conversation conversation = (Conversation) message.getConversation(); + replaceToast(getString(resId, conversation.getName())); if (mReturnToPrevious) { finish(); } else { - switchToConversation(message.getConversation()); + switchToConversation(conversation); } } }); diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java index 7a1809a98..1b0553bed 100644 --- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java +++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java @@ -63,6 +63,7 @@ import de.pixart.messenger.R; import de.pixart.messenger.crypto.axolotl.FingerprintStatus; import de.pixart.messenger.entities.Account; import de.pixart.messenger.entities.Conversation; +import de.pixart.messenger.entities.Conversational; import de.pixart.messenger.entities.DownloadableFile; import de.pixart.messenger.entities.Message; import de.pixart.messenger.entities.Message.FileParams; @@ -594,10 +595,13 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie } } if (message.getConversation().getMode() == Conversation.MODE_MULTI && message.getStatus() == Message.STATUS_RECEIVED) { - Pattern pattern = NotificationService.generateNickHighlightPattern(message.getConversation().getMucOptions().getActualNick()); - Matcher matcher = pattern.matcher(body); - while (matcher.find()) { - body.setSpan(new StyleSpan(Typeface.BOLD), matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + if (message.getConversation() instanceof Conversation) { + final Conversation conversation = (Conversation) message.getConversation(); + Pattern pattern = NotificationService.generateNickHighlightPattern(conversation.getMucOptions().getActualNick()); + Matcher matcher = pattern.matcher(body); + while (matcher.find()) { + body.setSpan(new StyleSpan(Typeface.BOLD), matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + } } } Matcher matcher = Emoticons.generatePattern(body).matcher(body); @@ -798,7 +802,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie final Message message = getItem(position); final boolean omemoEncryption = message.getEncryption() == Message.ENCRYPTION_AXOLOTL; final boolean isInValidSession = message.isValidInSession() && (!omemoEncryption || message.isTrusted()); - final Conversation conversation = message.getConversation(); + final Conversational conversation = message.getConversation(); final Account account = conversation.getAccount(); final int type = getItemViewType(position); ViewHolder viewHolder; @@ -875,7 +879,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie viewHolder.status_message.setVisibility(View.GONE); viewHolder.contact_picture.setVisibility(View.GONE); viewHolder.load_more_messages.setVisibility(View.VISIBLE); - viewHolder.load_more_messages.setOnClickListener(v -> loadMoreMessages(message.getConversation())); + viewHolder.load_more_messages.setOnClickListener(v -> loadMoreMessages((Conversation) message.getConversation())); } else { viewHolder.status_message.setVisibility(View.VISIBLE); viewHolder.load_more_messages.setVisibility(View.GONE); @@ -943,7 +947,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie } } else if (message.getEncryption() == Message.ENCRYPTION_PGP) { if (account.isPgpDecryptionServiceConnected()) { - if (!account.hasPendingPgpIntent(conversation)) { + if (conversation instanceof Conversation && !account.hasPendingPgpIntent((Conversation) conversation)) { displayInfoMessage(viewHolder, activity.getString(R.string.message_decrypting), darkBackground); } else { displayInfoMessage(viewHolder, activity.getString(R.string.pgp_message), darkBackground); diff --git a/src/main/java/de/pixart/messenger/ui/interfaces/OnSearchResultsAvailable.java b/src/main/java/de/pixart/messenger/ui/interfaces/OnSearchResultsAvailable.java new file mode 100644 index 000000000..57f2a40cc --- /dev/null +++ b/src/main/java/de/pixart/messenger/ui/interfaces/OnSearchResultsAvailable.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2018, Daniel Gultsch All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package de.pixart.messenger.ui.interfaces; + +import java.util.List; + +import de.pixart.messenger.entities.Message; + +public interface OnSearchResultsAvailable { + + void onSearchResultsAvailable(String term, List<Message> messages); + +}
\ No newline at end of file |