added recyclerview and improve travel cards

This commit is contained in:
Chumva 2018-04-24 12:35:59 +03:00
parent a0e68124a1
commit 9a25f7c525
8 changed files with 88 additions and 97 deletions

View file

@ -6,20 +6,11 @@
android:gravity="center"
android:orientation="vertical">
<ScrollView
android:id="@+id/scroll_view"
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/cards_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="@dimen/map_markers_recycler_view_padding_bottom">
</LinearLayout>
</ScrollView>
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="@dimen/map_markers_recycler_view_padding_bottom"/>
</LinearLayout>

View file

@ -7,7 +7,7 @@
android:layout_gravity="center_horizontal"
android:layout_marginBottom="@dimen/list_content_padding"
android:layout_marginTop="@dimen/list_content_padding"
android:background="@drawable/wikivoyage_card_bg">
android:background="@drawable/travel_card_bg">
<LinearLayout
android:layout_width="match_parent"
@ -51,7 +51,17 @@
android:layout_height="1dp"
android:background="?attr/wikivoyage_card_divider_color" />
<include layout="@layout/bottom_buttons" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/left_bottom_button_text"
android:layout_width="wrap_content"
android:layout_height="@dimen/bottom_sheet_title_height"
android:layout_gravity="center"
android:background="?attr/selectableItemBackground"
android:gravity="center"
android:textColor="?attr/color_dialog_buttons"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:text="@string/get_unlimited_access" />
</LinearLayout>

View file

@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="@dimen/list_content_padding"
android:layout_marginTop="@dimen/list_content_padding"
android:background="@drawable/wikivoyage_card_bg">
android:background="@drawable/travel_card_bg">
<LinearLayout
android:layout_width="match_parent"
@ -16,11 +17,12 @@
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:background="@color/wikivoyage_start_editing_background">
<ImageView
android:id="@+id/background_image"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="@dimen/wikivoyage_explore_card_image_height"
android:contentDescription="@string/welcome_to_open_beta"
android:src="@drawable/img_help_wikivoyage_contribute" />
@ -58,7 +60,17 @@
android:layout_height="1dp"
android:background="?attr/wikivoyage_card_divider_color" />
<include layout="@layout/bottom_buttons" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/left_bottom_button_text"
android:layout_width="wrap_content"
android:layout_height="@dimen/bottom_sheet_title_height"
android:layout_gravity="center"
android:background="?attr/selectableItemBackground"
android:gravity="center"
android:textColor="?attr/color_dialog_buttons"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:text="@string/start_editing" />
</LinearLayout>

View file

@ -428,5 +428,6 @@
<color name="wikivoyage_primary_text_light">#212121</color>
<color name="wikivoyage_primary_text_dark">#cccccc</color>
<color name="wikivoyage_secondary_text">#727272</color>
<color name="wikivoyage_start_editing_background">#339966</color>
</resources>

View file

@ -3,6 +3,8 @@ package net.osmand.plus.wikivoyage.explore;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -27,18 +29,16 @@ public class ExploreTabFragment extends BaseOsmAndFragment {
final View mainView = inflater.inflate(R.layout.fragment_explore_tab, container, false);
LinearLayout linearLayout = (LinearLayout) mainView.findViewById(R.id.cards_list);
ArrayList<BaseTravelCard> items = new ArrayList<>();
BaseTravelCard openBetaTravelCard = new OpenBetaTravelCard(app, getFragmentManager(), nightMode);
BaseTravelCard openBetaTravelCard = new OpenBetaTravelCard(app, nightMode, getFragmentManager());
BaseTravelCard startEditingTravelCard = new StartEditingTravelCard(app, nightMode);
items.add(openBetaTravelCard);
items.add(startEditingTravelCard);
for (BaseTravelCard item : items) {
item.inflate(app, linearLayout, nightMode);
}
final RecyclerView rv = (RecyclerView) mainView.findViewById(R.id.recycler_view);
rv.setLayoutManager(new LinearLayoutManager(getContext()));
return mainView;
}
}

View file

@ -4,44 +4,45 @@ 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.view.ViewGroup;
import android.support.v7.widget.RecyclerView;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
public abstract class BaseTravelCard {
protected static final int INVALID_POSITION = -1;
protected OsmandApplication app;
protected int position = INVALID_POSITION;
protected boolean nightMode;
public abstract void inflate(OsmandApplication app, ViewGroup container, boolean nightMode);
public BaseTravelCard(OsmandApplication app, boolean nightMode) {
this.app = app;
this.nightMode = nightMode;
}
public abstract void bindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder);
public abstract int getCardType();
@ColorInt
protected int getResolvedColor(@ColorRes int colorId) {
return ContextCompat.getColor(app, colorId);
}
protected Drawable getIcon(@DrawableRes int drawableRes, @ColorRes int color) {
return app.getIconsCache().getIcon(drawableRes, color);
protected Drawable getContentIcon(@DrawableRes int icon) {
return getColoredIcon(icon, R.color.icon_color);
}
protected Drawable getIcon(@DrawableRes int drawableRes) {
return app.getIconsCache().getIcon(drawableRes);
protected Drawable getActiveIcon(@DrawableRes int icon) {
return getColoredIcon(icon, R.color.wikivoyage_active_light, R.color.wikivoyage_active_dark);
}
protected Drawable getIcon(int iconId, int colorLightId, int colorDarkId) {
return app.getIconsCache().getIcon(iconId, nightMode ? colorLightId : colorDarkId);
protected Drawable getColoredIcon(@DrawableRes int icon, @ColorRes int colorLight, @ColorRes int colorDark) {
return getColoredIcon(icon, nightMode ? colorDark : colorLight);
}
protected void onLeftButtonClickAction() {
protected Drawable getColoredIcon(@DrawableRes int icon, @ColorRes int color) {
return app.getIconsCache().getIcon(icon, color);
}
protected void onRightButtonClickAction() {
}
}
}

View file

@ -1,10 +1,11 @@
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.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
@ -14,47 +15,34 @@ import net.osmand.plus.dialogs.ChoosePlanDialogFragment;
public class OpenBetaTravelCard extends BaseTravelCard {
private FragmentManager fm;
private FragmentManager fragmentManager;
public OpenBetaTravelCard(OsmandApplication app, FragmentManager fm, boolean nightMode) {
this.app = app;
this.fm = fm;
this.nightMode = nightMode;
public OpenBetaTravelCard(OsmandApplication app, boolean nightMode, FragmentManager fragmentManager) {
super(app, nightMode);
this.fragmentManager = fragmentManager;
}
public OpenBetaTravelCard(OsmandApplication app, FragmentManager fm, int position, boolean nightMode) {
this.app = app;
this.fm = fm;
this.position = position;
this.nightMode = nightMode;
}
@Override
public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) {
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, container, false);
.inflate(R.layout.wikivoyage_open_beta_card, null, false);
ImageView imageView = (ImageView) view.findViewById(R.id.background_image);
imageView.setImageDrawable(getIcon(R.drawable.img_help_wikivoyage_articles));
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) {
onLeftButtonClickAction();
ChoosePlanDialogFragment.showFreeVersionInstance(fragmentManager);
}
});
if (position != INVALID_POSITION) {
container.addView(view, position);
} else {
container.addView(view);
}
}
@Override
protected void onLeftButtonClickAction() {
ChoosePlanDialogFragment.showFreeVersionInstance(fm);
public int getCardType() {
return 0;
}
}

View file

@ -1,12 +1,13 @@
package net.osmand.plus.wikivoyage.explore.travelcards;
import android.net.Uri;
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.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
@ -16,46 +17,33 @@ import net.osmand.plus.R;
public class StartEditingTravelCard extends BaseTravelCard {
public StartEditingTravelCard(OsmandApplication app, boolean nightMode) {
this.app = app;
this.nightMode = nightMode;
}
public StartEditingTravelCard(OsmandApplication app, int position, boolean nightMode) {
this.app = app;
this.position = position;
this.nightMode = nightMode;
super(app, nightMode);
}
@Override
public void inflate(OsmandApplication app, ViewGroup container, boolean nightMode) {
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_start_editing_card, container, false);
.inflate(R.layout.wikivoyage_open_beta_card, null, false);
ImageView imageView = (ImageView) view.findViewById(R.id.background_image);
imageView.setImageDrawable(getIcon(R.drawable.img_help_wikivoyage_contribute));
((TextView) view.findViewById(R.id.title)).setText(R.string.start_editing_card_image_text);
((TextView) view.findViewById(R.id.description)).setText(R.string.start_editing_card_description);
((TextView) view.findViewById(R.id.left_bottom_button_text)).setText(R.string.start_editing);
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) {
onLeftButtonClickAction();
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 (position != INVALID_POSITION) {
container.addView(view, position);
} else {
container.addView(view);
}
}
@Override
protected void onLeftButtonClickAction() {
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));
public int getCardType() {
return 1;
}
}