mirror of
https://github.com/etesync/android
synced 2024-11-21 23:48:11 +00:00
snap
This commit is contained in:
parent
88dad0a538
commit
d8d5591f52
@ -67,6 +67,7 @@ import java.util.logging.Logger
|
||||
import javax.net.ssl.HostnameVerifier
|
||||
|
||||
import at.bitfire.cert4android.CustomCertManager
|
||||
import at.bitfire.ical4android.AndroidCalendar
|
||||
import at.bitfire.ical4android.CalendarStorageException
|
||||
import at.bitfire.vcard4android.ContactsStorageException
|
||||
import io.requery.Persistable
|
||||
@ -294,8 +295,8 @@ class App : Application() {
|
||||
// Generate account settings to make sure account is migrated.
|
||||
AccountSettings(this, account)
|
||||
|
||||
val calendars = LocalCalendar.find(account, this.contentResolver.acquireContentProviderClient(CalendarContract.CONTENT_URI)!!,
|
||||
LocalCalendar.Factory.INSTANCE, null, null) as Array<LocalCalendar>
|
||||
val calendars = AndroidCalendar.find(account, this.contentResolver.acquireContentProviderClient(CalendarContract.CONTENT_URI)!!,
|
||||
LocalCalendar.Factory, null, null)
|
||||
for (calendar in calendars) {
|
||||
calendar.fixEtags()
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ class LocalAddressBook(
|
||||
val accountManager = AccountManager.get(context)
|
||||
|
||||
val account = Account(accountName(mainAccount, info), App.addressBookAccountType)
|
||||
if (!accountManager.addAccountExplicitly(account, null, initialUserData(mainAccount, info.url.toString())))
|
||||
if (!accountManager.addAccountExplicitly(account, null, initialUserData(mainAccount, info.uid!!)))
|
||||
throw ContactsStorageException("Couldn't create address book account")
|
||||
|
||||
val addressBook = LocalAddressBook(context, account, provider)
|
||||
@ -276,7 +276,7 @@ class LocalAddressBook(
|
||||
try {
|
||||
val cursor = provider?.query(syncAdapterURI(RawContacts.CONTENT_URI), null, null, null, null)
|
||||
try {
|
||||
return cursor?.count.toLong()
|
||||
return cursor?.count?.toLong()!!
|
||||
} finally {
|
||||
cursor?.close()
|
||||
}
|
||||
@ -286,31 +286,6 @@ class LocalAddressBook(
|
||||
|
||||
}
|
||||
|
||||
internal fun getByGroupMembership(groupID: Long): Array<LocalContact> {
|
||||
try {
|
||||
val cursor = provider.query(syncAdapterURI(ContactsContract.Data.CONTENT_URI),
|
||||
arrayOf(RawContacts.Data.RAW_CONTACT_ID),
|
||||
"(" + GroupMembership.MIMETYPE + "=? AND " + GroupMembership.GROUP_ROW_ID + "=?) OR (" + CachedGroupMembership.MIMETYPE + "=? AND " + CachedGroupMembership.GROUP_ID + "=?)",
|
||||
arrayOf(GroupMembership.CONTENT_ITEM_TYPE, groupID.toString(), CachedGroupMembership.CONTENT_ITEM_TYPE, groupID.toString()), null)
|
||||
|
||||
val ids = HashSet<Long>()
|
||||
while (cursor != null && cursor.moveToNext())
|
||||
ids.add(cursor.getLong(0))
|
||||
|
||||
cursor!!.close()
|
||||
|
||||
val contacts = arrayOfNulls<LocalContact>(ids.size)
|
||||
var i = 0
|
||||
for (id in ids)
|
||||
contacts[i++] = LocalContact(this, id, null, null)
|
||||
return contacts
|
||||
} catch (e: RemoteException) {
|
||||
throw ContactsStorageException("Couldn't query contacts", e)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
fun deleteAll() {
|
||||
try {
|
||||
provider?.delete(syncAdapterURI(RawContacts.CONTENT_URI), null, null)
|
||||
@ -322,6 +297,22 @@ class LocalAddressBook(
|
||||
}
|
||||
|
||||
|
||||
/* special group operations */
|
||||
fun getByGroupMembership(groupID: Long): List<LocalContact> {
|
||||
val ids = HashSet<Long>()
|
||||
provider!!.query(syncAdapterURI(ContactsContract.Data.CONTENT_URI),
|
||||
arrayOf(RawContacts.Data.RAW_CONTACT_ID),
|
||||
"(${GroupMembership.MIMETYPE}=? AND ${GroupMembership.GROUP_ROW_ID}=?) OR (${CachedGroupMembership.MIMETYPE}=? AND ${CachedGroupMembership.GROUP_ID}=?)",
|
||||
arrayOf(GroupMembership.CONTENT_ITEM_TYPE, groupID.toString(), CachedGroupMembership.CONTENT_ITEM_TYPE, groupID.toString()),
|
||||
null)?.use { cursor ->
|
||||
while (cursor.moveToNext())
|
||||
ids += cursor.getLong(0)
|
||||
}
|
||||
|
||||
return ids.map { findContactByID(it) }
|
||||
}
|
||||
|
||||
|
||||
/* special group operations */
|
||||
|
||||
/**
|
||||
@ -356,7 +347,6 @@ class LocalAddressBook(
|
||||
|
||||
/** Fix all of the etags of all of the non-dirty contacts to be non-null.
|
||||
* Currently set to all ones. */
|
||||
@Throws(ContactsStorageException::class)
|
||||
fun fixEtags() {
|
||||
val newEtag = "1111111111111111111111111111111111111111111111111111111111111111"
|
||||
val where = ContactsContract.RawContacts.DIRTY + "=0 AND " + AndroidContact.COLUMN_ETAG + " IS NULL"
|
||||
@ -364,7 +354,7 @@ class LocalAddressBook(
|
||||
val values = ContentValues(1)
|
||||
values.put(AndroidContact.COLUMN_ETAG, newEtag)
|
||||
try {
|
||||
val fixed = provider.update(syncAdapterURI(RawContacts.CONTENT_URI),
|
||||
val fixed = provider?.update(syncAdapterURI(RawContacts.CONTENT_URI),
|
||||
values, where, null)
|
||||
App.log.info("Fixed entries: " + fixed.toString())
|
||||
} catch (e: RemoteException) {
|
||||
|
@ -201,7 +201,7 @@ class LocalCalendar private constructor(
|
||||
syncAdapterURI(Events.CONTENT_URI), null,
|
||||
Events.CALENDAR_ID + "=?", arrayOf(id.toString()), null)
|
||||
try {
|
||||
return cursor?.count.toLong()
|
||||
return cursor?.count?.toLong()!!
|
||||
} finally {
|
||||
cursor?.close()
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ class LocalContact : AndroidContact, LocalAddress {
|
||||
val values = ContentValues(2)
|
||||
values.put(AndroidContact.COLUMN_FILENAME, uid)
|
||||
values.put(AndroidContact.COLUMN_UID, uid)
|
||||
addressBook.provider.update(rawContactSyncURI(), values, null, null)
|
||||
addressBook.provider?.update(rawContactSyncURI(), values, null, null)
|
||||
|
||||
fileName = uid
|
||||
}
|
||||
@ -133,7 +133,7 @@ class LocalContact : AndroidContact, LocalAddress {
|
||||
override fun insertDataRows(batch: BatchOperation) {
|
||||
super.insertDataRows(batch)
|
||||
|
||||
if (contact.unknownProperties != null) {
|
||||
if (contact?.unknownProperties != null) {
|
||||
val op: BatchOperation.Operation
|
||||
val builder = ContentProviderOperation.newInsert(dataSyncURI())
|
||||
if (id == null) {
|
||||
@ -143,7 +143,7 @@ class LocalContact : AndroidContact, LocalAddress {
|
||||
builder.withValue(UnknownProperties.RAW_CONTACT_ID, id)
|
||||
}
|
||||
builder.withValue(UnknownProperties.MIMETYPE, UnknownProperties.CONTENT_ITEM_TYPE)
|
||||
.withValue(UnknownProperties.UNKNOWN_PROPERTIES, contact.unknownProperties)
|
||||
.withValue(UnknownProperties.UNKNOWN_PROPERTIES, contact?.unknownProperties)
|
||||
batch.enqueue(op)
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ class LocalEvent : AndroidEvent, LocalResource<Event> {
|
||||
eTag = row.getAsString(COLUMN_ETAG)
|
||||
event?.uid = row.getAsString(COLUMN_UID)
|
||||
|
||||
event.sequence = row.getAsInteger(COLUMN_SEQUENCE)
|
||||
event?.sequence = row.getAsInteger(COLUMN_SEQUENCE)
|
||||
val isOrganizer = row.getAsInteger(Events.IS_ORGANIZER)
|
||||
weAreOrganizer = isOrganizer != null && isOrganizer != 0
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -66,8 +66,8 @@ class LocalTask : AndroidTask, LocalResource<Task> {
|
||||
override fun buildTask(builder: ContentProviderOperation.Builder, update: Boolean) {
|
||||
super.buildTask(builder, update)
|
||||
builder.withValue(TaskContract.Tasks._SYNC_ID, fileName)
|
||||
.withValue(COLUMN_UID, task.uid)
|
||||
.withValue(COLUMN_SEQUENCE, task.sequence)
|
||||
.withValue(COLUMN_UID, task?.uid)
|
||||
.withValue(COLUMN_SEQUENCE, task?.sequence)
|
||||
.withValue(COLUMN_ETAG, eTag)
|
||||
}
|
||||
|
||||
|
@ -80,6 +80,9 @@ class LocalTaskList private constructor(
|
||||
return tasks
|
||||
}
|
||||
|
||||
override fun findAll(): List<LocalTask>
|
||||
= queryTasks(null, null)
|
||||
|
||||
override fun findWithoutFileName(): List<LocalTask>
|
||||
= queryTasks(Tasks._SYNC_ID + " IS NULL", null)
|
||||
|
||||
@ -89,10 +92,10 @@ class LocalTaskList private constructor(
|
||||
override fun count(): Long {
|
||||
try {
|
||||
val cursor = provider.client.query(
|
||||
TaskProvider.syncAdapterUri(provider.tasksUri()), null,
|
||||
TaskProvider.syncAdapterUri(provider.tasksUri(), account), null,
|
||||
Tasks.LIST_ID + "=?", arrayOf(id.toString()), null)
|
||||
try {
|
||||
return cursor?.count.toLong()
|
||||
return cursor?.count?.toLong()!!
|
||||
} finally {
|
||||
cursor?.close()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user