From b90d2714a9a7273c4e3508b23ca8a4bc47f01c73 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Sun, 6 Jan 2019 12:38:53 +0000 Subject: [PATCH] snap --- .../syncadapter/CalendarSyncManager.kt | 28 +++++++++---------- .../syncadapter/syncadapter/SyncManager.kt | 22 +++++++-------- .../syncadapter/ui/JournalItemActivity.kt | 10 +++---- ical4android | 2 +- 4 files changed, 30 insertions(+), 32 deletions(-) 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 79c3a9b8..559921e4 100644 --- a/app/src/main/java/com/etesync/syncadapter/syncadapter/CalendarSyncManager.kt +++ b/app/src/main/java/com/etesync/syncadapter/syncadapter/CalendarSyncManager.kt @@ -48,15 +48,15 @@ import at.bitfire.ical4android.CalendarStorageException import at.bitfire.ical4android.Event import at.bitfire.ical4android.InvalidCalendarException import at.bitfire.vcard4android.ContactsStorageException -import com.etesync.syncadapter.resource.LocalCollection import okhttp3.HttpUrl +import java.io.StringReader /** * * 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) { override val syncErrorTitle: String get() = context.getString(R.string.sync_error_calendar, account.name) @@ -66,7 +66,7 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra account.name) init { - localCollection = calendar as LocalCollection + localCollection = calendar } override fun notificationId(): Int { @@ -98,9 +98,9 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra @Throws(IOException::class, ContactsStorageException::class, CalendarStorageException::class, InvalidCalendarException::class) override fun processSyncEntry(cEntry: SyncEntry) { - val `is` = ByteArrayInputStream(cEntry.content.toByteArray(Charsets.UTF_8)) + val inputReader = StringReader(cEntry.content) - val events = Event.fromStream(`is`, Charsets.UTF_8) + val events = Event.fromReader(inputReader) if (events.size == 0) { App.log.warning("Received VCard without data, ignoring") return @@ -109,7 +109,7 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra } val event = events[0] - val local = localCollection!!.findByUid(event.uid) as LocalEvent? + val local = localCollection!!.findByUid(event.uid!!) if (cEntry.isAction(SyncEntry.Actions.ADD) || cEntry.isAction(SyncEntry.Actions.CHANGE)) { processEvent(event, local) @@ -153,14 +153,14 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra intent.putExtra(Intent.EXTRA_SUBJECT, context.getString(R.string.sync_calendar_attendees_email_subject, event.summary, - dateFormatDate.format(event.dtStart.date))) + dateFormatDate.format(event.dtStart?.date))) intent.putExtra(Intent.EXTRA_TEXT, context.getString(R.string.sync_calendar_attendees_email_content, event.summary, formatEventDates(event), if (event.location != null) event.location else "", formatAttendees(event.attendees))) - val uri = createAttachmentFromString(context, event.uid, icsContent) + val uri = createAttachmentFromString(context, event.uid!!, icsContent) if (uri == null) { App.log.severe("Unable to create attachment from calendar event") return @@ -176,7 +176,7 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra } @Throws(IOException::class, ContactsStorageException::class, CalendarStorageException::class) - private fun processEvent(newData: Event, localEvent: LocalEvent?): LocalResource { + private fun processEvent(newData: Event, localEvent: LocalEvent?): LocalEvent { var localEvent = localEvent // delete local event, if it exists if (localEvent != null) { @@ -218,23 +218,23 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra private fun formatEventDates(event: Event): String { val locale = Locale.getDefault() - val timezone = if (event.dtStart.timeZone != null) event.dtStart.timeZone else TimeZone.getTimeZone("UTC") - val dateFormatString = if (event.isAllDay) "EEEE, MMM dd" else "EEEE, MMM dd @ hh:mm a" + val timezone = if (event.dtStart?.timeZone != null) event.dtStart?.timeZone else TimeZone.getTimeZone("UTC") + val dateFormatString = if (event.isAllDay()) "EEEE, MMM dd" else "EEEE, MMM dd @ hh:mm a" val longDateFormat = SimpleDateFormat(dateFormatString, locale) longDateFormat.timeZone = timezone val shortDateFormat = SimpleDateFormat("hh:mm a", locale) shortDateFormat.timeZone = timezone - val startDate = event.dtStart.date + val startDate = event.dtStart?.date val endDate = event.getEndDate(true)!!.date - val tzName = timezone.getDisplayName(timezone.inDaylightTime(startDate), TimeZone.SHORT) + val tzName = timezone.getDisplayName(timezone?.inDaylightTime(startDate)!!, TimeZone.SHORT) val cal1 = Calendar.getInstance() val cal2 = Calendar.getInstance() cal1.time = startDate cal2.time = endDate val sameDay = cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR) - if (sameDay && event.isAllDay) { + if (sameDay && event.isAllDay()) { return longDateFormat.format(startDate) } return if (sameDay) diff --git a/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncManager.kt b/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncManager.kt index bc613fc1..421fb073 100644 --- a/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncManager.kt +++ b/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncManager.kt @@ -55,12 +55,12 @@ import okhttp3.OkHttpClient import com.etesync.syncadapter.Constants.KEY_ACCOUNT import com.etesync.syncadapter.model.SyncEntry.Actions.ADD -abstract class SyncManager @Throws(Exceptions.IntegrityException::class, Exceptions.GenericCryptoException::class) +abstract class SyncManager> @Throws(Exceptions.IntegrityException::class, Exceptions.GenericCryptoException::class) constructor(protected val context: Context, protected val account: Account, protected val settings: AccountSettings, protected val extras: Bundle, protected val authority: String, protected val syncResult: SyncResult, journalUid: String, protected val serviceType: CollectionInfo.Type, accountName: String) { protected val notificationManager: NotificationHelper protected val info: CollectionInfo - protected var localCollection: LocalCollection? = null + protected var localCollection: LocalCollection? = null protected var httpClient: OkHttpClient @@ -89,8 +89,8 @@ constructor(protected val context: Context, protected val account: Account, prot /** * Dirty and deleted resources. We need to save them so we safely ignore ones that were added after we started. */ - private var localDeleted: List? = null - protected var localDirty: Array = arrayOf() + private var localDeleted: List? = null + protected var localDirty: List = LinkedList() protected abstract val syncErrorTitle: String @@ -227,8 +227,6 @@ constructor(protected val context: Context, protected val account: Account, prot } catch (e: OutOfMemoryError) { if (e is Exceptions.HttpException) { syncResult.stats.numParseExceptions++ - } else if (e is CalendarStorageException || e is ContactsStorageException) { - syncResult.databaseError = true } else { syncResult.stats.numParseExceptions++ } @@ -412,7 +410,7 @@ constructor(protected val context: Context, protected val account: Account, prot local.clearDirty(local.uuid!!) } if (left > 0) { - localDirty = Arrays.copyOfRange(localDirty, left, localDirty.size) + localDirty = localDirty.drop(left) } if (pushed > 0) { @@ -467,7 +465,7 @@ constructor(protected val context: Context, protected val account: Account, prot remoteCTag = journalEntity.getLastUid(data) localDeleted = processLocallyDeleted() - localDirty = localCollection!!.dirty + localDirty = localCollection!!.findDirty() // This is done after fetching the local dirty so all the ones we are using will be prepared prepareDirty() } @@ -478,9 +476,9 @@ constructor(protected val context: Context, protected val account: Account, prot * Checks Thread.interrupted() before each request to allow quick sync cancellation. */ @Throws(CalendarStorageException::class, ContactsStorageException::class) - private fun processLocallyDeleted(): List { - val localList = localCollection!!.deleted - val ret = ArrayList(localList.size) + private fun processLocallyDeleted(): List { + val localList = localCollection!!.findDeleted() + val ret = ArrayList(localList.size) for (local in localList) { if (Thread.interrupted()) @@ -504,7 +502,7 @@ constructor(protected val context: Context, protected val account: Account, prot continue } - App.log.fine("Found local record #" + local.id + " without file name; generating file name/UID if necessary") + App.log.fine("Found local record without file name; generating file name/UID if necessary") local.prepareForUpload() } } 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 ffb778ae..b395cd4d 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/JournalItemActivity.kt +++ b/app/src/main/java/com/etesync/syncadapter/ui/JournalItemActivity.kt @@ -279,7 +279,7 @@ class JournalItemActivity : BaseActivity(), Refreshable { // ORG, TITLE, ROLE if (contact.organization != null) { - addInfoItem(view.context, aboutCard, getString(R.string.journal_item_organization), contact.jobTitle, contact.organization.values[0]) + addInfoItem(view.context, aboutCard, getString(R.string.journal_item_organization), contact.jobTitle, contact.organization?.values!![0]) } if (contact.jobDescription != null) { addInfoItem(view.context, aboutCard, getString(R.string.journal_item_job_description), null, contact.jobTitle) @@ -291,8 +291,8 @@ class JournalItemActivity : BaseActivity(), Refreshable { } // NICKNAME - if (contact.nickName != null && contact.nickName.values.size > 0) { - addInfoItem(view.context, aboutCard, getString(R.string.journal_item_nickname), null, contact.nickName.values[0]) + if (contact.nickName != null && !contact.nickName?.values?.isEmpty()!!) { + addInfoItem(view.context, aboutCard, getString(R.string.journal_item_nickname), null, contact.nickName?.values!![0]) } // ADR @@ -314,11 +314,11 @@ class JournalItemActivity : BaseActivity(), Refreshable { // ANNIVERSARY if (contact.anniversary != null) { - addInfoItem(view.context, aboutCard, getString(R.string.journal_item_anniversary), null, getDisplayedDate(contact.anniversary.date, contact.anniversary.partialDate)) + addInfoItem(view.context, aboutCard, getString(R.string.journal_item_anniversary), null, getDisplayedDate(contact.anniversary?.date, contact.anniversary?.partialDate!!)) } // BDAY if (contact.birthDay != null) { - addInfoItem(view.context, aboutCard, getString(R.string.journal_item_birthday), null, getDisplayedDate(contact.birthDay.date, contact.birthDay.partialDate)) + addInfoItem(view.context, aboutCard, getString(R.string.journal_item_birthday), null, getDisplayedDate(contact.birthDay?.date, contact.birthDay?.partialDate!!)) } // RELATED diff --git a/ical4android b/ical4android index fef93f94..2437b0b7 160000 --- a/ical4android +++ b/ical4android @@ -1 +1 @@ -Subproject commit fef93f94bbc1265e53e55c95fe86e8c33e2e4f0f +Subproject commit 2437b0b7aedf4fa1907a88c72781cff4c8291e40