From d01ff166d1e2d85cb9fbd75eb3553e42c161eb87 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 8 Feb 2021 17:38:21 +0200 Subject: [PATCH 1/5] Open wpt menu from TrackMenuFragment --- OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java | 4 +++- OsmAnd/src/net/osmand/plus/track/TrackPointsCard.java | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index 6776ea8354..13b3188933 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -828,7 +828,9 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card @Override protected void onHeaderClick() { - updateMenuState(); + if (getCurrentMenuState() == MenuState.HEADER_ONLY) { + updateMenuState(); + } } private void adjustMapPosition(int y) { diff --git a/OsmAnd/src/net/osmand/plus/track/TrackPointsCard.java b/OsmAnd/src/net/osmand/plus/track/TrackPointsCard.java index ec3bc0446e..d605f9ed43 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackPointsCard.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackPointsCard.java @@ -26,6 +26,8 @@ import net.osmand.AndroidUtils; import net.osmand.Collator; import net.osmand.GPXUtilities.WptPt; import net.osmand.OsmAndCollator; +import net.osmand.data.LatLon; +import net.osmand.data.PointDescription; import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType; @@ -173,6 +175,12 @@ public class TrackPointsCard extends BaseCard implements OnChildClickListener, O @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { + GpxDisplayItem item = adapter.getChild(groupPosition, childPosition); + if (item != null && item.locationStart != null) { + LatLon location = new LatLon(item.locationStart.lat, item.locationStart.lon); + PointDescription description = new PointDescription(PointDescription.POINT_TYPE_WPT, item.name); + mapActivity.getContextMenu().show(location, description, item.locationStart); + } return true; } From 02117a8ffd79f8432d36f2c1acdac715a7a0d28c Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 8 Feb 2021 18:34:08 +0200 Subject: [PATCH 2/5] 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 { From 095c22a03528bdd4cbac03ed9dd5beffc5e4eb50 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Mon, 8 Feb 2021 19:28:59 +0200 Subject: [PATCH 3/5] Add line on top of selected tab item --- .../drawable/bottom_navigation_item_bg_dark.xml | 8 ++++++++ .../drawable/bottom_navigation_item_bg_light.xml | 8 ++++++++ .../drawable/navigation_item_active_bg_dark.xml | 15 +++++++++++++++ .../drawable/navigation_item_active_bg_light.xml | 15 +++++++++++++++ OsmAnd/res/layout/track_menu.xml | 2 +- OsmAnd/res/values/attrs.xml | 1 + OsmAnd/res/values/styles.xml | 2 ++ 7 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 OsmAnd/res/drawable/bottom_navigation_item_bg_dark.xml create mode 100644 OsmAnd/res/drawable/bottom_navigation_item_bg_light.xml create mode 100644 OsmAnd/res/drawable/navigation_item_active_bg_dark.xml create mode 100644 OsmAnd/res/drawable/navigation_item_active_bg_light.xml diff --git a/OsmAnd/res/drawable/bottom_navigation_item_bg_dark.xml b/OsmAnd/res/drawable/bottom_navigation_item_bg_dark.xml new file mode 100644 index 0000000000..f0934052c1 --- /dev/null +++ b/OsmAnd/res/drawable/bottom_navigation_item_bg_dark.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/bottom_navigation_item_bg_light.xml b/OsmAnd/res/drawable/bottom_navigation_item_bg_light.xml new file mode 100644 index 0000000000..f410c7a1ff --- /dev/null +++ b/OsmAnd/res/drawable/bottom_navigation_item_bg_light.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/navigation_item_active_bg_dark.xml b/OsmAnd/res/drawable/navigation_item_active_bg_dark.xml new file mode 100644 index 0000000000..de8b54eb6e --- /dev/null +++ b/OsmAnd/res/drawable/navigation_item_active_bg_dark.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/drawable/navigation_item_active_bg_light.xml b/OsmAnd/res/drawable/navigation_item_active_bg_light.xml new file mode 100644 index 0000000000..31d31f1c40 --- /dev/null +++ b/OsmAnd/res/drawable/navigation_item_active_bg_light.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/track_menu.xml b/OsmAnd/res/layout/track_menu.xml index db0f8a47f9..e62361afc2 100644 --- a/OsmAnd/res/layout/track_menu.xml +++ b/OsmAnd/res/layout/track_menu.xml @@ -206,7 +206,7 @@ android:layout_height="@dimen/context_menu_action_buttons_height" android:layout_gravity="bottom" android:background="?attr/wikivoyage_card_bg_color" - osmand:itemBackground="?attr/wikivoyage_card_bg_color" + osmand:itemBackground="?attr/bottom_navigation_item_background" osmand:itemIconTint="@color/bottom_navigation_color_selector_light" osmand:itemTextColor="@color/bottom_navigation_color_selector_light" osmand:labelVisibilityMode="labeled" diff --git a/OsmAnd/res/values/attrs.xml b/OsmAnd/res/values/attrs.xml index c745589ef7..f75867c8e8 100644 --- a/OsmAnd/res/values/attrs.xml +++ b/OsmAnd/res/values/attrs.xml @@ -142,6 +142,7 @@ + diff --git a/OsmAnd/res/values/styles.xml b/OsmAnd/res/values/styles.xml index 5c074185ef..4648cba1cc 100644 --- a/OsmAnd/res/values/styles.xml +++ b/OsmAnd/res/values/styles.xml @@ -249,6 +249,7 @@ @color/text_input_background_light @drawable/img_help_announcement_time_day @color/switch_button_active_light + @drawable/bottom_navigation_item_bg_light