1
0
mirror of https://github.com/etesync/android synced 2024-12-22 22:58:29 +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)
}
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).

View File

@ -90,7 +90,7 @@ class LocalEvent : AndroidEvent, LocalResource<Event> {
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)

View File

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

View File

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

View File

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

View File

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

View File

@ -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<Void, Void, Event>() {
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<View>(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<View>(R.id.organizer_container)
organizer.visibility = View.GONE
val organizerView = view.findViewById<View>(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<Void, Void, Contact>() {
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()
}

View File

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

View File

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

View File

@ -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.")

View File

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

View File

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