mirror of
https://github.com/etesync/android
synced 2024-11-22 07:58:09 +00:00
snap
This commit is contained in:
parent
af8aed3ebd
commit
b90d2714a9
@ -48,15 +48,15 @@ import at.bitfire.ical4android.CalendarStorageException
|
|||||||
import at.bitfire.ical4android.Event
|
import at.bitfire.ical4android.Event
|
||||||
import at.bitfire.ical4android.InvalidCalendarException
|
import at.bitfire.ical4android.InvalidCalendarException
|
||||||
import at.bitfire.vcard4android.ContactsStorageException
|
import at.bitfire.vcard4android.ContactsStorageException
|
||||||
import com.etesync.syncadapter.resource.LocalCollection
|
|
||||||
import okhttp3.HttpUrl
|
import okhttp3.HttpUrl
|
||||||
|
import java.io.StringReader
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Synchronization manager for CardDAV collections; handles contacts and groups.
|
* Synchronization manager for CardDAV collections; handles contacts and groups.
|
||||||
*/
|
*/
|
||||||
class CalendarSyncManager @Throws(Exceptions.IntegrityException::class, Exceptions.GenericCryptoException::class)
|
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
|
override val syncErrorTitle: String
|
||||||
get() = context.getString(R.string.sync_error_calendar, account.name)
|
get() = context.getString(R.string.sync_error_calendar, account.name)
|
||||||
@ -66,7 +66,7 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra
|
|||||||
account.name)
|
account.name)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
localCollection = calendar as LocalCollection<LocalResource>
|
localCollection = calendar
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun notificationId(): Int {
|
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)
|
@Throws(IOException::class, ContactsStorageException::class, CalendarStorageException::class, InvalidCalendarException::class)
|
||||||
override fun processSyncEntry(cEntry: SyncEntry) {
|
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) {
|
if (events.size == 0) {
|
||||||
App.log.warning("Received VCard without data, ignoring")
|
App.log.warning("Received VCard without data, ignoring")
|
||||||
return
|
return
|
||||||
@ -109,7 +109,7 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra
|
|||||||
}
|
}
|
||||||
|
|
||||||
val event = events[0]
|
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)) {
|
if (cEntry.isAction(SyncEntry.Actions.ADD) || cEntry.isAction(SyncEntry.Actions.CHANGE)) {
|
||||||
processEvent(event, local)
|
processEvent(event, local)
|
||||||
@ -153,14 +153,14 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra
|
|||||||
intent.putExtra(Intent.EXTRA_SUBJECT,
|
intent.putExtra(Intent.EXTRA_SUBJECT,
|
||||||
context.getString(R.string.sync_calendar_attendees_email_subject,
|
context.getString(R.string.sync_calendar_attendees_email_subject,
|
||||||
event.summary,
|
event.summary,
|
||||||
dateFormatDate.format(event.dtStart.date)))
|
dateFormatDate.format(event.dtStart?.date)))
|
||||||
intent.putExtra(Intent.EXTRA_TEXT,
|
intent.putExtra(Intent.EXTRA_TEXT,
|
||||||
context.getString(R.string.sync_calendar_attendees_email_content,
|
context.getString(R.string.sync_calendar_attendees_email_content,
|
||||||
event.summary,
|
event.summary,
|
||||||
formatEventDates(event),
|
formatEventDates(event),
|
||||||
if (event.location != null) event.location else "",
|
if (event.location != null) event.location else "",
|
||||||
formatAttendees(event.attendees)))
|
formatAttendees(event.attendees)))
|
||||||
val uri = createAttachmentFromString(context, event.uid, icsContent)
|
val uri = createAttachmentFromString(context, event.uid!!, icsContent)
|
||||||
if (uri == null) {
|
if (uri == null) {
|
||||||
App.log.severe("Unable to create attachment from calendar event")
|
App.log.severe("Unable to create attachment from calendar event")
|
||||||
return
|
return
|
||||||
@ -176,7 +176,7 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Throws(IOException::class, ContactsStorageException::class, CalendarStorageException::class)
|
@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
|
var localEvent = localEvent
|
||||||
// delete local event, if it exists
|
// delete local event, if it exists
|
||||||
if (localEvent != null) {
|
if (localEvent != null) {
|
||||||
@ -218,23 +218,23 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra
|
|||||||
|
|
||||||
private fun formatEventDates(event: Event): String {
|
private fun formatEventDates(event: Event): String {
|
||||||
val locale = Locale.getDefault()
|
val locale = Locale.getDefault()
|
||||||
val timezone = if (event.dtStart.timeZone != null) event.dtStart.timeZone else TimeZone.getTimeZone("UTC")
|
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 dateFormatString = if (event.isAllDay()) "EEEE, MMM dd" else "EEEE, MMM dd @ hh:mm a"
|
||||||
val longDateFormat = SimpleDateFormat(dateFormatString, locale)
|
val longDateFormat = SimpleDateFormat(dateFormatString, locale)
|
||||||
longDateFormat.timeZone = timezone
|
longDateFormat.timeZone = timezone
|
||||||
val shortDateFormat = SimpleDateFormat("hh:mm a", locale)
|
val shortDateFormat = SimpleDateFormat("hh:mm a", locale)
|
||||||
shortDateFormat.timeZone = timezone
|
shortDateFormat.timeZone = timezone
|
||||||
|
|
||||||
val startDate = event.dtStart.date
|
val startDate = event.dtStart?.date
|
||||||
val endDate = event.getEndDate(true)!!.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 cal1 = Calendar.getInstance()
|
||||||
val cal2 = Calendar.getInstance()
|
val cal2 = Calendar.getInstance()
|
||||||
cal1.time = startDate
|
cal1.time = startDate
|
||||||
cal2.time = endDate
|
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)
|
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 longDateFormat.format(startDate)
|
||||||
}
|
}
|
||||||
return if (sameDay)
|
return if (sameDay)
|
||||||
|
@ -55,12 +55,12 @@ import okhttp3.OkHttpClient
|
|||||||
import com.etesync.syncadapter.Constants.KEY_ACCOUNT
|
import com.etesync.syncadapter.Constants.KEY_ACCOUNT
|
||||||
import com.etesync.syncadapter.model.SyncEntry.Actions.ADD
|
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) {
|
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 notificationManager: NotificationHelper
|
||||||
protected val info: CollectionInfo
|
protected val info: CollectionInfo
|
||||||
protected var localCollection: LocalCollection<LocalResource>? = null
|
protected var localCollection: LocalCollection<T>? = null
|
||||||
|
|
||||||
protected var httpClient: OkHttpClient
|
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.
|
* 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
|
private var localDeleted: List<T>? = null
|
||||||
protected var localDirty: Array<LocalResource> = arrayOf()
|
protected var localDirty: List<T> = LinkedList()
|
||||||
|
|
||||||
protected abstract val syncErrorTitle: String
|
protected abstract val syncErrorTitle: String
|
||||||
|
|
||||||
@ -227,8 +227,6 @@ constructor(protected val context: Context, protected val account: Account, prot
|
|||||||
} catch (e: OutOfMemoryError) {
|
} catch (e: OutOfMemoryError) {
|
||||||
if (e is Exceptions.HttpException) {
|
if (e is Exceptions.HttpException) {
|
||||||
syncResult.stats.numParseExceptions++
|
syncResult.stats.numParseExceptions++
|
||||||
} else if (e is CalendarStorageException || e is ContactsStorageException) {
|
|
||||||
syncResult.databaseError = true
|
|
||||||
} else {
|
} else {
|
||||||
syncResult.stats.numParseExceptions++
|
syncResult.stats.numParseExceptions++
|
||||||
}
|
}
|
||||||
@ -412,7 +410,7 @@ constructor(protected val context: Context, protected val account: Account, prot
|
|||||||
local.clearDirty(local.uuid!!)
|
local.clearDirty(local.uuid!!)
|
||||||
}
|
}
|
||||||
if (left > 0) {
|
if (left > 0) {
|
||||||
localDirty = Arrays.copyOfRange(localDirty, left, localDirty.size)
|
localDirty = localDirty.drop(left)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pushed > 0) {
|
if (pushed > 0) {
|
||||||
@ -467,7 +465,7 @@ constructor(protected val context: Context, protected val account: Account, prot
|
|||||||
remoteCTag = journalEntity.getLastUid(data)
|
remoteCTag = journalEntity.getLastUid(data)
|
||||||
|
|
||||||
localDeleted = processLocallyDeleted()
|
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
|
// This is done after fetching the local dirty so all the ones we are using will be prepared
|
||||||
prepareDirty()
|
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.
|
* Checks Thread.interrupted() before each request to allow quick sync cancellation.
|
||||||
*/
|
*/
|
||||||
@Throws(CalendarStorageException::class, ContactsStorageException::class)
|
@Throws(CalendarStorageException::class, ContactsStorageException::class)
|
||||||
private fun processLocallyDeleted(): List<LocalResource> {
|
private fun processLocallyDeleted(): List<T> {
|
||||||
val localList = localCollection!!.deleted
|
val localList = localCollection!!.findDeleted()
|
||||||
val ret = ArrayList<LocalResource>(localList.size)
|
val ret = ArrayList<T>(localList.size)
|
||||||
|
|
||||||
for (local in localList) {
|
for (local in localList) {
|
||||||
if (Thread.interrupted())
|
if (Thread.interrupted())
|
||||||
@ -504,7 +502,7 @@ constructor(protected val context: Context, protected val account: Account, prot
|
|||||||
continue
|
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()
|
local.prepareForUpload()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -279,7 +279,7 @@ class JournalItemActivity : BaseActivity(), Refreshable {
|
|||||||
|
|
||||||
// ORG, TITLE, ROLE
|
// ORG, TITLE, ROLE
|
||||||
if (contact.organization != null) {
|
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) {
|
if (contact.jobDescription != null) {
|
||||||
addInfoItem(view.context, aboutCard, getString(R.string.journal_item_job_description), null, contact.jobTitle)
|
addInfoItem(view.context, aboutCard, getString(R.string.journal_item_job_description), null, contact.jobTitle)
|
||||||
@ -291,8 +291,8 @@ class JournalItemActivity : BaseActivity(), Refreshable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NICKNAME
|
// NICKNAME
|
||||||
if (contact.nickName != null && contact.nickName.values.size > 0) {
|
if (contact.nickName != null && !contact.nickName?.values?.isEmpty()!!) {
|
||||||
addInfoItem(view.context, aboutCard, getString(R.string.journal_item_nickname), null, contact.nickName.values[0])
|
addInfoItem(view.context, aboutCard, getString(R.string.journal_item_nickname), null, contact.nickName?.values!![0])
|
||||||
}
|
}
|
||||||
|
|
||||||
// ADR
|
// ADR
|
||||||
@ -314,11 +314,11 @@ class JournalItemActivity : BaseActivity(), Refreshable {
|
|||||||
|
|
||||||
// ANNIVERSARY
|
// ANNIVERSARY
|
||||||
if (contact.anniversary != null) {
|
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
|
// BDAY
|
||||||
if (contact.birthDay != null) {
|
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
|
// RELATED
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit fef93f94bbc1265e53e55c95fe86e8c33e2e4f0f
|
Subproject commit 2437b0b7aedf4fa1907a88c72781cff4c8291e40
|
Loading…
Reference in New Issue
Block a user