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 | |
parent | 345e2b7da1f1bc39a2e6d2274813adc7b6a410c0 (diff) |
make private messages in MUCs more visible
9 files changed, 132 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; diff --git a/src/main/res/drawable/message_bubble_received_light_dark_private.xml b/src/main/res/drawable/message_bubble_received_light_dark_private.xml new file mode 100644 index 000000000..28bdb9b15 --- /dev/null +++ b/src/main/res/drawable/message_bubble_received_light_dark_private.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="utf-8"?> +<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> + <stroke android:width="2dp" android:color="@color/accent"/> + <corners + android:topLeftRadius="0dp" + android:topRightRadius="5dp" + android:bottomRightRadius="5dp" + android:bottomLeftRadius="5dp" /> + <padding + android:bottom="2dp" + android:left="6dp" + android:right="6dp" + android:top="2dp" /> + <solid android:color="@color/darkwhite" /> +</shape>
\ No newline at end of file diff --git a/src/main/res/drawable/message_bubble_received_light_private.xml b/src/main/res/drawable/message_bubble_received_light_private.xml new file mode 100644 index 000000000..6752d9393 --- /dev/null +++ b/src/main/res/drawable/message_bubble_received_light_private.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="utf-8"?> +<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> + <stroke android:width="2dp" android:color="@color/accent"/> + <corners + android:topLeftRadius="0dp" + android:topRightRadius="5dp" + android:bottomRightRadius="5dp" + android:bottomLeftRadius="5dp" /> + <padding + android:bottom="2dp" + android:left="6dp" + android:right="6dp" + android:top="2dp" /> + <solid android:color="@color/lightwhite" /> +</shape>
\ No newline at end of file diff --git a/src/main/res/drawable/message_bubble_received_warning_dark_private.xml b/src/main/res/drawable/message_bubble_received_warning_dark_private.xml new file mode 100644 index 000000000..758d6d2e8 --- /dev/null +++ b/src/main/res/drawable/message_bubble_received_warning_dark_private.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="utf-8"?> +<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> + <stroke android:width="2dp" android:color="@color/accent"/> + <corners + android:topLeftRadius="0dp" + android:topRightRadius="5dp" + android:bottomRightRadius="5dp" + android:bottomLeftRadius="5dp" /> + <padding + android:bottom="4dp" + android:left="6dp" + android:right="6dp" + android:top="4dp" /> + <solid android:color="@color/darkred" /> +</shape>
\ No newline at end of file diff --git a/src/main/res/drawable/message_bubble_received_warning_private.xml b/src/main/res/drawable/message_bubble_received_warning_private.xml new file mode 100644 index 000000000..6aef6105e --- /dev/null +++ b/src/main/res/drawable/message_bubble_received_warning_private.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="utf-8"?> +<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> + <stroke android:width="2dp" android:color="@color/accent"/> + <corners + android:topLeftRadius="0dp" + android:topRightRadius="5dp" + android:bottomRightRadius="5dp" + android:bottomLeftRadius="5dp" /> + <padding + android:bottom="4dp" + android:left="6dp" + android:right="6dp" + android:top="4dp" /> + <solid android:color="@color/lightred" /> +</shape>
\ No newline at end of file diff --git a/src/main/res/drawable/message_bubble_sent_dark_private.xml b/src/main/res/drawable/message_bubble_sent_dark_private.xml new file mode 100644 index 000000000..e37c43ad3 --- /dev/null +++ b/src/main/res/drawable/message_bubble_sent_dark_private.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="utf-8"?> +<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> + <stroke android:width="2dp" android:color="@color/accent"/> + <corners + android:topLeftRadius="5dp" + android:topRightRadius="5dp" + android:bottomRightRadius="0dp" + android:bottomLeftRadius="5dp" /> + <padding + android:bottom="4dp" + android:left="6dp" + android:right="6dp" + android:top="4dp" /> + <solid android:color="@color/darkblue" /> +</shape>
\ No newline at end of file diff --git a/src/main/res/drawable/message_bubble_sent_private.xml b/src/main/res/drawable/message_bubble_sent_private.xml new file mode 100644 index 000000000..e83ded310 --- /dev/null +++ b/src/main/res/drawable/message_bubble_sent_private.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="utf-8"?> +<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> + <stroke android:width="2dp" android:color="@color/accent"/> + <corners + android:topLeftRadius="5dp" + android:topRightRadius="5dp" + android:bottomRightRadius="0dp" + android:bottomLeftRadius="5dp" /> + <padding + android:bottom="4dp" + android:left="6dp" + android:right="6dp" + android:top="4dp" /> + <solid android:color="@color/lightblue" /> +</shape>
\ No newline at end of file diff --git a/src/main/res/values/themes.xml b/src/main/res/values/themes.xml index 1672e1576..cebd97038 100644 --- a/src/main/res/values/themes.xml +++ b/src/main/res/values/themes.xml @@ -194,6 +194,9 @@ <item name="windowActionModeOverlay">true</item> <item name="android:actionModeBackground">@color/accent</item> + <item name="android:homeAsUpIndicator" type="reference">@drawable/ic_arrow_back_white_24dp + </item> + <item name="TextSizeCaption">12sp</item> <item name="TextSizeBody1">14sp</item> <item name="TextSizeBody2">14sp</item> |