From 7a44e467f0be89a350173fbe06085b98a2cf5ad4 Mon Sep 17 00:00:00 2001 From: akaessens <24660231+akaessens@users.noreply.github.com> Date: Sun, 30 Aug 2020 19:03:17 +0200 Subject: [PATCH] add high res image preview, fix reset on activity return --- app/src/main/AndroidManifest.xml | 2 ++ .../com/akdev/nofbeventscraper/FbScraper.java | 33 ++++++++++++------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d65dfe3..6abb4c8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -32,8 +32,10 @@ + diff --git a/app/src/main/java/com/akdev/nofbeventscraper/FbScraper.java b/app/src/main/java/com/akdev/nofbeventscraper/FbScraper.java index 2715624..323a6ec 100644 --- a/app/src/main/java/com/akdev/nofbeventscraper/FbScraper.java +++ b/app/src/main/java/com/akdev/nofbeventscraper/FbScraper.java @@ -192,8 +192,8 @@ public class FbScraper extends AsyncTask { try { String url = fixURI(input_url); - // use correct system user agent because of facebook ToS - String user_agent = System.getProperty("http.agent"); + // use default android user agent + String user_agent = "Mozilla/5.0 (X11; Linux x86_64)"; Document document = Jsoup.connect(url).userAgent(user_agent).get(); if (document == null) { @@ -205,15 +205,26 @@ public class FbScraper extends AsyncTask { JSONObject reader = new JSONObject(json); - event = new FbEvent( - url, - readFromJson(reader, "name"), - toZonedDateTime(readFromJson(reader, "startDate")), - toZonedDateTime(readFromJson(reader, "endDate")), - fixDescriptionLinks(readFromJson(reader, "description")), - fixLocation(readFromJson(reader, "location")), - readFromJson(reader, "image") - ); + + String name = readFromJson(reader, "name"); + ZonedDateTime start_date = toZonedDateTime(readFromJson(reader, "startDate")); + ZonedDateTime end_date = toZonedDateTime(readFromJson(reader, "endDate")); + String description = fixDescriptionLinks(readFromJson(reader, "description")); + String location = fixLocation(readFromJson(reader, "location")); + + String image_url = readFromJson(reader, "image"); // get from json + + try { + // possibly get higher res image from event header + image_url = document.getElementsByClass("scaledImageFitWidth") + .first().attr("src"); + + } catch (Exception e) { + // ignore + } + + event = new FbEvent(url, name,start_date, end_date, description, location, image_url); + } catch (URISyntaxException | MalformedURLException e) { e.printStackTrace();