|
|
@ -33,9 +33,14 @@ import androidx.preference.PreferenceManager;
|
|
|
|
|
|
|
|
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedInputStream;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.Calendar;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
@ -85,17 +90,29 @@ public class CalendarHelper {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static ICalendar parse(Context context, File file) throws IOException {
|
|
|
|
static ICalendar parse(Context context, File file) throws IOException {
|
|
|
|
try (ICalReader reader = new ICalReader(file)) {
|
|
|
|
try (InputStream is = new BufferedInputStream(new FileInputStream(file))) {
|
|
|
|
|
|
|
|
// https://en.wikipedia.org/wiki/Byte_order_mark#UTF-8
|
|
|
|
|
|
|
|
byte[] utf8_bom = "\uFEFF".getBytes(StandardCharsets.UTF_8);
|
|
|
|
|
|
|
|
byte[] bom = new byte[utf8_bom.length];
|
|
|
|
|
|
|
|
is.mark(bom.length);
|
|
|
|
|
|
|
|
is.read(bom);
|
|
|
|
|
|
|
|
if (!Arrays.equals(bom, utf8_bom))
|
|
|
|
|
|
|
|
is.reset();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try (ICalReader reader = new ICalReader(is)) {
|
|
|
|
ICalendar icalendar = reader.readNext();
|
|
|
|
ICalendar icalendar = reader.readNext();
|
|
|
|
if (icalendar == null)
|
|
|
|
|
|
|
|
throw new IOException("Invalid iCal file");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (ParseWarning warning : reader.getWarnings())
|
|
|
|
for (ParseWarning warning : reader.getWarnings())
|
|
|
|
EntityLog.log(context, "Event warning " + warning);
|
|
|
|
EntityLog.log(context, "Event warning " + warning);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// https://icalendar.org/validator.html
|
|
|
|
|
|
|
|
if (icalendar == null)
|
|
|
|
|
|
|
|
throw new IOException("Invalid iCal file");
|
|
|
|
|
|
|
|
|
|
|
|
return icalendar;
|
|
|
|
return icalendar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static String getTimeZoneID(ICalendar icalendar, ICalProperty property) {
|
|
|
|
static String getTimeZoneID(ICalendar icalendar, ICalProperty property) {
|
|
|
|
TimezoneInfo tzinfo = icalendar.getTimezoneInfo();
|
|
|
|
TimezoneInfo tzinfo = icalendar.getTimezoneInfo();
|
|
|
|