Improve BaseTravelCard

This commit is contained in:
Alex Sytnyk 2018-04-23 17:28:11 +03:00
parent ec6f918422
commit 6d85738816

View file

@ -4,11 +4,15 @@ import android.graphics.drawable.Drawable;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
public class BaseTravelCard {
public abstract class BaseTravelCard {
protected OsmandApplication app;
protected boolean nightMode;
@ -18,16 +22,28 @@ public class BaseTravelCard {
this.nightMode = nightMode;
}
public abstract RecyclerView.ViewHolder createViewHolder(@NonNull ViewGroup parent);
public abstract void bindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder);
@ColorInt
protected int getResolvedColor(@ColorRes int colorId) {
return ContextCompat.getColor(app, colorId);
}
protected Drawable getIcon(@DrawableRes int iconId, @ColorRes int colorLightId, @ColorRes int colorDarkId) {
return getIcon(iconId, nightMode ? colorLightId : colorDarkId);
protected Drawable getContentIcon(@DrawableRes int icon) {
return getColoredIcon(icon, R.color.icon_color);
}
protected Drawable getIcon(@DrawableRes int drawableRes, @ColorRes int color) {
return app.getIconsCache().getIcon(drawableRes, color);
protected Drawable getActiveIcon(@DrawableRes int icon) {
return getColoredIcon(icon, R.color.wikivoyage_active_light, R.color.wikivoyage_active_dark);
}
protected Drawable getColoredIcon(@DrawableRes int icon, @ColorRes int colorLight, @ColorRes int colorDark) {
return getColoredIcon(icon, nightMode ? colorDark : colorLight);
}
protected Drawable getColoredIcon(@DrawableRes int icon, @ColorRes int color) {
return app.getIconsCache().getIcon(icon, color);
}
}