diff --git a/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java b/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java index 3ef6a54652..959669a665 100644 --- a/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java +++ b/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java @@ -273,6 +273,10 @@ public class Amenity extends MapObject { return null; } + public String getTagContent(String tag) { + return getTagContent(tag, null); + } + public String getTagContent(String tag, String lang) { if (lang != null) { String translateName = getAdditionalInfo(tag + ":" + lang); diff --git a/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml b/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml new file mode 100644 index 0000000000..eb97f02c0b --- /dev/null +++ b/OsmAnd/res/layout/wikivoyage_travel_gpx_card.xml @@ -0,0 +1,242 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java new file mode 100644 index 0000000000..8393ec98a6 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelGpx.java @@ -0,0 +1,8 @@ +package net.osmand.plus.wikivoyage.data; + +public class TravelGpx extends TravelArticle { + public String user; + public float totalDistance = 0; + public double diffElevationUp = 0; + public double diffElevationDown = 0; +} diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreRvAdapter.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreRvAdapter.java index a95614bdb8..5341edcb9d 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreRvAdapter.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreRvAdapter.java @@ -20,6 +20,8 @@ import net.osmand.plus.wikivoyage.explore.travelcards.StartEditingTravelCard; 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.DownloadUpdateVH; +import net.osmand.plus.wikivoyage.explore.travelcards.TravelGpxCard; +import net.osmand.plus.wikivoyage.explore.travelcards.TravelGpxCard.TravelGpxVH; import net.osmand.plus.wikivoyage.explore.travelcards.TravelNeededMapsCard; import net.osmand.plus.wikivoyage.explore.travelcards.TravelNeededMapsCard.NeededMapsVH; @@ -48,6 +50,9 @@ public class ExploreRvAdapter extends RecyclerView.Adapter 0; i--) { BaseTravelCard o = items.get(i); - if (o instanceof ArticleTravelCard) { + if (o instanceof ArticleTravelCard || o instanceof TravelGpxCard) { return i; } } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java index c53027fb7a..ae6b0cace7 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/ExploreTabFragment.java @@ -28,6 +28,7 @@ import net.osmand.plus.download.DownloadResources; import net.osmand.plus.download.DownloadValidationManager; import net.osmand.plus.download.IndexItem; import net.osmand.plus.wikivoyage.data.TravelArticle; +import net.osmand.plus.wikivoyage.data.TravelGpx; import net.osmand.plus.wikivoyage.data.TravelHelper; import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper; import net.osmand.plus.wikivoyage.explore.travelcards.ArticleTravelCard; @@ -36,6 +37,7 @@ import net.osmand.plus.wikivoyage.explore.travelcards.HeaderTravelCard; import net.osmand.plus.wikivoyage.explore.travelcards.OpenBetaTravelCard; import net.osmand.plus.wikivoyage.explore.travelcards.StartEditingTravelCard; import net.osmand.plus.wikivoyage.explore.travelcards.TravelDownloadUpdateCard; +import net.osmand.plus.wikivoyage.explore.travelcards.TravelGpxCard; import net.osmand.plus.wikivoyage.explore.travelcards.TravelNeededMapsCard; import java.io.IOException; @@ -183,7 +185,11 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadEv List popularArticles = app.getTravelHelper().getPopularArticles(); for (TravelArticle article : popularArticles) { - items.add(new ArticleTravelCard(app, nightMode, article, fm)); + if (article instanceof TravelGpx) { + items.add(new TravelGpxCard(app, nightMode, (TravelGpx) article, fm)); + } else { + items.add(new ArticleTravelCard(app, nightMode, article, fm)); + } } } } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java new file mode 100644 index 0000000000..32790cc094 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java @@ -0,0 +1,120 @@ +package net.osmand.plus.wikivoyage.explore.travelcards; + +import android.graphics.drawable.Drawable; +import android.view.View; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.fragment.app.FragmentManager; +import androidx.recyclerview.widget.RecyclerView; + +import net.osmand.plus.OsmAndFormatter; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.wikipedia.WikiArticleHelper; +import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment; +import net.osmand.plus.wikivoyage.data.TravelGpx; +import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper; + +public class TravelGpxCard extends BaseTravelCard { + + public static final int TYPE = 3; + + private final TravelGpx article; + private final Drawable readIcon; + private final FragmentManager fragmentManager; + private boolean isLastItem; + + public TravelGpxCard(@NonNull OsmandApplication app, boolean nightMode, @NonNull TravelGpx article, + @NonNull FragmentManager fragmentManager) { + super(app, nightMode); + this.article = article; + readIcon = getActiveIcon(R.drawable.ic_action_read_article); + this.fragmentManager = fragmentManager; + } + + @Override + public void bindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder) { + if (viewHolder instanceof TravelGpxVH) { + final TravelGpxVH holder = (TravelGpxVH) viewHolder; + holder.title.setText(article.getTitle()); + holder.content.setText(WikiArticleHelper.getPartialContent(article.getContent())); + holder.distance.setText(OsmAndFormatter.getFormattedDistance(article.totalDistance,app)); + holder.diffElevationUp.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationUp,app)); + holder.diffElevationDown.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationDown,app)); + holder.leftButton.setText(app.getString(R.string.shared_string_view)); + View.OnClickListener readClickListener = new View.OnClickListener() { + @Override + public void onClick(View v) { + if (fragmentManager != null) { + WikivoyageArticleDialogFragment.showInstance(app, fragmentManager, + article.generateIdentifier(), article.getLang()); + } + } + }; + holder.leftButton.setOnClickListener(readClickListener); + holder.itemView.setOnClickListener(readClickListener); + holder.leftButton.setCompoundDrawablesWithIntrinsicBounds(readIcon, null, null, null); + updateSaveButton(holder); + holder.divider.setVisibility(isLastItem ? View.GONE : View.VISIBLE); + holder.shadow.setVisibility(isLastItem ? View.VISIBLE : View.GONE); + } + } + + private void updateSaveButton(final TravelGpxVH holder) { + if (article != null) { + final TravelLocalDataHelper helper = app.getTravelHelper().getBookmarksHelper(); + final boolean saved = helper.isArticleSaved(article); + Drawable icon = getActiveIcon(saved ? R.drawable.ic_action_read_later_fill : R.drawable.ic_action_read_later); + holder.rightButton.setText(saved ? R.string.shared_string_remove : R.string.shared_string_save); + holder.rightButton.setCompoundDrawablesWithIntrinsicBounds(null, null, icon, null); + holder.rightButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if (saved) { + helper.removeArticleFromSaved(article); + } else { + app.getTravelHelper().createGpxFile(article); + helper.addArticleToSaved(article); + } + updateSaveButton(holder); + } + }); + } + } + + public static class TravelGpxVH extends RecyclerView.ViewHolder { + + final TextView title; + final TextView content; + final TextView distance; + final TextView diffElevationUp; + final TextView diffElevationDown; + final TextView leftButton; + final TextView rightButton; + final View divider; + final View shadow; + + public TravelGpxVH(final View itemView) { + super(itemView); + title = itemView.findViewById(R.id.title); + content = itemView.findViewById(R.id.content); + distance = itemView.findViewById(R.id.distance); + diffElevationUp = itemView.findViewById(R.id.diff_ele_up); + diffElevationDown = itemView.findViewById(R.id.diff_ele_down); + leftButton = itemView.findViewById(R.id.left_button); + rightButton = itemView.findViewById(R.id.right_button); + divider = itemView.findViewById(R.id.divider); + shadow = itemView.findViewById(R.id.shadow); + } + } + + public void setLastItem(boolean lastItem) { + isLastItem = lastItem; + } + + @Override + public int getCardType() { + return TYPE; + } +}