From 5c4066c2116a27360216ceef28de732e21a1c20d Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Mon, 23 Apr 2018 16:43:53 +0300 Subject: [PATCH 1/4] Add BaseTravelCard --- .../explore/travelcards/BaseTravelCard.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/BaseTravelCard.java diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/BaseTravelCard.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/BaseTravelCard.java new file mode 100644 index 0000000000..2886fc0678 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/BaseTravelCard.java @@ -0,0 +1,33 @@ +package net.osmand.plus.wikivoyage.explore.travelcards; + +import android.graphics.drawable.Drawable; +import android.support.annotation.ColorInt; +import android.support.annotation.ColorRes; +import android.support.annotation.DrawableRes; +import android.support.v4.content.ContextCompat; + +import net.osmand.plus.OsmandApplication; + +public class BaseTravelCard { + + protected OsmandApplication app; + protected boolean nightMode; + + public BaseTravelCard(OsmandApplication app, boolean nightMode) { + this.app = app; + this.nightMode = nightMode; + } + + @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 getIcon(@DrawableRes int drawableRes, @ColorRes int color) { + return app.getIconsCache().getIcon(drawableRes, color); + } +} From ec6f918422294d989da95e2f4d20d8566c9bdfb2 Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Mon, 23 Apr 2018 16:48:24 +0300 Subject: [PATCH 2/4] Create travel card background --- OsmAnd/res/drawable/travel_card_bg.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 OsmAnd/res/drawable/travel_card_bg.xml diff --git a/OsmAnd/res/drawable/travel_card_bg.xml b/OsmAnd/res/drawable/travel_card_bg.xml new file mode 100644 index 0000000000..de280be397 --- /dev/null +++ b/OsmAnd/res/drawable/travel_card_bg.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + From 6d857388169c5ae0c951a8af8bf4caf1bb415bb1 Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Mon, 23 Apr 2018 17:28:11 +0300 Subject: [PATCH 3/4] Improve BaseTravelCard --- .../explore/travelcards/BaseTravelCard.java | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/BaseTravelCard.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/BaseTravelCard.java index 2886fc0678..64021f2102 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/BaseTravelCard.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/BaseTravelCard.java @@ -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); } } From c13b920a60216af6d942cafe6a726fbd8e0aa087 Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Mon, 23 Apr 2018 17:35:34 +0300 Subject: [PATCH 4/4] Change methods in BaseTravelCard --- .../plus/wikivoyage/explore/travelcards/BaseTravelCard.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/BaseTravelCard.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/BaseTravelCard.java index 64021f2102..8b6a14965f 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/BaseTravelCard.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/BaseTravelCard.java @@ -7,7 +7,6 @@ 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; @@ -22,10 +21,10 @@ public abstract class BaseTravelCard { this.nightMode = nightMode; } - public abstract RecyclerView.ViewHolder createViewHolder(@NonNull ViewGroup parent); - public abstract void bindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder); + public abstract int getCardType(); + @ColorInt protected int getResolvedColor(@ColorRes int colorId) { return ContextCompat.getColor(app, colorId);