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(
|
RecipientPreference.Model(
|
||||||
recipient = member.member,
|
recipient = member.member,
|
||||||
isAdmin = member.isAdmin,
|
isAdmin = member.isAdmin,
|
||||||
|
lifecycleOwner = viewLifecycleOwner,
|
||||||
onClick = {
|
onClick = {
|
||||||
RecipientBottomSheetDialogFragment.show(parentFragmentManager, member.member.id, groupState.groupId)
|
RecipientBottomSheetDialogFragment.show(parentFragmentManager, member.member.id, groupState.groupId)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -449,6 +449,7 @@ sealed class ConversationSettingsViewModel(
|
|||||||
internalEvents.onNext(ConversationSettingsEvent.ShowMembersAdded(it.numberOfMembersAdded))
|
internalEvents.onNext(ConversationSettingsEvent.ShowMembersAdded(it.numberOfMembersAdded))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
is GroupAddMembersResult.Failure -> internalEvents.onNext(ConversationSettingsEvent.ShowAddMembersToGroupError(it.reason))
|
is GroupAddMembersResult.Failure -> internalEvents.onNext(ConversationSettingsEvent.ShowAddMembersToGroupError(it.reason))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import android.text.SpannableStringBuilder
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.lifecycle.LifecycleOwner
|
||||||
|
import androidx.lifecycle.Observer
|
||||||
import org.thoughtcrime.securesms.R
|
import org.thoughtcrime.securesms.R
|
||||||
import org.thoughtcrime.securesms.badges.BadgeImageView
|
import org.thoughtcrime.securesms.badges.BadgeImageView
|
||||||
import org.thoughtcrime.securesms.components.AvatarImageView
|
import org.thoughtcrime.securesms.components.AvatarImageView
|
||||||
@@ -28,6 +30,7 @@ object RecipientPreference {
|
|||||||
class Model(
|
class Model(
|
||||||
val recipient: Recipient,
|
val recipient: Recipient,
|
||||||
val isAdmin: Boolean = false,
|
val isAdmin: Boolean = false,
|
||||||
|
val lifecycleOwner: LifecycleOwner? = null,
|
||||||
val onClick: (() -> Unit)? = null
|
val onClick: (() -> Unit)? = null
|
||||||
) : PreferenceModel<Model>() {
|
) : PreferenceModel<Model>() {
|
||||||
override fun areItemsTheSame(newItem: Model): Boolean {
|
override fun areItemsTheSame(newItem: Model): Boolean {
|
||||||
@@ -48,6 +51,14 @@ object RecipientPreference {
|
|||||||
private val admin: View? = itemView.findViewById(R.id.admin)
|
private val admin: View? = itemView.findViewById(R.id.admin)
|
||||||
private val badge: BadgeImageView = itemView.findViewById(R.id.recipient_badge)
|
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) {
|
override fun bind(model: Model) {
|
||||||
if (model.onClick != null) {
|
if (model.onClick != null) {
|
||||||
itemView.setOnClickListener { model.onClick.invoke() }
|
itemView.setOnClickListener { model.onClick.invoke() }
|
||||||
@@ -55,32 +66,58 @@ object RecipientPreference {
|
|||||||
itemView.setOnClickListener(null)
|
itemView.setOnClickListener(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
avatar.setRecipient(model.recipient)
|
if (model.lifecycleOwner != null) {
|
||||||
badge.setBadgeFromRecipient(model.recipient)
|
observeRecipient(model.lifecycleOwner, model.recipient)
|
||||||
name.text = if (model.recipient.isSelf) {
|
} 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)
|
context.getString(R.string.Recipient_you)
|
||||||
} else {
|
} else {
|
||||||
if (model.recipient.isSystemContact) {
|
if (recipient.isSystemContact) {
|
||||||
SpannableStringBuilder(model.recipient.getDisplayName(context)).apply {
|
SpannableStringBuilder(recipient.getDisplayName(context)).apply {
|
||||||
val drawable = ContextUtil.requireDrawable(context, R.drawable.symbol_person_circle_24).apply {
|
val drawable = ContextUtil.requireDrawable(context, R.drawable.symbol_person_circle_24).apply {
|
||||||
setTint(ContextCompat.getColor(context, R.color.signal_colorOnSurface))
|
setTint(ContextCompat.getColor(context, R.color.signal_colorOnSurface))
|
||||||
}
|
}
|
||||||
SpanUtil.appendCenteredImageSpan(this, drawable, 16, 16)
|
SpanUtil.appendCenteredImageSpan(this, drawable, 16, 16)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
model.recipient.getDisplayName(context)
|
recipient.getDisplayName(context)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val aboutText = model.recipient.combinedAboutAndEmoji
|
val aboutText = recipient.combinedAboutAndEmoji
|
||||||
if (aboutText.isNullOrEmpty()) {
|
if (aboutText.isNullOrEmpty()) {
|
||||||
about?.visibility = View.GONE
|
about?.visibility = View.GONE
|
||||||
} else {
|
} else {
|
||||||
about?.text = model.recipient.combinedAboutAndEmoji
|
about?.text = recipient.combinedAboutAndEmoji
|
||||||
about?.visibility = View.VISIBLE
|
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();
|
holder.onDetachedFromWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewRecycled(@NonNull MappingViewHolder<?> holder) {
|
||||||
|
super.onViewRecycled(holder);
|
||||||
|
holder.onViewRecycled();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
|
public void onAttachedToRecyclerView(@NonNull RecyclerView recyclerView) {
|
||||||
super.onAttachedToRecyclerView(recyclerView);
|
super.onAttachedToRecyclerView(recyclerView);
|
||||||
|
|||||||
@@ -35,6 +35,9 @@ public abstract class MappingViewHolder<Model> extends RecyclerView.ViewHolder {
|
|||||||
public void onDetachedFromWindow() {
|
public void onDetachedFromWindow() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void onViewRecycled() {
|
||||||
|
}
|
||||||
|
|
||||||
public abstract void bind(@NonNull Model model);
|
public abstract void bind(@NonNull Model model);
|
||||||
|
|
||||||
public void setPayload(@NonNull List<Object> payload) {
|
public void setPayload(@NonNull List<Object> payload) {
|
||||||
|
|||||||
Reference in New Issue
Block a user