Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/news-android.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid-Development <david-dev@live.de>2022-05-22 18:48:16 +0300
committerDavid Luhmer <david-dev@live.de>2022-05-22 18:48:16 +0300
commitfe15c6c573dd7d6dd79a68f18e450614e95083a3 (patch)
treeb072904668b0dadac9bb35fc602faffa3627df44 /News-Android-App
parente18ef6b8263a16b949f7ae3ed4b5864c6b5cbcfa (diff)
fix crash on long tap on webview due to missing html - fix #1061
Signed-off-by: David Luhmer <david-dev@live.de>
Diffstat (limited to 'News-Android-App')
-rw-r--r--News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailFragment.java29
1 files changed, 20 insertions, 9 deletions
diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailFragment.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailFragment.java
index f8a3dfee..b629a37e 100644
--- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailFragment.java
+++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailFragment.java
@@ -425,23 +425,28 @@ public class NewsDetailFragment extends Fragment implements RssItemToHtmlTask.Li
public void onCreateContextMenu(@NonNull ContextMenu menu, @NonNull View view, ContextMenu.ContextMenuInfo menuInfo) {
- if (!(view instanceof WebView)) {
+ if (!(view instanceof WebView)) {
Log.w(TAG, "onCreateContextMenu - no webview reference found");
return;
}
+ if (view != binding.webview) {
+ Log.d(TAG, "onCreateContextMenu - wrong webview - skip creation of context menu");
+ }
+
WebView.HitTestResult result = ((WebView) view).getHitTestResult();
if (result == null) {
Log.d(TAG, "onCreateContextMenu - no webview hit result");
return;
}
- int type = result.getType();
- Document htmlDoc = Jsoup.parse(html);
- FragmentTransaction ft = requireFragmentManager().beginTransaction();
- String text;
- DialogFragment newFragment;
+ if (html == null) {
+ Log.e(TAG, "onCreateContextMenu - html is not set - failed to load RSS item");
+ return;
+ }
+ int type = result.getType();
+ DialogFragment newFragment = null;
switch (type) {
case WebView.HitTestResult.IMAGE_TYPE:
@@ -455,6 +460,7 @@ public class NewsDetailFragment extends Fragment implements RssItemToHtmlTask.Li
String imgsrcval;
imgsrcval = imageUrl.substring(imageUrl.lastIndexOf('/') + 1);
+ Document htmlDoc = Jsoup.parse(html);
Elements imgtag = htmlDoc.getElementsByAttributeValueContaining("src", imageUrl);
try {
@@ -475,18 +481,19 @@ public class NewsDetailFragment extends Fragment implements RssItemToHtmlTask.Li
String title = imgsrcval;
int titleIcon = android.R.drawable.ic_menu_gallery;
- text = (imgtitle.isEmpty()) ? imgaltval : imgtitle;
+ String text = (imgtitle.isEmpty()) ? imgaltval : imgtitle;
// Create and show the dialog.
newFragment = NewsDetailImageDialogFragment.newInstanceImage(title, titleIcon, text, mImageUrl);
- newFragment.show(ft, "menu_fragment_dialog");
}
break;
case WebView.HitTestResult.SRC_ANCHOR_TYPE:
String url = result.getExtra();
URL mUrl;
+ String text;
try {
+ Document htmlDoc = Jsoup.parse(html);
Elements urltag = htmlDoc.getElementsByAttributeValueContaining("href", url);
text = urltag.text();
mUrl = new URL(url);
@@ -496,7 +503,6 @@ public class NewsDetailFragment extends Fragment implements RssItemToHtmlTask.Li
// Create and show the dialog.
newFragment = NewsDetailImageDialogFragment.newInstanceUrl(text, mUrl.toString());
- newFragment.show(ft, "menu_fragment_dialog");
break;
case WebView.HitTestResult.EMAIL_TYPE:
case WebView.HitTestResult.GEO_TYPE:
@@ -506,6 +512,11 @@ public class NewsDetailFragment extends Fragment implements RssItemToHtmlTask.Li
default:
Log.v(TAG, "Unknown type: " + type + ". Skipping..");
}
+
+ if (newFragment != null) {
+ FragmentTransaction ft = getParentFragmentManager().beginTransaction();
+ newFragment.show(ft, "menu_fragment_dialog");
+ }
}
/**