package com.wireguard.android; import android.databinding.BindingAdapter; import android.databinding.ObservableArrayMap; import android.databinding.ObservableList; import android.widget.ListView; /** * Static methods for use by generated code in the Android data binding library. */ public final class BindingAdapters { @BindingAdapter({"items", "layout"}) public static void arrayMapBinding(ListView view, ObservableArrayMap oldMap, int oldLayoutId, ObservableArrayMap newMap, int newLayoutId) { // Remove any existing binding when there is no new map. if (newMap == null) { view.setAdapter(null); return; } // The ListAdapter interface is not generic, so this cannot be checked. @SuppressWarnings("unchecked") ObservableArrayMapAdapter adapter = (ObservableArrayMapAdapter) view.getAdapter(); // If the layout changes, any existing adapter must be replaced. if (newLayoutId != oldLayoutId) adapter = null; // Add a new binding if there was none, or if it must be replaced due to a layout change. if (adapter == null) { adapter = new ObservableArrayMapAdapter<>(view.getContext(), newLayoutId, newMap); view.setAdapter(adapter); } else if (newMap != oldMap) { // Changing the list only requires modifying the existing adapter. adapter.setMap(newMap); } } @BindingAdapter({"items", "layout"}) public static void listBinding(ListView view, ObservableList oldList, int oldLayoutId, ObservableList newList, int newLayoutId) { // Remove any existing binding when there is no new list. if (newList == null) { view.setAdapter(null); return; } // The ListAdapter interface is not generic, so this cannot be checked. @SuppressWarnings("unchecked") ObservableListAdapter adapter = (ObservableListAdapter) view.getAdapter(); // If the layout changes, any existing adapter must be replaced. if (newLayoutId != oldLayoutId) adapter = null; // Add a new binding if there was none, or if it must be replaced due to a layout change. if (adapter == null) { adapter = new ObservableListAdapter<>(view.getContext(), newLayoutId, newList); view.setAdapter(adapter); } else if (newList != oldList) { // Changing the list only requires modifying the existing adapter. adapter.setList(newList); } } private BindingAdapters() { } }