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

View File

@ -80,7 +80,8 @@
android:id="@+id/messagesListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="0dp"
android:paddingBottom="20dp"
android:clipToPadding="false"
android:visibility="gone"
app:dateHeaderTextSize="13sp"
app:incomingBubblePaddingBottom="@dimen/message_bubble_corners_vertical_padding"
@ -108,7 +109,8 @@
app:outcomingTextLinkColor="@color/high_emphasis_text"
app:outcomingTextSize="@dimen/chat_text_size"
app:outcomingTimeTextSize="12sp"
app:textAutoLink="all" />
app:textAutoLink="all"
tools:visibility="visible"/>
<com.nextcloud.ui.popupbubble.PopupBubble
android:id="@+id/popupBubbleView"
@ -148,12 +150,13 @@
app:iconPadding="0dp"
app:iconSize="24dp" />
</RelativeLayout>
<LinearLayout
android:id="@+id/typing_indicator_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:layout_marginBottom="-20dp">
<View
android:id="@+id/separator_1"
@ -164,13 +167,23 @@
<TextView
android:id="@+id/typing_indicator"
android:layout_width="match_parent"
android:layout_height="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>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<com.nextcloud.talk.ui.MessageInput
android:id="@+id/messageInputView"
android:layout_width="match_parent"

View File

@ -448,8 +448,8 @@ How to translate with transifex:
<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="typing_is_typing">is typing</string>
<string name="typing_are_typing">are typing</string>
<string name="typing_is_typing">is typing</string>
<string name="typing_are_typing">are 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>