1
0
mirror of https://github.com/etesync/android synced 2024-11-22 07:58:09 +00:00
This commit is contained in:
Tom Hacohen 2019-01-06 11:57:53 +00:00
parent d8d5591f52
commit af8aed3ebd
12 changed files with 38 additions and 46 deletions

View File

@ -199,7 +199,7 @@ class LocalAddressBook(
accountManager.removeAccount(account, null, null) accountManager.removeAccount(account, null, null)
} }
override fun findAll(): List<LocalAddress> = queryContacts(RawContacts.DELETED + "== 0", null) override fun findAll(): List<LocalContact> = queryContacts(RawContacts.DELETED + "== 0", null)
/** /**
* Returns an array of local contacts/groups which have been deleted locally. (DELETED != 0). * Returns an array of local contacts/groups which have been deleted locally. (DELETED != 0).

View File

@ -90,7 +90,7 @@ class LocalEvent : AndroidEvent, LocalResource<Event> {
val buildException = recurrence != null val buildException = recurrence != null
val eventToBuild = if (buildException) recurrence else event 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(COLUMN_SEQUENCE, eventToBuild?.sequence)
.withValue(CalendarContract.Events.DIRTY, if (saveAsDirty) 1 else 0) .withValue(CalendarContract.Events.DIRTY, if (saveAsDirty) 1 else 0)
.withValue(CalendarContract.Events.DELETED, 0) .withValue(CalendarContract.Events.DELETED, 0)

View File

@ -12,7 +12,7 @@ import at.bitfire.ical4android.CalendarStorageException
import at.bitfire.vcard4android.ContactsStorageException import at.bitfire.vcard4android.ContactsStorageException
interface LocalResource<in TData: Any> { interface LocalResource<in TData: Any> {
val uuid: String val uuid: String?
/** True if doesn't exist on server yet, false otherwise. */ /** True if doesn't exist on server yet, false otherwise. */
val isLocalOnly: Boolean val isLocalOnly: Boolean

View File

@ -108,10 +108,6 @@ class AddressBooksSyncAdapterService : SyncAdapterService() {
notificationManager.notify(title, context.getString(syncPhase)) notificationManager.notify(title, context.getString(syncPhase))
} catch (e: OutOfMemoryError) { } 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 syncPhase = R.string.sync_phase_journals
val title = context.getString(R.string.sync_error_contacts, account.name) val title = context.getString(R.string.sync_error_contacts, account.name)
notificationManager.setThrowable(e) notificationManager.setThrowable(e)

View File

@ -56,12 +56,12 @@ import okhttp3.HttpUrl
* 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(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) 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, get() = context.getString(R.string.sync_successfully_calendar, info.displayName,
account.name) account.name)
@ -78,7 +78,7 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra
if (!super.prepare()) if (!super.prepare())
return false return false
journal = JournalEntryManager(httpClient, remote, localCalendar().name) journal = JournalEntryManager(httpClient, remote, localCalendar().name!!)
return true return true
} }
@ -137,7 +137,7 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra
for (local in localDirty) { for (local in localDirty) {
val event = (local as LocalEvent).event val event = (local as LocalEvent).event
if (event.attendees.isEmpty()) { if (event?.attendees?.isEmpty()!!) {
return return
} }
createInviteAttendeesNotification(event, local.content) createInviteAttendeesNotification(event, local.content)
@ -145,7 +145,7 @@ constructor(context: Context, account: Account, settings: AccountSettings, extra
} }
private fun createInviteAttendeesNotification(event: Event, icsContent: String) { 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) val intent = Intent(Intent.ACTION_SEND)
intent.type = "text/plain" intent.type = "text/plain"
intent.putExtra(Intent.EXTRA_EMAIL, getEmailAddresses(event.attendees, false)) intent.putExtra(Intent.EXTRA_EMAIL, getEmailAddresses(event.attendees, false))

View File

@ -32,7 +32,6 @@ import com.etesync.syncadapter.BuildConfig
import com.etesync.syncadapter.Constants import com.etesync.syncadapter.Constants
import com.etesync.syncadapter.R import com.etesync.syncadapter.R
import ezvcard.Ezvcard import ezvcard.Ezvcard
import org.apache.commons.io.IOUtils
import org.apache.commons.lang3.time.DateFormatUtils import org.apache.commons.lang3.time.DateFormatUtils
import java.io.IOException import java.io.IOException
import java.util.logging.Level import java.util.logging.Level
@ -143,9 +142,9 @@ class AboutActivity : BaseActivity() {
override fun loadInBackground(): Spanned? { override fun loadInBackground(): Spanned? {
App.log.fine("Loading license file $fileName") App.log.fine("Loading license file $fileName")
try { try {
val `is` = context.resources.assets.open(fileName) val inputStream = context.resources.assets.open(fileName)
val raw = IOUtils.toByteArray(`is`) val raw = inputStream.readBytes()
`is`.close() inputStream.close()
content = Html.fromHtml(String(raw)) content = Html.fromHtml(String(raw))
return content return content
} catch (e: IOException) { } catch (e: IOException) {

View File

@ -27,9 +27,8 @@ import com.etesync.syncadapter.model.JournalEntity
import com.etesync.syncadapter.model.SyncEntry import com.etesync.syncadapter.model.SyncEntry
import com.etesync.syncadapter.ui.journalviewer.ListEntriesFragment.Companion.setJournalEntryView import com.etesync.syncadapter.ui.journalviewer.ListEntriesFragment.Companion.setJournalEntryView
import ezvcard.util.PartialDate import ezvcard.util.PartialDate
import org.apache.commons.codec.Charsets
import java.io.ByteArrayInputStream
import java.io.IOException import java.io.IOException
import java.io.StringReader
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.* import java.util.*
@ -154,10 +153,10 @@ class JournalItemActivity : BaseActivity(), Refreshable {
private inner class LoadEventTask internal constructor(internal var view: View) : AsyncTask<Void, Void, Event>() { private inner class LoadEventTask internal constructor(internal var view: View) : AsyncTask<Void, Void, Event>() {
override fun doInBackground(vararg aVoids: Void): Event? { override fun doInBackground(vararg aVoids: Void): Event? {
val `is` = ByteArrayInputStream(syncEntry.content.toByteArray(Charsets.UTF_8)) val inputReader = StringReader(syncEntry.content)
try { try {
return Event.fromStream(`is`, Charsets.UTF_8, null)[0] return Event.fromReader(inputReader, null)[0]
} catch (e: InvalidCalendarException) { } catch (e: InvalidCalendarException) {
e.printStackTrace() e.printStackTrace()
} catch (e: IOException) { } catch (e: IOException) {
@ -175,16 +174,17 @@ class JournalItemActivity : BaseActivity(), Refreshable {
setTextViewText(view, R.id.title, event.summary) 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) setTextViewText(view, R.id.where, event.location)
if (event.organizer != null) { val organizer = event.organizer
if (organizer != null) {
val tv = view.findViewById<View>(R.id.organizer) as TextView val tv = view.findViewById<View>(R.id.organizer) as TextView
tv.text = event.organizer.calAddress.toString().replaceFirst("mailto:".toRegex(), "") tv.text = organizer.calAddress.toString().replaceFirst("mailto:".toRegex(), "")
} else { } else {
val organizer = view.findViewById<View>(R.id.organizer_container) val organizerView = view.findViewById<View>(R.id.organizer_container)
organizer.visibility = View.GONE organizerView.visibility = View.GONE
} }
setTextViewText(view, R.id.description, event.description) 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<Void, Void, Contact>() { private inner class LoadContactTask internal constructor(internal var view: View) : AsyncTask<Void, Void, Contact>() {
override fun doInBackground(vararg aVoids: Void): Contact? { override fun doInBackground(vararg aVoids: Void): Contact? {
val `is` = ByteArrayInputStream(syncEntry.content.toByteArray(Charsets.UTF_8)) val reader = StringReader(syncEntry.content)
try { try {
return Contact.fromStream(`is`, Charsets.UTF_8, null)[0] return Contact.fromReader(reader, null)[0]
} catch (e: IOException) { } catch (e: IOException) {
e.printStackTrace() e.printStackTrace()
} }

View File

@ -171,7 +171,7 @@ class ViewCollectionActivity : BaseActivity(), Refreshable {
if (info.type == CollectionInfo.Type.CALENDAR) { if (info.type == CollectionInfo.Type.CALENDAR) {
try { try {
val providerClient = contentResolver.acquireContentProviderClient(CalendarContract.CONTENT_URI) 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() providerClient!!.release()
if (resource == null) { if (resource == null) {
return null return null

View File

@ -77,7 +77,7 @@ class CalendarAccount protected constructor(val account: Account) {
try { try {
val localCalendar = LocalCalendar.findByName(calendarAccount.account, val localCalendar = LocalCalendar.findByName(calendarAccount.account,
contentProviderClient, contentProviderClient,
LocalCalendar.Factory.INSTANCE, getString(cur, Calendars.NAME)!!) LocalCalendar.Factory, getString(cur, Calendars.NAME)!!)
if (localCalendar != null) calendarAccount.calendars.add(localCalendar) if (localCalendar != null) calendarAccount.calendars.add(localCalendar)
} catch (ex: Exception) { } catch (ex: Exception) {
ex.printStackTrace() ex.printStackTrace()

View File

@ -32,10 +32,7 @@ import com.etesync.syncadapter.syncadapter.ContactsSyncManager
import com.etesync.syncadapter.ui.Refreshable import com.etesync.syncadapter.ui.Refreshable
import com.etesync.syncadapter.ui.importlocal.ResultFragment.ImportResult import com.etesync.syncadapter.ui.importlocal.ResultFragment.ImportResult
import org.apache.commons.codec.Charsets import org.apache.commons.codec.Charsets
import java.io.File import java.io.*
import java.io.FileInputStream
import java.io.FileNotFoundException
import java.io.IOException
class ImportFragment : DialogFragment() { class ImportFragment : DialogFragment() {
@ -204,11 +201,11 @@ class ImportFragment : DialogFragment() {
val result = ImportResult() val result = ImportResult()
try { try {
val importStream = FileInputStream(importFile!!) val importReader = FileReader(importFile!!)
if (info!!.type == CollectionInfo.Type.CALENDAR) { if (info!!.type == CollectionInfo.Type.CALENDAR) {
val events = Event.fromStream(importStream, Charsets.UTF_8) val events = Event.fromReader(importReader, null)
importStream.close() importReader.close()
if (events.size == 0) { if (events.size == 0) {
App.log.warning("Empty/invalid file.") App.log.warning("Empty/invalid file.")
@ -223,7 +220,7 @@ class ImportFragment : DialogFragment() {
val provider = context!!.contentResolver.acquireContentProviderClient(CalendarContract.CONTENT_URI) val provider = context!!.contentResolver.acquireContentProviderClient(CalendarContract.CONTENT_URI)
val localCalendar: LocalCalendar? val localCalendar: LocalCalendar?
try { try {
localCalendar = LocalCalendar.findByName(account, provider, LocalCalendar.Factory.INSTANCE, info!!.uid!!) localCalendar = LocalCalendar.findByName(account, provider, LocalCalendar.Factory, info!!.uid!!)
if (localCalendar == null) { if (localCalendar == null) {
throw FileNotFoundException("Failed to load local resource.") throw FileNotFoundException("Failed to load local resource.")
} }
@ -251,7 +248,7 @@ class ImportFragment : DialogFragment() {
} else if (info!!.type == CollectionInfo.Type.ADDRESS_BOOK) { } else if (info!!.type == CollectionInfo.Type.ADDRESS_BOOK) {
// FIXME: Handle groups and download icon? // FIXME: Handle groups and download icon?
val downloader = ContactsSyncManager.ResourceDownloader(context!!) val downloader = ContactsSyncManager.ResourceDownloader(context!!)
val contacts = Contact.fromStream(importStream, Charsets.UTF_8, downloader) val contacts = Contact.fromReader(importReader, downloader)
if (contacts.size == 0) { if (contacts.size == 0) {
App.log.warning("Empty/invalid file.") App.log.warning("Empty/invalid file.")

View File

@ -78,7 +78,7 @@ class LocalCalendarImportFragment : ListFragment() {
} }
override fun getChild(groupPosition: Int, childPosititon: Int): Any { 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 { override fun getChildId(groupPosition: Int, childPosition: Int): Long {
@ -198,9 +198,9 @@ class LocalCalendarImportFragment : ListFragment() {
val result = ResultFragment.ImportResult() val result = ResultFragment.ImportResult()
try { try {
val localCalendar = LocalCalendar.findByName(account, val localCalendar = LocalCalendar.findByName(account,
context!!.contentResolver.acquireContentProviderClient(CalendarContract.CONTENT_URI), context!!.contentResolver.acquireContentProviderClient(CalendarContract.CONTENT_URI)!!,
LocalCalendar.Factory.INSTANCE, info!!.uid!!) LocalCalendar.Factory, info!!.uid!!)
val localEvents = fromCalendar.all val localEvents = fromCalendar.findAll()
val total = localEvents.size val total = localEvents.size
progressDialog!!.max = total progressDialog!!.max = total
result.total = total.toLong() result.total = total.toLong()
@ -208,7 +208,7 @@ class LocalCalendarImportFragment : ListFragment() {
for (currentLocalEvent in localEvents) { for (currentLocalEvent in localEvents) {
val event = currentLocalEvent.event val event = currentLocalEvent.event
try { try {
val localEvent = LocalEvent(localCalendar!!, event, null, null) val localEvent = LocalEvent(localCalendar!!, event!!, null, null)
localEvent.addAsDirty() localEvent.addAsDirty()
result.added++ result.added++
} catch (e: CalendarStorageException) { } catch (e: CalendarStorageException) {

View File

@ -133,7 +133,7 @@ class LocalContactImportFragment : Fragment() {
val addressBook = LocalAddressBook.findByUid(context!!, val addressBook = LocalAddressBook.findByUid(context!!,
context!!.contentResolver.acquireContentProviderClient(ContactsContract.RawContacts.CONTENT_URI)!!, context!!.contentResolver.acquireContentProviderClient(ContactsContract.RawContacts.CONTENT_URI)!!,
account, info!!.uid!!) account, info!!.uid!!)
val localContacts = localAddressBook.all val localContacts = localAddressBook.findAll()
val total = localContacts.size val total = localContacts.size
progressDialog!!.max = total progressDialog!!.max = total
result.total = total.toLong() result.total = total.toLong()
@ -142,7 +142,7 @@ class LocalContactImportFragment : Fragment() {
val contact = currentLocalContact.contact val contact = currentLocalContact.contact
try { try {
val localContact = LocalContact(addressBook!!, contact, null, null) val localContact = LocalContact(addressBook!!, contact!!, null, null)
localContact.createAsDirty() localContact.createAsDirty()
result.added++ result.added++
} catch (e: ContactsStorageException) { } catch (e: ContactsStorageException) {