From 02117a8ffd79f8432d36f2c1acdac715a7a0d28c Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 8 Feb 2021 18:34:08 +0200 Subject: [PATCH] Add description to overview card --- OsmAnd/res/layout/gpx_overview_fragment.xml | 16 +++++++++ .../osmand/plus/track/DescriptionCard.java | 18 +++------- .../GpxReadDescriptionDialogFragment.java | 18 +++++----- .../net/osmand/plus/track/OverviewCard.java | 33 +++++++++++++++++++ .../plus/wikipedia/WikiArticleHelper.java | 11 +++++++ 5 files changed, 73 insertions(+), 23 deletions(-) diff --git a/OsmAnd/res/layout/gpx_overview_fragment.xml b/OsmAnd/res/layout/gpx_overview_fragment.xml index 426633eb83..3b205ae60e 100644 --- a/OsmAnd/res/layout/gpx_overview_fragment.xml +++ b/OsmAnd/res/layout/gpx_overview_fragment.xml @@ -6,6 +6,22 @@ android:layout_height="wrap_content" android:orientation="vertical"> + + \n" + content + "\n"; } - public static void showInstance(@NonNull FragmentActivity activity, @NonNull String title, @NonNull String imageUrl, @NonNull String description) { + public static void showInstance(@NonNull FragmentActivity activity, @NonNull String title, @Nullable String imageUrl, @NonNull String description) { FragmentManager fragmentManager = activity.getSupportFragmentManager(); if (!fragmentManager.isStateSaved()) { Bundle args = new Bundle(); diff --git a/OsmAnd/src/net/osmand/plus/track/OverviewCard.java b/OsmAnd/src/net/osmand/plus/track/OverviewCard.java index 5d46a69c25..d0a396499d 100644 --- a/OsmAnd/src/net/osmand/plus/track/OverviewCard.java +++ b/OsmAnd/src/net/osmand/plus/track/OverviewCard.java @@ -4,7 +4,9 @@ import android.annotation.SuppressLint; import android.graphics.drawable.Drawable; import android.view.MotionEvent; import android.view.View; +import android.view.View.OnClickListener; import android.widget.ImageView; +import android.widget.TextView; import androidx.annotation.ColorRes; import androidx.annotation.DrawableRes; @@ -13,18 +15,23 @@ import androidx.appcompat.widget.AppCompatImageView; import androidx.recyclerview.widget.RecyclerView; import net.osmand.GPXUtilities.GPXFile; +import net.osmand.GPXUtilities.Metadata; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.myplaces.SegmentActionsListener; import net.osmand.plus.routepreparationmenu.cards.BaseCard; +import net.osmand.util.Algorithms; +import static net.osmand.plus.myplaces.TrackActivityFragmentAdapter.getMetadataImageLink; import static net.osmand.plus.myplaces.TrackActivityFragmentAdapter.isGpxFileSelected; import static net.osmand.plus.track.OptionsCard.APPEARANCE_BUTTON_INDEX; import static net.osmand.plus.track.OptionsCard.DIRECTIONS_BUTTON_INDEX; import static net.osmand.plus.track.OptionsCard.EDIT_BUTTON_INDEX; import static net.osmand.plus.track.OptionsCard.SHOW_ON_MAP_BUTTON_INDEX; +import static net.osmand.plus.wikipedia.WikiArticleHelper.getFirstParagraph; public class OverviewCard extends BaseCard { @@ -63,6 +70,7 @@ public class OverviewCard extends BaseCard { RecyclerView blocksView = view.findViewById(R.id.recycler_overview); blockStatisticsBuilder.setBlocksView(blocksView); + setupDescription(); initShowButton(iconColorDef, iconColorPres); initAppearanceButton(iconColorDef, iconColorPres); if (fileAvailable) { @@ -125,6 +133,31 @@ public class OverviewCard extends BaseCard { iv.setImageDrawable(icon); } + private void setupDescription() { + GPXFile gpxFile = getGPXFile(); + if (gpxFile.metadata == null) { + gpxFile.metadata = new Metadata(); + } + + TextView description = view.findViewById(R.id.description); + final String descriptionHtml = gpxFile.metadata.getDescription(); + if (Algorithms.isBlank(descriptionHtml)) { + AndroidUiHelper.updateVisibility(description, false); + } else { + description.setText(getFirstParagraph(descriptionHtml)); + description.setOnClickListener(new OnClickListener() { + @Override + public void onClick(View v) { + GPXFile gpxFile = getGPXFile(); + String title = gpxFile.metadata.getArticleTitle(); + String imageUrl = getMetadataImageLink(gpxFile.metadata); + GpxReadDescriptionDialogFragment.showInstance(mapActivity, title, imageUrl, descriptionHtml); + } + }); + AndroidUiHelper.updateVisibility(description, true); + } + } + private void setOnTouchItem(View item, final ImageView image, final ImageView filled, @DrawableRes final Integer resId, @ColorRes final int colorDef, @ColorRes final int colorPres) { item.setOnTouchListener(new View.OnTouchListener() { @SuppressLint("ClickableViewAccessibility") diff --git a/OsmAnd/src/net/osmand/plus/wikipedia/WikiArticleHelper.java b/OsmAnd/src/net/osmand/plus/wikipedia/WikiArticleHelper.java index 56137a780c..7b72024b12 100644 --- a/OsmAnd/src/net/osmand/plus/wikipedia/WikiArticleHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikipedia/WikiArticleHelper.java @@ -333,6 +333,17 @@ public class WikiArticleHelper { return res.toString(); } + @Nullable + public static String getFirstParagraph(String descriptionHtml) { + if (descriptionHtml != null) { + String firstParagraph = WikiArticleHelper.getPartialContent(descriptionHtml); + if (!Algorithms.isEmpty(firstParagraph)) { + return firstParagraph; + } + } + return descriptionHtml; + } + public static String buildTravelUrl(String url, String lang) { String title = url.replace(" ", "_"); try {