Collapse adjacent conversation updates.

fork-5.53.8
Greyson Parrelli 2021-01-23 14:40:26 -05:00
rodzic c6008a4f90
commit e05cadafe6
9 zmienionych plików z 130 dodań i 15 usunięć

Wyświetl plik

@ -6,6 +6,7 @@ import android.text.Spannable;
import android.text.SpannableString;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;
@ -30,10 +31,12 @@ import org.thoughtcrime.securesms.database.model.UpdateDescription;
import org.thoughtcrime.securesms.mms.GlideRequests;
import org.thoughtcrime.securesms.recipients.LiveRecipient;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.util.DateUtils;
import org.thoughtcrime.securesms.util.IdentityUtil;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.ThemeUtil;
import org.thoughtcrime.securesms.util.Util;
import org.thoughtcrime.securesms.util.ViewUtil;
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
import org.thoughtcrime.securesms.util.livedata.LiveDataUtil;
import org.whispersystems.libsignal.util.guava.Optional;
@ -101,7 +104,7 @@ public final class ConversationUpdateItem extends FrameLayout
{
this.batchSelected = batchSelected;
bind(lifecycleOwner, conversationMessage, nextMessageRecord, conversationRecipient, hasWallpaper);
bind(lifecycleOwner, conversationMessage, previousMessageRecord, nextMessageRecord, conversationRecipient, hasWallpaper);
}
@Override
@ -116,6 +119,7 @@ public final class ConversationUpdateItem extends FrameLayout
private void bind(@NonNull LifecycleOwner lifecycleOwner,
@NonNull ConversationMessage conversationMessage,
@NonNull Optional<MessageRecord> previousMessageRecord,
@NonNull Optional<MessageRecord> nextMessageRecord,
@NonNull Recipient conversationRecipient,
boolean hasWallpaper)
@ -133,12 +137,6 @@ public final class ConversationUpdateItem extends FrameLayout
groupObserver.observe(lifecycleOwner, null);
}
if (hasWallpaper) {
background.setBackgroundResource(R.drawable.wallpaper_bubble_background_12);
} else {
background.setBackground(null);
}
int textColor = ContextCompat.getColor(getContext(), R.color.conversation_item_update_text_color);
if (ThemeUtil.isDarkTheme(getContext()) && hasWallpaper) {
textColor = ContextCompat.getColor(getContext(), R.color.core_grey_15);
@ -159,6 +157,16 @@ public final class ConversationUpdateItem extends FrameLayout
observeDisplayBody(lifecycleOwner, spannableMessage);
present(conversationMessage, nextMessageRecord, conversationRecipient);
presentBackground(shouldCollapse(messageRecord, previousMessageRecord),
shouldCollapse(messageRecord, nextMessageRecord),
hasWallpaper);
}
private static boolean shouldCollapse(@NonNull MessageRecord current, @NonNull Optional<MessageRecord> candidate) {
return candidate.isPresent() &&
candidate.get().isUpdate() &&
DateUtils.isSameDay(current.getTimestamp(), candidate.get().getTimestamp());
}
/** After a short delay, if the main data hasn't shown yet, then a loading message is displayed. */
@ -294,6 +302,71 @@ public final class ConversationUpdateItem extends FrameLayout
}
}
private void presentBackground(boolean collapseAbove, boolean collapseBelow, boolean hasWallpaper) {
int marginDefault = getContext().getResources().getDimensionPixelOffset(R.dimen.conversation_update_vertical_margin);
int marginCollapsed = 0;
int paddingDefault = getContext().getResources().getDimensionPixelOffset(R.dimen.conversation_update_vertical_padding);
int paddingCollapsed = getContext().getResources().getDimensionPixelOffset(R.dimen.conversation_update_vertical_padding_collapsed);
if (collapseAbove && collapseBelow) {
ViewUtil.setTopMargin(background, marginCollapsed);
ViewUtil.setBottomMargin(background, marginCollapsed);
ViewUtil.setPaddingTop(background, paddingCollapsed);
ViewUtil.setPaddingBottom(background, paddingCollapsed);
ViewUtil.updateLayoutParams(background, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
if (hasWallpaper) {
background.setBackgroundResource(R.drawable.conversation_update_wallpaper_background_middle);
} else {
background.setBackground(null);
}
} else if (collapseAbove) {
ViewUtil.setTopMargin(background, marginCollapsed);
ViewUtil.setBottomMargin(background, marginDefault);
ViewUtil.setPaddingTop(background, paddingCollapsed);
ViewUtil.setPaddingBottom(background, paddingDefault);
ViewUtil.updateLayoutParams(background, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
if (hasWallpaper) {
background.setBackgroundResource(R.drawable.conversation_update_wallpaper_background_bottom);
} else {
background.setBackground(null);
}
} else if (collapseBelow) {
ViewUtil.setTopMargin(background, paddingDefault);
ViewUtil.setBottomMargin(background, paddingCollapsed);
ViewUtil.setPaddingTop(background, paddingDefault);
ViewUtil.setPaddingBottom(background, paddingCollapsed);
ViewUtil.updateLayoutParams(background, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
if (hasWallpaper) {
background.setBackgroundResource(R.drawable.conversation_update_wallpaper_background_top);
} else {
background.setBackground(null);
}
} else {
ViewUtil.setTopMargin(background, marginDefault);
ViewUtil.setBottomMargin(background, marginDefault);
ViewUtil.setPaddingTop(background, paddingDefault);
ViewUtil.setPaddingBottom(background, paddingDefault);
ViewUtil.updateLayoutParams(background, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
if (hasWallpaper) {
background.setBackgroundResource(R.drawable.conversation_update_wallpaper_background_singular);
} else {
background.setBackground(null);
}
}
}
@Override
public void setOnClickListener(View.OnClickListener l) {
super.setOnClickListener(new InternalClickListener(l));

Wyświetl plik

@ -250,6 +250,11 @@ public final class ViewUtil {
view.requestLayout();
}
public static void setBottomMargin(@NonNull View view, int margin) {
((ViewGroup.MarginLayoutParams) view.getLayoutParams()).bottomMargin = margin;
view.requestLayout();
}
public static void setPaddingTop(@NonNull View view, int padding) {
view.setPadding(view.getPaddingLeft(), padding, view.getPaddingRight(), view.getPaddingBottom());
}

Wyświetl plik

@ -10,6 +10,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;

Wyświetl plik

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/wallpaper_bubble_color" />
<corners android:bottomLeftRadius="12dp"
android:bottomRightRadius="12dp"/>
</shape>

Wyświetl plik

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/wallpaper_bubble_color" />
</shape>

Wyświetl plik

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/wallpaper_bubble_color" />
<corners android:radius="12dp" />
</shape>

Wyświetl plik

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/wallpaper_bubble_color" />
<corners android:topLeftRadius="12dp"
android:topRightRadius="12dp"/>
</shape>

Wyświetl plik

@ -8,21 +8,20 @@
android:background="@drawable/conversation_item_background"
android:focusable="true"
android:paddingStart="26dp"
android:paddingEnd="26dp"
android:clipToPadding="false"
android:clipChildren="false">
android:paddingEnd="26dp">
<LinearLayout
android:id="@+id/conversation_update_background"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="100dp"
android:layout_gravity="center"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_marginTop="@dimen/conversation_update_vertical_margin"
android:layout_marginBottom="@dimen/conversation_update_vertical_margin"
android:orientation="vertical"
android:gravity="center"
android:paddingTop="8dp"
android:paddingBottom="8dp"
android:paddingTop="@dimen/conversation_update_vertical_padding"
android:paddingBottom="@dimen/conversation_update_vertical_padding"
android:paddingStart="10dp"
android:paddingEnd="10dp">

Wyświetl plik

@ -162,4 +162,8 @@
<dimen name="wave_form_bar_width">2dp</dimen>
<dimen name="review_card_icon_arc_radius">14.5dp</dimen>
<dimen name="conversation_update_vertical_margin">2dp</dimen>
<dimen name="conversation_update_vertical_padding">8dp</dimen>
<dimen name="conversation_update_vertical_padding_collapsed">2dp</dimen>
</resources>