Add description to overview card

This commit is contained in:
Vitaliy 2021-02-08 18:34:08 +02:00
parent d01ff166d1
commit 02117a8ffd
5 changed files with 73 additions and 23 deletions

View file

@ -6,6 +6,22 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:ellipsize="end"
android:letterSpacing="@dimen/description_letter_spacing"
android:maxLines="2"
android:minHeight="@dimen/default_desc_line_height"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"
osmand:lineHeight="@dimen/default_desc_line_height"
osmand:typeface="@string/font_roboto_regular"
tools:text="Amsterdam is the Netherlands' capital and financial, cultural and creative centre with more" />
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_overview" android:id="@+id/recycler_overview"
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -4,6 +4,9 @@ import android.view.View;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatImageView;
import com.squareup.picasso.Callback; import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso; import com.squareup.picasso.Picasso;
import com.squareup.picasso.RequestCreator; import com.squareup.picasso.RequestCreator;
@ -16,13 +19,10 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.widgets.TextViewEx; import net.osmand.plus.widgets.TextViewEx;
import net.osmand.plus.wikipedia.WikiArticleHelper;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatImageView;
import static net.osmand.plus.myplaces.TrackActivityFragmentAdapter.getMetadataImageLink; import static net.osmand.plus.myplaces.TrackActivityFragmentAdapter.getMetadataImageLink;
import static net.osmand.plus.wikipedia.WikiArticleHelper.getFirstParagraph;
public class DescriptionCard extends BaseCard { public class DescriptionCard extends BaseCard {
@ -98,16 +98,6 @@ public class DescriptionCard extends BaseCard {
}); });
} }
private String getFirstParagraph(String descriptionHtml) {
if (descriptionHtml != null) {
String firstParagraph = WikiArticleHelper.getPartialContent(descriptionHtml);
if (!Algorithms.isEmpty(firstParagraph)) {
return firstParagraph;
}
}
return descriptionHtml;
}
private void setupImage(final String imageUrl) { private void setupImage(final String imageUrl) {
if (imageUrl == null) { if (imageUrl == null) {
return; return;

View file

@ -16,6 +16,14 @@ import android.webkit.WebSettings;
import android.webkit.WebView; import android.webkit.WebView;
import android.webkit.WebViewClient; import android.webkit.WebViewClient;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import com.squareup.picasso.Callback; import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso; import com.squareup.picasso.Picasso;
import com.squareup.picasso.RequestCreator; import com.squareup.picasso.RequestCreator;
@ -32,14 +40,6 @@ import net.osmand.plus.widgets.WebViewEx;
import net.osmand.plus.wikivoyage.WikivoyageUtils; import net.osmand.plus.wikivoyage.WikivoyageUtils;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
public class GpxReadDescriptionDialogFragment extends BaseOsmAndDialogFragment { public class GpxReadDescriptionDialogFragment extends BaseOsmAndDialogFragment {
public static final String TAG = GpxReadDescriptionDialogFragment.class.getSimpleName(); public static final String TAG = GpxReadDescriptionDialogFragment.class.getSimpleName();
@ -242,7 +242,7 @@ public class GpxReadDescriptionDialogFragment extends BaseOsmAndDialogFragment {
return "<body style=\"color:white;\">\n" + content + "</body>\n"; return "<body style=\"color:white;\">\n" + content + "</body>\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(); FragmentManager fragmentManager = activity.getSupportFragmentManager();
if (!fragmentManager.isStateSaved()) { if (!fragmentManager.isStateSaved()) {
Bundle args = new Bundle(); Bundle args = new Bundle();

View file

@ -4,7 +4,9 @@ import android.annotation.SuppressLint;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.ColorRes; import androidx.annotation.ColorRes;
import androidx.annotation.DrawableRes; import androidx.annotation.DrawableRes;
@ -13,18 +15,23 @@ import androidx.appcompat.widget.AppCompatImageView;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.Metadata;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.myplaces.SegmentActionsListener; import net.osmand.plus.myplaces.SegmentActionsListener;
import net.osmand.plus.routepreparationmenu.cards.BaseCard; 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.myplaces.TrackActivityFragmentAdapter.isGpxFileSelected;
import static net.osmand.plus.track.OptionsCard.APPEARANCE_BUTTON_INDEX; 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.DIRECTIONS_BUTTON_INDEX;
import static net.osmand.plus.track.OptionsCard.EDIT_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.track.OptionsCard.SHOW_ON_MAP_BUTTON_INDEX;
import static net.osmand.plus.wikipedia.WikiArticleHelper.getFirstParagraph;
public class OverviewCard extends BaseCard { public class OverviewCard extends BaseCard {
@ -63,6 +70,7 @@ public class OverviewCard extends BaseCard {
RecyclerView blocksView = view.findViewById(R.id.recycler_overview); RecyclerView blocksView = view.findViewById(R.id.recycler_overview);
blockStatisticsBuilder.setBlocksView(blocksView); blockStatisticsBuilder.setBlocksView(blocksView);
setupDescription();
initShowButton(iconColorDef, iconColorPres); initShowButton(iconColorDef, iconColorPres);
initAppearanceButton(iconColorDef, iconColorPres); initAppearanceButton(iconColorDef, iconColorPres);
if (fileAvailable) { if (fileAvailable) {
@ -125,6 +133,31 @@ public class OverviewCard extends BaseCard {
iv.setImageDrawable(icon); 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) { 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() { item.setOnTouchListener(new View.OnTouchListener() {
@SuppressLint("ClickableViewAccessibility") @SuppressLint("ClickableViewAccessibility")

View file

@ -333,6 +333,17 @@ public class WikiArticleHelper {
return res.toString(); 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) { public static String buildTravelUrl(String url, String lang) {
String title = url.replace(" ", "_"); String title = url.replace(" ", "_");
try { try {