Merge pull request #5562 from osmandapp/gpx_card

Gpx card
This commit is contained in:
Vitaliy 2018-06-11 15:51:51 +03:00 committed by GitHub
commit c09d7ba766
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 274 additions and 3 deletions

View 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:id="@+id/background_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
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>

View file

@ -8,6 +8,7 @@
android:orientation="vertical">
<FrameLayout
android:id="@+id/background_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/wikivoyage_card_bg_color">
@ -172,4 +173,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>

View file

@ -86,7 +86,7 @@
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?attr/wikivoyage_primary_text_color"
android:textSize="@dimen/default_list_text_size"
@ -95,7 +95,7 @@
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="2"
android:textColor="@color/wikivoyage_secondary_text"

View file

@ -0,0 +1,67 @@
package net.osmand.plus.myplaces;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.AppBarLayout;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.LinearLayout;
import net.osmand.AndroidUtils;
import net.osmand.plus.R;
import net.osmand.plus.base.BaseOsmAndDialogFragment;
public class GpxDescriptionDialogFragment extends BaseOsmAndDialogFragment {
public static final String TAG = GpxDescriptionDialogFragment.class.getSimpleName();
public static final String CONTENT_KEY = "content_key";
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
Context ctx = getContext();
final Toolbar topBar = new Toolbar(ctx);
topBar.setClickable(true);
Drawable back = getMyApplication().getUIUtilities().getIcon(R.drawable.ic_arrow_back);
topBar.setNavigationIcon(back);
topBar.setNavigationContentDescription(R.string.access_shared_string_navigate_up);
topBar.setTitle(R.string.description);
topBar.setBackgroundColor(ContextCompat.getColor(ctx, AndroidUtils.resolveAttribute(ctx, R.attr.pstsTabBackground)));
topBar.setTitleTextColor(ContextCompat.getColor(ctx, AndroidUtils.resolveAttribute(ctx, R.attr.pstsTextColor)));
topBar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
dismiss();
}
});
AppBarLayout appBar = new AppBarLayout(ctx);
appBar.addView(topBar);
WebView webView = new WebView(ctx);
webView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
webView.getSettings().setTextZoom((int) (getResources().getConfiguration().fontScale * 100f));
Bundle args = getArguments();
if (args != null) {
String content = args.getString(CONTENT_KEY);
if (content != null) {
webView.loadData(content, "text/html", "UTF-8");
}
}
LinearLayout mainLl = new LinearLayout(ctx);
mainLl.setOrientation(LinearLayout.VERTICAL);
mainLl.addView(appBar);
mainLl.addView(webView);
return mainLl;
}
}

View file

@ -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;
@ -25,7 +28,12 @@ import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.RequestCreator;
import net.osmand.AndroidUtils;
import net.osmand.PicassoUtils;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.QuadRect;
@ -47,6 +55,11 @@ 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.widgets.tools.CropCircleTransformation;
import net.osmand.plus.wikipedia.WikiArticleHelper;
import net.osmand.plus.wikivoyage.WikivoyageUtils;
import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment;
import net.osmand.plus.wikivoyage.data.TravelArticle;
import net.osmand.render.RenderingRulesStorage;
import java.lang.ref.WeakReference;
@ -78,6 +91,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 +173,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 +243,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 +447,111 @@ 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)) {
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 final TravelArticle article) {
View card = LayoutInflater.from(context).inflate(R.layout.wikivoyage_article_card, null);
card.findViewById(R.id.background_view).setBackgroundColor(ContextCompat.getColor(context,
app.getSettings().isLightContent() ? R.color.list_item_light : R.color.list_item_dark));
((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());
final ImageView icon = (ImageView) card.findViewById(R.id.icon);
final String url = TravelArticle.getImageUrl(article.getImageTitle(), false);
final PicassoUtils picassoUtils = PicassoUtils.getPicasso(app);
RequestCreator rc = Picasso.get().load(url);
WikivoyageUtils.setupNetworkPolicy(app.getSettings(), rc);
rc.transform(new CropCircleTransformation())
.into(icon, new Callback() {
@Override
public void onSuccess() {
icon.setVisibility(View.VISIBLE);
picassoUtils.setResultLoaded(url, true);
}
@Override
public void onError(Exception e) {
picassoUtils.setResultLoaded(url, false);
}
});
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) {
TrackActivity activity = getTrackActivity();
if (activity != null) {
WikivoyageArticleDialogFragment.showInstance(app,
activity.getSupportFragmentManager(), article.getTripId(), article.getLang());
}
}
});
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 final 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);
card.findViewById(R.id.background_view).setBackgroundColor(ContextCompat.getColor(context,
app.getSettings().isLightContent() ? R.color.list_item_light : R.color.list_item_dark));
((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) {
TrackActivity activity = getTrackActivity();
if (activity != null) {
Bundle args = new Bundle();
args.putString(GpxDescriptionDialogFragment.CONTENT_KEY, descHtml);
GpxDescriptionDialogFragment fragment = new GpxDescriptionDialogFragment();
fragment.setArguments(args);
fragment.show(activity.getSupportFragmentManager(), GpxDescriptionDialogFragment.TAG);
}
}
});
return card;
}
return null;
}
public boolean isGpxFileSelected(GPXFile gpxFile) {
return gpxFile != null &&
((gpxFile.showCurrentTrack && app.getSelectedGpxHelper().getSelectedCurrentRecordingTrack() != null) ||

View file

@ -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);

View file

@ -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>());

View file

@ -12,6 +12,7 @@ import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -23,7 +24,7 @@ public class TravelLocalDataHelper {
private WikivoyageLocalDataDbHelper dbHelper;
private Map<String, WikivoyageSearchHistoryItem> historyMap;
private Map<String, WikivoyageSearchHistoryItem> historyMap = new HashMap<>();
private List<TravelArticle> savedArticles = new ArrayList<>();
private Listener listener;