From a1a433f11d01055b1cea23cede01e946f6145c03 Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Thu, 7 Jun 2018 23:19:55 +0300 Subject: [PATCH] Gpx description card in progress --- OsmAnd/res/layout/gpx_description_card.xml | 64 +++++++++++++ OsmAnd/res/layout/wikivoyage_article_card.xml | 6 ++ .../TrackActivityFragmentAdapter.java | 92 +++++++++++++++++++ .../plus/myplaces/TrackPointFragment.java | 1 + .../plus/myplaces/TrackSegmentFragment.java | 1 + 5 files changed, 164 insertions(+) create mode 100644 OsmAnd/res/layout/gpx_description_card.xml diff --git a/OsmAnd/res/layout/gpx_description_card.xml b/OsmAnd/res/layout/gpx_description_card.xml new file mode 100644 index 0000000000..9c6ba33729 --- /dev/null +++ b/OsmAnd/res/layout/gpx_description_card.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/res/layout/wikivoyage_article_card.xml b/OsmAnd/res/layout/wikivoyage_article_card.xml index 75b112dc39..fa8d3a31be 100644 --- a/OsmAnd/res/layout/wikivoyage_article_card.xml +++ b/OsmAnd/res/layout/wikivoyage_article_card.xml @@ -172,4 +172,10 @@ android:visibility="gone" tools:visibility="visible"/> + + diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java index 36fc8fd2ec..d206503d7a 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackActivityFragmentAdapter.java @@ -4,6 +4,7 @@ import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; import android.os.AsyncTask; import android.os.Bundle; import android.support.annotation.NonNull; @@ -13,6 +14,8 @@ import android.support.v4.app.Fragment; import android.support.v4.content.ContextCompat; import android.support.v7.widget.ListPopupWindow; import android.support.v7.widget.SwitchCompat; +import android.text.Html; +import android.text.TextUtils; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; @@ -24,6 +27,7 @@ import android.widget.ImageView; import android.widget.ListView; import android.widget.ProgressBar; import android.widget.TextView; +import android.widget.Toast; import net.osmand.AndroidUtils; import net.osmand.data.LatLon; @@ -47,6 +51,8 @@ import net.osmand.plus.activities.TrackActivity; import net.osmand.plus.dialogs.ConfigureMapMenu; import net.osmand.plus.measurementtool.NewGpxData; import net.osmand.plus.myplaces.TrackBitmapDrawer.TrackBitmapDrawerListener; +import net.osmand.plus.wikipedia.WikiArticleHelper; +import net.osmand.plus.wikivoyage.data.TravelArticle; import net.osmand.render.RenderingRulesStorage; import java.lang.ref.WeakReference; @@ -78,6 +84,8 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { private ImageView imageView; private ProgressBar progressBar; + private boolean showDescriptionCard; + private boolean fabMenuOpened = false; private FloatingActionButton menuFab; private FloatingActionButton waypointFab; @@ -158,6 +166,12 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { LayoutInflater inflater = LayoutInflater.from(context); headerView = inflater.inflate(R.layout.gpx_item_list_header, null, false); listView.addHeaderView(headerView); + if (showDescriptionCard) { + View card = getDescriptionCardView(context); + if (card != null) { + listView.addHeaderView(card, null, false); + } + } listView.addFooterView(inflater.inflate(R.layout.list_shadow_footer, null, false)); View emptyView = new View(context); emptyView.setLayoutParams(new AbsListView.LayoutParams( @@ -222,6 +236,10 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { this.trackBitmapSelectionSupported = trackBitmapSelectionSupported; } + public void setShowDescriptionCard(boolean showDescriptionCard) { + this.showDescriptionCard = showDescriptionCard; + } + private void refreshTrackBitmap() { TrackBitmapDrawer trackDrawer = getTrackBitmapDrawer(); if (trackDrawer != null) { @@ -422,6 +440,80 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener { } } + @Nullable + private View getDescriptionCardView(Context context) { + GPXFile gpx = getGpx(); + if (gpx == null || gpx.metadata == null) { + return null; + } + + TravelArticle article = getTravelArticle(gpx.metadata); + if (article != null) { + return createTravelArticleCard(context, article); + } + + if (!TextUtils.isEmpty(gpx.metadata.desc)) { + return createDescriptionCard(context, gpx.metadata.desc); + } + + return null; + } + + @Nullable + private TravelArticle getTravelArticle(@NonNull GPXUtilities.Metadata metadata) { + String title = metadata.getArticleTitle(); + String lang = metadata.getArticleLang(); + if (!TextUtils.isEmpty(title) && !TextUtils.isEmpty(lang)) { + // FIXME: check immediately after deleting the Travel DB + return app.getTravelDbHelper().getArticle(title, lang); + } + return null; + } + + private Drawable getReadIcon() { + int colorId = app.getSettings().isLightContent() ? R.color.wikivoyage_active_light : R.color.wikivoyage_active_dark; + return app.getUIUtilities().getIcon(R.drawable.ic_action_read_article, colorId); + } + + private View createTravelArticleCard(final Context context, @NonNull TravelArticle article) { + View card = LayoutInflater.from(context).inflate(R.layout.wikivoyage_article_card, null); + ((TextView) card.findViewById(R.id.title)).setText(article.getTitle()); + ((TextView) card.findViewById(R.id.content)).setText(WikiArticleHelper.getPartialContent(article.getContent())); + ((TextView) card.findViewById(R.id.part_of)).setText(article.getGeoDescription()); + // FIXME: icon + TextView readBtn = (TextView) card.findViewById(R.id.left_button); + readBtn.setText(app.getString(R.string.shared_string_read)); + readBtn.setCompoundDrawablesWithIntrinsicBounds(getReadIcon(), null, null, null); + readBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Toast.makeText(context, "Read", Toast.LENGTH_SHORT).show(); // FIXME + } + }); + card.findViewById(R.id.right_button).setVisibility(View.GONE); + card.findViewById(R.id.divider).setVisibility(View.GONE); + card.findViewById(R.id.list_item_divider).setVisibility(View.VISIBLE); + return card; + } + + private View createDescriptionCard(final Context context, @NonNull String descHtml) { + String desc = Html.fromHtml(descHtml).toString().trim(); + if (!TextUtils.isEmpty(desc)) { + View card = LayoutInflater.from(context).inflate(R.layout.gpx_description_card, null); + ((TextView) card.findViewById(R.id.description)).setText(desc); + TextView readBtn = (TextView) card.findViewById(R.id.read_button); + readBtn.setCompoundDrawablesWithIntrinsicBounds(getReadIcon(), null, null, null); + readBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Toast.makeText(context, "Read", Toast.LENGTH_SHORT).show(); // FIXME + } + }); + return card; + } + return null; + } + public boolean isGpxFileSelected(GPXFile gpxFile) { return gpxFile != null && ((gpxFile.showCurrentTrack && app.getSelectedGpxHelper().getSelectedCurrentRecordingTrack() != null) || diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java index 4f31f31bdc..fa71cbbfde 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java @@ -133,6 +133,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements GpxDisplayItemType.TRACK_POINTS, GpxDisplayItemType.TRACK_ROUTE_POINTS); fragmentAdapter.setShowMapOnly(true); fragmentAdapter.setTrackBitmapSelectionSupported(false); + fragmentAdapter.setShowDescriptionCard(true); fragmentAdapter.onCreateView(mainView); setContent(listView); diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java index 25711761bc..d69c75d0e7 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java @@ -119,6 +119,7 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit GpxDisplayItemType.TRACK_SEGMENT); fragmentAdapter.setShowMapOnly(false); fragmentAdapter.setTrackBitmapSelectionSupported(true); + fragmentAdapter.setShowDescriptionCard(false); fragmentAdapter.onCreateView(view); adapter = new SegmentGPXAdapter(inflater.getContext(), new ArrayList());