@BindingConversion public static String convertQuantityToString(Quantity quantity) { Log.d("Quantity", "convert quantity to string " + quantity); if (quantity == null) { return null; } return quantity.toString(); }
@BindingConversion public static Quantity convertStringToQuantity(String string) { Log.d("Quantity", "convert string to quantity " + string); if (string == null) { return Quantity.ZERO; } return new Quantity(string); }
/** * Allows to pass additional parameter (click listener) * to adapter created by {@link me.tatarka.bindingcollectionadapter.BindingRecyclerViewAdapters} * * @param clickListener click listener to be bound to all items. * @return */ @BindingConversion public static BindingRecyclerViewAdapterFactory toRecyclerViewAdapterFactory(final CategoryClickListener clickListener) { return new BindingRecyclerViewAdapterFactory() { public <T> BindingRecyclerViewAdapter<T> create(RecyclerView recyclerView, ItemViewArg<T> arg) { return new CategoriesRecyclerViewAdapter<>(arg, clickListener); } }; }
@BindingConversion public static String convertDate(Date date) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); return sdf.format(date); }
@BindingConversion public static ItemView resToResHolder(@LayoutRes int layoutRes) { int defaultBindingVariable = BR.item; return ItemView.of(defaultBindingVariable, layoutRes); }
@BindingConversion public static ColorDrawable convertColorToDrawable(int color) { return color != 0 ? new ColorDrawable(color) : null; }
@BindingConversion public static int convertBooleanToVisibility(boolean visible) { return visible ? View.VISIBLE : View.GONE; }
@BindingConversion public static String dateToString(Date date) { return Utils.formatDate(date); }
@BindingConversion public static String intToString(int integer) { return integer == 0 ? "" : String.valueOf(integer); }
@BindingConversion public static String doubleToString(double d) { return d == 0 ? "" : String.valueOf(d); }
@BindingConversion public static ColorDrawable convertColorToDrawable(int color) { return new ColorDrawable(color); }
@BindingConversion public static ColorDrawable convertColorToDrawable(int color) { Log.d("BindingConversion", "convertColorToDrawable:" + color); return new ColorDrawable(color); }
@BindingConversion public static int convertBoolToVisibility(boolean visible) { return visible ? View.VISIBLE : View.GONE; }
@BindingConversion public static String convertToString(ObservableString s) { return s.get(); }
@BindingConversion public static int booleanToVisibility(boolean visible) { return visible ? View.VISIBLE : View.GONE; }
@BindingConversion public static int convertBooleanToInt(Boolean value) { return (value != null && value) ? View.VISIBLE : View.GONE; }
@BindingConversion public static <T> ItemBinding<T> toItemBinding(OnItemBind<T> onItemBind) { return ItemBinding.of(onItemBind); }
@BindingConversion public static Typeface convertStringToFace(String fontName) { try { return Typeface.create(fontName, 0); } catch (Exception e) { return null; } }