From 5675e544b528c182cb99ab66572f94e5015e1cea Mon Sep 17 00:00:00 2001 From: Ricki Hirner Date: Sat, 28 May 2016 16:00:23 +0200 Subject: [PATCH] Better alarm handling * ical4android: better alarm handling * API change: pass OutputStream instead of returning it --- .../at/bitfire/davdroid/SSLSocketFactoryCompat.java | 1 - .../at/bitfire/davdroid/log/PlainTextFormatter.java | 2 -- .../at/bitfire/davdroid/resource/LocalCalendar.java | 1 - .../davdroid/syncadapter/CalendarSyncManager.java | 9 +++++++-- .../davdroid/syncadapter/ContactsSyncManager.java | 12 ++++++++++-- .../davdroid/syncadapter/TasksSyncManager.java | 9 +++++++-- .../bitfire/davdroid/ui/AccountSettingsActivity.java | 8 -------- .../ui/setup/DetectConfigurationFragment.java | 1 - ical4android | 2 +- vcard4android | 2 +- 10 files changed, 26 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/at/bitfire/davdroid/SSLSocketFactoryCompat.java b/app/src/main/java/at/bitfire/davdroid/SSLSocketFactoryCompat.java index 5c96e277..4274b110 100644 --- a/app/src/main/java/at/bitfire/davdroid/SSLSocketFactoryCompat.java +++ b/app/src/main/java/at/bitfire/davdroid/SSLSocketFactoryCompat.java @@ -15,7 +15,6 @@ import android.text.TextUtils; import java.io.IOException; import java.net.InetAddress; import java.net.Socket; -import java.net.UnknownHostException; import java.security.GeneralSecurityException; import java.util.Arrays; import java.util.HashSet; diff --git a/app/src/main/java/at/bitfire/davdroid/log/PlainTextFormatter.java b/app/src/main/java/at/bitfire/davdroid/log/PlainTextFormatter.java index 35983be0..74d3c9cf 100644 --- a/app/src/main/java/at/bitfire/davdroid/log/PlainTextFormatter.java +++ b/app/src/main/java/at/bitfire/davdroid/log/PlainTextFormatter.java @@ -8,8 +8,6 @@ package at.bitfire.davdroid.log; -import android.util.Log; - import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.commons.lang3.time.DateFormatUtils; diff --git a/app/src/main/java/at/bitfire/davdroid/resource/LocalCalendar.java b/app/src/main/java/at/bitfire/davdroid/resource/LocalCalendar.java index 5d99acfd..780c24d0 100644 --- a/app/src/main/java/at/bitfire/davdroid/resource/LocalCalendar.java +++ b/app/src/main/java/at/bitfire/davdroid/resource/LocalCalendar.java @@ -44,7 +44,6 @@ import at.bitfire.ical4android.CalendarStorageException; import at.bitfire.ical4android.DateUtils; import at.bitfire.vcard4android.ContactsStorageException; import lombok.Cleanup; -import okhttp3.HttpUrl; public class LocalCalendar extends AndroidCalendar implements LocalCollection { diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarSyncManager.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarSyncManager.java index 488ac52e..5e216d3d 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarSyncManager.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarSyncManager.java @@ -17,6 +17,7 @@ import org.apache.commons.codec.Charsets; import org.apache.commons.lang3.StringUtils; import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; @@ -96,10 +97,14 @@ public class CalendarSyncManager extends SyncManager { @Override protected RequestBody prepareUpload(LocalResource resource) throws IOException, CalendarStorageException { LocalEvent local = (LocalEvent)resource; - App.log.log(Level.FINE, "Preparing upload of event " + local.getFileName(), new Object[] { local.getEvent() }); + App.log.log(Level.FINE, "Preparing upload of event " + local.getFileName(), local.getEvent()); + + ByteArrayOutputStream os = new ByteArrayOutputStream(); + local.getEvent().write(os); + return RequestBody.create( DavCalendar.MIME_ICALENDAR, - local.getEvent().toStream().toByteArray() + os.toByteArray() ); } diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncManager.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncManager.java index 06f2474c..7ce1306b 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncManager.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/ContactsSyncManager.java @@ -14,12 +14,16 @@ import android.content.ContentValues; import android.content.Context; import android.content.SyncResult; import android.os.Bundle; +import android.os.Environment; import android.provider.ContactsContract; import org.apache.commons.codec.Charsets; import org.apache.commons.lang3.StringUtils; import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; @@ -130,10 +134,14 @@ public class ContactsSyncManager extends SyncManager { @Override protected RequestBody prepareUpload(LocalResource resource) throws IOException, ContactsStorageException { LocalContact local = (LocalContact)resource; - App.log.log(Level.FINE, "Preparing upload of contact " + local.getFileName(), new Object[] { local.getContact() }); + App.log.log(Level.FINE, "Preparing upload of contact " + local.getFileName(), local.getContact()); + + ByteArrayOutputStream os = new ByteArrayOutputStream(); + local.getContact().write(hasVCard4 ? VCardVersion.V4_0 : VCardVersion.V3_0, os); + return RequestBody.create( hasVCard4 ? DavAddressBook.MIME_VCARD4 : DavAddressBook.MIME_VCARD3_UTF8, - local.getContact().toStream(hasVCard4 ? VCardVersion.V4_0 : VCardVersion.V3_0).toByteArray() + os.toByteArray() ); } diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/TasksSyncManager.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/TasksSyncManager.java index 518d365a..2ed3f80c 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/TasksSyncManager.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/TasksSyncManager.java @@ -17,6 +17,7 @@ import org.apache.commons.codec.Charsets; import org.apache.commons.lang3.StringUtils; import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; @@ -90,10 +91,14 @@ public class TasksSyncManager extends SyncManager { @Override protected RequestBody prepareUpload(LocalResource resource) throws IOException, CalendarStorageException { LocalTask local = (LocalTask)resource; - App.log.log(Level.FINE, "Preparing upload of task " + local.getFileName(), new Object[] { local.getTask() }); + App.log.log(Level.FINE, "Preparing upload of task " + local.getFileName(), local.getTask() ); + + ByteArrayOutputStream os = new ByteArrayOutputStream(); + local.getTask().write(os); + return RequestBody.create( DavCalendar.MIME_ICALENDAR, - local.getTask().toStream().toByteArray() + os.toByteArray() ); } diff --git a/app/src/main/java/at/bitfire/davdroid/ui/AccountSettingsActivity.java b/app/src/main/java/at/bitfire/davdroid/ui/AccountSettingsActivity.java index 8192324d..52169013 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/AccountSettingsActivity.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/AccountSettingsActivity.java @@ -9,16 +9,11 @@ package at.bitfire.davdroid.ui; import android.accounts.Account; -import android.content.DialogInterface; import android.content.Intent; -import android.net.wifi.WifiConfiguration; -import android.net.wifi.WifiInfo; -import android.net.wifi.WifiManager; import android.os.Bundle; import android.provider.CalendarContract; import android.provider.ContactsContract; import android.support.v4.app.NavUtils; -import android.support.v7.app.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.support.v7.preference.EditTextPreference; import android.support.v7.preference.ListPreference; @@ -28,9 +23,6 @@ import android.support.v7.preference.SwitchPreferenceCompat; import android.text.TextUtils; import android.view.MenuItem; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; import java.util.logging.Level; import at.bitfire.davdroid.AccountSettings; diff --git a/app/src/main/java/at/bitfire/davdroid/ui/setup/DetectConfigurationFragment.java b/app/src/main/java/at/bitfire/davdroid/ui/setup/DetectConfigurationFragment.java index f011104b..455bc3fc 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/setup/DetectConfigurationFragment.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/setup/DetectConfigurationFragment.java @@ -22,7 +22,6 @@ import android.support.v4.content.Loader; import android.support.v7.app.AlertDialog; import at.bitfire.davdroid.App; -import at.bitfire.davdroid.InvalidAccountException; import at.bitfire.davdroid.R; import at.bitfire.davdroid.ui.DebugInfoActivity; import at.bitfire.davdroid.ui.setup.DavResourceFinder.Configuration; diff --git a/ical4android b/ical4android index 34a0a838..baffbc62 160000 --- a/ical4android +++ b/ical4android @@ -1 +1 @@ -Subproject commit 34a0a838ed2116b8ee2b022749d710a4f3e6a04c +Subproject commit baffbc628b9ca9733c1b97671d6ae8854cd06391 diff --git a/vcard4android b/vcard4android index c75322ea..33cc8fbf 160000 --- a/vcard4android +++ b/vcard4android @@ -1 +1 @@ -Subproject commit c75322ea59d8d6b204418f27e19f6604e6a4ac59 +Subproject commit 33cc8fbf59a114dbcaadfa3cc0fbba5fa01589d2