Add TravelNeededMapsCard and related stuff
This commit is contained in:
parent
371585234a
commit
a67b47d717
7 changed files with 146 additions and 14 deletions
|
@ -76,6 +76,7 @@
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<View
|
<View
|
||||||
|
android:id="@+id/divider"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="1dp"
|
android:layout_height="1dp"
|
||||||
android:layout_marginLeft="@dimen/bottom_sheet_divider_margin_start"
|
android:layout_marginLeft="@dimen/bottom_sheet_divider_margin_start"
|
||||||
|
|
|
@ -28,14 +28,13 @@
|
||||||
osmand:typeface="@string/font_roboto_medium"/>
|
osmand:typeface="@string/font_roboto_medium"/>
|
||||||
|
|
||||||
<net.osmand.plus.widgets.TextViewEx
|
<net.osmand.plus.widgets.TextViewEx
|
||||||
android:id="@+id/description"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:lineSpacingMultiplier="@dimen/text_button_line_spacing_multiplier"
|
android:lineSpacingMultiplier="@dimen/text_button_line_spacing_multiplier"
|
||||||
|
android:text="@string/maps_you_need_descr"
|
||||||
android:textColor="@color/wikivoyage_secondary_text"
|
android:textColor="@color/wikivoyage_secondary_text"
|
||||||
android:textSize="@dimen/travel_card_primary_text_size"
|
android:textSize="@dimen/travel_card_primary_text_size"
|
||||||
osmand:typeface="@string/font_roboto_regular"
|
osmand:typeface="@string/font_roboto_regular"/>
|
||||||
tools:text="@string/maps_you_need_descr"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
<string name="purchase_cancelled_dialog_title">You have cancel OsmAnd Live subscription</string>
|
<string name="purchase_cancelled_dialog_title">You have cancel OsmAnd Live subscription</string>
|
||||||
<string name="purchase_cancelled_dialog_descr">Renew subscription to continue use the all features:</string>
|
<string name="purchase_cancelled_dialog_descr">Renew subscription to continue use the all features:</string>
|
||||||
|
|
||||||
<string name="maps_you_need_descr">You read articles: %1$s. Based on this, we suggest you download these maps:</string>
|
<string name="maps_you_need_descr">Based on the articles you saved, we recommend you to download following maps:</string>
|
||||||
<string name="maps_you_need">Maps you need</string>
|
<string name="maps_you_need">Maps you need</string>
|
||||||
<string name="osmand_team">OsmAnd team</string>
|
<string name="osmand_team">OsmAnd team</string>
|
||||||
<string name="popular_destinations">Popular destinations</string>
|
<string name="popular_destinations">Popular destinations</string>
|
||||||
|
|
|
@ -19,13 +19,16 @@ import net.osmand.plus.wikivoyage.explore.travelcards.StartEditingTravelCard;
|
||||||
import net.osmand.plus.wikivoyage.explore.travelcards.StartEditingTravelCard.StartEditingTravelVH;
|
import net.osmand.plus.wikivoyage.explore.travelcards.StartEditingTravelCard.StartEditingTravelVH;
|
||||||
import net.osmand.plus.wikivoyage.explore.travelcards.TravelDownloadUpdateCard;
|
import net.osmand.plus.wikivoyage.explore.travelcards.TravelDownloadUpdateCard;
|
||||||
import net.osmand.plus.wikivoyage.explore.travelcards.TravelDownloadUpdateCard.DownloadUpdateVH;
|
import net.osmand.plus.wikivoyage.explore.travelcards.TravelDownloadUpdateCard.DownloadUpdateVH;
|
||||||
|
import net.osmand.plus.wikivoyage.explore.travelcards.TravelNeededMapsCard;
|
||||||
|
import net.osmand.plus.wikivoyage.explore.travelcards.TravelNeededMapsCard.NeededMapsVH;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
|
||||||
private static final int DOWNLOAD_UPDATE_CARD_POSITION = 0;
|
private static final int FIRST_POSITION = 0;
|
||||||
|
private static final int SECOND_POSITION = 1;
|
||||||
|
|
||||||
private final List<BaseTravelCard> items = new ArrayList<>();
|
private final List<BaseTravelCard> items = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -48,6 +51,9 @@ public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
||||||
case HeaderTravelCard.TYPE:
|
case HeaderTravelCard.TYPE:
|
||||||
return new HeaderTravelVH(inflate(parent, R.layout.wikivoyage_list_header));
|
return new HeaderTravelVH(inflate(parent, R.layout.wikivoyage_list_header));
|
||||||
|
|
||||||
|
case TravelNeededMapsCard.TYPE:
|
||||||
|
return new NeededMapsVH(inflate(parent, R.layout.travel_needed_maps_card));
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new RuntimeException("Unsupported view type: " + viewType);
|
throw new RuntimeException("Unsupported view type: " + viewType);
|
||||||
}
|
}
|
||||||
|
@ -131,23 +137,45 @@ public class ExploreRvAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setNeededMapsCard(TravelNeededMapsCard card) {
|
||||||
|
if (addItem(getNeededMapsCardPosition(), card)) {
|
||||||
|
notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getNeededMapsCardPosition() {
|
||||||
|
if (downloadUpdateCardExists(FIRST_POSITION)) {
|
||||||
|
return SECOND_POSITION;
|
||||||
|
}
|
||||||
|
return FIRST_POSITION;
|
||||||
|
}
|
||||||
|
|
||||||
public void setDownloadUpdateCard(TravelDownloadUpdateCard card) {
|
public void setDownloadUpdateCard(TravelDownloadUpdateCard card) {
|
||||||
if (addItem(DOWNLOAD_UPDATE_CARD_POSITION, card)) {
|
if (addItem(getDownloadUpdateCardPosition(), card)) {
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateDownloadUpdateCard() {
|
public void updateDownloadUpdateCard() {
|
||||||
notifyItemChanged(DOWNLOAD_UPDATE_CARD_POSITION);
|
int pos = getDownloadUpdateCardPosition();
|
||||||
|
if (downloadUpdateCardExists(pos)) {
|
||||||
|
notifyItemChanged(pos);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeDownloadUpdateCard() {
|
public void removeDownloadUpdateCard() {
|
||||||
if (items.size() > DOWNLOAD_UPDATE_CARD_POSITION) {
|
int pos = getDownloadUpdateCardPosition();
|
||||||
BaseTravelCard card = getItem(DOWNLOAD_UPDATE_CARD_POSITION);
|
if (downloadUpdateCardExists(pos)) {
|
||||||
if (card.getCardType() == TravelDownloadUpdateCard.TYPE) {
|
removeItem(pos);
|
||||||
removeItem(DOWNLOAD_UPDATE_CARD_POSITION);
|
notifyItemRemoved(pos);
|
||||||
notifyItemRemoved(DOWNLOAD_UPDATE_CARD_POSITION);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getDownloadUpdateCardPosition() {
|
||||||
|
return FIRST_POSITION;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean downloadUpdateCardExists(int position) {
|
||||||
|
return items.size() > position && items.get(position).getCardType() == TravelDownloadUpdateCard.TYPE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ import net.osmand.plus.wikivoyage.explore.travelcards.HeaderTravelCard;
|
||||||
import net.osmand.plus.wikivoyage.explore.travelcards.OpenBetaTravelCard;
|
import net.osmand.plus.wikivoyage.explore.travelcards.OpenBetaTravelCard;
|
||||||
import net.osmand.plus.wikivoyage.explore.travelcards.StartEditingTravelCard;
|
import net.osmand.plus.wikivoyage.explore.travelcards.StartEditingTravelCard;
|
||||||
import net.osmand.plus.wikivoyage.explore.travelcards.TravelDownloadUpdateCard;
|
import net.osmand.plus.wikivoyage.explore.travelcards.TravelDownloadUpdateCard;
|
||||||
|
import net.osmand.plus.wikivoyage.explore.travelcards.TravelNeededMapsCard;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -153,6 +154,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
|
||||||
this.mainIndexItem = mainIndexItem;
|
this.mainIndexItem = mainIndexItem;
|
||||||
this.neededIndexItems = neededIndexItems;
|
this.neededIndexItems = neededIndexItems;
|
||||||
addDownloadUpdateCard();
|
addDownloadUpdateCard();
|
||||||
|
addNeededMapsCard();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addDownloadUpdateCard() {
|
private void addDownloadUpdateCard() {
|
||||||
|
@ -209,6 +211,12 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addNeededMapsCard() {
|
||||||
|
if (!neededIndexItems.isEmpty()) {
|
||||||
|
adapter.setNeededMapsCard(new TravelNeededMapsCard(getMyApplication(), nightMode, neededIndexItems));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private String getWikivoyageFileName() {
|
private String getWikivoyageFileName() {
|
||||||
File selectedTravelBook = getMyApplication().getTravelDbHelper().getSelectedTravelBook();
|
File selectedTravelBook = getMyApplication().getTravelDbHelper().getSelectedTravelBook();
|
||||||
|
|
|
@ -128,7 +128,7 @@ public class TravelDownloadUpdateCard extends BaseTravelCard {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private String getFileTitle() {
|
private String getFileTitle() {
|
||||||
return indexItem == null ? "" : indexItem.getBasename().replace("_", " ");
|
return indexItem == null ? "" : indexItem.getVisibleName(app, app.getRegions(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
|
|
@ -0,0 +1,96 @@
|
||||||
|
package net.osmand.plus.wikivoyage.explore.travelcards;
|
||||||
|
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.download.IndexItem;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class TravelNeededMapsCard extends BaseTravelCard {
|
||||||
|
|
||||||
|
public static final int TYPE = 70;
|
||||||
|
|
||||||
|
private List<IndexItem> items;
|
||||||
|
|
||||||
|
private Drawable downloadIcon;
|
||||||
|
|
||||||
|
public TravelNeededMapsCard(OsmandApplication app, boolean nightMode, List<IndexItem> items) {
|
||||||
|
super(app, nightMode);
|
||||||
|
this.items = items;
|
||||||
|
downloadIcon = getActiveIcon(R.drawable.ic_action_import);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void bindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder) {
|
||||||
|
if (viewHolder instanceof NeededMapsVH) {
|
||||||
|
NeededMapsVH holder = (NeededMapsVH) viewHolder;
|
||||||
|
adjustChildCount(holder.itemsContainer);
|
||||||
|
for (int i = 0; i < items.size(); i++) {
|
||||||
|
boolean lastItem = i == items.size() - 1;
|
||||||
|
IndexItem item = items.get(i);
|
||||||
|
View view = holder.itemsContainer.getChildAt(i);
|
||||||
|
((ImageView) view.findViewById(R.id.icon))
|
||||||
|
.setImageDrawable(getActiveIcon(item.getType().getIconResource()));
|
||||||
|
((TextView) view.findViewById(R.id.title)).setText(item.getVisibleName(app, app.getRegions(), false));
|
||||||
|
((TextView) view.findViewById(R.id.description)).setText(getItemDescription(item));
|
||||||
|
((ImageView) view.findViewById(R.id.icon_action)).setImageDrawable(downloadIcon);
|
||||||
|
view.findViewById(R.id.divider).setVisibility(lastItem ? View.GONE : View.VISIBLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCardType() {
|
||||||
|
return TYPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void adjustChildCount(LinearLayout itemsContainer) {
|
||||||
|
int itemsCount = items.size();
|
||||||
|
int childCount = itemsContainer.getChildCount();
|
||||||
|
if (itemsCount == childCount) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (itemsCount > childCount) {
|
||||||
|
LayoutInflater inflater = LayoutInflater.from(itemsContainer.getContext());
|
||||||
|
for (int i = childCount; i < itemsCount; i++) {
|
||||||
|
inflater.inflate(R.layout.travel_needed_map_item, itemsContainer);
|
||||||
|
}
|
||||||
|
} else if (itemsCount < childCount) {
|
||||||
|
itemsContainer.removeViews(0, childCount - itemsCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getItemDescription(IndexItem item) {
|
||||||
|
return app.getString(R.string.file_size_in_mb, item.getArchiveSizeMB()) + " • " + item.getType().getString(app);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class NeededMapsVH extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
|
final LinearLayout itemsContainer;
|
||||||
|
final View secondaryBtnContainer;
|
||||||
|
final TextView secondaryBtn;
|
||||||
|
final View buttonsDivider;
|
||||||
|
final View primaryBtnContainer;
|
||||||
|
final TextView primaryButton;
|
||||||
|
|
||||||
|
@SuppressWarnings("RedundantCast")
|
||||||
|
public NeededMapsVH(View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
itemsContainer = (LinearLayout) itemView.findViewById(R.id.items_container);
|
||||||
|
secondaryBtnContainer = itemView.findViewById(R.id.secondary_btn_container);
|
||||||
|
secondaryBtn = (TextView) itemView.findViewById(R.id.secondary_button);
|
||||||
|
buttonsDivider = itemView.findViewById(R.id.buttons_divider);
|
||||||
|
primaryBtnContainer = itemView.findViewById(R.id.primary_btn_container);
|
||||||
|
primaryButton = (TextView) itemView.findViewById(R.id.primary_button);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue