Skip to content

Commit

Permalink
Merge pull request #14 from 4a1e2y5/share
Browse files Browse the repository at this point in the history
Add share option to link context menu and in-app browser
  • Loading branch information
FranckRJ authored Jun 7, 2020
2 parents 5870999 + 2f42e54 commit 868460c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
return true;
case R.id.action_reload_page_webbrowser:
browserWebView.reload();
return true;
case R.id.action_share_url_webbrowser:
Utils.shareThisLink(currentUrl, this);
return true;
default:
return super.onOptionsItemSelected(item);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class LinkMenuDialogFragment extends DialogFragment {
private static final int POS_OPEN_IN_WEB_BROWSER = 0;
private static final int POS_OPEN_IN_INTERN_BROWSER = 1;
private static final int POS_COPY = 2;
private static final int POS_SHARE_URL = 3;

private String urlOfLink;

Expand All @@ -33,25 +34,26 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
}

builder.setTitle(urlOfLink);
builder.setItems(R.array.choicesForLinkMenu, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (getActivity() != null) {
switch (which) {
case POS_OPEN_IN_WEB_BROWSER:
Utils.openLinkInExternalBrowser(urlOfLink, getActivity());
break;
case POS_OPEN_IN_INTERN_BROWSER:
Utils.openLinkInInternalBrowser(urlOfLink, getActivity());
break;
case POS_COPY:
Utils.putStringInClipboard(urlOfLink, getActivity());
Toast.makeText(getActivity(), R.string.copyDone, Toast.LENGTH_SHORT).show();
break;
}
builder.setItems(R.array.choicesForLinkMenu, (dialog, which) -> {
if (getActivity() != null) {
switch (which) {
case POS_OPEN_IN_WEB_BROWSER:
Utils.openLinkInExternalBrowser(urlOfLink, getActivity());
break;
case POS_OPEN_IN_INTERN_BROWSER:
Utils.openLinkInInternalBrowser(urlOfLink, getActivity());
break;
case POS_COPY:
Utils.putStringInClipboard(urlOfLink, getActivity());
Toast.makeText(getActivity(), R.string.copyDone, Toast.LENGTH_SHORT).show();
break;
case POS_SHARE_URL:
Utils.shareThisLink(urlOfLink, getActivity());
break;

}
dialog.dismiss();
}
dialog.dismiss();
});

return builder.create();
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/menu/menu_webbrowser.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@
<item
android:id="@+id/action_reload_page_webbrowser"
android:title="@string/refresh"/>
<item
android:id="@+id/action_share_url_webbrowser"
android:title="@string/share" />
</menu>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@
<item>@string/openInExternalBrowser</item>
<item>@string/openInInternBrowser</item>
<item>@string/copy</item>
<item>@string/share</item>
</string-array>
<string-array name="choicesForMessageMenu">
<item>@string/openCDV</item>
Expand Down

0 comments on commit 868460c

Please sign in to comment.