@BindingConversion public static String ownerToString(Owner owner) { return(owner.profileImage); }
@BindingConversion public static String convertToString(String s) { return s != null ? s : EMPTY_STRING; }
@BindingConversion public static Integer convertToInteger(String d) { try { return Integer.parseInt(d); } catch (NumberFormatException e) { return 0; } }
@BindingConversion public static String convertToString(boolean d) { return String.valueOf(d); }
@BindingConversion public static ColorDrawable convertColorToDrawable(int color) { return new ColorDrawable(color); } }
@BindingConversion @NonNull public static ViewProvider getViewProviderForStaticLayout(@LayoutRes final int layoutId) { return new ViewProvider() { @Override public int getView(ViewModel vm) { return layoutId; } }; }
@BindingConversion public static String convertDate(Date date) { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); return sdf.format(date); } }
@BindingConversion public static String convertToString(@Nullable Long d) { return d != null? d.toString() : EMPTY_STRING; }
@BindingConversion public static String convertDateToDisplayedText(Date date) { return new SimpleDateFormat("yyyy.MM.dd").format(date); }
@BindingConversion public static ColorDrawable convertColorToDrawable(int color) { Log.d("BindingConversion", "convertColorToDrawable:" + color); return new ColorDrawable(color); }
@BindingConversion public static String changeToYearMonthDay(Date date){ SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd"); if(date==null){ date=new Date(); } return simpleDateFormat.format(date); }
@BindingConversion @Nullable public static Double convertToDouble(@Nullable String d) { return d != null ? Double.parseDouble(d) : null; }
@BindingConversion @Nullable public static <T extends ViewModel> Observable<List<ViewModel>> toListObservable(@Nullable List<T> specificList) { return specificList == null ? null : Observable.just((List<ViewModel>)new ArrayList<ViewModel>(specificList)); }
@BindingConversion @Nullable public static <T extends ViewModel> Observable<List<ViewModel>> toGenericList(@Nullable Observable<List<T>> specificList) { return specificList == null ? null : specificList.map(new Function<List<T>, List<ViewModel>>() { @Override public List<ViewModel> apply(List<T> ts) throws Exception { return new ArrayList<ViewModel>(ts); } }); }
@BindingConversion @InverseMethod("convertToInteger") public static String convertToString(@Nullable Integer d) { return d != null ? d.toString() : EMPTY_STRING; }
@BindingConversion @Nullable public static <U extends ViewModel> io.reactivex.Observable<List<ViewModel>> toV1GenericList(@Nullable Observable<List<U>> specificList) { return specificList == null ? null : RxJavaInterop.toV2Observable(specificList).map(new Function<List<U>, List<ViewModel>>() { @Override public List<ViewModel> apply(List<U> ts) throws Exception { return new ArrayList<ViewModel>(ts); } }); } }
@BindingConversion @InverseMethod("convertToDouble") public static String convertToString(@Nullable Double d) { return d != null? d.toString() : EMPTY_STRING; }
@BindingConversion @InverseMethod("convertToIntegerZeroIsEmpty") public static String convertToStringZeroIsEmpty(@Nullable Integer d) { return d != null && d > 0 ? d.toString() : EMPTY_STRING; }
@BindingConversion public static Integer convertToIntegerZeroIsEmpty(String d) { return convertToInteger(d); }
@BindingConversion public static String convertUserToCharSequence(User user) { return user.getFullName(); }