diff options
Diffstat (limited to 'app/src/main/java/com/wireguard/android/databinding/ObservableKeyedRecyclerViewAdapter.java')
-rw-r--r-- | app/src/main/java/com/wireguard/android/databinding/ObservableKeyedRecyclerViewAdapter.java | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/app/src/main/java/com/wireguard/android/databinding/ObservableKeyedRecyclerViewAdapter.java b/app/src/main/java/com/wireguard/android/databinding/ObservableKeyedRecyclerViewAdapter.java index 4a5ac3d2..79168e48 100644 --- a/app/src/main/java/com/wireguard/android/databinding/ObservableKeyedRecyclerViewAdapter.java +++ b/app/src/main/java/com/wireguard/android/databinding/ObservableKeyedRecyclerViewAdapter.java @@ -14,6 +14,7 @@ import android.support.annotation.NonNull; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView.Adapter; import android.view.LayoutInflater; +import android.view.View; import android.view.ViewGroup; import com.wireguard.android.BR; @@ -26,12 +27,13 @@ import java.lang.ref.WeakReference; * A generic {@code RecyclerView.Adapter} backed by a {@code ObservableKeyedList}. */ -class ObservableKeyedRecyclerViewAdapter<K, E extends Keyed<? extends K>> extends Adapter<ObservableKeyedRecyclerViewAdapter.ViewHolder> { +public class ObservableKeyedRecyclerViewAdapter<K, E extends Keyed<? extends K>> extends Adapter<ObservableKeyedRecyclerViewAdapter.ViewHolder> { private final OnListChangedCallback<E> callback = new OnListChangedCallback<>(this); private final int layoutId; private final LayoutInflater layoutInflater; private ObservableKeyedList<K, E> list; + private RowConfigurationHandler rowConfigurationHandler; ObservableKeyedRecyclerViewAdapter(final Context context, final int layoutId, final ObservableKeyedList<K, E> list) { @@ -67,12 +69,17 @@ class ObservableKeyedRecyclerViewAdapter<K, E extends Keyed<? extends K>> extend return new ViewHolder(DataBindingUtil.inflate(layoutInflater, layoutId, parent, false)); } + @SuppressWarnings("unchecked") @Override public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) { holder.binding.setVariable(BR.collection, list); holder.binding.setVariable(BR.key, getKey(position)); holder.binding.setVariable(BR.item, getItem(position)); holder.binding.executePendingBindings(); + + if (rowConfigurationHandler != null) { + rowConfigurationHandler.onConfigureRow(holder.binding.getRoot(), getItem(position), position); + } } void setList(final ObservableKeyedList<K, E> newList) { @@ -85,6 +92,10 @@ class ObservableKeyedRecyclerViewAdapter<K, E extends Keyed<? extends K>> extend notifyDataSetChanged(); } + void setRowConfigurationHandler(final RowConfigurationHandler rowConfigurationHandler) { + this.rowConfigurationHandler = rowConfigurationHandler; + } + private static final class OnListChangedCallback<E extends Keyed<?>> extends ObservableList.OnListChangedCallback<ObservableList<E>> { @@ -138,4 +149,8 @@ class ObservableKeyedRecyclerViewAdapter<K, E extends Keyed<? extends K>> extend } } + public interface RowConfigurationHandler<T> { + void onConfigureRow(View view, T item, int position); + } + } |