Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions app/src/main/java/com/cylonid/nativealpha/WebViewActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public class WebViewActivity extends AppCompatActivity implements EasyPermission
private String urlOnFirstPageload = "";
private boolean fallbackToDefaultLongClickBehaviour = false;
private PopupMenu mPopupMenu = null;
private String lastLongClickedLinkUrl = null;

private AdFilter adFilter;

Expand Down Expand Up @@ -254,6 +255,15 @@ private void setupWebView() {
fallbackToDefaultLongClickBehaviour = false;
return false;
}

WebView.HitTestResult result = wv.getHitTestResult();
if (result.getType() == WebView.HitTestResult.SRC_ANCHOR_TYPE ||
result.getType() == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
lastLongClickedLinkUrl = result.getExtra();
} else {
lastLongClickedLinkUrl = null;
}

showWebViewPopupMenu();
return true;
});
Expand Down Expand Up @@ -433,7 +443,8 @@ private void showWebViewPopupMenu() {
View center = findViewById(R.id.anchorCenterScreen);
mPopupMenu = IconPopupMenuHelper.getMenu(center, R.menu.wv_context_menu, WebViewActivity.this);

String currentUrl = wv.getUrl();
boolean hasLink = lastLongClickedLinkUrl != null && !lastLongClickedLinkUrl.isEmpty();
String currentUrl = hasLink ? lastLongClickedLinkUrl : wv.getUrl();
String title = "";
if (currentUrl != null) {
title = currentUrl.length() < 32 ? currentUrl : currentUrl.substring(0, 32) + "…";
Expand All @@ -454,9 +465,9 @@ private void showWebViewPopupMenu() {
spanString.setSpan(foregroundColorSpan, 0, spanString.length(),0);
item.setTitle(spanString);
}
if(wv.canGoForward()) mPopupMenu.getMenu().getItem(2).setVisible(true);
if(wv.canGoForward()) mPopupMenu.getMenu().findItem(R.id.cmItemForward).setVisible(true);
if(BuildConfig.DEBUG) {
mPopupMenu.getMenu().getItem(6).setVisible(true);
mPopupMenu.getMenu().findItem(R.id.cmShowAdblockProviders).setVisible(true);
}
mPopupMenu.setOnMenuItemClickListener(menuItem -> {
switch(menuItem.getItemId()) {
Expand All @@ -478,7 +489,7 @@ private void showWebViewPopupMenu() {
new ShareCompat.IntentBuilder(WebViewActivity.this)
.setType("text/plain")
.setChooserTitle("Share URL")
.setText(wv.getUrl())
.setText(hasLink ? lastLongClickedLinkUrl : wv.getUrl())
.startChooser();
return true;
case R.id.cmItemCloseWebApp:
Expand Down Expand Up @@ -547,7 +558,7 @@ protected void onResume() {
wv.resumeTimers();
this.setDarkModeIfNeeded();


if(webapp.isBiometricProtection()) {
View fullActivityView = findViewById(R.id.webviewActivity);
fullActivityView.setVisibility(View.GONE);
Expand Down