aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-02-04 21:24:43 +0100
committerChristian Schneppe <christian@pix-art.de>2018-02-04 21:24:43 +0100
commit513bc9a3a07e88c0b461dbd58e6480ae1dbe50ec (patch)
tree7b94c38e1d56ff2eabcdafb38a61bdf336ad66e1 /src/main/java
parentbc4d112060cbe822bef0dda8d5104db725deeb1b (diff)
highlight searchword in messages
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/de/pixart/messenger/ui/ConversationFragment.java3
-rw-r--r--src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java14
2 files changed, 16 insertions, 1 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
index b97dda837..0ceb93598 100644
--- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
+++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java
@@ -103,7 +103,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
private TextView messagehint_message;
private RelativeLayout textsend;
private RelativeLayout searchfield;
- private EditText searchfield_input;
+ public EditText searchfield_input;
private ImageButton searchUp;
private ImageButton searchDown;
private TextView snackbarMessage;
@@ -1616,6 +1616,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
+ activity.refreshUi();
}
};
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 b005bf9e2..561bc8013 100644
--- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
+++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
@@ -19,6 +19,7 @@ import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.format.DateUtils;
+import android.text.style.BackgroundColorSpan;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
@@ -491,6 +492,19 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
final String nick = UIHelper.getMessageDisplayName(message);
SpannableStringBuilder body = message.getMergedBody();
boolean hasMeCommand = message.hasMeCommand();
+ String searchQuery = activity.mConversationFragment.searchfield_input.getText().toString().toLowerCase().trim();
+ if (((!searchQuery.isEmpty() || !searchQuery.contains("")) && searchQuery.length() >= 3) && body.toString().toLowerCase().contains(searchQuery)) {
+ int ofe = body.toString().toLowerCase().indexOf(searchQuery, 0);
+ for (int ofs = 0; ofs < body.length() && ofe != -1; ofs = ofe + 1) {
+ ofe = body.toString().toLowerCase().indexOf(searchQuery, ofs);
+ if (ofe == -1) {
+ break;
+ } else {
+ body.setSpan(new StyleSpan(Typeface.BOLD), ofe, ofe + searchQuery.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ body.setSpan(new BackgroundColorSpan(0xFFFFFF00), ofe, ofe + searchQuery.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ }
+ }
+ }
if (hasMeCommand) {
body = body.replace(0, Message.ME_COMMAND.length(), nick);
}