Fix issue #414
This commit is contained in:
parent
2a68fa01dd
commit
0269bfce3d
|
@ -22,15 +22,11 @@ import android.util.Patterns;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLConnection;
|
|
||||||
import java.security.KeyManagementException;
|
import java.security.KeyManagementException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
|
||||||
|
|
||||||
import app.fedilab.android.client.HttpsConnection;
|
import app.fedilab.android.client.HttpsConnection;
|
||||||
import app.fedilab.android.helper.Helper;
|
import app.fedilab.android.helper.Helper;
|
||||||
import app.fedilab.android.interfaces.OnRetrieveMetaDataInterface;
|
import app.fedilab.android.interfaces.OnRetrieveMetaDataInterface;
|
||||||
|
@ -48,7 +44,7 @@ public class RetrieveMetaDataAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
private boolean error = false;
|
private boolean error = false;
|
||||||
private String image, title, description, sharedSubject, sharedText;
|
private String image, title, description, sharedSubject, sharedText;
|
||||||
private WeakReference<Context> contextWeakReference;
|
private WeakReference<Context> contextWeakReference;
|
||||||
private boolean shouldFetchMetaData = true;
|
private boolean shouldFetchMetaData;
|
||||||
|
|
||||||
public RetrieveMetaDataAsyncTask(Context context, boolean shouldFetchMetaData, String sharedSubject, String sharedText, String url, OnRetrieveMetaDataInterface onRetrieveRemoteAccountInterface) {
|
public RetrieveMetaDataAsyncTask(Context context, boolean shouldFetchMetaData, String sharedSubject, String sharedText, String url, OnRetrieveMetaDataInterface onRetrieveRemoteAccountInterface) {
|
||||||
this.url = url;
|
this.url = url;
|
||||||
|
@ -95,14 +91,7 @@ public class RetrieveMetaDataAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
Pattern descriptionPattern = Pattern.compile("meta[ a-zA-Z=\"'-]+property=[\"']og:description[\"']\\s+content=[\"']([^>]*)[\"']");
|
Pattern descriptionPattern = Pattern.compile("meta[ a-zA-Z=\"'-]+property=[\"']og:description[\"']\\s+content=[\"']([^>]*)[\"']");
|
||||||
Pattern imagePattern = Pattern.compile("meta[ a-zA-Z=\"'-]+property=[\"']og:image[\"']\\s+content=[\"']([^>]*)[\"']");
|
Pattern imagePattern = Pattern.compile("meta[ a-zA-Z=\"'-]+property=[\"']og:image[\"']\\s+content=[\"']([^>]*)[\"']");
|
||||||
try {
|
try {
|
||||||
if (!potentialUrl.startsWith("http")) {
|
|
||||||
potentialUrl = "https://" + potentialUrl;
|
|
||||||
}
|
|
||||||
URLConnection conn = new URL(potentialUrl).openConnection();
|
|
||||||
if (conn instanceof HttpsURLConnection) {
|
|
||||||
error = true;
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
String response = new HttpsConnection(this.contextWeakReference.get(), null).get(potentialUrl);
|
String response = new HttpsConnection(this.contextWeakReference.get(), null).get(potentialUrl);
|
||||||
Matcher matcherTitle = titlePattern.matcher(response);
|
Matcher matcherTitle = titlePattern.matcher(response);
|
||||||
Matcher matcherDescription = descriptionPattern.matcher(response);
|
Matcher matcherDescription = descriptionPattern.matcher(response);
|
||||||
|
@ -115,7 +104,6 @@ public class RetrieveMetaDataAsyncTask extends AsyncTask<Void, Void, Void> {
|
||||||
descriptionEncoded = matcherDescription.group(1);
|
descriptionEncoded = matcherDescription.group(1);
|
||||||
while (matcherImage.find())
|
while (matcherImage.find())
|
||||||
image = matcherImage.group(1);
|
image = matcherImage.group(1);
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
if (titleEncoded != null)
|
if (titleEncoded != null)
|
||||||
title = Html.fromHtml(titleEncoded, Html.FROM_HTML_MODE_LEGACY).toString();
|
title = Html.fromHtml(titleEncoded, Html.FROM_HTML_MODE_LEGACY).toString();
|
||||||
|
|
Loading…
Reference in New Issue