diff options
author | Christian Schneppe <christian.schneppe@pix-art.de> | 2019-11-15 17:12:17 +0100 |
---|---|---|
committer | Christian Schneppe <christian.schneppe@pix-art.de> | 2019-11-15 17:14:11 +0100 |
commit | 5c26aec10d45c878c31e0ac80982b08d0fe4b69f (patch) | |
tree | 9345d6947e33d4dc192d705ffbef1c811160061d /src/main/java | |
parent | 345e2b7da1f1bc39a2e6d2274813adc7b6a410c0 (diff) |
make private messages in MUCs more visible
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/ConversationFragment.java | 27 | ||||
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java | 29 |
2 files changed, 39 insertions, 17 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index fdeb4a56f..37b283ecd 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -14,6 +14,7 @@ import android.content.Intent; import android.content.IntentSender.SendIntentException; import android.content.SharedPreferences; import android.content.pm.PackageManager; +import android.graphics.Typeface; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -22,7 +23,10 @@ import android.os.SystemClock; import android.preference.PreferenceManager; import android.provider.MediaStore; import android.text.Editable; +import android.text.Spannable; +import android.text.SpannableStringBuilder; import android.text.TextUtils; +import android.text.style.StyleSpan; import android.util.Log; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; @@ -927,12 +931,12 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke this.binding.textInputHint.setVisibility(View.VISIBLE); this.binding.textInputHint.setText(R.string.send_corrected_message); this.binding.textinput.setHint(R.string.send_corrected_message); - } else if (multi && conversation.getNextCounterpart() != null) { + } else if (isPrivateMessage()) { this.binding.textinput.setHint(R.string.send_unencrypted_message); this.binding.textInputHint.setVisibility(View.VISIBLE); - this.binding.textInputHint.setText(getString( - R.string.send_private_message_to, - conversation.getNextCounterpart().getResource())); + SpannableStringBuilder hint = new SpannableStringBuilder(getString(R.string.send_private_message_to, conversation.getNextCounterpart().getResource())); + hint.setSpan(new StyleSpan(Typeface.BOLD), 0, hint.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + this.binding.textInputHint.setText(hint); } else if (multi && !conversation.getMucOptions().participating()) { this.binding.textInputHint.setVisibility(View.VISIBLE); this.binding.textInputHint.setText(R.string.ask_for_writeaccess); @@ -944,6 +948,10 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } } + private boolean isPrivateMessage() { + return conversation != null && conversation.getMode() == Conversation.MODE_MULTI && conversation.getNextCounterpart() != null; + } + public void setupIme() { this.binding.textinput.refreshIme(); } @@ -1156,7 +1164,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke binding.textinput.addTextChangedListener(new StylingHelper.MessageEditorStyler(binding.textinput)); binding.textinput.setOnEditorActionListener(mEditorActionListener); binding.textinput.setRichContentListener(new String[]{"image/*"}, mEditorContentListener); - binding.messageInputBox.setBackgroundResource(messageInputBubble()); + binding.messageInputBox.setBackgroundResource(messageInputBubble(false)); binding.textSendButton.setOnClickListener(this.mSendButtonListener); binding.textSendButton.setOnLongClickListener(this.mSendButtonLongListener); @@ -1172,13 +1180,11 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke messageListAdapter.setOnContactPictureLongClicked(this); messageListAdapter.setOnQuoteListener(text -> quoteText(text, getUsername(selectedMessage))); binding.messagesView.setAdapter(messageListAdapter); - registerForContextMenu(binding.messagesView); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { this.binding.textinput.setCustomInsertionActionModeCallback(new EditMessageActionModeCallback(this.binding.textinput)); } - + return binding.getRoot(); } @@ -2632,6 +2638,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke public void updateSendButton() { updateChatMsgHint(); + binding.messageInputBox.setBackgroundResource(messageInputBubble(isPrivateMessage())); boolean hasAttachments = mediaPreviewAdapter != null && mediaPreviewAdapter.hasAttachments(); boolean useSendButtonToIndicateStatus = activity != null && PreferenceManager.getDefaultSharedPreferences(activity).getBoolean("send_button_status", getResources().getBoolean(R.bool.send_button_status)); final Conversation c = this.conversation; @@ -3087,8 +3094,8 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } } - private int messageInputBubble() { - return activity.isDarkTheme() ? R.drawable.message_bubble_sent_dark : R.drawable.message_bubble_sent; + private int messageInputBubble(final boolean isPrivate) { + return isPrivate ? activity.isDarkTheme() ? R.drawable.message_bubble_sent_dark_private : R.drawable.message_bubble_sent_private : activity.isDarkTheme() ? R.drawable.message_bubble_sent_dark : R.drawable.message_bubble_sent; } public Conversation getConversation() { 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 dffbd6a6f..9d9c68b19 100644 --- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java +++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java @@ -198,6 +198,10 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie } } + private int getMessageTextColorPrivate() { + return ContextCompat.getColor(activity, R.color.accent); + } + private int getWarningTextColor(boolean onDark) { if (onDark) { return ContextCompat.getColor(activity, R.color.white70); @@ -574,12 +578,11 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie int privateMarkerIndex = privateMarker.length(); if (startsWithQuote) { body.insert(privateMarkerIndex, "\n\n"); - body.setSpan(new DividerSpan(false), privateMarkerIndex, privateMarkerIndex + 2, - Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + body.setSpan(new DividerSpan(false), privateMarkerIndex, privateMarkerIndex + 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } else { body.insert(privateMarkerIndex, " "); } - body.setSpan(new ForegroundColorSpan(getMessageTextColor(darkBackground, false)), 0, privateMarkerIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + body.setSpan(new ForegroundColorSpan(getMessageTextColorPrivate()), 0, privateMarkerIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); body.setSpan(new StyleSpan(Typeface.BOLD), 0, privateMarkerIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); if (hasMeCommand) { body.setSpan(new StyleSpan(Typeface.BOLD_ITALIC), privateMarkerIndex + 1, privateMarkerIndex + 1 + nick.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); @@ -879,7 +882,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie body.append("\n"); body.append(messageBody); } - body.setSpan(new ForegroundColorSpan(getMessageTextColor(darkBackground, false)), 0, privateMarker.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + body.setSpan(new ForegroundColorSpan(getMessageTextColorPrivate()), 0, privateMarker.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); body.setSpan(new StyleSpan(Typeface.BOLD), 0, privateMarker.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); MyLinkify.addLinks(body, false); viewHolder.messageBody.setAutoLinkMask(0); @@ -1132,11 +1135,19 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie if (type == RECEIVED) { if (isInValidSession) { - viewHolder.message_box.setBackgroundResource(darkBackground ? R.drawable.message_bubble_received_light_dark : R.drawable.message_bubble_received_light); + if (message.isPrivateMessage()) { + viewHolder.message_box.setBackgroundResource(darkBackground ? R.drawable.message_bubble_received_light_dark_private : R.drawable.message_bubble_received_light_private); + } else { + viewHolder.message_box.setBackgroundResource(darkBackground ? R.drawable.message_bubble_received_light_dark : R.drawable.message_bubble_received_light); + } viewHolder.encryption.setVisibility(View.GONE); viewHolder.encryption.setTextColor(this.getMessageTextColor(darkBackground, false)); } else { - viewHolder.message_box.setBackgroundResource(darkBackground ? R.drawable.message_bubble_received_warning_dark : R.drawable.message_bubble_received_warning); + if (message.isPrivateMessage()) { + viewHolder.message_box.setBackgroundResource(darkBackground ? R.drawable.message_bubble_received_warning_dark : R.drawable.message_bubble_received_warning); + } else { + viewHolder.message_box.setBackgroundResource(darkBackground ? R.drawable.message_bubble_received_warning_dark : R.drawable.message_bubble_received_warning); + } viewHolder.encryption.setVisibility(View.VISIBLE); viewHolder.encryption.setTextColor(this.getWarningTextColor(darkBackground)); if (omemoEncryption && !message.isTrusted()) { @@ -1148,7 +1159,11 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie } if (type == SENT) { - viewHolder.message_box.setBackgroundResource(activity.isDarkTheme() ? R.drawable.message_bubble_sent_dark : R.drawable.message_bubble_sent); + if (message.isPrivateMessage()) { + viewHolder.message_box.setBackgroundResource(activity.isDarkTheme() ? R.drawable.message_bubble_sent_dark_private : R.drawable.message_bubble_sent_private); + } else { + viewHolder.message_box.setBackgroundResource(activity.isDarkTheme() ? R.drawable.message_bubble_sent_dark : R.drawable.message_bubble_sent); + } } displayStatus(viewHolder, message, type, darkBackground); return view; |