From 2660d23d7901f153214e648ddbb22097421fc74c Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 25 May 2018 16:14:17 +0300 Subject: [PATCH 1/2] add popup for sharing article links --- .../fragment_wikivoyage_article_dialog.xml | 9 ----- .../WikivoyageArticleDialogFragment.java | 34 +++++++++++++++++-- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/OsmAnd/res/layout/fragment_wikivoyage_article_dialog.xml b/OsmAnd/res/layout/fragment_wikivoyage_article_dialog.xml index fb463df1fa..e828e0ea7f 100644 --- a/OsmAnd/res/layout/fragment_wikivoyage_article_dialog.xml +++ b/OsmAnd/res/layout/fragment_wikivoyage_article_dialog.xml @@ -54,15 +54,6 @@ tools:text="En" tools:textColor="?attr/wikivoyage_active_color"/> - - diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java index 3f6b611952..82b7293a67 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java @@ -16,6 +16,7 @@ import android.support.v7.widget.Toolbar; import android.text.TextUtils; import android.view.Gravity; import android.view.LayoutInflater; +import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; @@ -34,6 +35,7 @@ import net.osmand.plus.activities.TrackActivity; import net.osmand.plus.development.OsmandDevelopmentPlugin; import net.osmand.plus.helpers.FileNameTranslationHelper; import net.osmand.plus.wikipedia.WikiArticleBaseDialogFragment; +import net.osmand.plus.wikipedia.WikiArticleHelper; import net.osmand.plus.wikivoyage.WikivoyageShowPicturesDialogFragment; import net.osmand.plus.wikivoyage.WikivoyageWebViewClient; import net.osmand.plus.wikivoyage.data.TravelArticle; @@ -60,7 +62,9 @@ public class WikivoyageArticleDialogFragment extends WikiArticleBaseDialogFragme private static final String SELECTED_LANG_KEY = "selected_lang_key"; private static final String EMPTY_URL = "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d4//"; - + + private static final int MENU_ITEM_SHARE = 0; + private long tripId = NO_VALUE; private ArrayList langs; private String selectedLang; @@ -426,4 +430,30 @@ public class WikivoyageArticleDialogFragment extends WikiArticleBaseDialogFragme fragmentManager.popBackStackImmediate(pop, 0); } } -} + + protected void setupToolbar(Toolbar toolbar) { + super.setupToolbar(toolbar); + toolbar.setOverflowIcon(getIcon(R.drawable.ic_overflow_menu_white, R.color.icon_color)); + + Menu menu = toolbar.getMenu(); + MenuItem.OnMenuItemClickListener itemClickListener = new MenuItem.OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + OsmandApplication app = getMyApplication(); + if (app != null) { + int itemId = item.getItemId(); + if (itemId == MENU_ITEM_SHARE) { + Intent intent = new Intent(Intent.ACTION_SEND); + intent.putExtra(Intent.EXTRA_TEXT, WikiArticleHelper.buildTravelUrl(article.getTitle(), article.getLang())); + intent.setType("text/plain"); + startActivity(Intent.createChooser(intent, getString(R.string.shared_string_share))); + return true; + } + } + return false; + } + }; + MenuItem itemShow = menu.add(0, MENU_ITEM_SHARE, 0, R.string.shared_string_share); + itemShow.setOnMenuItemClickListener(itemClickListener); + } +} \ No newline at end of file From 843962d0ecbc4d625636c0ec84339310886cc4d4 Mon Sep 17 00:00:00 2001 From: Chumva Date: Fri, 25 May 2018 16:24:24 +0300 Subject: [PATCH 2/2] add Override --- .../plus/wikivoyage/article/WikivoyageArticleDialogFragment.java | 1 + 1 file changed, 1 insertion(+) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java index 82b7293a67..8f23e4d7cf 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleDialogFragment.java @@ -431,6 +431,7 @@ public class WikivoyageArticleDialogFragment extends WikiArticleBaseDialogFragme } } + @Override protected void setupToolbar(Toolbar toolbar) { super.setupToolbar(toolbar); toolbar.setOverflowIcon(getIcon(R.drawable.ic_overflow_menu_white, R.color.icon_color));