Gpx description card in progress
This commit is contained in:
parent
74052f02d5
commit
a1a433f11d
5 changed files with 164 additions and 0 deletions
64
OsmAnd/res/layout/gpx_description_card.xml
Normal file
64
OsmAnd/res/layout/gpx_description_card.xml
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/wikivoyage_card_bg_color"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="@dimen/bottom_sheet_content_padding_small"
|
||||
android:paddingTop="@dimen/content_padding">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/description"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="@dimen/context_menu_padding_margin_tiny"
|
||||
android:layout_marginLeft="@dimen/content_padding"
|
||||
android:layout_marginRight="@dimen/content_padding"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="5"
|
||||
android:textAppearance="@style/TextAppearance.ContextMenuSubtitle"
|
||||
tools:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard." />
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/bottom_sheet_content_padding_small"
|
||||
android:layout_marginStart="@dimen/bottom_sheet_content_padding_small"
|
||||
android:background="@drawable/rounded_background_3dp">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/read_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:drawablePadding="@dimen/bottom_sheet_content_padding_small"
|
||||
android:ellipsize="end"
|
||||
android:gravity="center_vertical"
|
||||
android:letterSpacing="@dimen/text_button_letter_spacing"
|
||||
android:maxLines="1"
|
||||
android:paddingBottom="@dimen/context_menu_padding_margin_tiny"
|
||||
android:paddingLeft="@dimen/bottom_sheet_content_padding_small"
|
||||
android:paddingRight="@dimen/bottom_sheet_content_padding_small"
|
||||
android:paddingTop="@dimen/context_menu_padding_margin_tiny"
|
||||
android:text="@string/shared_string_read"
|
||||
android:textColor="?attr/wikivoyage_active_color"
|
||||
android:textSize="@dimen/text_button_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium"
|
||||
tools:drawableLeft="@drawable/ic_action_read_article"
|
||||
tools:drawableTint="?attr/wikivoyage_active_color"
|
||||
tools:ignore="UnusedAttribute" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<include layout="@layout/list_item_divider" />
|
||||
|
||||
</LinearLayout>
|
|
@ -172,4 +172,10 @@
|
|||
android:visibility="gone"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
<include
|
||||
android:id="@+id/list_item_divider"
|
||||
layout="@layout/list_item_divider"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -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) ||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<GpxDisplayItem>());
|
||||
|
|
Loading…
Reference in a new issue