delete builder for cards
This commit is contained in:
parent
f6e554bbf2
commit
6ae461ff20
6 changed files with 243 additions and 216 deletions
|
@ -42,7 +42,7 @@
|
|||
android:layout_marginLeft="@dimen/list_content_padding"
|
||||
android:layout_marginRight="@dimen/list_content_padding"
|
||||
android:layout_marginStart="@dimen/list_content_padding"
|
||||
tools:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard." />
|
||||
tools:text="@string/welcome_to_open_beta_description" />
|
||||
|
||||
<View
|
||||
android:id="@+id/bottom_divider"
|
|
@ -35,8 +35,8 @@
|
|||
android:layout_marginRight="@dimen/list_content_padding"
|
||||
android:layout_marginStart="@dimen/list_content_padding"
|
||||
android:layout_marginTop="42dp"
|
||||
android:text="@string/start_editing_card_image_text"
|
||||
android:textColor="@color/primary_text_dark" />
|
||||
android:textColor="@color/primary_text_dark"
|
||||
tools:text="@string/start_editing_card_image_text" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
|
@ -51,7 +51,7 @@
|
|||
android:layout_marginRight="@dimen/list_content_padding"
|
||||
android:layout_marginStart="@dimen/list_content_padding"
|
||||
android:layout_marginTop="@dimen/list_content_padding"
|
||||
android:text="@string/start_editing_card_description" />
|
||||
tools:text="@string/start_editing_card_description" />
|
||||
|
||||
<View
|
||||
android:id="@+id/bottom_divider"
|
||||
|
|
|
@ -12,6 +12,8 @@ import net.osmand.plus.OsmandApplication;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.BaseOsmAndFragment;
|
||||
import net.osmand.plus.wikivoyage.explore.travelcards.BaseTravelCard;
|
||||
import net.osmand.plus.wikivoyage.explore.travelcards.OpenBetaTravelCard;
|
||||
import net.osmand.plus.wikivoyage.explore.travelcards.StartEditingTravelCard;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
@ -28,22 +30,10 @@ public class ExploreTabFragment extends BaseOsmAndFragment {
|
|||
LinearLayout linearLayout = (LinearLayout) mainView.findViewById(R.id.cards_list);
|
||||
ArrayList<BaseTravelCard> items = new ArrayList<>();
|
||||
|
||||
BaseTravelCard openBeta = new BaseTravelCard.Builder()
|
||||
.setLayoutId(R.layout.wikivoyage_base_card)
|
||||
.setBackgroundImage(getIconsCache().getIcon(R.drawable.img_help_wikivoyage_articles))
|
||||
.setLeftButtonText(getString(R.string.get_unlimited_access))
|
||||
.setDescription(getString(R.string.welcome_to_open_beta_description))
|
||||
.setTitle(getString(R.string.welcome_to_open_beta))
|
||||
.create();
|
||||
items.add(openBeta);
|
||||
|
||||
BaseTravelCard startEditing = new BaseTravelCard.Builder()
|
||||
.setLayoutId(R.layout.wikivoyage_start_editing_card)
|
||||
.setBackgroundImage(getIconsCache().getIcon(R.drawable.img_help_wikivoyage_contribute))
|
||||
.setLeftButtonText(getString(R.string.start_editing))
|
||||
.setDescription(getString(R.string.start_editing_card_description))
|
||||
.create();
|
||||
items.add(startEditing);
|
||||
BaseTravelCard openBetaTravelCard = new OpenBetaTravelCard(getMyActivity());
|
||||
BaseTravelCard startEditingTravelCard = new StartEditingTravelCard(getMyActivity());
|
||||
items.add(openBetaTravelCard);
|
||||
items.add(startEditingTravelCard);
|
||||
|
||||
for (BaseTravelCard item : items) {
|
||||
item.inflate(app, linearLayout, nightMode);
|
||||
|
|
|
@ -3,231 +3,82 @@ 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.annotation.LayoutRes;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.OsmandActionBarActivity;
|
||||
|
||||
public class BaseTravelCard {
|
||||
public abstract class BaseTravelCard {
|
||||
|
||||
private static final int INVALID_POSITION = -1;
|
||||
private static final int DEFAULT_VALUE = -1;
|
||||
protected static final int INVALID_POSITION = -1;
|
||||
protected static final int DEFAULT_VALUE = -1;
|
||||
|
||||
protected View view;
|
||||
private View.OnClickListener onLeftButtonClickListener;
|
||||
private View.OnClickListener onRightButtonClickListener;
|
||||
protected OsmandActionBarActivity activity;
|
||||
|
||||
@LayoutRes
|
||||
protected int layoutId;
|
||||
@ColorRes
|
||||
protected int bottomDividerColorId;
|
||||
protected int position = INVALID_POSITION;
|
||||
|
||||
private Object tag;
|
||||
private OsmandApplication app;
|
||||
public abstract void inflate(OsmandApplication app, ViewGroup container, boolean nightMode);
|
||||
|
||||
protected Drawable image;
|
||||
protected String rightBottomButtonText;
|
||||
protected String leftBottomButtonText;
|
||||
protected String description;
|
||||
protected String title;
|
||||
|
||||
protected int position;
|
||||
|
||||
public View getView() {
|
||||
return view;
|
||||
}
|
||||
|
||||
public Object getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public BaseTravelCard(View view,
|
||||
@LayoutRes int layoutId,
|
||||
Object tag,
|
||||
Drawable image,
|
||||
View.OnClickListener onLeftButtonClickListener,
|
||||
View.OnClickListener onRightButtonClickListener,
|
||||
int position,
|
||||
String rightBottomButtonText,
|
||||
String leftBottomButtonText,
|
||||
@ColorRes int bottomDividerColorId,
|
||||
String description,
|
||||
String title) {
|
||||
this.view = view;
|
||||
this.layoutId = layoutId;
|
||||
this.image = image;
|
||||
this.tag = tag;
|
||||
this.onLeftButtonClickListener = onLeftButtonClickListener;
|
||||
this.onRightButtonClickListener = onRightButtonClickListener;
|
||||
this.position = position;
|
||||
this.rightBottomButtonText = rightBottomButtonText;
|
||||
this.leftBottomButtonText = leftBottomButtonText;
|
||||
this.bottomDividerColorId = bottomDividerColorId;
|
||||
this.description = description;
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
protected BaseTravelCard() {
|
||||
|
||||
}
|
||||
|
||||
public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) {
|
||||
View view = getView(app, container, nightMode);
|
||||
if (image != null) {
|
||||
ImageView imageView = (ImageView) view.findViewById(R.id.background_image);
|
||||
imageView.setImageDrawable(image);
|
||||
}
|
||||
if (title != null) {
|
||||
((TextView) view.findViewById(R.id.title)).setText(title);
|
||||
}
|
||||
if (description != null) {
|
||||
((TextView) view.findViewById(R.id.description)).setText(description);
|
||||
}
|
||||
if (bottomDividerColorId != DEFAULT_VALUE) {
|
||||
view.findViewById(R.id.bottom_divider).setBackgroundColor(getResolvedColor(bottomDividerColorId));
|
||||
}
|
||||
if (leftBottomButtonText != null) {
|
||||
view.findViewById(R.id.left_bottom_button).setOnClickListener(onLeftButtonClickListener);
|
||||
((TextView) view.findViewById(R.id.left_bottom_button_text)).setText(leftBottomButtonText);
|
||||
}
|
||||
if (rightBottomButtonText != null) {
|
||||
|
||||
if (bottomDividerColorId != DEFAULT_VALUE) {
|
||||
View buttonsDivider = view.findViewById(R.id.bottom_buttons_divider);
|
||||
buttonsDivider.setVisibility(View.VISIBLE);
|
||||
buttonsDivider.setBackgroundColor(getResolvedColor(bottomDividerColorId));
|
||||
}
|
||||
|
||||
View rightButton = view.findViewById(R.id.right_bottom_button);
|
||||
rightButton.setVisibility(View.VISIBLE);
|
||||
rightButton.setOnClickListener(onRightButtonClickListener);
|
||||
((TextView) rightButton.findViewById(R.id.right_bottom_button_text)).setText(rightBottomButtonText);
|
||||
}
|
||||
if (position != INVALID_POSITION) {
|
||||
container.addView(view, position);
|
||||
} else {
|
||||
container.addView(view);
|
||||
}
|
||||
}
|
||||
|
||||
private View getView(OsmandApplication app, ViewGroup parent, boolean nightMode) {
|
||||
if (view != null) {
|
||||
return view;
|
||||
}
|
||||
this.app = app;
|
||||
if (layoutId != DEFAULT_VALUE) {
|
||||
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
|
||||
return view = LayoutInflater.from(new ContextThemeWrapper(app, themeRes))
|
||||
.inflate(layoutId, parent, false);
|
||||
}
|
||||
throw new RuntimeException("BaseTravelCard must have specified view or layoutId.");
|
||||
}
|
||||
protected abstract View getView(OsmandApplication app, ViewGroup parent, boolean nightMode);
|
||||
|
||||
@ColorInt
|
||||
protected int getResolvedColor(@ColorRes int colorId) {
|
||||
return ContextCompat.getColor(app, colorId);
|
||||
return ContextCompat.getColor(activity, colorId);
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
protected Drawable getIcon(@DrawableRes int drawableRes, @ColorRes int color) {
|
||||
return activity.getMyApplication().getIconsCache().getIcon(drawableRes, color);
|
||||
}
|
||||
|
||||
protected View customView;
|
||||
protected View.OnClickListener onLeftButtonClickListener;
|
||||
protected View.OnClickListener onRightButtonClickListener;
|
||||
protected Drawable getBackgroundIcon(@DrawableRes int drawableRes) {
|
||||
return activity.getMyApplication().getIconsCache().getIcon(drawableRes);
|
||||
}
|
||||
|
||||
@LayoutRes
|
||||
protected int layoutId = DEFAULT_VALUE;
|
||||
@ColorRes
|
||||
protected int dividerColorId = DEFAULT_VALUE;
|
||||
@StringRes
|
||||
protected int getTitleId() {
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
protected Drawable image;
|
||||
protected String rightBottomButtonText;
|
||||
protected String leftBottomButtonText;
|
||||
protected String description;
|
||||
protected String title;
|
||||
protected Object tag;
|
||||
@StringRes
|
||||
protected int getDescriptionId() {
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
protected int position = INVALID_POSITION;
|
||||
@StringRes
|
||||
protected int getLeftButtonTextId() {
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
public Builder setCustomView(View customView) {
|
||||
this.customView = customView;
|
||||
return this;
|
||||
}
|
||||
protected void onLeftButtonClickAction() {
|
||||
|
||||
public Builder setTag(Object tag) {
|
||||
this.tag = tag;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public Builder setLayoutId(@LayoutRes int layoutId) {
|
||||
this.layoutId = layoutId;
|
||||
return this;
|
||||
}
|
||||
@StringRes
|
||||
protected int getRightButtonTextId() {
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
public Builder setBackgroundImage(Drawable image) {
|
||||
this.image = image;
|
||||
return this;
|
||||
}
|
||||
protected void onRightButtonClickAction() {
|
||||
|
||||
public Builder setOnLeftButtonClickListener(View.OnClickListener onLeftButtonClickListener) {
|
||||
this.onLeftButtonClickListener = onLeftButtonClickListener;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public Builder setOnRightButtonClickListener(View.OnClickListener onRightButtonClickListener) {
|
||||
this.onRightButtonClickListener = onRightButtonClickListener;
|
||||
return this;
|
||||
}
|
||||
@ColorRes
|
||||
protected int getBottomDividerColorId() {
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
public Builder setRightButtonText(String rightBottomButtonText) {
|
||||
this.rightBottomButtonText = rightBottomButtonText;
|
||||
return this;
|
||||
}
|
||||
@LayoutRes
|
||||
protected int getLayoutId() {
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
public Builder setLeftButtonText(String leftBottomButtonText) {
|
||||
this.leftBottomButtonText = leftBottomButtonText;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setTitle(String title) {
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setDescription(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setPosition(int position) {
|
||||
this.position = position;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setBottomDividerColorId(@ColorRes int dividerColorId) {
|
||||
this.dividerColorId = dividerColorId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BaseTravelCard create() {
|
||||
return new BaseTravelCard(customView,
|
||||
layoutId,
|
||||
tag,
|
||||
image,
|
||||
onLeftButtonClickListener,
|
||||
onRightButtonClickListener,
|
||||
position,
|
||||
rightBottomButtonText,
|
||||
leftBottomButtonText,
|
||||
dividerColorId,
|
||||
description,
|
||||
title);
|
||||
}
|
||||
protected boolean isNightMode() {
|
||||
return !activity.getMyApplication().getSettings().isLightContent();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
package net.osmand.plus.wikivoyage.explore.travelcards;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.OsmandActionBarActivity;
|
||||
import net.osmand.plus.dialogs.ChoosePlanDialogFragment;
|
||||
|
||||
public class OpenBetaTravelCard extends BaseTravelCard {
|
||||
|
||||
|
||||
public OpenBetaTravelCard(OsmandActionBarActivity activity) {
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
public OpenBetaTravelCard(OsmandActionBarActivity activity, int position) {
|
||||
this.activity = activity;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) {
|
||||
View view = getView(app, container, isNightMode());
|
||||
ImageView imageView = (ImageView) view.findViewById(R.id.background_image);
|
||||
imageView.setImageDrawable(getBackgroundIcon(R.drawable.img_help_wikivoyage_articles));
|
||||
((TextView) view.findViewById(R.id.title)).setText(getTitleId());
|
||||
((TextView) view.findViewById(R.id.description)).setText(getDescriptionId());
|
||||
|
||||
((TextView) view.findViewById(R.id.left_bottom_button_text)).setText(getLeftButtonTextId());
|
||||
|
||||
view.findViewById(R.id.left_bottom_button).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onLeftButtonClickAction();
|
||||
}
|
||||
});
|
||||
if (position != INVALID_POSITION) {
|
||||
container.addView(view, position);
|
||||
} else {
|
||||
container.addView(view);
|
||||
}
|
||||
}
|
||||
|
||||
protected View getView(OsmandApplication app, ViewGroup parent, boolean nightMode) {
|
||||
if (view != null) {
|
||||
return view;
|
||||
}
|
||||
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
|
||||
return view = LayoutInflater.from(new ContextThemeWrapper(app, themeRes))
|
||||
.inflate(getLayoutId(), parent, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getTitleId() {
|
||||
return R.string.welcome_to_open_beta;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getDescriptionId() {
|
||||
return R.string.welcome_to_open_beta_description;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Drawable getBackgroundIcon(int drawableRes) {
|
||||
return super.getBackgroundIcon(drawableRes);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.wikivoyage_open_beta_card;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLeftButtonTextId() {
|
||||
return R.string.get_unlimited_access;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLeftButtonClickAction() {
|
||||
ChoosePlanDialogFragment.showFreeVersionInstance(activity.getSupportFragmentManager());
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
package net.osmand.plus.wikivoyage.explore.travelcards;
|
||||
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.support.customtabs.CustomTabsIntent;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.OsmandActionBarActivity;
|
||||
|
||||
public class StartEditingTravelCard extends BaseTravelCard {
|
||||
|
||||
public StartEditingTravelCard(OsmandActionBarActivity activity) {
|
||||
this.activity = activity;
|
||||
|
||||
}
|
||||
|
||||
public StartEditingTravelCard(OsmandActionBarActivity activity, int position) {
|
||||
this.activity = activity;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) {
|
||||
View view = getView(app, container, isNightMode());
|
||||
ImageView imageView = (ImageView) view.findViewById(R.id.background_image);
|
||||
imageView.setImageDrawable(getBackgroundIcon(R.drawable.img_help_wikivoyage_contribute));
|
||||
((TextView) view.findViewById(R.id.title)).setText(getTitleId());
|
||||
((TextView) view.findViewById(R.id.description)).setText(getDescriptionId());
|
||||
|
||||
((TextView) view.findViewById(R.id.left_bottom_button_text)).setText(getLeftButtonTextId());
|
||||
|
||||
view.findViewById(R.id.left_bottom_button).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onLeftButtonClickAction();
|
||||
}
|
||||
});
|
||||
if (position != INVALID_POSITION) {
|
||||
container.addView(view, position);
|
||||
} else {
|
||||
container.addView(view);
|
||||
}
|
||||
}
|
||||
|
||||
protected View getView(OsmandApplication app, ViewGroup parent, boolean nightMode) {
|
||||
if (view != null) {
|
||||
return view;
|
||||
}
|
||||
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
|
||||
return view = LayoutInflater.from(new ContextThemeWrapper(app, themeRes))
|
||||
.inflate(getLayoutId(), parent, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getTitleId() {
|
||||
return R.string.start_editing_card_image_text;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getDescriptionId() {
|
||||
return R.string.start_editing_card_description;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Drawable getBackgroundIcon(int drawableRes) {
|
||||
return super.getBackgroundIcon(drawableRes);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.wikivoyage_start_editing_card;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLeftButtonTextId() {
|
||||
return R.string.start_editing;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLeftButtonClickAction() {
|
||||
CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder()
|
||||
.setToolbarColor(ContextCompat.getColor(activity, isNightMode() ? R.color.actionbar_dark_color : R.color.actionbar_light_color))
|
||||
.build();
|
||||
String text = "https://" + activity.getMyApplication().getLanguage().toLowerCase() + ".m.wikivoyage.org";
|
||||
customTabsIntent.launchUrl(activity, Uri.parse(text));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue