diff --git a/src/main/java/ru/touchin/roboswag/components/adapters/BindableViewHolder.java b/src/main/java/ru/touchin/roboswag/components/adapters/BindableViewHolder.java index 62901f4..f417c3b 100644 --- a/src/main/java/ru/touchin/roboswag/components/adapters/BindableViewHolder.java +++ b/src/main/java/ru/touchin/roboswag/components/adapters/BindableViewHolder.java @@ -19,8 +19,14 @@ package ru.touchin.roboswag.components.adapters; +import android.graphics.drawable.Drawable; +import android.support.annotation.ColorInt; +import android.support.annotation.ColorRes; +import android.support.annotation.DrawableRes; import android.support.annotation.IdRes; import android.support.annotation.NonNull; +import android.support.annotation.StringRes; +import android.support.v4.content.ContextCompat; import android.support.v7.widget.RecyclerView; import android.view.View; @@ -61,6 +67,57 @@ public class BindableViewHolder extends RecyclerView.ViewHolder implements Lifec return viewById; } + /** + * Return the string value associated with a particular resource ID. It + * will be stripped of any styled text information. + * + * @param resId The resource id to search for data; + * @return String The string data associated with the resource. + */ + @NonNull + public String getString(@StringRes final int resId) { + return itemView.getResources().getString(resId); + } + + /** + * Return the string value associated with a particular resource ID. It + * will be stripped of any styled text information. + * + * @param resId The resource id to search for data; + * @param formatArgs The format arguments that will be used for substitution. + * @return String The string data associated with the resource. + */ + @NonNull + public String getString(@StringRes final int resId, final Object... formatArgs) { + return itemView.getResources().getString(resId, formatArgs); + } + + /** + * Return the color value associated with a particular resource ID. + * Starting in {@link android.os.Build.VERSION_CODES#M}, the returned + * color will be styled for the specified Context's theme. + * + * @param resId The resource id to search for data; + * @return int A single color value in the form 0xAARRGGBB. + */ + @ColorInt + public int getColor(@ColorRes final int resId) { + return ContextCompat.getColor(itemView.getContext(), resId); + } + + /** + * Returns a drawable object associated with a particular resource ID. + * Starting in {@link android.os.Build.VERSION_CODES#LOLLIPOP}, the + * returned drawable will be styled for the specified Context's theme. + * + * @param resId The resource id to search for data; + * @return Drawable An object that can be used to draw this resource. + */ + @NonNull + public Drawable getDrawable(@DrawableRes final int resId) { + return ContextCompat.getDrawable(itemView.getContext(), resId); + } + @NonNull @Override public Subscription bind(@NonNull final Observable observable, @NonNull final Action1 onNextAction) {