1
0
mirror of https://github.com/etesync/android synced 2024-11-21 23:48:11 +00:00
This commit is contained in:
Tom Hacohen 2019-01-06 12:38:53 +00:00
parent af8aed3ebd
commit b90d2714a9
4 changed files with 30 additions and 32 deletions

View File

@ -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<LocalEvent>(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<LocalResource>
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)

View File

@ -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<T: LocalResource<*>> @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<LocalResource>? = null
protected var localCollection: LocalCollection<T>? = 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<LocalResource>? = null
protected var localDirty: Array<LocalResource> = arrayOf()
private var localDeleted: List<T>? = null
protected var localDirty: List<T> = 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<LocalResource> {
val localList = localCollection!!.deleted
val ret = ArrayList<LocalResource>(localList.size)
private fun processLocallyDeleted(): List<T> {
val localList = localCollection!!.findDeleted()
val ret = ArrayList<T>(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()
}
}

View File

@ -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

@ -1 +1 @@
Subproject commit fef93f94bbc1265e53e55c95fe86e8c33e2e4f0f
Subproject commit 2437b0b7aedf4fa1907a88c72781cff4c8291e40