diff options
author | tom79 <tschneider.ac@gmail.com> | 2017-09-02 10:59:07 +0200 |
---|---|---|
committer | tom79 <tschneider.ac@gmail.com> | 2017-09-02 10:59:07 +0200 |
commit | 138711168428bcce6c1c41189d7e77e72c52b6dd (patch) | |
tree | 71d83907fee00675cdd21d51ac46ee48dcd08e78 /app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveMetaDataAsyncTask.java | |
parent | 831eed8799db2251df299753d948c508e17c7e8c (diff) |
grab an extract of an article with title and picture when sharing (issue #10)
Diffstat (limited to 'app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveMetaDataAsyncTask.java')
-rw-r--r-- | app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveMetaDataAsyncTask.java | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveMetaDataAsyncTask.java b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveMetaDataAsyncTask.java index 6874dcf4f..788466cfc 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveMetaDataAsyncTask.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/asynctasks/RetrieveMetaDataAsyncTask.java @@ -33,7 +33,7 @@ public class RetrieveMetaDataAsyncTask extends AsyncTask<Void, Void, Void> { private OnRetrieveMetaDataInterface listener; private String url; private boolean error = false; - private String imageUrl, content; + private String image, title, description; public RetrieveMetaDataAsyncTask(String url, OnRetrieveMetaDataInterface onRetrieveRemoteAccountInterface){ this.url = url; @@ -47,13 +47,19 @@ public class RetrieveMetaDataAsyncTask extends AsyncTask<Void, Void, Void> { Document document = Jsoup.connect(url).userAgent(userAgent).get(); Elements metaOgTitle = document.select("meta[property=og:title]"); if (metaOgTitle != null) { - content = metaOgTitle.attr("content"); + title = metaOgTitle.attr("content"); } else { - content = document.title(); + title = document.title(); + } + Elements metaOgDescription = document.select("meta[property=og:description]"); + if (metaOgDescription != null) { + description = metaOgDescription.attr("content"); + } else { + description = ""; } Elements metaOgImage = document.select("meta[property=og:image]"); if (metaOgImage != null) { - imageUrl = metaOgImage.attr("content"); + image = metaOgImage.attr("content"); } } catch (IOException | IndexOutOfBoundsException e) { error = true; @@ -63,7 +69,7 @@ public class RetrieveMetaDataAsyncTask extends AsyncTask<Void, Void, Void> { @Override protected void onPostExecute(Void result) { - listener.onRetrieveRemoteAccount(error, imageUrl, content); + listener.onRetrieveMetaData(error, image, title, description); } } |