From af8aed3ebd601a44fbe0216890e31f0c40681370 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Sun, 6 Jan 2019 11:57:53 +0000 Subject: [PATCH] snap --- .../syncadapter/resource/LocalAddressBook.kt | 2 +- .../syncadapter/resource/LocalEvent.kt | 2 +- .../syncadapter/resource/LocalResource.kt | 2 +- .../AddressBooksSyncAdapterService.kt | 4 ---- .../syncadapter/CalendarSyncManager.kt | 12 +++++----- .../etesync/syncadapter/ui/AboutActivity.kt | 7 +++--- .../syncadapter/ui/JournalItemActivity.kt | 22 +++++++++---------- .../syncadapter/ui/ViewCollectionActivity.kt | 2 +- .../ui/importlocal/CalendarAccount.kt | 2 +- .../ui/importlocal/ImportFragment.kt | 15 +++++-------- .../LocalCalendarImportFragment.kt | 10 ++++----- .../importlocal/LocalContactImportFragment.kt | 4 ++-- 12 files changed, 38 insertions(+), 46 deletions(-) diff --git a/app/src/main/java/com/etesync/syncadapter/resource/LocalAddressBook.kt b/app/src/main/java/com/etesync/syncadapter/resource/LocalAddressBook.kt index 09674279..90eb08b3 100644 --- a/app/src/main/java/com/etesync/syncadapter/resource/LocalAddressBook.kt +++ b/app/src/main/java/com/etesync/syncadapter/resource/LocalAddressBook.kt @@ -199,7 +199,7 @@ class LocalAddressBook( accountManager.removeAccount(account, null, null) } - override fun findAll(): List = queryContacts(RawContacts.DELETED + "== 0", null) + override fun findAll(): List = queryContacts(RawContacts.DELETED + "== 0", null) /** * Returns an array of local contacts/groups which have been deleted locally. (DELETED != 0). diff --git a/app/src/main/java/com/etesync/syncadapter/resource/LocalEvent.kt b/app/src/main/java/com/etesync/syncadapter/resource/LocalEvent.kt index 74b30fb1..3a0c3056 100644 --- a/app/src/main/java/com/etesync/syncadapter/resource/LocalEvent.kt +++ b/app/src/main/java/com/etesync/syncadapter/resource/LocalEvent.kt @@ -90,7 +90,7 @@ class LocalEvent : AndroidEvent, LocalResource { val buildException = recurrence != null val eventToBuild = if (buildException) recurrence else event - builder.withValue(COLUMN_UID, event.uid) + builder.withValue(COLUMN_UID, event?.uid) .withValue(COLUMN_SEQUENCE, eventToBuild?.sequence) .withValue(CalendarContract.Events.DIRTY, if (saveAsDirty) 1 else 0) .withValue(CalendarContract.Events.DELETED, 0) diff --git a/app/src/main/java/com/etesync/syncadapter/resource/LocalResource.kt b/app/src/main/java/com/etesync/syncadapter/resource/LocalResource.kt index 9ce2f184..d4413fac 100644 --- a/app/src/main/java/com/etesync/syncadapter/resource/LocalResource.kt +++ b/app/src/main/java/com/etesync/syncadapter/resource/LocalResource.kt @@ -12,7 +12,7 @@ import at.bitfire.ical4android.CalendarStorageException import at.bitfire.vcard4android.ContactsStorageException interface LocalResource { - val uuid: String + val uuid: String? /** True if doesn't exist on server yet, false otherwise. */ val isLocalOnly: Boolean diff --git a/app/src/main/java/com/etesync/syncadapter/syncadapter/AddressBooksSyncAdapterService.kt b/app/src/main/java/com/etesync/syncadapter/syncadapter/AddressBooksSyncAdapterService.kt index fece6f4b..9f6e7a9d 100644 --- a/app/src/main/java/com/etesync/syncadapter/syncadapter/AddressBooksSyncAdapterService.kt +++ b/app/src/main/java/com/etesync/syncadapter/syncadapter/AddressBooksSyncAdapterService.kt @@ -108,10 +108,6 @@ class AddressBooksSyncAdapterService : SyncAdapterService() { notificationManager.notify(title, context.getString(syncPhase)) } catch (e: OutOfMemoryError) { - if (e is ContactsStorageException || e is SQLiteException) { - App.log.log(Level.SEVERE, "Couldn't prepare local address books", e) - syncResult.databaseError = true - } val syncPhase = R.string.sync_phase_journals val title = context.getString(R.string.sync_error_contacts, account.name) notificationManager.setThrowable(e) diff --git a/app/src/main/java/com/etesync/syncadapter/syncadapter/CalendarSyncManager.kt b/app/src/main/java/com/etesync/syncadapter/syncadapter/CalendarSyncManager.kt index a43ff749..79c3a9b8 100644 --- a/app/src/main/java/com/etesync/syncadapter/syncadapter/CalendarSyncManager.kt +++ b/app/src/main/java/com/etesync/syncadapter/syncadapter/CalendarSyncManager.kt @@ -56,12 +56,12 @@ import okhttp3.HttpUrl * Synchronization manager for CardDAV collections; handles contacts and groups. */ class CalendarSyncManager @Throws(Exceptions.IntegrityException::class, Exceptions.GenericCryptoException::class) -constructor(context: Context, account: Account, settings: AccountSettings, extras: Bundle, authority: String, result: SyncResult, calendar: LocalCalendar, private val remote: HttpUrl) : SyncManager(context, account, settings, extras, authority, result, calendar.name, CollectionInfo.Type.CALENDAR, account.name) { +constructor(context: Context, account: Account, settings: AccountSettings, extras: Bundle, authority: String, result: SyncResult, calendar: LocalCalendar, private val remote: HttpUrl) : SyncManager(context, account, settings, extras, authority, result, calendar.name!!, CollectionInfo.Type.CALENDAR, account.name) { - protected override val syncErrorTitle: String + override val syncErrorTitle: String get() = context.getString(R.string.sync_error_calendar, account.name) - protected override val syncSuccessfullyTitle: String + override val syncSuccessfullyTitle: String get() = context.getString(R.string.sync_successfully_calendar, info.displayName, account.name) @@ -78,7 +78,7 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra if (!super.prepare()) return false - journal = JournalEntryManager(httpClient, remote, localCalendar().name) + journal = JournalEntryManager(httpClient, remote, localCalendar().name!!) return true } @@ -137,7 +137,7 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra for (local in localDirty) { val event = (local as LocalEvent).event - if (event.attendees.isEmpty()) { + if (event?.attendees?.isEmpty()!!) { return } createInviteAttendeesNotification(event, local.content) @@ -145,7 +145,7 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra } private fun createInviteAttendeesNotification(event: Event, icsContent: String) { - val notificationHelper = NotificationHelper(context, event.uid, event.uid.hashCode()) + val notificationHelper = NotificationHelper(context, event.uid!!, event.uid!!.hashCode()) val intent = Intent(Intent.ACTION_SEND) intent.type = "text/plain" intent.putExtra(Intent.EXTRA_EMAIL, getEmailAddresses(event.attendees, false)) diff --git a/app/src/main/java/com/etesync/syncadapter/ui/AboutActivity.kt b/app/src/main/java/com/etesync/syncadapter/ui/AboutActivity.kt index 5da8fc31..55edaa48 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/AboutActivity.kt +++ b/app/src/main/java/com/etesync/syncadapter/ui/AboutActivity.kt @@ -32,7 +32,6 @@ import com.etesync.syncadapter.BuildConfig import com.etesync.syncadapter.Constants import com.etesync.syncadapter.R import ezvcard.Ezvcard -import org.apache.commons.io.IOUtils import org.apache.commons.lang3.time.DateFormatUtils import java.io.IOException import java.util.logging.Level @@ -143,9 +142,9 @@ class AboutActivity : BaseActivity() { override fun loadInBackground(): Spanned? { App.log.fine("Loading license file $fileName") try { - val `is` = context.resources.assets.open(fileName) - val raw = IOUtils.toByteArray(`is`) - `is`.close() + val inputStream = context.resources.assets.open(fileName) + val raw = inputStream.readBytes() + inputStream.close() content = Html.fromHtml(String(raw)) return content } catch (e: IOException) { diff --git a/app/src/main/java/com/etesync/syncadapter/ui/JournalItemActivity.kt b/app/src/main/java/com/etesync/syncadapter/ui/JournalItemActivity.kt index 300dde4c..ffb778ae 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/JournalItemActivity.kt +++ b/app/src/main/java/com/etesync/syncadapter/ui/JournalItemActivity.kt @@ -27,9 +27,8 @@ import com.etesync.syncadapter.model.JournalEntity import com.etesync.syncadapter.model.SyncEntry import com.etesync.syncadapter.ui.journalviewer.ListEntriesFragment.Companion.setJournalEntryView import ezvcard.util.PartialDate -import org.apache.commons.codec.Charsets -import java.io.ByteArrayInputStream import java.io.IOException +import java.io.StringReader import java.text.SimpleDateFormat import java.util.* @@ -154,10 +153,10 @@ class JournalItemActivity : BaseActivity(), Refreshable { private inner class LoadEventTask internal constructor(internal var view: View) : AsyncTask() { override fun doInBackground(vararg aVoids: Void): Event? { - val `is` = ByteArrayInputStream(syncEntry.content.toByteArray(Charsets.UTF_8)) + val inputReader = StringReader(syncEntry.content) try { - return Event.fromStream(`is`, Charsets.UTF_8, null)[0] + return Event.fromReader(inputReader, null)[0] } catch (e: InvalidCalendarException) { e.printStackTrace() } catch (e: IOException) { @@ -175,16 +174,17 @@ class JournalItemActivity : BaseActivity(), Refreshable { setTextViewText(view, R.id.title, event.summary) - setTextViewText(view, R.id.when_datetime, getDisplayedDatetime(event.dtStart.date.time, event.dtEnd.date.time, event.isAllDay, context)) + setTextViewText(view, R.id.when_datetime, getDisplayedDatetime(event.dtStart?.date?.time!!, event.dtEnd?.date!!.time, event.isAllDay(), context)) setTextViewText(view, R.id.where, event.location) - if (event.organizer != null) { + val organizer = event.organizer + if (organizer != null) { val tv = view.findViewById(R.id.organizer) as TextView - tv.text = event.organizer.calAddress.toString().replaceFirst("mailto:".toRegex(), "") + tv.text = organizer.calAddress.toString().replaceFirst("mailto:".toRegex(), "") } else { - val organizer = view.findViewById(R.id.organizer_container) - organizer.visibility = View.GONE + val organizerView = view.findViewById(R.id.organizer_container) + organizerView.visibility = View.GONE } setTextViewText(view, R.id.description, event.description) @@ -220,10 +220,10 @@ class JournalItemActivity : BaseActivity(), Refreshable { private inner class LoadContactTask internal constructor(internal var view: View) : AsyncTask() { override fun doInBackground(vararg aVoids: Void): Contact? { - val `is` = ByteArrayInputStream(syncEntry.content.toByteArray(Charsets.UTF_8)) + val reader = StringReader(syncEntry.content) try { - return Contact.fromStream(`is`, Charsets.UTF_8, null)[0] + return Contact.fromReader(reader, null)[0] } catch (e: IOException) { e.printStackTrace() } diff --git a/app/src/main/java/com/etesync/syncadapter/ui/ViewCollectionActivity.kt b/app/src/main/java/com/etesync/syncadapter/ui/ViewCollectionActivity.kt index b7165a4e..c9ffc801 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/ViewCollectionActivity.kt +++ b/app/src/main/java/com/etesync/syncadapter/ui/ViewCollectionActivity.kt @@ -171,7 +171,7 @@ class ViewCollectionActivity : BaseActivity(), Refreshable { if (info.type == CollectionInfo.Type.CALENDAR) { try { val providerClient = contentResolver.acquireContentProviderClient(CalendarContract.CONTENT_URI) - val resource = LocalCalendar.findByName(account, providerClient, LocalCalendar.Factory.INSTANCE, info.uid!!) + val resource = LocalCalendar.findByName(account, providerClient, LocalCalendar.Factory, info.uid!!) providerClient!!.release() if (resource == null) { return null diff --git a/app/src/main/java/com/etesync/syncadapter/ui/importlocal/CalendarAccount.kt b/app/src/main/java/com/etesync/syncadapter/ui/importlocal/CalendarAccount.kt index 89c90c8b..1c351c9a 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/importlocal/CalendarAccount.kt +++ b/app/src/main/java/com/etesync/syncadapter/ui/importlocal/CalendarAccount.kt @@ -77,7 +77,7 @@ class CalendarAccount protected constructor(val account: Account) { try { val localCalendar = LocalCalendar.findByName(calendarAccount.account, contentProviderClient, - LocalCalendar.Factory.INSTANCE, getString(cur, Calendars.NAME)!!) + LocalCalendar.Factory, getString(cur, Calendars.NAME)!!) if (localCalendar != null) calendarAccount.calendars.add(localCalendar) } catch (ex: Exception) { ex.printStackTrace() diff --git a/app/src/main/java/com/etesync/syncadapter/ui/importlocal/ImportFragment.kt b/app/src/main/java/com/etesync/syncadapter/ui/importlocal/ImportFragment.kt index f93ea582..2acc50af 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/importlocal/ImportFragment.kt +++ b/app/src/main/java/com/etesync/syncadapter/ui/importlocal/ImportFragment.kt @@ -32,10 +32,7 @@ import com.etesync.syncadapter.syncadapter.ContactsSyncManager import com.etesync.syncadapter.ui.Refreshable import com.etesync.syncadapter.ui.importlocal.ResultFragment.ImportResult import org.apache.commons.codec.Charsets -import java.io.File -import java.io.FileInputStream -import java.io.FileNotFoundException -import java.io.IOException +import java.io.* class ImportFragment : DialogFragment() { @@ -204,11 +201,11 @@ class ImportFragment : DialogFragment() { val result = ImportResult() try { - val importStream = FileInputStream(importFile!!) + val importReader = FileReader(importFile!!) if (info!!.type == CollectionInfo.Type.CALENDAR) { - val events = Event.fromStream(importStream, Charsets.UTF_8) - importStream.close() + val events = Event.fromReader(importReader, null) + importReader.close() if (events.size == 0) { App.log.warning("Empty/invalid file.") @@ -223,7 +220,7 @@ class ImportFragment : DialogFragment() { val provider = context!!.contentResolver.acquireContentProviderClient(CalendarContract.CONTENT_URI) val localCalendar: LocalCalendar? try { - localCalendar = LocalCalendar.findByName(account, provider, LocalCalendar.Factory.INSTANCE, info!!.uid!!) + localCalendar = LocalCalendar.findByName(account, provider, LocalCalendar.Factory, info!!.uid!!) if (localCalendar == null) { throw FileNotFoundException("Failed to load local resource.") } @@ -251,7 +248,7 @@ class ImportFragment : DialogFragment() { } else if (info!!.type == CollectionInfo.Type.ADDRESS_BOOK) { // FIXME: Handle groups and download icon? val downloader = ContactsSyncManager.ResourceDownloader(context!!) - val contacts = Contact.fromStream(importStream, Charsets.UTF_8, downloader) + val contacts = Contact.fromReader(importReader, downloader) if (contacts.size == 0) { App.log.warning("Empty/invalid file.") diff --git a/app/src/main/java/com/etesync/syncadapter/ui/importlocal/LocalCalendarImportFragment.kt b/app/src/main/java/com/etesync/syncadapter/ui/importlocal/LocalCalendarImportFragment.kt index 8484bfb9..db3b9750 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/importlocal/LocalCalendarImportFragment.kt +++ b/app/src/main/java/com/etesync/syncadapter/ui/importlocal/LocalCalendarImportFragment.kt @@ -78,7 +78,7 @@ class LocalCalendarImportFragment : ListFragment() { } override fun getChild(groupPosition: Int, childPosititon: Int): Any { - return calendarAccounts[groupPosition].getCalendars()[childPosititon].displayName + return calendarAccounts[groupPosition].getCalendars()[childPosititon].displayName!! } override fun getChildId(groupPosition: Int, childPosition: Int): Long { @@ -198,9 +198,9 @@ class LocalCalendarImportFragment : ListFragment() { val result = ResultFragment.ImportResult() try { val localCalendar = LocalCalendar.findByName(account, - context!!.contentResolver.acquireContentProviderClient(CalendarContract.CONTENT_URI), - LocalCalendar.Factory.INSTANCE, info!!.uid!!) - val localEvents = fromCalendar.all + context!!.contentResolver.acquireContentProviderClient(CalendarContract.CONTENT_URI)!!, + LocalCalendar.Factory, info!!.uid!!) + val localEvents = fromCalendar.findAll() val total = localEvents.size progressDialog!!.max = total result.total = total.toLong() @@ -208,7 +208,7 @@ class LocalCalendarImportFragment : ListFragment() { for (currentLocalEvent in localEvents) { val event = currentLocalEvent.event try { - val localEvent = LocalEvent(localCalendar!!, event, null, null) + val localEvent = LocalEvent(localCalendar!!, event!!, null, null) localEvent.addAsDirty() result.added++ } catch (e: CalendarStorageException) { diff --git a/app/src/main/java/com/etesync/syncadapter/ui/importlocal/LocalContactImportFragment.kt b/app/src/main/java/com/etesync/syncadapter/ui/importlocal/LocalContactImportFragment.kt index 0d829d84..55d3ad51 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/importlocal/LocalContactImportFragment.kt +++ b/app/src/main/java/com/etesync/syncadapter/ui/importlocal/LocalContactImportFragment.kt @@ -133,7 +133,7 @@ class LocalContactImportFragment : Fragment() { val addressBook = LocalAddressBook.findByUid(context!!, context!!.contentResolver.acquireContentProviderClient(ContactsContract.RawContacts.CONTENT_URI)!!, account, info!!.uid!!) - val localContacts = localAddressBook.all + val localContacts = localAddressBook.findAll() val total = localContacts.size progressDialog!!.max = total result.total = total.toLong() @@ -142,7 +142,7 @@ class LocalContactImportFragment : Fragment() { val contact = currentLocalContact.contact try { - val localContact = LocalContact(addressBook!!, contact, null, null) + val localContact = LocalContact(addressBook!!, contact!!, null, null) localContact.createAsDirty() result.added++ } catch (e: ContactsStorageException) {