Search in sources :

Example 1 with BindableConversationItem

use of org.thoughtcrime.securesms.BindableConversationItem in project Signal-Android by WhisperSystems.

the class ConversationAdapter method onCreateViewHolder.

@SuppressLint("ClickableViewAccessibility")
@Override
@NonNull
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    switch(viewType) {
        case MESSAGE_TYPE_INCOMING_TEXT:
        case MESSAGE_TYPE_INCOMING_MULTIMEDIA:
        case MESSAGE_TYPE_OUTGOING_TEXT:
        case MESSAGE_TYPE_OUTGOING_MULTIMEDIA:
        case MESSAGE_TYPE_UPDATE:
            View itemView = CachedInflater.from(parent.getContext()).inflate(getLayoutForViewType(viewType), parent, false);
            BindableConversationItem bindable = (BindableConversationItem) itemView;
            itemView.setOnClickListener((v) -> {
                if (clickListener != null) {
                    clickListener.onItemClick(bindable.getMultiselectPartForLatestTouch());
                }
            });
            itemView.setOnLongClickListener((v) -> {
                if (clickListener != null) {
                    clickListener.onItemLongClick(itemView, bindable.getMultiselectPartForLatestTouch());
                }
                return true;
            });
            bindable.setEventListener(clickListener);
            return new ConversationViewHolder(itemView);
        case MESSAGE_TYPE_PLACEHOLDER:
            View v = new FrameLayout(parent.getContext());
            v.setLayoutParams(new FrameLayout.LayoutParams(1, ViewUtil.dpToPx(100)));
            return new PlaceholderViewHolder(v);
        case MESSAGE_TYPE_HEADER:
            return new HeaderViewHolder(CachedInflater.from(parent.getContext()).inflate(R.layout.cursor_adapter_header_footer_view, parent, false));
        case MESSAGE_TYPE_FOOTER:
            return new FooterViewHolder(CachedInflater.from(parent.getContext()).inflate(R.layout.cursor_adapter_header_footer_view, parent, false));
        default:
            throw new IllegalStateException("Cannot create viewholder for type: " + viewType);
    }
}
Also used : BindableConversationItem(org.thoughtcrime.securesms.BindableConversationItem) FrameLayout(android.widget.FrameLayout) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) NonNull(androidx.annotation.NonNull) SuppressLint(android.annotation.SuppressLint)

Example 2 with BindableConversationItem

use of org.thoughtcrime.securesms.BindableConversationItem in project Signal-Android by signalapp.

the class ConversationAdapter method onCreateViewHolder.

@SuppressLint("ClickableViewAccessibility")
@Override
@NonNull
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    switch(viewType) {
        case MESSAGE_TYPE_INCOMING_TEXT:
        case MESSAGE_TYPE_INCOMING_MULTIMEDIA:
        case MESSAGE_TYPE_OUTGOING_TEXT:
        case MESSAGE_TYPE_OUTGOING_MULTIMEDIA:
        case MESSAGE_TYPE_UPDATE:
            View itemView = CachedInflater.from(parent.getContext()).inflate(getLayoutForViewType(viewType), parent, false);
            BindableConversationItem bindable = (BindableConversationItem) itemView;
            itemView.setOnClickListener((v) -> {
                if (clickListener != null) {
                    clickListener.onItemClick(bindable.getMultiselectPartForLatestTouch());
                }
            });
            itemView.setOnLongClickListener((v) -> {
                if (clickListener != null) {
                    clickListener.onItemLongClick(itemView, bindable.getMultiselectPartForLatestTouch());
                }
                return true;
            });
            bindable.setEventListener(clickListener);
            return new ConversationViewHolder(itemView);
        case MESSAGE_TYPE_PLACEHOLDER:
            View v = new FrameLayout(parent.getContext());
            v.setLayoutParams(new FrameLayout.LayoutParams(1, ViewUtil.dpToPx(100)));
            return new PlaceholderViewHolder(v);
        case MESSAGE_TYPE_HEADER:
            return new HeaderViewHolder(CachedInflater.from(parent.getContext()).inflate(R.layout.cursor_adapter_header_footer_view, parent, false));
        case MESSAGE_TYPE_FOOTER:
            return new FooterViewHolder(CachedInflater.from(parent.getContext()).inflate(R.layout.cursor_adapter_header_footer_view, parent, false));
        default:
            throw new IllegalStateException("Cannot create viewholder for type: " + viewType);
    }
}
Also used : BindableConversationItem(org.thoughtcrime.securesms.BindableConversationItem) FrameLayout(android.widget.FrameLayout) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) NonNull(androidx.annotation.NonNull) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)2 View (android.view.View)2 FrameLayout (android.widget.FrameLayout)2 TextView (android.widget.TextView)2 NonNull (androidx.annotation.NonNull)2 RecyclerView (androidx.recyclerview.widget.RecyclerView)2 BindableConversationItem (org.thoughtcrime.securesms.BindableConversationItem)2