From ad514f2d2900fe90659ceac01d4fbffd3d13a52c Mon Sep 17 00:00:00 2001 From: Chumva Date: Tue, 24 Apr 2018 14:08:05 +0300 Subject: [PATCH] add holders for cards --- OsmAnd/res/layout/bottom_buttons.xml | 55 ------------------- .../res/layout/wikivoyage_open_beta_card.xml | 2 +- .../layout/wikivoyage_start_editing_card.xml | 2 +- .../explore/ExploreTabFragment.java | 1 - .../travelcards/OpenBetaTravelCard.java | 46 ++++++++++------ .../travelcards/StartEditingTravelCard.java | 53 +++++++++++------- 6 files changed, 64 insertions(+), 95 deletions(-) delete mode 100644 OsmAnd/res/layout/bottom_buttons.xml diff --git a/OsmAnd/res/layout/bottom_buttons.xml b/OsmAnd/res/layout/bottom_buttons.xml deleted file mode 100644 index ad2e474496..0000000000 --- a/OsmAnd/res/layout/bottom_buttons.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/OsmAnd/res/layout/wikivoyage_open_beta_card.xml b/OsmAnd/res/layout/wikivoyage_open_beta_card.xml index 93b709dd03..5ba3eefd55 100644 --- a/OsmAnd/res/layout/wikivoyage_open_beta_card.xml +++ b/OsmAnd/res/layout/wikivoyage_open_beta_card.xml @@ -52,7 +52,7 @@ android:background="?attr/wikivoyage_card_divider_color" /> items = new ArrayList<>(); BaseTravelCard openBetaTravelCard = new OpenBetaTravelCard(app, nightMode, getFragmentManager()); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/OpenBetaTravelCard.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/OpenBetaTravelCard.java index 86aa1a1247..44ac5ba3f3 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/OpenBetaTravelCard.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/OpenBetaTravelCard.java @@ -3,8 +3,6 @@ package net.osmand.plus.wikivoyage.explore.travelcards; import android.support.annotation.NonNull; import android.support.v4.app.FragmentManager; import android.support.v7.widget.RecyclerView; -import android.view.ContextThemeWrapper; -import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; import android.widget.TextView; @@ -22,23 +20,37 @@ public class OpenBetaTravelCard extends BaseTravelCard { this.fragmentManager = fragmentManager; } - @Override public void bindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder) { - final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; - View view = LayoutInflater.from(new ContextThemeWrapper(app, themeRes)) - .inflate(R.layout.wikivoyage_open_beta_card, null, false); - ImageView imageView = (ImageView) view.findViewById(R.id.background_image); - imageView.setImageResource(R.drawable.img_help_wikivoyage_articles); - ((TextView) view.findViewById(R.id.title)).setText(R.string.welcome_to_open_beta); - ((TextView) view.findViewById(R.id.description)).setText(R.string.welcome_to_open_beta_description); - ((TextView) view.findViewById(R.id.left_bottom_button_text)).setText(R.string.get_unlimited_access); - view.findViewById(R.id.left_bottom_button).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - ChoosePlanDialogFragment.showFreeVersionInstance(fragmentManager); - } - }); + if (viewHolder instanceof OpenBetaTravelVH) { + final OpenBetaTravelVH holder = (OpenBetaTravelVH) viewHolder; + holder.title.setText(R.string.welcome_to_open_beta); + holder.description.setText(R.string.welcome_to_open_beta_description); + holder.backgroundImage.setImageResource(R.drawable.img_help_wikivoyage_articles); + holder.button.setText(R.string.get_unlimited_access); + holder.button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + ChoosePlanDialogFragment.showFreeVersionInstance(fragmentManager); + } + }); + } + } + + class OpenBetaTravelVH extends RecyclerView.ViewHolder { + + final TextView title; + final TextView description; + final TextView button; + final ImageView backgroundImage; + + OpenBetaTravelVH(final View itemView) { + super(itemView); + title = (TextView) itemView.findViewById(R.id.title); + description = (TextView) itemView.findViewById(R.id.description); + button = (TextView) itemView.findViewById(R.id.bottom_button_text); + backgroundImage = (ImageView) itemView.findViewById(R.id.background_image); + } } @Override diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/StartEditingTravelCard.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/StartEditingTravelCard.java index 44082c160b..c8ef49aa16 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/StartEditingTravelCard.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/StartEditingTravelCard.java @@ -5,8 +5,6 @@ import android.support.annotation.NonNull; import android.support.customtabs.CustomTabsIntent; import android.support.v4.content.ContextCompat; import android.support.v7.widget.RecyclerView; -import android.view.ContextThemeWrapper; -import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; import android.widget.TextView; @@ -22,24 +20,39 @@ public class StartEditingTravelCard extends BaseTravelCard { @Override public void bindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder) { - final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; - View view = LayoutInflater.from(new ContextThemeWrapper(app, themeRes)) - .inflate(R.layout.wikivoyage_open_beta_card, null, false); - ImageView imageView = (ImageView) view.findViewById(R.id.background_image); - imageView.setImageResource(R.drawable.img_help_wikivoyage_articles); - ((TextView) view.findViewById(R.id.title)).setText(R.string.welcome_to_open_beta); - ((TextView) view.findViewById(R.id.description)).setText(R.string.welcome_to_open_beta_description); - ((TextView) view.findViewById(R.id.left_bottom_button_text)).setText(R.string.get_unlimited_access); - view.findViewById(R.id.left_bottom_button).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder() - .setToolbarColor(ContextCompat.getColor(app, nightMode ? R.color.actionbar_dark_color : R.color.actionbar_light_color)) - .build(); - String text = "https://" + app.getLanguage().toLowerCase() + ".m.wikivoyage.org"; - customTabsIntent.launchUrl(app, Uri.parse(text)); - } - }); + if (viewHolder instanceof OpenBetaTravelVH) { + final OpenBetaTravelVH holder = (OpenBetaTravelVH) viewHolder; + holder.title.setText(R.string.start_editing_card_image_text); + holder.description.setText(R.string.start_editing_card_description); + holder.backgroundImage.setImageResource(R.drawable.img_help_wikivoyage_contribute); + holder.button.setText(R.string.start_editing); + holder.button.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder() + .setToolbarColor(ContextCompat.getColor(app, nightMode ? R.color.actionbar_dark_color : R.color.actionbar_light_color)) + .build(); + String text = "https://" + app.getLanguage().toLowerCase() + ".m.wikivoyage.org"; + customTabsIntent.launchUrl(app, Uri.parse(text)); + } + }); + } + } + + class OpenBetaTravelVH extends RecyclerView.ViewHolder { + + final TextView title; + final TextView description; + final TextView button; + final ImageView backgroundImage; + + OpenBetaTravelVH(final View itemView) { + super(itemView); + title = (TextView) itemView.findViewById(R.id.title); + description = (TextView) itemView.findViewById(R.id.description); + button = (TextView) itemView.findViewById(R.id.bottom_button_text); + backgroundImage = (ImageView) itemView.findViewById(R.id.background_image); + } } @Override