package com.metova.privvy.sample.ui.list;

import com.metova.privvy.sample.R;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

class ListAdapter extends RecyclerView.Adapter<ListAdapter.ListHolder>{

    private List<ListViewModel> numbers;

    private ListClickCallback callback;


    ListAdapter(ListClickCallback callback) {
        this.callback = callback;
    }

    void setNumbers(List<ListViewModel> numbers) {
        this.numbers = numbers;
        notifyDataSetChanged();
    }

    void setListItem(ListViewModel viewModel) {
        this.numbers.set(viewModel.number(), viewModel);
        notifyItemChanged(viewModel.number());
    }

    @Override
    public ListHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View inflatedView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.list_listitem, parent, false);
        inflatedView.setOnClickListener(v -> callback.onItemClicked(v));
        return new ListHolder(inflatedView);
    }

    @Override
    public void onBindViewHolder(ListHolder holder, int position) {
        holder.description.setText(String.valueOf(numbers.get(position).description()));
        holder.value.setText(String.valueOf(numbers.get(position).number()));
    }

    @Override
    public int getItemCount() {
        return numbers.size();
    }

    static class ListHolder extends RecyclerView.ViewHolder {

        TextView description;
        TextView value;

        ListHolder(View itemView) {
            super(itemView);

            description = (TextView) itemView.findViewById(R.id.listitem_descriptor);
            value = (TextView) itemView.findViewById(R.id.listitem_value);
        }
    }

    interface ListClickCallback {
        void onItemClicked(View v);
    }
}

@@ -1021,81 +1021,8 @@
 e);%0A
-        inflatedView.setOnClickListener(v -%3E callback.onItemClicked(v));%0A
     
@@ -1059,16 +1059,26 @@
 atedView
+, callback
 );%0A    %7D
@@ -1573,38 +1573,143 @@
 View
-) %7B%0A            super(itemView
+, ListClickCallback clickCallback) %7B%0A            super(itemView);%0A%0A            itemView.setOnClickListener(clickCallback::onItemClicked
 );%0A%0A
@@ -1879,16 +1879,17 @@
       %7D%0A
+%0A
     %7D%0A%0A 

Move click listener to ViewHolder