From 96bd39fe3aed56f87906f46fb4768e167ae1dd9f Mon Sep 17 00:00:00 2001 From: moezbhatti Date: Mon, 9 Sep 2019 00:11:06 -0400 Subject: [PATCH] #286 - Remove bubbles and enlarge emoji --- .../moez/QKSMS/common/util/TextViewStyler.kt | 10 +++++++ .../moez/QKSMS/feature/compose/BubbleUtils.kt | 3 +- .../QKSMS/feature/compose/MessagesAdapter.kt | 22 +++++++++++++-- .../QKSMS/feature/compose/part/VCardBinder.kt | 2 +- .../src/main/res/drawable/message_emoji.xml | 28 +++++++++++++++++++ .../main/res/drawable/message_in_first.xml | 5 ++++ .../src/main/res/drawable/message_in_last.xml | 5 ++++ .../main/res/drawable/message_in_middle.xml | 5 ++++ .../src/main/res/drawable/message_only.xml | 5 ++++ .../main/res/drawable/message_out_first.xml | 5 ++++ .../main/res/drawable/message_out_last.xml | 5 ++++ .../main/res/drawable/message_out_middle.xml | 5 ++++ .../main/res/layout/message_list_item_in.xml | 4 --- .../main/res/layout/message_list_item_out.xml | 4 --- presentation/src/main/res/values/attrs.xml | 1 + 15 files changed, 96 insertions(+), 13 deletions(-) create mode 100644 presentation/src/main/res/drawable/message_emoji.xml diff --git a/presentation/src/main/java/com/moez/QKSMS/common/util/TextViewStyler.kt b/presentation/src/main/java/com/moez/QKSMS/common/util/TextViewStyler.kt index cd701a30..e934d750 100644 --- a/presentation/src/main/java/com/moez/QKSMS/common/util/TextViewStyler.kt +++ b/presentation/src/main/java/com/moez/QKSMS/common/util/TextViewStyler.kt @@ -49,6 +49,7 @@ class TextViewStyler @Inject constructor( const val SIZE_TERTIARY = 2 const val SIZE_TOOLBAR = 3 const val SIZE_DIALOG = 4 + const val SIZE_EMOJI = 5 fun applyEditModeAttributes(textView: TextView, attrs: AttributeSet?) { textView.run { @@ -84,6 +85,7 @@ class TextViewStyler @Inject constructor( SIZE_TERTIARY -> 12f SIZE_TOOLBAR -> 20f SIZE_DIALOG -> 18f + SIZE_EMOJI -> 32f else -> textSize / paint.density } } @@ -177,6 +179,14 @@ class TextViewStyler @Inject constructor( Preferences.TEXT_SIZE_LARGER -> 24f else -> 18f } + + SIZE_EMOJI -> textView.textSize = when (textSizePref) { + Preferences.TEXT_SIZE_SMALL -> 28f + Preferences.TEXT_SIZE_NORMAL -> 32f + Preferences.TEXT_SIZE_LARGE -> 36f + Preferences.TEXT_SIZE_LARGER -> 40f + else -> 32f + } } } diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/compose/BubbleUtils.kt b/presentation/src/main/java/com/moez/QKSMS/feature/compose/BubbleUtils.kt index afcde924..cb7dad0e 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/compose/BubbleUtils.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/compose/BubbleUtils.kt @@ -32,8 +32,9 @@ object BubbleUtils { return message.compareSender(other) && diff < TIMESTAMP_THRESHOLD } - fun getBubble(canGroupWithPrevious: Boolean, canGroupWithNext: Boolean, isMe: Boolean): Int { + fun getBubble(emojiOnly: Boolean, canGroupWithPrevious: Boolean, canGroupWithNext: Boolean, isMe: Boolean): Int { return when { + emojiOnly -> R.drawable.message_emoji !canGroupWithPrevious && canGroupWithNext -> if (isMe) R.drawable.message_out_first else R.drawable.message_in_first canGroupWithPrevious && canGroupWithNext -> if (isMe) R.drawable.message_out_middle else R.drawable.message_in_middle canGroupWithPrevious && !canGroupWithNext -> if (isMe) R.drawable.message_out_last else R.drawable.message_in_last diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/compose/MessagesAdapter.kt b/presentation/src/main/java/com/moez/QKSMS/feature/compose/MessagesAdapter.kt index 7cc8f876..91ec5d94 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/compose/MessagesAdapter.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/compose/MessagesAdapter.kt @@ -40,6 +40,7 @@ import com.moez.QKSMS.common.base.QkRealmAdapter import com.moez.QKSMS.common.base.QkViewHolder import com.moez.QKSMS.common.util.Colors import com.moez.QKSMS.common.util.DateFormatter +import com.moez.QKSMS.common.util.TextViewStyler import com.moez.QKSMS.common.util.extensions.dpToPx import com.moez.QKSMS.common.util.extensions.forwardTouches import com.moez.QKSMS.common.util.extensions.setBackgroundTint @@ -71,12 +72,19 @@ class MessagesAdapter @Inject constructor( private val colors: Colors, private val dateFormatter: DateFormatter, private val navigator: Navigator, - private val prefs: Preferences + private val prefs: Preferences, + private val textViewStyler: TextViewStyler ) : QkRealmAdapter() { companion object { private const val VIEW_TYPE_MESSAGE_IN = 0 private const val VIEW_TYPE_MESSAGE_OUT = 1 + + // Thanks to Cory Kilger for this regex + // https://gist.github.com/cmkilger/b8f7dba3e76244a84e7e + private val EMOJI_REGEX = Regex( + "^[\\s\n\r]*(?:(?:[\u00a9\u00ae\u203c\u2049\u2122\u2139\u2194-\u2199\u21a9-\u21aa\u231a-\u231b\u2328\u23cf\u23e9-\u23f3\u23f8-\u23fa\u24c2\u25aa-\u25ab\u25b6\u25c0\u25fb-\u25fe\u2600-\u2604\u260e\u2611\u2614-\u2615\u2618\u261d\u2620\u2622-\u2623\u2626\u262a\u262e-\u262f\u2638-\u263a\u2648-\u2653\u2660\u2663\u2665-\u2666\u2668\u267b\u267f\u2692-\u2694\u2696-\u2697\u2699\u269b-\u269c\u26a0-\u26a1\u26aa-\u26ab\u26b0-\u26b1\u26bd-\u26be\u26c4-\u26c5\u26c8\u26ce-\u26cf\u26d1\u26d3-\u26d4\u26e9-\u26ea\u26f0-\u26f5\u26f7-\u26fa\u26fd\u2702\u2705\u2708-\u270d\u270f\u2712\u2714\u2716\u271d\u2721\u2728\u2733-\u2734\u2744\u2747\u274c\u274e\u2753-\u2755\u2757\u2763-\u2764\u2795-\u2797\u27a1\u27b0\u27bf\u2934-\u2935\u2b05-\u2b07\u2b1b-\u2b1c\u2b50\u2b55\u3030\u303d\u3297\u3299\ud83c\udc04\ud83c\udccf\ud83c\udd70-\ud83c\udd71\ud83c\udd7e-\ud83c\udd7f\ud83c\udd8e\ud83c\udd91-\ud83c\udd9a\ud83c\ude01-\ud83c\ude02\ud83c\ude1a\ud83c\ude2f\ud83c\ude32-\ud83c\ude3a\ud83c\ude50-\ud83c\ude51\u200d\ud83c\udf00-\ud83d\uddff\ud83d\ude00-\ud83d\ude4f\ud83d\ude80-\ud83d\udeff\ud83e\udd00-\ud83e\uddff\udb40\udc20-\udb40\udc7f]|\u200d[\u2640\u2642]|[\ud83c\udde6-\ud83c\uddff]{2}|.[\u20e0\u20e3\ufe0f]+)+[\\s\n\r]*)+$") + } val clicks: Subject = PublishSubject.create() @@ -228,7 +236,7 @@ class MessagesAdapter @Inject constructor( } // Bind the body text - view.body.text = when (message.isSms()) { + val messageText = when (message.isSms()) { true -> message.body false -> { val subject = message.getCleansedSubject() @@ -249,8 +257,16 @@ class MessagesAdapter @Inject constructor( } } } - view.body.setVisible(message.isSms() || view.body.text.isNotBlank()) + val emojiOnly = messageText.isNotBlank() && messageText.matches(EMOJI_REGEX) + textViewStyler.setTextSize(view.body, when (emojiOnly) { + true -> TextViewStyler.SIZE_EMOJI + false -> TextViewStyler.SIZE_PRIMARY + }) + + view.body.text = messageText + view.body.setVisible(message.isSms() || messageText.isNotBlank()) view.body.setBackgroundResource(getBubble( + emojiOnly = emojiOnly, canGroupWithPrevious = canGroup(message, previous) || media.isNotEmpty(), canGroupWithNext = canGroup(message, next), isMe = message.isMe())) diff --git a/presentation/src/main/java/com/moez/QKSMS/feature/compose/part/VCardBinder.kt b/presentation/src/main/java/com/moez/QKSMS/feature/compose/part/VCardBinder.kt index 3cafd05a..5d6234ac 100644 --- a/presentation/src/main/java/com/moez/QKSMS/feature/compose/part/VCardBinder.kt +++ b/presentation/src/main/java/com/moez/QKSMS/feature/compose/part/VCardBinder.kt @@ -59,7 +59,7 @@ class VCardBinder( canGroupWithNext: Boolean ) { val uri = ContentUris.withAppendedId(CursorToPartImpl.CONTENT_URI, part.id) - val bubble = BubbleUtils.getBubble(canGroupWithPrevious, canGroupWithNext, message.isMe()) + val bubble = BubbleUtils.getBubble(false, canGroupWithPrevious, canGroupWithNext, message.isMe()) view.setOnClickListener { navigator.saveVcard(uri) } view.vCardBackground.setBackgroundResource(bubble) diff --git a/presentation/src/main/res/drawable/message_emoji.xml b/presentation/src/main/res/drawable/message_emoji.xml new file mode 100644 index 00000000..9d41280a --- /dev/null +++ b/presentation/src/main/res/drawable/message_emoji.xml @@ -0,0 +1,28 @@ + + + + + + + + diff --git a/presentation/src/main/res/drawable/message_in_first.xml b/presentation/src/main/res/drawable/message_in_first.xml index 8dccfd71..782bf98a 100644 --- a/presentation/src/main/res/drawable/message_in_first.xml +++ b/presentation/src/main/res/drawable/message_in_first.xml @@ -26,5 +26,10 @@ android:topLeftRadius="18dp" android:topRightRadius="18dp" /> + \ No newline at end of file diff --git a/presentation/src/main/res/drawable/message_in_last.xml b/presentation/src/main/res/drawable/message_in_last.xml index f35444e4..56ef609b 100644 --- a/presentation/src/main/res/drawable/message_in_last.xml +++ b/presentation/src/main/res/drawable/message_in_last.xml @@ -26,5 +26,10 @@ android:topLeftRadius="4dp" android:topRightRadius="18dp" /> + \ No newline at end of file diff --git a/presentation/src/main/res/drawable/message_in_middle.xml b/presentation/src/main/res/drawable/message_in_middle.xml index 9dd8456b..2742f4d2 100644 --- a/presentation/src/main/res/drawable/message_in_middle.xml +++ b/presentation/src/main/res/drawable/message_in_middle.xml @@ -26,5 +26,10 @@ android:topLeftRadius="4dp" android:topRightRadius="18dp" /> + \ No newline at end of file diff --git a/presentation/src/main/res/drawable/message_only.xml b/presentation/src/main/res/drawable/message_only.xml index 9da69a09..a3d86635 100644 --- a/presentation/src/main/res/drawable/message_only.xml +++ b/presentation/src/main/res/drawable/message_only.xml @@ -22,5 +22,10 @@ + \ No newline at end of file diff --git a/presentation/src/main/res/drawable/message_out_first.xml b/presentation/src/main/res/drawable/message_out_first.xml index c5a8aed4..3a150c09 100644 --- a/presentation/src/main/res/drawable/message_out_first.xml +++ b/presentation/src/main/res/drawable/message_out_first.xml @@ -26,5 +26,10 @@ android:topLeftRadius="18dp" android:topRightRadius="18dp" /> + \ No newline at end of file diff --git a/presentation/src/main/res/drawable/message_out_last.xml b/presentation/src/main/res/drawable/message_out_last.xml index d99903e2..683cc950 100644 --- a/presentation/src/main/res/drawable/message_out_last.xml +++ b/presentation/src/main/res/drawable/message_out_last.xml @@ -26,5 +26,10 @@ android:topLeftRadius="18dp" android:topRightRadius="4dp" /> + \ No newline at end of file diff --git a/presentation/src/main/res/drawable/message_out_middle.xml b/presentation/src/main/res/drawable/message_out_middle.xml index 1b7eda34..006b9480 100644 --- a/presentation/src/main/res/drawable/message_out_middle.xml +++ b/presentation/src/main/res/drawable/message_out_middle.xml @@ -26,5 +26,10 @@ android:topLeftRadius="18dp" android:topRightRadius="4dp" /> + \ No newline at end of file diff --git a/presentation/src/main/res/layout/message_list_item_in.xml b/presentation/src/main/res/layout/message_list_item_in.xml index a03e96f0..2201260d 100644 --- a/presentation/src/main/res/layout/message_list_item_in.xml +++ b/presentation/src/main/res/layout/message_list_item_in.xml @@ -98,10 +98,6 @@ android:background="@drawable/message_only" android:gravity="start|center_vertical" android:minHeight="36dp" - android:paddingStart="12dp" - android:paddingTop="8dp" - android:paddingEnd="12dp" - android:paddingBottom="8dp" app:layout_constrainedWidth="true" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0" diff --git a/presentation/src/main/res/layout/message_list_item_out.xml b/presentation/src/main/res/layout/message_list_item_out.xml index dbdff4b2..8ab607f7 100644 --- a/presentation/src/main/res/layout/message_list_item_out.xml +++ b/presentation/src/main/res/layout/message_list_item_out.xml @@ -92,10 +92,6 @@ android:backgroundTint="?attr/bubbleColor" android:gravity="start|center_vertical" android:minHeight="36dp" - android:paddingStart="12dp" - android:paddingTop="8dp" - android:paddingEnd="12dp" - android:paddingBottom="8dp" app:layout_constrainedWidth="true" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="1" diff --git a/presentation/src/main/res/values/attrs.xml b/presentation/src/main/res/values/attrs.xml index 2e430b5b..3d79ccfe 100644 --- a/presentation/src/main/res/values/attrs.xml +++ b/presentation/src/main/res/values/attrs.xml @@ -36,6 +36,7 @@ +