kopia lustrzana https://github.com/ryukoposting/Signal-Android
Fix alignment on Update messages.
rodzic
9cc1ae4a29
commit
1dbb6013cb
|
@ -167,7 +167,7 @@ public final class ConversationUpdateItem extends FrameLayout
|
|||
}
|
||||
|
||||
UpdateDescription updateDescription = Objects.requireNonNull(messageRecord.getUpdateDisplayBody(getContext()));
|
||||
LiveData<SpannableString> liveUpdateMessage = LiveUpdateMessage.fromMessageDescription(getContext(), updateDescription, textColor);
|
||||
LiveData<SpannableString> liveUpdateMessage = LiveUpdateMessage.fromMessageDescription(getContext(), updateDescription, textColor, true);
|
||||
LiveData<SpannableString> spannableMessage = loading(liveUpdateMessage);
|
||||
|
||||
observeDisplayBody(lifecycleOwner, spannableMessage);
|
||||
|
|
|
@ -556,7 +556,7 @@ public final class ConversationListItem extends ConstraintLayout
|
|||
}
|
||||
|
||||
private static @NonNull LiveData<SpannableString> emphasisAdded(@NonNull Context context, @NonNull UpdateDescription description, @ColorInt int defaultTint) {
|
||||
return emphasisAdded(LiveUpdateMessage.fromMessageDescription(context, description, defaultTint));
|
||||
return emphasisAdded(LiveUpdateMessage.fromMessageDescription(context, description, defaultTint, false));
|
||||
}
|
||||
|
||||
private static @NonNull LiveData<SpannableString> emphasisAdded(@NonNull LiveData<SpannableString> description) {
|
||||
|
|
|
@ -35,9 +35,12 @@ public final class LiveUpdateMessage {
|
|||
* recreates the string asynchronously when they change.
|
||||
*/
|
||||
@AnyThread
|
||||
public static LiveData<SpannableString> fromMessageDescription(@NonNull Context context, @NonNull UpdateDescription updateDescription, @ColorInt int defaultTint) {
|
||||
public static LiveData<SpannableString> fromMessageDescription(@NonNull Context context,
|
||||
@NonNull UpdateDescription updateDescription,
|
||||
@ColorInt int defaultTint,
|
||||
boolean adjustPosition) {
|
||||
if (updateDescription.isStringStatic()) {
|
||||
return LiveDataUtil.just(toSpannable(context, updateDescription, updateDescription.getStaticString(), defaultTint));
|
||||
return LiveDataUtil.just(toSpannable(context, updateDescription, updateDescription.getStaticString(), defaultTint, adjustPosition));
|
||||
}
|
||||
|
||||
List<LiveData<Recipient>> allMentionedRecipients = Stream.of(updateDescription.getMentioned())
|
||||
|
@ -47,7 +50,7 @@ public final class LiveUpdateMessage {
|
|||
LiveData<?> mentionedRecipientChangeStream = allMentionedRecipients.isEmpty() ? LiveDataUtil.just(new Object())
|
||||
: LiveDataUtil.merge(allMentionedRecipients);
|
||||
|
||||
return LiveDataUtil.mapAsync(mentionedRecipientChangeStream, event -> toSpannable(context, updateDescription, updateDescription.getString(), defaultTint));
|
||||
return LiveDataUtil.mapAsync(mentionedRecipientChangeStream, event -> toSpannable(context, updateDescription, updateDescription.getString(), defaultTint, adjustPosition));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -59,7 +62,7 @@ public final class LiveUpdateMessage {
|
|||
return LiveDataUtil.mapAsync(Recipient.live(recipientId).getLiveDataResolved(), createStringInBackground);
|
||||
}
|
||||
|
||||
private static @NonNull SpannableString toSpannable(@NonNull Context context, @NonNull UpdateDescription updateDescription, @NonNull String string, @ColorInt int defaultTint) {
|
||||
private static @NonNull SpannableString toSpannable(@NonNull Context context, @NonNull UpdateDescription updateDescription, @NonNull String string, @ColorInt int defaultTint, boolean adjustPosition) {
|
||||
boolean isDarkTheme = ThemeUtil.isDarkTheme(context);
|
||||
int drawableResource = updateDescription.getIconResource();
|
||||
int tint = isDarkTheme ? updateDescription.getDarkTint() : updateDescription.getLightTint();
|
||||
|
@ -75,13 +78,14 @@ public final class LiveUpdateMessage {
|
|||
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
|
||||
drawable.setColorFilter(tint, PorterDuff.Mode.SRC_ATOP);
|
||||
|
||||
InsetDrawable insetDrawable = new InsetDrawable(drawable, 0, 0, 0, ViewUtil.dpToPx(-3));
|
||||
int insetTop = adjustPosition ? ViewUtil.dpToPx(2) : 0;
|
||||
InsetDrawable insetDrawable = new InsetDrawable(drawable, 0, insetTop, 0, 0);
|
||||
insetDrawable.setBounds(0, 0, drawable.getIntrinsicWidth(), insetDrawable.getIntrinsicHeight());
|
||||
|
||||
Drawable spaceDrawable = new ColorDrawable(Color.TRANSPARENT);
|
||||
spaceDrawable.setBounds(0, 0, ViewUtil.dpToPx(8), drawable.getIntrinsicHeight());
|
||||
|
||||
Spannable stringWithImage = new SpannableStringBuilder().append(SpanUtil.buildImageSpanBottomAligned(drawable)).append(SpanUtil.buildImageSpan(spaceDrawable)).append(string);
|
||||
Spannable stringWithImage = new SpannableStringBuilder().append(SpanUtil.buildImageSpan(drawable)).append(SpanUtil.buildImageSpan(spaceDrawable)).append(string);
|
||||
|
||||
return new SpannableString(SpanUtil.color(tint, stringWithImage));
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ import android.text.style.ClickableSpan;
|
|||
import android.text.style.DynamicDrawableSpan;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.text.style.ImageSpan;
|
||||
import android.text.style.MetricAffectingSpan;
|
||||
import android.text.style.RelativeSizeSpan;
|
||||
import android.text.style.StyleSpan;
|
||||
import android.text.style.TypefaceSpan;
|
||||
|
@ -106,13 +105,6 @@ public final class SpanUtil {
|
|||
return imageSpan;
|
||||
}
|
||||
|
||||
public static CharSequence buildImageSpanBottomAligned(@NonNull Drawable drawable) {
|
||||
SpannableString imageSpan = new SpannableString(" ");
|
||||
imageSpan.setSpan(new ImageSpan(drawable, DynamicDrawableSpan.ALIGN_BOTTOM), 0, imageSpan.length(), 0);
|
||||
|
||||
return imageSpan;
|
||||
}
|
||||
|
||||
public static CharSequence learnMore(@NonNull Context context,
|
||||
@ColorInt int color,
|
||||
@NonNull View.OnClickListener onLearnMoreClicked)
|
||||
|
|
Ładowanie…
Reference in New Issue