kopia lustrzana https://github.com/ryukoposting/Signal-Android
Add badge treatments as per spec.
rodzic
70355aa70e
commit
7bbfc2d34c
|
@ -9,6 +9,7 @@ import org.thoughtcrime.securesms.R
|
|||
import org.thoughtcrime.securesms.badges.glide.BadgeSpriteTransformation
|
||||
import org.thoughtcrime.securesms.badges.models.Badge
|
||||
import org.thoughtcrime.securesms.mms.GlideApp
|
||||
import org.thoughtcrime.securesms.mms.GlideRequests
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.util.ThemeUtil
|
||||
import org.thoughtcrime.securesms.util.visible
|
||||
|
@ -28,31 +29,46 @@ class BadgeImageView @JvmOverloads constructor(
|
|||
}
|
||||
|
||||
fun setBadgeFromRecipient(recipient: Recipient?) {
|
||||
getGlideRequests()?.let {
|
||||
setBadgeFromRecipient(recipient, it)
|
||||
}
|
||||
}
|
||||
|
||||
fun setBadgeFromRecipient(recipient: Recipient?, glideRequests: GlideRequests) {
|
||||
if (recipient == null || recipient.badges.isEmpty()) {
|
||||
setBadge(null)
|
||||
setBadge(null, glideRequests)
|
||||
} else {
|
||||
setBadge(recipient.badges[0])
|
||||
setBadge(recipient.badges[0], glideRequests)
|
||||
}
|
||||
}
|
||||
|
||||
fun setBadge(badge: Badge?) {
|
||||
getGlideRequests()?.let {
|
||||
setBadge(badge, it)
|
||||
}
|
||||
}
|
||||
|
||||
fun setBadge(badge: Badge?, glideRequests: GlideRequests) {
|
||||
visible = badge != null
|
||||
|
||||
try {
|
||||
if (badge != null) {
|
||||
GlideApp
|
||||
.with(this)
|
||||
.load(badge)
|
||||
.downsample(DownsampleStrategy.NONE)
|
||||
.transform(BadgeSpriteTransformation(BadgeSpriteTransformation.Size.fromInteger(badgeSize), badge.imageDensity, ThemeUtil.isDarkTheme(context)))
|
||||
.into(this)
|
||||
} else {
|
||||
GlideApp
|
||||
.with(this)
|
||||
.clear(this)
|
||||
}
|
||||
if (badge != null) {
|
||||
glideRequests
|
||||
.load(badge)
|
||||
.downsample(DownsampleStrategy.NONE)
|
||||
.transform(BadgeSpriteTransformation(BadgeSpriteTransformation.Size.fromInteger(badgeSize), badge.imageDensity, ThemeUtil.isDarkTheme(context)))
|
||||
.into(this)
|
||||
} else {
|
||||
glideRequests
|
||||
.clear(this)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getGlideRequests(): GlideRequests? {
|
||||
return try {
|
||||
GlideApp.with(this)
|
||||
} catch (e: IllegalArgumentException) {
|
||||
// Do nothing. Activity was destroyed.
|
||||
// View not attached to an activity or activity destroyed
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.components.settings.conversation.preferences
|
|||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.badges.BadgeImageView
|
||||
import org.thoughtcrime.securesms.components.AvatarImageView
|
||||
import org.thoughtcrime.securesms.components.settings.PreferenceModel
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
|
@ -40,11 +41,13 @@ object RecipientPreference {
|
|||
private val name: TextView = itemView.findViewById(R.id.recipient_name)
|
||||
private val about: TextView = itemView.findViewById(R.id.recipient_about)
|
||||
private val admin: View = itemView.findViewById(R.id.admin)
|
||||
private val badge: BadgeImageView = itemView.findViewById(R.id.recipient_badge)
|
||||
|
||||
override fun bind(model: Model) {
|
||||
itemView.setOnClickListener { model.onClick() }
|
||||
|
||||
avatar.setRecipient(model.recipient)
|
||||
badge.setBadgeFromRecipient(model.recipient)
|
||||
name.text = if (model.recipient.isSelf) {
|
||||
context.getString(R.string.Recipient_you)
|
||||
} else {
|
||||
|
|
|
@ -67,6 +67,7 @@ import org.thoughtcrime.securesms.BindableConversationItem;
|
|||
import org.thoughtcrime.securesms.MediaPreviewActivity;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.attachments.DatabaseAttachment;
|
||||
import org.thoughtcrime.securesms.badges.BadgeImageView;
|
||||
import org.thoughtcrime.securesms.components.AlertView;
|
||||
import org.thoughtcrime.securesms.components.AudioView;
|
||||
import org.thoughtcrime.securesms.components.AvatarImageView;
|
||||
|
@ -183,6 +184,7 @@ public final class ConversationItem extends RelativeLayout implements BindableCo
|
|||
private AvatarImageView contactPhoto;
|
||||
private AlertView alertView;
|
||||
protected ReactionsConversationView reactionsView;
|
||||
private BadgeImageView badgeImageView;
|
||||
|
||||
private @NonNull Set<MultiselectPart> batchSelected = new HashSet<>();
|
||||
private @NonNull Outliner outliner = new Outliner();
|
||||
|
@ -264,6 +266,7 @@ public final class ConversationItem extends RelativeLayout implements BindableCo
|
|||
this.reply = findViewById(R.id.reply_icon_wrapper);
|
||||
this.replyIcon = findViewById(R.id.reply_icon);
|
||||
this.reactionsView = findViewById(R.id.reactions_view);
|
||||
this.badgeImageView = findViewById(R.id.badge);
|
||||
|
||||
setOnClickListener(new ClickListener(null));
|
||||
|
||||
|
@ -1250,6 +1253,7 @@ public final class ConversationItem extends RelativeLayout implements BindableCo
|
|||
});
|
||||
|
||||
contactPhoto.setAvatar(glideRequests, recipient, false);
|
||||
badgeImageView.setBadgeFromRecipient(recipient, glideRequests);
|
||||
}
|
||||
|
||||
private void linkifyMessageBody(@NonNull Spannable messageBody,
|
||||
|
@ -1486,8 +1490,10 @@ public final class ConversationItem extends RelativeLayout implements BindableCo
|
|||
|
||||
if (!next.isPresent() || next.get().isUpdate() || !current.getRecipient().equals(next.get().getRecipient())) {
|
||||
contactPhoto.setVisibility(VISIBLE);
|
||||
badgeImageView.setVisibility(VISIBLE);
|
||||
} else {
|
||||
contactPhoto.setVisibility(GONE);
|
||||
badgeImageView.setVisibility(GONE);
|
||||
}
|
||||
} else {
|
||||
if (groupSenderHolder != null) {
|
||||
|
@ -1497,6 +1503,10 @@ public final class ConversationItem extends RelativeLayout implements BindableCo
|
|||
if (contactPhotoHolder != null) {
|
||||
contactPhotoHolder.setVisibility(GONE);
|
||||
}
|
||||
|
||||
if (badgeImageView != null) {
|
||||
badgeImageView.setVisibility(GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import androidx.recyclerview.widget.DiffUtil;
|
|||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.badges.BadgeImageView;
|
||||
import org.thoughtcrime.securesms.components.AvatarImageView;
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiTextView;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
|
@ -168,6 +169,7 @@ final class GroupMemberListAdapter extends LifecycleRecyclerAdapter<GroupMemberL
|
|||
|
||||
final Context context;
|
||||
final AvatarImageView avatar;
|
||||
final BadgeImageView badge;
|
||||
final TextView recipient;
|
||||
final EmojiTextView about;
|
||||
final CheckBox selected;
|
||||
|
@ -190,6 +192,7 @@ final class GroupMemberListAdapter extends LifecycleRecyclerAdapter<GroupMemberL
|
|||
|
||||
this.context = itemView.getContext();
|
||||
this.avatar = itemView.findViewById(R.id.recipient_avatar);
|
||||
this.badge = itemView.findViewById(R.id.recipient_badge);
|
||||
this.recipient = itemView.findViewById(R.id.recipient_name);
|
||||
this.about = itemView.findViewById(R.id.recipient_about);
|
||||
this.selected = itemView.findViewById(R.id.recipient_selected);
|
||||
|
@ -212,6 +215,7 @@ final class GroupMemberListAdapter extends LifecycleRecyclerAdapter<GroupMemberL
|
|||
void bindImageAndText(@NonNull Recipient recipient, @NonNull String displayText, @Nullable String about) {
|
||||
this.recipient.setText(displayText);
|
||||
this.avatar.setRecipient(recipient);
|
||||
this.badge.setBadgeFromRecipient(recipient);
|
||||
|
||||
if (this.about != null) {
|
||||
this.about.setText(about);
|
||||
|
|
|
@ -7,6 +7,7 @@ import androidx.annotation.NonNull;
|
|||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.badges.BadgeImageView;
|
||||
import org.thoughtcrime.securesms.components.AvatarImageView;
|
||||
import org.thoughtcrime.securesms.components.FromTextView;
|
||||
import org.thoughtcrime.securesms.util.DateUtils;
|
||||
|
@ -21,6 +22,7 @@ final class RecipientViewHolder extends RecyclerView.ViewHolder {
|
|||
private final TextView error;
|
||||
private final View conflictButton;
|
||||
private final View unidentifiedDeliveryIcon;
|
||||
private final BadgeImageView badge;
|
||||
private MessageDetailsAdapter.Callbacks callbacks;
|
||||
|
||||
RecipientViewHolder(@NonNull View itemView, @NonNull MessageDetailsAdapter.Callbacks callbacks) {
|
||||
|
@ -34,12 +36,14 @@ final class RecipientViewHolder extends RecyclerView.ViewHolder {
|
|||
error = itemView.findViewById(R.id.message_details_recipient_error_description);
|
||||
conflictButton = itemView.findViewById(R.id.message_details_recipient_conflict_button);
|
||||
unidentifiedDeliveryIcon = itemView.findViewById(R.id.message_details_recipient_ud_indicator);
|
||||
badge = itemView.findViewById(R.id.message_details_recipient_badge);
|
||||
}
|
||||
|
||||
void bind(RecipientDeliveryStatus data) {
|
||||
unidentifiedDeliveryIcon.setVisibility(TextSecurePreferences.isShowUnidentifiedDeliveryIndicatorsEnabled(itemView.getContext()) && data.isUnidentified() ? View.VISIBLE : View.GONE);
|
||||
fromView.setText(data.getRecipient());
|
||||
avatar.setRecipient(data.getRecipient());
|
||||
badge.setBadgeFromRecipient(data.getRecipient());
|
||||
|
||||
if (data.getKeyMismatchFailure() != null) {
|
||||
timestamp.setVisibility(View.GONE);
|
||||
|
|
|
@ -25,13 +25,13 @@
|
|||
|
||||
<org.thoughtcrime.securesms.badges.BadgeImageView
|
||||
android:id="@+id/contact_badge"
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_marginStart="24dp"
|
||||
android:layout_marginTop="24dp"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginTop="22dp"
|
||||
android:contentDescription="@string/ImageView__badge"
|
||||
android:visibility="gone"
|
||||
app:badge_size="small"
|
||||
app:badge_size="medium"
|
||||
app:layout_constraintStart_toStartOf="@id/contact_photo_image"
|
||||
app:layout_constraintTop_toTopOf="@id/contact_photo_image"
|
||||
tools:visibility="visible" />
|
||||
|
|
|
@ -53,6 +53,18 @@
|
|||
|
||||
</FrameLayout>
|
||||
|
||||
<org.thoughtcrime.securesms.badges.BadgeImageView
|
||||
android:id="@+id/badge"
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_alignStart="@id/contact_photo_container"
|
||||
android:layout_alignTop="@id/contact_photo_container"
|
||||
android:layout_marginStart="14dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:visibility="gone"
|
||||
app:badge_size="small"
|
||||
tools:background="@color/red" />
|
||||
|
||||
<org.thoughtcrime.securesms.conversation.ConversationItemBodyBubble
|
||||
android:id="@+id/body_bubble"
|
||||
android:layout_width="wrap_content"
|
||||
|
|
|
@ -53,6 +53,18 @@
|
|||
|
||||
</FrameLayout>
|
||||
|
||||
<org.thoughtcrime.securesms.badges.BadgeImageView
|
||||
android:id="@+id/badge"
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="16dp"
|
||||
android:layout_alignStart="@id/contact_photo_container"
|
||||
android:layout_alignTop="@id/contact_photo_container"
|
||||
android:layout_marginStart="14dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:visibility="gone"
|
||||
app:badge_size="small"
|
||||
tools:background="@color/red" />
|
||||
|
||||
<org.thoughtcrime.securesms.conversation.ConversationItemBodyBubble
|
||||
android:id="@+id/body_bubble"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -106,19 +118,19 @@
|
|||
android:textColor="@color/signal_text_primary"
|
||||
android:textColorLink="@color/signal_text_primary"
|
||||
app:emoji_maxLength="1000"
|
||||
app:scaleEmojis="true"
|
||||
app:measureLastLine="true"
|
||||
app:scaleEmojis="true"
|
||||
tools:text="Mango pickle lorem ipsum" />
|
||||
|
||||
<org.thoughtcrime.securesms.components.ConversationItemFooter
|
||||
android:id="@+id/conversation_item_footer"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
android:layout_marginStart="@dimen/message_bubble_horizontal_padding"
|
||||
android:layout_marginTop="-5dp"
|
||||
android:layout_marginEnd="@dimen/message_bubble_horizontal_padding"
|
||||
android:layout_marginBottom="@dimen/message_bubble_bottom_padding"
|
||||
android:layout_gravity="end"
|
||||
android:alpha="0.7"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
|
|
|
@ -19,6 +19,19 @@
|
|||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:src="@tools:sample/avatars" />
|
||||
|
||||
<org.thoughtcrime.securesms.badges.BadgeImageView
|
||||
android:id="@+id/recipient_badge"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginTop="22dp"
|
||||
android:contentDescription="@string/ImageView__badge"
|
||||
android:visibility="gone"
|
||||
app:badge_size="medium"
|
||||
app:layout_constraintStart_toStartOf="@id/recipient_avatar"
|
||||
app:layout_constraintTop_toTopOf="@id/recipient_avatar"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<androidx.appcompat.widget.AppCompatCheckBox
|
||||
android:id="@+id/recipient_selected"
|
||||
android:layout_width="22dp"
|
||||
|
|
|
@ -30,6 +30,19 @@
|
|||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
|
||||
<org.thoughtcrime.securesms.badges.BadgeImageView
|
||||
android:id="@+id/message_details_recipient_badge"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginTop="22dp"
|
||||
android:contentDescription="@string/ImageView__badge"
|
||||
android:visibility="gone"
|
||||
app:badge_size="medium"
|
||||
app:layout_constraintStart_toStartOf="@id/message_details_recipient_avatar"
|
||||
app:layout_constraintTop_toTopOf="@id/message_details_recipient_avatar"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<org.thoughtcrime.securesms.components.FromTextView
|
||||
android:id="@+id/message_details_recipient_name"
|
||||
android:layout_width="0dp"
|
||||
|
|
Ładowanie…
Reference in New Issue