Browse Source

Adding share option to context menu

master
anthony restaino 8 years ago
parent
commit
b0d07298dd
  1. 9
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  2. 25
      app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java
  3. 22
      app/src/main/java/acr/browser/lightning/utils/IntentUtils.java

9
app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java

@ -110,6 +110,7 @@ import acr.browser.lightning.interpolator.BezierDecelerateInterpolator; @@ -110,6 +110,7 @@ import acr.browser.lightning.interpolator.BezierDecelerateInterpolator;
import acr.browser.lightning.receiver.NetworkReceiver;
import acr.browser.lightning.search.SuggestionsAdapter;
import acr.browser.lightning.utils.DrawableUtils;
import acr.browser.lightning.utils.IntentUtils;
import acr.browser.lightning.utils.Preconditions;
import acr.browser.lightning.utils.ProxyUtils;
import acr.browser.lightning.utils.ThemeUtils;
@ -780,13 +781,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -780,13 +781,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
overridePendingTransition(R.anim.slide_up_in, R.anim.fade_out_scale);
return true;
case R.id.action_share:
if (currentUrl != null && !UrlUtils.isSpecialUrl(currentUrl)) {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_SUBJECT, currentView.getTitle());
shareIntent.putExtra(Intent.EXTRA_TEXT, currentUrl);
startActivity(Intent.createChooser(shareIntent, getResources().getString(R.string.dialog_title_share)));
}
new IntentUtils(this).shareUrl(currentUrl, currentView != null ? currentView.getTitle() : null);
return true;
case R.id.action_bookmarks:
openBookmarks();

25
app/src/main/java/acr/browser/lightning/dialog/LightningDialogBuilder.java

@ -31,6 +31,7 @@ import acr.browser.lightning.database.HistoryItem; @@ -31,6 +31,7 @@ import acr.browser.lightning.database.HistoryItem;
import acr.browser.lightning.database.bookmark.BookmarkModel;
import acr.browser.lightning.database.history.HistoryModel;
import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.utils.IntentUtils;
import acr.browser.lightning.utils.Preconditions;
import acr.browser.lightning.utils.Utils;
@ -114,6 +115,12 @@ public class LightningDialogBuilder { @@ -114,6 +115,12 @@ public class LightningDialogBuilder {
uiController.handleNewTab(NewTab.INCOGNITO, item.getUrl());
}
},
new BrowserDialog.Item(R.string.action_share) {
@Override
public void onClick() {
new IntentUtils(activity).shareUrl(item.getUrl(), item.getTitle());
}
},
new BrowserDialog.Item(R.string.dialog_copy_link) {
@Override
public void onClick() {
@ -277,6 +284,12 @@ public class LightningDialogBuilder { @@ -277,6 +284,12 @@ public class LightningDialogBuilder {
uiController.handleNewTab(NewTab.INCOGNITO, url);
}
},
new BrowserDialog.Item(R.string.action_share) {
@Override
public void onClick() {
new IntentUtils(activity).shareUrl(url, null);
}
},
new BrowserDialog.Item(R.string.dialog_copy_link) {
@Override
public void onClick() {
@ -323,6 +336,12 @@ public class LightningDialogBuilder { @@ -323,6 +336,12 @@ public class LightningDialogBuilder {
uiController.handleNewTab(NewTab.INCOGNITO, url);
}
},
new BrowserDialog.Item(R.string.action_share) {
@Override
public void onClick() {
new IntentUtils(activity).shareUrl(url, null);
}
},
new BrowserDialog.Item(R.string.dialog_copy_link) {
@Override
public void onClick() {
@ -359,6 +378,12 @@ public class LightningDialogBuilder { @@ -359,6 +378,12 @@ public class LightningDialogBuilder {
uiController.handleNewTab(NewTab.INCOGNITO, url);
}
},
new BrowserDialog.Item(R.string.action_share) {
@Override
public void onClick() {
new IntentUtils(activity).shareUrl(url, null);
}
},
new BrowserDialog.Item(R.string.dialog_copy_link) {
@Override
public void onClick() {

22
app/src/main/java/acr/browser/lightning/utils/IntentUtils.java

@ -18,7 +18,9 @@ import java.util.List; @@ -18,7 +18,9 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import acr.browser.lightning.R;
import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.controller.UIController;
public class IntentUtils {
@ -112,4 +114,24 @@ public class IntentUtils { @@ -112,4 +114,24 @@ public class IntentUtils {
}
return false;
}
/**
* Shares a URL to the system.
*
* @param url the URL to share. If the URL is null
* or a special URL, no sharing will occur.
* @param title the title of the URL to share. This
* is optional.
*/
public void shareUrl(@Nullable String url, @Nullable String title) {
if (url != null && !UrlUtils.isSpecialUrl(url)) {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
if (title != null) {
shareIntent.putExtra(Intent.EXTRA_SUBJECT, title);
}
shareIntent.putExtra(Intent.EXTRA_TEXT, url);
mActivity.startActivity(Intent.createChooser(shareIntent, mActivity.getString(R.string.dialog_title_share)));
}
}
}

Loading…
Cancel
Save