improve typing indicator design

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2023-05-17 17:15:26 +02:00
parent 6adca2395d
commit ecec266765
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
3 changed files with 51 additions and 32 deletions

View File

@ -62,6 +62,7 @@ import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.MotionEvent import android.view.MotionEvent
import android.view.View import android.view.View
import android.view.animation.AccelerateDecelerateInterpolator
import android.view.animation.AlphaAnimation import android.view.animation.AlphaAnimation
import android.view.animation.Animation import android.view.animation.Animation
import android.view.animation.LinearInterpolator import android.view.animation.LinearInterpolator
@ -344,15 +345,11 @@ class ChatActivity :
val typingString: SpannableStringBuilder val typingString: SpannableStringBuilder
when (typingParticipants.size) { when (typingParticipants.size) {
0 -> { 0 -> typingString = SpannableStringBuilder().append(binding.typingIndicator.text)
typingString = SpannableStringBuilder().append("")
}
1 -> { 1 -> typingString = SpannableStringBuilder()
typingString = SpannableStringBuilder()
.bold { append(participantNames[0]) } .bold { append(participantNames[0]) }
.append(WHITESPACE + context.resources?.getString(R.string.typing_is_typing)) .append(WHITESPACE + context.resources?.getString(R.string.typing_is_typing))
}
2 -> typingString = SpannableStringBuilder() 2 -> typingString = SpannableStringBuilder()
.bold { append(participantNames[0]) } .bold { append(participantNames[0]) }
@ -378,11 +375,9 @@ class ChatActivity :
else -> { else -> {
val moreTypersAmount = typingParticipants.size - 3 val moreTypersAmount = typingParticipants.size - 3
val othersTyping = context.resources?.getString(R.string.typing_x_others)?.let { val othersTyping = context.resources?.getString(R.string.typing_x_others)?.let {
String.format(it, moreTypersAmount) String.format(it, moreTypersAmount)
} }
typingString = SpannableStringBuilder() typingString = SpannableStringBuilder()
.bold { append(participantNames[0]) } .bold { append(participantNames[0]) }
.append(COMMA) .append(COMMA)
@ -393,12 +388,22 @@ class ChatActivity :
} }
} }
val typingIndicatorHeight = DisplayUtils.convertDpToPixel(20f,context)
runOnUiThread { runOnUiThread {
if (participantNames.size > 0) { if (participantNames.size > 0) {
binding.typingIndicator.visibility = View.VISIBLE binding.typingIndicatorWrapper.animate()
.translationY(binding.messageInputView.y - typingIndicatorHeight)
.setInterpolator(AccelerateDecelerateInterpolator())
.duration = TYPING_INDICATOR_ANIMATION_DURATION
} else { } else {
binding.typingIndicator.visibility = View.GONE binding.typingIndicatorWrapper.animate()
.translationY(binding.messageInputView.y)
.setInterpolator(AccelerateDecelerateInterpolator())
.duration = TYPING_INDICATOR_ANIMATION_DURATION
} }
binding.typingIndicator.text = typingString binding.typingIndicator.text = typingString
} }
} }
@ -3765,5 +3770,6 @@ class ChatActivity :
private const val WHITESPACE = " " private const val WHITESPACE = " "
private const val COMMA = ", " private const val COMMA = ", "
private const val TYPING_INDICATOR_ANIMATION_DURATION = 200L
} }
} }

View File

@ -80,7 +80,8 @@
android:id="@+id/messagesListView" android:id="@+id/messagesListView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:paddingBottom="0dp" android:paddingBottom="20dp"
android:clipToPadding="false"
android:visibility="gone" android:visibility="gone"
app:dateHeaderTextSize="13sp" app:dateHeaderTextSize="13sp"
app:incomingBubblePaddingBottom="@dimen/message_bubble_corners_vertical_padding" app:incomingBubblePaddingBottom="@dimen/message_bubble_corners_vertical_padding"
@ -108,7 +109,8 @@
app:outcomingTextLinkColor="@color/high_emphasis_text" app:outcomingTextLinkColor="@color/high_emphasis_text"
app:outcomingTextSize="@dimen/chat_text_size" app:outcomingTextSize="@dimen/chat_text_size"
app:outcomingTimeTextSize="12sp" app:outcomingTimeTextSize="12sp"
app:textAutoLink="all" /> app:textAutoLink="all"
tools:visibility="visible"/>
<com.nextcloud.ui.popupbubble.PopupBubble <com.nextcloud.ui.popupbubble.PopupBubble
android:id="@+id/popupBubbleView" android:id="@+id/popupBubbleView"
@ -148,6 +150,33 @@
app:iconPadding="0dp" app:iconPadding="0dp"
app:iconSize="24dp" /> app:iconSize="24dp" />
<LinearLayout
android:id="@+id/typing_indicator_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:layout_marginBottom="-20dp">
<View
android:id="@+id/separator_1"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/controller_chat_separator" />
<TextView
android:id="@+id/typing_indicator"
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_marginStart="@dimen/side_margin"
android:layout_marginEnd="@dimen/side_margin"
android:background="@color/bg_default"
android:textColor="@color/low_emphasis_text"
tools:text="Marcel is typing">
</TextView>
</LinearLayout>
</RelativeLayout> </RelativeLayout>
<LinearLayout <LinearLayout
@ -155,22 +184,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<View
android:id="@+id/separator_1"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/controller_chat_separator" />
<TextView
android:id="@+id/typing_indicator"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="@dimen/side_margin"
android:layout_marginEnd="@dimen/side_margin"
android:textColor="@color/low_emphasis_text"
tools:text="Marcel is typing">
</TextView>
<com.nextcloud.talk.ui.MessageInput <com.nextcloud.talk.ui.MessageInput
android:id="@+id/messageInputView" android:id="@+id/messageInputView"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -448,10 +448,10 @@ How to translate with transifex:
<string name="open_in_files_app">Open in Files app</string> <string name="open_in_files_app">Open in Files app</string>
<string name="send_to_forbidden">You are not allowed to share content to this chat</string> <string name="send_to_forbidden">You are not allowed to share content to this chat</string>
<string name="typing_is_typing">is typing</string> <string name="typing_is_typing">is typing</string>
<string name="typing_are_typing">are typing</string> <string name="typing_are_typing">are typing</string>
<string name="typing_1_other">and 1 other is typing…</string> <string name="typing_1_other">and 1 other is typing </string>
<string name="typing_x_others">and %1$s others are typing…</string> <string name="typing_x_others">and %1$s others are typing </string>
<!-- Upload --> <!-- Upload -->
<string name="nc_add_file">Add to conversation</string> <string name="nc_add_file">Add to conversation</string>