mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-26 03:40:56 +01:00
Add foundational UX and state support for Group Calling.
This commit is contained in:
committed by
Greyson Parrelli
parent
7baf8052a2
commit
dc4faf57cb
@@ -113,20 +113,20 @@ public class MappingAdapter extends ListAdapter<MappingModel<?>, MappingViewHold
|
||||
}
|
||||
|
||||
public interface Factory<T extends MappingModel<T>> {
|
||||
@NonNull MappingViewHolder<T> createViewHolder(ViewGroup parent);
|
||||
@NonNull MappingViewHolder<T> createViewHolder(@NonNull ViewGroup parent);
|
||||
}
|
||||
|
||||
public static class LayoutFactory<T extends MappingModel<T>> implements Factory<T> {
|
||||
private Function<View, MappingViewHolder<T>> creator;
|
||||
private final int layout;
|
||||
|
||||
public LayoutFactory(Function<View, MappingViewHolder<T>> creator, @LayoutRes int layout) {
|
||||
public LayoutFactory(@NonNull Function<View, MappingViewHolder<T>> creator, @LayoutRes int layout) {
|
||||
this.creator = creator;
|
||||
this.layout = layout;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull MappingViewHolder<T> createViewHolder(ViewGroup parent) {
|
||||
public @NonNull MappingViewHolder<T> createViewHolder(@NonNull ViewGroup parent) {
|
||||
return creator.apply(LayoutInflater.from(parent.getContext()).inflate(layout, parent, false));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,5 +23,9 @@ public abstract class MappingViewHolder<Model extends MappingModel<Model>> exten
|
||||
return itemView.findViewById(id);
|
||||
}
|
||||
|
||||
public @NonNull Context getContext() {
|
||||
return itemView.getContext();
|
||||
}
|
||||
|
||||
public abstract void bind(@NonNull Model model);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.thoughtcrime.securesms.util.viewholders;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.util.MappingModel;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class RecipientMappingModel<T extends RecipientMappingModel<T>> implements MappingModel<T> {
|
||||
|
||||
public abstract @NonNull Recipient getRecipient();
|
||||
|
||||
public @NonNull String getName(@NonNull Context context) {
|
||||
return getRecipient().getDisplayName(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areItemsTheSame(@NonNull T newItem) {
|
||||
return getRecipient().getId().equals(newItem.getRecipient().getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areContentsTheSame(@NonNull T newItem) {
|
||||
Context context = ApplicationDependencies.getApplication();
|
||||
return getName(context).equals(newItem.getName(context)) && Objects.equals(getRecipient().getContactPhoto(), newItem.getRecipient().getContactPhoto());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package org.thoughtcrime.securesms.util.viewholders;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.components.AvatarImageView;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.util.MappingAdapter;
|
||||
import org.thoughtcrime.securesms.util.MappingViewHolder;
|
||||
|
||||
public class RecipientViewHolder<T extends RecipientMappingModel<T>> extends MappingViewHolder<T> {
|
||||
|
||||
protected final @Nullable AvatarImageView avatar;
|
||||
protected final @Nullable TextView name;
|
||||
protected final @Nullable EventListener<T> eventListener;
|
||||
|
||||
public RecipientViewHolder(@NonNull View itemView, @Nullable EventListener<T> eventListener) {
|
||||
super(itemView);
|
||||
this.eventListener = eventListener;
|
||||
|
||||
avatar = findViewById(R.id.recipient_view_avatar);
|
||||
name = findViewById(R.id.recipient_view_name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(@NonNull T model) {
|
||||
if (avatar != null) {
|
||||
avatar.setRecipient(model.getRecipient());
|
||||
}
|
||||
|
||||
if (name != null) {
|
||||
name.setText(model.getName(context));
|
||||
}
|
||||
|
||||
if (eventListener != null) {
|
||||
itemView.setOnClickListener(v -> eventListener.onModelClick(model));
|
||||
} else {
|
||||
itemView.setOnClickListener(null);
|
||||
}
|
||||
}
|
||||
|
||||
public static @NonNull <T extends RecipientMappingModel<T>> MappingAdapter.Factory<T> createFactory(@LayoutRes int layout, @Nullable EventListener<T> listener) {
|
||||
return new MappingAdapter.LayoutFactory<>(view -> new RecipientViewHolder<>(view, listener), layout);
|
||||
}
|
||||
|
||||
public interface EventListener<T extends RecipientMappingModel<T>> {
|
||||
default void onModelClick(@NonNull T model) {
|
||||
onClick(model.getRecipient());
|
||||
}
|
||||
|
||||
void onClick(@NonNull Recipient recipient);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user