mirror of
https://github.com/akaessens/NoFbEventScraper
synced 2025-06-05 23:29:13 +02:00
MinSdk down to 23, replace ZonedDateTime with Date
This commit is contained in:
@ -6,7 +6,7 @@ android {
|
|||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "com.akdev.nofbeventscraper"
|
applicationId "com.akdev.nofbeventscraper"
|
||||||
minSdkVersion 26
|
minSdkVersion 23
|
||||||
targetSdkVersion 29
|
targetSdkVersion 29
|
||||||
versionCode 7
|
versionCode 7
|
||||||
versionName "0.3.1"
|
versionName "0.3.1"
|
||||||
|
@ -42,15 +42,16 @@ public class ScraperUnitTest {
|
|||||||
|
|
||||||
FbScraper scraper = new FbScraper(null, "");
|
FbScraper scraper = new FbScraper(null, "");
|
||||||
|
|
||||||
String exp = "2020-10-23T05:00+02:00";
|
String in = "2020-01-01T12:00:00+0100";
|
||||||
String in = "2020-10-23T05:00:00+0200";
|
String exp = "Mi., 01 Jan. 2020 12:00 MEZ";
|
||||||
String act = scraper.toZonedDateTime(in).toString();
|
|
||||||
|
String act = FbEvent.dateTimeToString(scraper.parseToDate(in));
|
||||||
assertEquals(exp, act);
|
assertEquals(exp, act);
|
||||||
|
|
||||||
|
|
||||||
exp = null;
|
exp = "";
|
||||||
in = "";
|
in = "";
|
||||||
ZonedDateTime act2 = scraper.toZonedDateTime(in);
|
String act2 = FbEvent.dateTimeToString(scraper.parseToDate(in));
|
||||||
assertEquals(exp, act2);
|
assertEquals(exp, act2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package com.akdev.nofbeventscraper;
|
package com.akdev.nofbeventscraper;
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.util.Date;
|
||||||
import java.time.format.FormatStyle;
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Objects of this class store immutable information about
|
* Objects of this class store immutable information about
|
||||||
@ -12,14 +12,14 @@ public class FbEvent {
|
|||||||
|
|
||||||
public final String url;
|
public final String url;
|
||||||
public final String name;
|
public final String name;
|
||||||
public final ZonedDateTime start_date;
|
public final Date start_date;
|
||||||
public final ZonedDateTime end_date;
|
public final Date end_date;
|
||||||
public final String description;
|
public final String description;
|
||||||
public final String location;
|
public final String location;
|
||||||
public final String image_url;
|
public final String image_url;
|
||||||
|
|
||||||
|
|
||||||
public FbEvent(String url, String name, ZonedDateTime start_date, ZonedDateTime end_date,
|
public FbEvent(String url, String name, Date start_date, Date end_date,
|
||||||
String description, String location, String image_url) {
|
String description, String location, String image_url) {
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@ -33,28 +33,27 @@ public class FbEvent {
|
|||||||
/**
|
/**
|
||||||
* Converts datetime to epoch.
|
* Converts datetime to epoch.
|
||||||
*
|
*
|
||||||
* @param zoned_date_time ZonedDateTime object
|
* @param date Date object
|
||||||
* @return Event begin time in milliseconds from the epoch for calendar intent or null
|
* @return Event begin time in milliseconds from the epoch for calendar intent or null
|
||||||
*/
|
*/
|
||||||
static Long dateTimeToEpoch(ZonedDateTime zoned_date_time) {
|
static Long dateTimeToEpoch(Date date) {
|
||||||
try {
|
try {
|
||||||
return zoned_date_time.toEpochSecond() * 1000;
|
return date.getTime();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a RFC formatted String representation of a ZonedDateTime
|
* Returns a locally formatted String representation of a Date
|
||||||
*
|
*
|
||||||
* @param zoned_date_time
|
* @param date
|
||||||
* @return RFC-1123 formatted String of zoned_date_time or empty String
|
* @return locally formatted String of date or empty String
|
||||||
*/
|
*/
|
||||||
static String dateTimeToString(ZonedDateTime zoned_date_time) {
|
static String dateTimeToString(Date date) {
|
||||||
try {
|
try {
|
||||||
return DateTimeFormatter
|
SimpleDateFormat formatter = new SimpleDateFormat("E, dd MMM yyyy HH:mm z", Locale.getDefault());
|
||||||
.RFC_1123_DATE_TIME
|
return formatter.format(date);
|
||||||
.format(zoned_date_time);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,6 @@ package com.akdev.nofbeventscraper;
|
|||||||
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.text.Editable;
|
|
||||||
import android.text.SpannableStringBuilder;
|
|
||||||
|
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
|
|
||||||
@ -17,8 +15,9 @@ import java.lang.ref.WeakReference;
|
|||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.time.ZonedDateTime;
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.util.Date;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@ -122,21 +121,22 @@ public class FbScraper extends AsyncTask<Void, Void, Void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a time string from the facebook event.
|
* Parses a time string from the facebook event into a Date
|
||||||
* Corrects format to ISO date time and parse into ZonedDateTime
|
|
||||||
*
|
*
|
||||||
* @param time_in time string from the event
|
* @param time_in time string from the event
|
||||||
* @return ZonedDateTime parsed from input or null
|
* @return Date parsed from input or null
|
||||||
*/
|
*/
|
||||||
protected ZonedDateTime toZonedDateTime(String time_in) {
|
protected Date parseToDate(String time_in) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// time in is missing a : in the timezone offset
|
// time in is missing a : in the timezone offset
|
||||||
Editable editable = new SpannableStringBuilder(time_in);
|
//Editable editable = new SpannableStringBuilder(time_in);
|
||||||
String time_str = editable.insert(22, ":").toString();
|
//String time_str = editable.insert(22, ":").toString();
|
||||||
|
|
||||||
// parse e.g. 2011-12-03T10:15:30+01:00
|
// parse e.g. 2011-12-03T10:15:30+0100
|
||||||
return ZonedDateTime.parse(time_str, DateTimeFormatter.ISO_OFFSET_DATE_TIME);
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.getDefault());
|
||||||
|
|
||||||
|
return sdf.parse(time_in);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -207,8 +207,8 @@ public class FbScraper extends AsyncTask<Void, Void, Void> {
|
|||||||
|
|
||||||
|
|
||||||
String name = readFromJson(reader, "name");
|
String name = readFromJson(reader, "name");
|
||||||
ZonedDateTime start_date = toZonedDateTime(readFromJson(reader, "startDate"));
|
Date start_date = parseToDate(readFromJson(reader, "startDate"));
|
||||||
ZonedDateTime end_date = toZonedDateTime(readFromJson(reader, "endDate"));
|
Date end_date = parseToDate(readFromJson(reader, "endDate"));
|
||||||
String description = fixDescriptionLinks(readFromJson(reader, "description"));
|
String description = fixDescriptionLinks(readFromJson(reader, "description"));
|
||||||
String location = fixLocation(readFromJson(reader, "location"));
|
String location = fixLocation(readFromJson(reader, "location"));
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user