mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-23 20:48:43 +00:00
Add support to dynamically update Recipient data in group settings.
This commit is contained in:
@@ -767,6 +767,7 @@ class ConversationSettingsFragment : DSLSettingsFragment(
|
||||
RecipientPreference.Model(
|
||||
recipient = member.member,
|
||||
isAdmin = member.isAdmin,
|
||||
lifecycleOwner = viewLifecycleOwner,
|
||||
onClick = {
|
||||
RecipientBottomSheetDialogFragment.show(parentFragmentManager, member.member.id, groupState.groupId)
|
||||
}
|
||||
|
||||
@@ -449,6 +449,7 @@ sealed class ConversationSettingsViewModel(
|
||||
internalEvents.onNext(ConversationSettingsEvent.ShowMembersAdded(it.numberOfMembersAdded))
|
||||
}
|
||||
}
|
||||
|
||||
is GroupAddMembersResult.Failure -> internalEvents.onNext(ConversationSettingsEvent.ShowAddMembersToGroupError(it.reason))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import android.text.SpannableStringBuilder
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.Observer
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.badges.BadgeImageView
|
||||
import org.thoughtcrime.securesms.components.AvatarImageView
|
||||
@@ -28,6 +30,7 @@ object RecipientPreference {
|
||||
class Model(
|
||||
val recipient: Recipient,
|
||||
val isAdmin: Boolean = false,
|
||||
val lifecycleOwner: LifecycleOwner? = null,
|
||||
val onClick: (() -> Unit)? = null
|
||||
) : PreferenceModel<Model>() {
|
||||
override fun areItemsTheSame(newItem: Model): Boolean {
|
||||
@@ -48,6 +51,14 @@ object RecipientPreference {
|
||||
private val admin: View? = itemView.findViewById(R.id.admin)
|
||||
private val badge: BadgeImageView = itemView.findViewById(R.id.recipient_badge)
|
||||
|
||||
private var recipient: Recipient? = null
|
||||
|
||||
private val recipientObserver = object : Observer<Recipient> {
|
||||
override fun onChanged(recipient: Recipient) {
|
||||
onRecipientChanged(recipient)
|
||||
}
|
||||
}
|
||||
|
||||
override fun bind(model: Model) {
|
||||
if (model.onClick != null) {
|
||||
itemView.setOnClickListener { model.onClick.invoke() }
|
||||
@@ -55,32 +66,58 @@ object RecipientPreference {
|
||||
itemView.setOnClickListener(null)
|
||||
}
|
||||
|
||||
avatar.setRecipient(model.recipient)
|
||||
badge.setBadgeFromRecipient(model.recipient)
|
||||
name.text = if (model.recipient.isSelf) {
|
||||
if (model.lifecycleOwner != null) {
|
||||
observeRecipient(model.lifecycleOwner, model.recipient)
|
||||
} else {
|
||||
onRecipientChanged(model.recipient)
|
||||
}
|
||||
|
||||
admin?.visible = model.isAdmin
|
||||
}
|
||||
|
||||
override fun onViewRecycled() {
|
||||
unbind()
|
||||
}
|
||||
|
||||
private fun onRecipientChanged(recipient: Recipient) {
|
||||
avatar.setRecipient(recipient)
|
||||
badge.setBadgeFromRecipient(recipient)
|
||||
name.text = if (recipient.isSelf) {
|
||||
context.getString(R.string.Recipient_you)
|
||||
} else {
|
||||
if (model.recipient.isSystemContact) {
|
||||
SpannableStringBuilder(model.recipient.getDisplayName(context)).apply {
|
||||
if (recipient.isSystemContact) {
|
||||
SpannableStringBuilder(recipient.getDisplayName(context)).apply {
|
||||
val drawable = ContextUtil.requireDrawable(context, R.drawable.symbol_person_circle_24).apply {
|
||||
setTint(ContextCompat.getColor(context, R.color.signal_colorOnSurface))
|
||||
}
|
||||
SpanUtil.appendCenteredImageSpan(this, drawable, 16, 16)
|
||||
}
|
||||
} else {
|
||||
model.recipient.getDisplayName(context)
|
||||
recipient.getDisplayName(context)
|
||||
}
|
||||
}
|
||||
|
||||
val aboutText = model.recipient.combinedAboutAndEmoji
|
||||
val aboutText = recipient.combinedAboutAndEmoji
|
||||
if (aboutText.isNullOrEmpty()) {
|
||||
about?.visibility = View.GONE
|
||||
} else {
|
||||
about?.text = model.recipient.combinedAboutAndEmoji
|
||||
about?.text = recipient.combinedAboutAndEmoji
|
||||
about?.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
admin?.visible = model.isAdmin
|
||||
private fun observeRecipient(lifecycleOwner: LifecycleOwner?, recipient: Recipient?) {
|
||||
this.recipient?.live()?.liveData?.removeObserver(recipientObserver)
|
||||
|
||||
this.recipient = recipient
|
||||
|
||||
lifecycleOwner?.let {
|
||||
this.recipient?.live()?.liveData?.observe(lifecycleOwner, recipientObserver)
|
||||
}
|
||||
}
|
||||
|
||||
private fun unbind() {
|
||||
observeRecipient(null, null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,6 +71,12 @@ public class MappingAdapter extends ListAdapter<MappingModel<?>, MappingViewHold
|
||||
holder.onDetachedFromWindow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewRecycled(@NonNull MappingViewHolder<?> holder) {
|
||||
super.onViewRecycled(holder);
|
||||
holder.onViewRecycled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
|
||||
super.onAttachedToRecyclerView(recyclerView);
|
||||
|
||||
@@ -35,6 +35,9 @@ public abstract class MappingViewHolder<Model> extends RecyclerView.ViewHolder {
|
||||
public void onDetachedFromWindow() {
|
||||
}
|
||||
|
||||
public void onViewRecycled() {
|
||||
}
|
||||
|
||||
public abstract void bind(@NonNull Model model);
|
||||
|
||||
public void setPayload(@NonNull List<Object> payload) {
|
||||
|
||||
Reference in New Issue
Block a user