diff --git a/OsmAnd/res/drawable/btn_border_active.xml b/OsmAnd/res/drawable/btn_border_active.xml index f670a7dfc9..e86fe414fa 100644 --- a/OsmAnd/res/drawable/btn_border_active.xml +++ b/OsmAnd/res/drawable/btn_border_active.xml @@ -1,8 +1,8 @@ + xmlns:android="http://schemas.android.com/apk/res/android" + android:shape="rectangle"> - - + + \ No newline at end of file diff --git a/OsmAnd/res/layout/dialog_edit_gpx_description.xml b/OsmAnd/res/layout/dialog_edit_gpx_description.xml index e8e8443c98..52b5f97bdc 100644 --- a/OsmAnd/res/layout/dialog_edit_gpx_description.xml +++ b/OsmAnd/res/layout/dialog_edit_gpx_description.xml @@ -1,85 +1,85 @@ + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" + android:background="?attr/card_and_list_background_basic" + xmlns:tools="http://schemas.android.com/tools" + xmlns:osmand="http://schemas.android.com/apk/res-auto"> - + - + - - + + - + - + - + - + - + \ No newline at end of file diff --git a/OsmAnd/res/layout/dialog_read_gpx_description.xml b/OsmAnd/res/layout/dialog_read_gpx_description.xml index d21ae172c9..f4cf390af5 100644 --- a/OsmAnd/res/layout/dialog_read_gpx_description.xml +++ b/OsmAnd/res/layout/dialog_read_gpx_description.xml @@ -1,95 +1,105 @@ + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:osmand="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/root" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" + android:background="?attr/list_background_color"> - + - + - + - + - + - + - + - + - + - + - + + - + - + diff --git a/OsmAnd/res/layout/gpx_description_preview_card.xml b/OsmAnd/res/layout/gpx_description_preview_card.xml index 20393d7295..79e3883534 100644 --- a/OsmAnd/res/layout/gpx_description_preview_card.xml +++ b/OsmAnd/res/layout/gpx_description_preview_card.xml @@ -17,93 +17,108 @@ - + - + - + - + - + - + + + + + + + + - diff --git a/OsmAnd/res/menu/edit_description_menu.xml b/OsmAnd/res/menu/edit_description_menu.xml index 8b3c09dc51..1d4e64be98 100644 --- a/OsmAnd/res/menu/edit_description_menu.xml +++ b/OsmAnd/res/menu/edit_description_menu.xml @@ -1,8 +1,8 @@ - + xmlns:osmand="http://schemas.android.com/apk/res-auto"> + diff --git a/OsmAnd/res/values/attrs.xml b/OsmAnd/res/values/attrs.xml index c1463657dc..c745589ef7 100644 --- a/OsmAnd/res/values/attrs.xml +++ b/OsmAnd/res/values/attrs.xml @@ -141,7 +141,7 @@ - + diff --git a/OsmAnd/src/net/osmand/FileUtils.java b/OsmAnd/src/net/osmand/FileUtils.java index 7fe28bf418..580450df60 100644 --- a/OsmAnd/src/net/osmand/FileUtils.java +++ b/OsmAnd/src/net/osmand/FileUtils.java @@ -196,8 +196,4 @@ public class FileUtils { public interface RenameCallback { void renamedTo(File file); } - - public interface GpxEditedCallback { - void onGpxChanged(); - } } diff --git a/OsmAnd/src/net/osmand/plus/track/DescriptionCard.java b/OsmAnd/src/net/osmand/plus/track/DescriptionCard.java index 94c3529e0c..6a6d5a21a0 100644 --- a/OsmAnd/src/net/osmand/plus/track/DescriptionCard.java +++ b/OsmAnd/src/net/osmand/plus/track/DescriptionCard.java @@ -23,90 +23,95 @@ import androidx.appcompat.widget.AppCompatImageView; public class DescriptionCard extends BaseCard { - private final GPXFile gpxFile; + private final GPXFile gpxFile; - public DescriptionCard(MapActivity mapActivity, GPXFile gpxFile) { - super(mapActivity); - this.gpxFile = gpxFile; - } + public DescriptionCard(MapActivity mapActivity, GPXFile gpxFile) { + super(mapActivity); + this.gpxFile = gpxFile; + } - @Override - public int getCardLayoutId() { - return R.layout.gpx_description_preview_card; - } + @Override + public int getCardLayoutId() { + return R.layout.gpx_description_preview_card; + } - @Override - protected void updateContent() { - final String title = gpxFile.metadata.getArticleTitle(); - final String imageUrl = getMetadataImageLink(gpxFile.metadata); - final String descriptionHtml = gpxFile.metadata.getDescription(); + @Override + protected void updateContent() { + if (gpxFile == null || gpxFile.metadata == null || gpxFile.metadata.getDescription() == null) { + AndroidUiHelper.updateVisibility(view, false); + return; + } - setupImage(imageUrl); + final String title = gpxFile.metadata.getArticleTitle(); + final String imageUrl = getMetadataImageLink(gpxFile.metadata); + final String descriptionHtml = gpxFile.metadata.getDescription(); - TextViewEx tvDescription = view.findViewById(R.id.description); - tvDescription.setText(getFirstParagraph(descriptionHtml)); + setupImage(imageUrl); - TextViewEx readBtn = view.findViewById(R.id.btn_read_full); - readBtn.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - GpxReadDescriptionDialogFragment.showInstance(mapActivity, title, imageUrl, descriptionHtml); - } - }); - TextViewEx editBtn = view.findViewById(R.id.btn_edit); - editBtn.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - GpxEditDescriptionDialogFragment.showInstance(mapActivity, descriptionHtml); - } - }); - } + TextViewEx tvDescription = view.findViewById(R.id.description); + tvDescription.setText(getFirstParagraph(descriptionHtml)); - @Nullable - private String getMetadataImageLink(@NonNull GPXUtilities.Metadata metadata) { - String link = metadata.link; - if (!TextUtils.isEmpty(link)) { - String lowerCaseLink = link.toLowerCase(); - if (lowerCaseLink.contains(".jpg") - || lowerCaseLink.contains(".jpeg") - || lowerCaseLink.contains(".png") - || lowerCaseLink.contains(".bmp") - || lowerCaseLink.contains(".webp")) { - return link; - } - } - return null; - } + TextViewEx readBtn = view.findViewById(R.id.btn_read_full); + readBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + GpxReadDescriptionDialogFragment.showInstance(mapActivity, title, imageUrl, descriptionHtml); + } + }); + TextViewEx editBtn = view.findViewById(R.id.btn_edit); + editBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + GpxEditDescriptionDialogFragment.showInstance(mapActivity, descriptionHtml); + } + }); + } - private String getFirstParagraph(String descriptionHtml) { - if (descriptionHtml != null) { - String firstParagraph = WikiArticleHelper.getPartialContent(descriptionHtml); - if (!TextUtils.isEmpty(firstParagraph)) { - return firstParagraph; - } - } - return descriptionHtml; - } + @Nullable + private String getMetadataImageLink(@NonNull GPXUtilities.Metadata metadata) { + String link = metadata.link; + if (!TextUtils.isEmpty(link)) { + String lowerCaseLink = link.toLowerCase(); + if (lowerCaseLink.contains(".jpg") + || lowerCaseLink.contains(".jpeg") + || lowerCaseLink.contains(".png") + || lowerCaseLink.contains(".bmp") + || lowerCaseLink.contains(".webp")) { + return link; + } + } + return null; + } - private void setupImage(final String imageUrl) { - if (imageUrl == null) { - return; - } - final PicassoUtils picasso = PicassoUtils.getPicasso(app); - RequestCreator rc = Picasso.get().load(imageUrl); - final AppCompatImageView image = view.findViewById(R.id.main_image); - rc.into(image, new Callback() { - @Override - public void onSuccess() { - picasso.setResultLoaded(imageUrl, true); - AndroidUiHelper.updateVisibility(image, true); - } + private String getFirstParagraph(String descriptionHtml) { + if (descriptionHtml != null) { + String firstParagraph = WikiArticleHelper.getPartialContent(descriptionHtml); + if (!TextUtils.isEmpty(firstParagraph)) { + return firstParagraph; + } + } + return descriptionHtml; + } - @Override - public void onError(Exception e) { - picasso.setResultLoaded(imageUrl, false); - } - }); - } + private void setupImage(final String imageUrl) { + if (imageUrl == null) { + return; + } + final PicassoUtils picasso = PicassoUtils.getPicasso(app); + RequestCreator rc = Picasso.get().load(imageUrl); + final AppCompatImageView image = view.findViewById(R.id.main_image); + rc.into(image, new Callback() { + @Override + public void onSuccess() { + picasso.setResultLoaded(imageUrl, true); + AndroidUiHelper.updateVisibility(image, true); + } + + @Override + public void onError(Exception e) { + picasso.setResultLoaded(imageUrl, false); + } + }); + } } diff --git a/OsmAnd/src/net/osmand/plus/track/GpxEditDescriptionDialogFragment.java b/OsmAnd/src/net/osmand/plus/track/GpxEditDescriptionDialogFragment.java index 7d9953fc5b..1607eda9b2 100644 --- a/OsmAnd/src/net/osmand/plus/track/GpxEditDescriptionDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/GpxEditDescriptionDialogFragment.java @@ -94,7 +94,7 @@ public class GpxEditDescriptionDialogFragment extends BaseOsmAndDialogFragment { log.error(errorMessage); } - trackMenuFragment.onGpxChanged(); + trackMenuFragment.updateContent(); if (readGpxFragment != null) { Bundle args = readGpxFragment.getArguments(); if (args != null) { diff --git a/OsmAnd/src/net/osmand/plus/track/GpxReadDescriptionDialogFragment.java b/OsmAnd/src/net/osmand/plus/track/GpxReadDescriptionDialogFragment.java index 6cd07e5a6b..ed5af7cdea 100644 --- a/OsmAnd/src/net/osmand/plus/track/GpxReadDescriptionDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/GpxReadDescriptionDialogFragment.java @@ -13,6 +13,7 @@ import android.view.View; import android.view.ViewGroup; import android.webkit.WebSettings; import android.webkit.WebView; +import android.webkit.WebViewClient; import com.squareup.picasso.Callback; import com.squareup.picasso.Picasso; @@ -25,6 +26,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.base.BaseOsmAndDialogFragment; import net.osmand.plus.helpers.AndroidUiHelper; +import net.osmand.plus.widgets.TextViewEx; import net.osmand.plus.widgets.WebViewEx; import net.osmand.plus.wikivoyage.WikivoyageUtils; @@ -59,13 +61,6 @@ public class GpxReadDescriptionDialogFragment extends BaseOsmAndDialogFragment { setupImage(view); setupWebView(view); - view.findViewById(R.id.btn_edit).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - GpxEditDescriptionDialogFragment.showInstance(getMyActivity(), getArgument(CONTENT_KEY)); - } - }); - return view; } @@ -153,7 +148,7 @@ public class GpxReadDescriptionDialogFragment extends BaseOsmAndDialogFragment { }); } - private void setupWebView(View view) { + private void setupWebView(final View view) { webView = view.findViewById(R.id.content); webView.setScrollbarFadingEnabled(true); webView.setVerticalScrollBarEnabled(false); @@ -163,6 +158,13 @@ public class GpxReadDescriptionDialogFragment extends BaseOsmAndDialogFragment { webView.getSettings().setDomStorageEnabled(true); webView.getSettings().setLoadWithOverviewMode(true); webView.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH); + webView.setWebViewClient(new WebViewClient() { + @Override + public void onPageCommitVisible(WebView webView, String url) { + super.onPageCommitVisible(webView, url); + setupDependentViews(view); + } + }); loadWebviewData(); } @@ -175,6 +177,21 @@ public class GpxReadDescriptionDialogFragment extends BaseOsmAndDialogFragment { } } + private void setupDependentViews(final View view) { + TextViewEx readBtn = view.findViewById(R.id.btn_edit); + readBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + GpxEditDescriptionDialogFragment.showInstance(getMyActivity(), getArgument(CONTENT_KEY)); + } + }); + AndroidUiHelper.setVisibility(View.VISIBLE, + readBtn, view.findViewById(R.id.divider), view.findViewById(R.id.bottom_empty_space)); + int backgroundColor = isNightMode(false) ? + R.color.activity_background_color_dark : R.color.activity_background_color_light; + view.findViewById(R.id.root).setBackgroundResource(backgroundColor); + } + private String getColoredContent(String content) { return "\n" + content + diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index d284d820ce..1af803a0f2 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -20,7 +20,6 @@ import com.google.android.material.bottomnavigation.BottomNavigationView; import net.osmand.AndroidUtils; import net.osmand.FileUtils; -import net.osmand.FileUtils.GpxEditedCallback; import net.osmand.FileUtils.RenameCallback; import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.Track; @@ -97,7 +96,7 @@ import static net.osmand.plus.track.OptionsCard.SHOW_ON_MAP_BUTTON_INDEX; import static net.osmand.plus.track.OptionsCard.UPLOAD_OSM_BUTTON_INDEX; public class TrackMenuFragment extends ContextMenuScrollFragment implements CardListener, - SegmentActionsListener, RenameCallback, OnTrackFileMoveListener, GpxEditedCallback { + SegmentActionsListener, RenameCallback, OnTrackFileMoveListener { public static final String TAG = TrackMenuFragment.class.getName(); private static final Log log = PlatformUtil.getLog(TrackMenuFragment.class); @@ -222,10 +221,6 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card } private void updateHeader() { - ViewGroup headerContainer = (ViewGroup) routeMenuTopShadowAll; - if (descriptionCard != null && descriptionCard.getView() != null) { - headerContainer.removeView(descriptionCard.getView()); - } if (menuType == TrackMenuType.OPTIONS) { headerTitle.setText(menuType.titleId); AndroidUiHelper.updateVisibility(headerIcon, false); @@ -233,17 +228,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card String fileName = Algorithms.getFileWithoutDirs(getGpx().path); headerTitle.setText(GpxUiHelper.getGpxTitle(fileName)); AndroidUiHelper.updateVisibility(headerIcon, true); - if (menuType == TrackMenuType.OVERVIEW) { - fillOverviewTab(headerContainer); - } } - runLayoutListener(); - headerContainer.post(new Runnable() { - @Override - public void run() { - openMenuScreen(menuType == TrackMenuType.OVERVIEW ? MenuState.HEADER_ONLY : MenuState.HALF_SCREEN, false); - } - }); } private void setupCards() { @@ -275,23 +260,21 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card optionsCard.setListener(this); cardsContainer.addView(optionsCard.build(mapActivity)); } + } else if (menuType == TrackMenuType.OVERVIEW) { + if (descriptionCard != null && descriptionCard.getView() != null) { + ViewGroup parent = ((ViewGroup) descriptionCard.getView().getParent()); + if (parent != null) { + cardsContainer.removeView(descriptionCard.getView()); + } + cardsContainer.addView(descriptionCard.getView()); + } else { + descriptionCard = new DescriptionCard(getMapActivity(), displayHelper.getGpx()); + cardsContainer.addView(descriptionCard.build(mapActivity)); + } } } } - private void fillOverviewTab(ViewGroup headerContainer) { - if (descriptionCard != null && descriptionCard.getView() != null) { - ViewGroup parent = ((ViewGroup) descriptionCard.getView().getParent()); - if (parent != null) { - parent.removeView(descriptionCard.getView()); - } - headerContainer.addView(descriptionCard.getView()); - } else { - descriptionCard = new DescriptionCard(getMapActivity(), displayHelper.getGpx()); - headerContainer.addView(descriptionCard.build(getMapActivity())); - } - } - @Override protected void calculateLayout(View view, boolean initLayout) { menuTitleHeight = routeMenuTopShadowAll.getHeight() @@ -623,6 +606,9 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card if (optionsCard != null) { optionsCard.updateContent(); } + if (descriptionCard != null) { + descriptionCard.updateContent(); + } setupCards(); } @@ -814,13 +800,6 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card } } - @Override - public void onGpxChanged() { - if (descriptionCard != null) { - descriptionCard.update(); - } - } - public static boolean showInstance(@NonNull MapActivity mapActivity, String path, boolean showCurrentTrack) { try { Bundle args = new Bundle();