kopia lustrzana https://github.com/ryukoposting/Signal-Android
Add support for multiple typing indicators in groups.
rodzic
8442143818
commit
334cf669ed
|
@ -1,27 +1,34 @@
|
|||
package org.thoughtcrime.securesms.components;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.mms.GlideRequests;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.whispersystems.libsignal.util.Pair;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class ConversationTypingView extends LinearLayout {
|
||||
public class ConversationTypingView extends ConstraintLayout {
|
||||
|
||||
private AvatarImageView avatar;
|
||||
private AvatarImageView avatar1;
|
||||
private AvatarImageView avatar2;
|
||||
private AvatarImageView avatar3;
|
||||
private View bubble;
|
||||
private TypingIndicatorView indicator;
|
||||
private TextView typistCount;
|
||||
|
||||
public ConversationTypingView(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
@ -31,9 +38,12 @@ public class ConversationTypingView extends LinearLayout {
|
|||
protected void onFinishInflate() {
|
||||
super.onFinishInflate();
|
||||
|
||||
avatar = findViewById(R.id.typing_avatar);
|
||||
bubble = findViewById(R.id.typing_bubble);
|
||||
indicator = findViewById(R.id.typing_indicator);
|
||||
avatar1 = findViewById(R.id.typing_avatar_1);
|
||||
avatar2 = findViewById(R.id.typing_avatar_2);
|
||||
avatar3 = findViewById(R.id.typing_avatar_3);
|
||||
typistCount = findViewById(R.id.typing_count);
|
||||
bubble = findViewById(R.id.typing_bubble);
|
||||
indicator = findViewById(R.id.typing_indicator);
|
||||
}
|
||||
|
||||
public void setTypists(@NonNull GlideRequests glideRequests, @NonNull List<Recipient> typists, boolean isGroupThread, boolean hasWallpaper) {
|
||||
|
@ -42,21 +52,44 @@ public class ConversationTypingView extends LinearLayout {
|
|||
return;
|
||||
}
|
||||
|
||||
Recipient typist = typists.get(0);
|
||||
avatar1.setVisibility(GONE);
|
||||
avatar2.setVisibility(GONE);
|
||||
avatar3.setVisibility(GONE);
|
||||
typistCount.setVisibility(GONE);
|
||||
|
||||
if (isGroupThread) {
|
||||
avatar.setAvatar(glideRequests, typist, true);
|
||||
avatar.setVisibility(VISIBLE);
|
||||
} else {
|
||||
avatar.setVisibility(GONE);
|
||||
presentGroupThreadAvatars(glideRequests, typists);
|
||||
}
|
||||
|
||||
if (hasWallpaper) {
|
||||
bubble.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.conversation_item_wallpaper_bubble_color));
|
||||
typistCount.getBackground().setColorFilter(ContextCompat.getColor(getContext(), R.color.conversation_item_wallpaper_bubble_color), PorterDuff.Mode.SRC_IN);
|
||||
} else {
|
||||
bubble.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.signal_background_secondary));
|
||||
typistCount.getBackground().setColorFilter(ContextCompat.getColor(getContext(), R.color.signal_background_secondary), PorterDuff.Mode.SRC_IN);
|
||||
}
|
||||
|
||||
indicator.startAnimation();
|
||||
}
|
||||
|
||||
private void presentGroupThreadAvatars(@NonNull GlideRequests glideRequests, @NonNull List<Recipient> typists) {
|
||||
avatar1.setAvatar(glideRequests, typists.get(0), typists.size() == 1);
|
||||
avatar1.setVisibility(VISIBLE);
|
||||
|
||||
if (typists.size() > 1) {
|
||||
avatar2.setAvatar(glideRequests, typists.get(1), false);
|
||||
avatar2.setVisibility(VISIBLE);
|
||||
}
|
||||
|
||||
if (typists.size() == 3) {
|
||||
avatar3.setAvatar(glideRequests, typists.get(2), false);
|
||||
avatar3.setVisibility(VISIBLE);
|
||||
}
|
||||
|
||||
if (typists.size() > 3) {
|
||||
typistCount.setText(getResources().getString(R.string.ConversationTypingView__plus_d, typists.size() - 2));
|
||||
typistCount.setVisibility(VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<corners android:radius="1000dp" />
|
||||
<solid android:color="@color/white" />
|
||||
</shape>
|
|
@ -2,25 +2,86 @@
|
|||
<org.thoughtcrime.securesms.components.ConversationTypingView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:paddingTop="2dp"
|
||||
android:gravity="center_vertical">
|
||||
android:paddingEnd="8dp">
|
||||
|
||||
<org.thoughtcrime.securesms.components.AvatarImageView
|
||||
android:id="@+id/typing_avatar"
|
||||
android:foreground="@drawable/contact_photo_background"
|
||||
android:id="@+id/typing_avatar_1"
|
||||
android:layout_width="@dimen/conversation_item_avatar_size"
|
||||
android:layout_height="@dimen/conversation_item_avatar_size"
|
||||
android:layout_marginStart="4dp"
|
||||
android:cropToPadding="true"
|
||||
android:contentDescription="@string/conversation_item_received__contact_photo_description"
|
||||
app:fallbackImageSize="small" />
|
||||
android:cropToPadding="true"
|
||||
android:foreground="@drawable/contact_photo_background"
|
||||
android:visibility="gone"
|
||||
app:fallbackImageSize="small"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<org.thoughtcrime.securesms.components.AvatarImageView
|
||||
android:id="@+id/typing_avatar_2"
|
||||
android:layout_width="@dimen/conversation_item_avatar_size"
|
||||
android:layout_height="@dimen/conversation_item_avatar_size"
|
||||
android:layout_marginStart="16dp"
|
||||
android:contentDescription="@string/conversation_item_received__contact_photo_description"
|
||||
android:cropToPadding="true"
|
||||
android:foreground="@drawable/contact_photo_background"
|
||||
android:visibility="gone"
|
||||
app:fallbackImageSize="small"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="@id/typing_avatar_1"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<org.thoughtcrime.securesms.components.AvatarImageView
|
||||
android:id="@+id/typing_avatar_3"
|
||||
android:layout_width="@dimen/conversation_item_avatar_size"
|
||||
android:layout_height="@dimen/conversation_item_avatar_size"
|
||||
android:layout_marginStart="16dp"
|
||||
android:contentDescription="@string/conversation_item_received__contact_photo_description"
|
||||
android:cropToPadding="true"
|
||||
android:foreground="@drawable/contact_photo_background"
|
||||
android:visibility="gone"
|
||||
app:fallbackImageSize="small"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="@id/typing_avatar_2"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/typing_count"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="@dimen/conversation_item_avatar_size"
|
||||
android:layout_marginStart="16dp"
|
||||
android:background="@drawable/tintable_pill_bg"
|
||||
android:gravity="center"
|
||||
android:minWidth="@dimen/conversation_item_avatar_size"
|
||||
android:paddingStart="4dp"
|
||||
android:paddingEnd="4dp"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
|
||||
android:textColor="@color/signal_text_secondary"
|
||||
android:visibility="gone"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="@id/typing_avatar_2"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:backgroundTint="@color/signal_background_secondary"
|
||||
tools:text="+1000000"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<androidx.constraintlayout.widget.Barrier
|
||||
android:id="@+id/typist_barrier"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:barrierDirection="end"
|
||||
app:constraint_referenced_ids="typing_avatar_1, typing_avatar_2, typing_avatar_3, typing_count" />
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:id="@+id/indicator_card"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
|
@ -28,7 +89,10 @@
|
|||
android:layout_marginBottom="1dp"
|
||||
app:cardCornerRadius="@dimen/message_corner_radius"
|
||||
app:cardElevation="0dp"
|
||||
app:contentPadding="0dp">
|
||||
app:contentPadding="0dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/typist_barrier"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/typing_bubble"
|
||||
|
@ -36,11 +100,11 @@
|
|||
android:layout_height="match_parent">
|
||||
|
||||
<org.thoughtcrime.securesms.components.TypingIndicatorView
|
||||
app:typingIndicator_tint="@color/signal_inverse_primary"
|
||||
android:id="@+id/typing_indicator"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="12dp" />
|
||||
android:layout_margin="12dp"
|
||||
app:typingIndicator_tint="@color/signal_inverse_primary" />
|
||||
|
||||
</FrameLayout>
|
||||
</androidx.cardview.widget.CardView>
|
||||
|
|
|
@ -377,6 +377,9 @@
|
|||
<string name="ConversationTitleView_verified">Verified</string>
|
||||
<string name="ConversationTitleView_you">You</string>
|
||||
|
||||
<!-- ConversationTypingView -->
|
||||
<string name="ConversationTypingView__plus_d">+%1$d</string>
|
||||
|
||||
<!-- CreateGroupActivity -->
|
||||
<string name="CreateGroupActivity_some_contacts_cannot_be_in_legacy_groups">Some contacts cannot be in legacy groups.</string>
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue