Commit 915cd6ec authored by Ricki Hirner's avatar Ricki Hirner 🐑

Restrict more method names by interfaces

parent 73e936ae
Pipeline #19013408 passed with stages
in 5 minutes and 56 seconds
......@@ -8,7 +8,9 @@
package at.bitfire.davdroid.resource
interface LocalAddress: LocalResource {
import at.bitfire.vcard4android.Contact
interface LocalAddress: LocalResource<Contact> {
fun resetDeleted()
......
......@@ -10,7 +10,7 @@ package at.bitfire.davdroid.resource
import at.bitfire.davdroid.model.SyncState
interface LocalCollection<out T: LocalResource> {
interface LocalCollection<out T: LocalResource<*>> {
/** collection title (used for user notifications etc.) **/
val title: String
......
......@@ -105,9 +105,9 @@ class LocalContact: AndroidContact, LocalAddress {
override fun populateData(mimeType: String, row: ContentValues) {
when (mimeType) {
CachedGroupMembership.CONTENT_ITEM_TYPE ->
cachedGroupMemberships.add(row.getAsLong(CachedGroupMembership.GROUP_ID))
cachedGroupMemberships += row.getAsLong(CachedGroupMembership.GROUP_ID)
GroupMembership.CONTENT_ITEM_TYPE ->
groupMemberships.add(row.getAsLong(GroupMembership.GROUP_ROW_ID))
groupMemberships += row.getAsLong(GroupMembership.GROUP_ROW_ID)
UnknownProperties.CONTENT_ITEM_TYPE ->
contact!!.unknownProperties = row.getAsString(UnknownProperties.UNKNOWN_PROPERTIES)
}
......@@ -189,7 +189,7 @@ class LocalContact: AndroidContact, LocalAddress {
.withValue(GroupMembership.RAW_CONTACT_ID, id)
.withValue(GroupMembership.GROUP_ROW_ID, groupID)
))
groupMemberships.add(groupID)
groupMemberships += groupID
batch.enqueue(BatchOperation.Operation(
ContentProviderOperation.newInsert(dataSyncURI())
......@@ -198,7 +198,7 @@ class LocalContact: AndroidContact, LocalAddress {
.withValue(CachedGroupMembership.GROUP_ID, groupID)
.withYieldAllowed(true)
))
cachedGroupMemberships.add(groupID)
cachedGroupMemberships += groupID
}
fun removeGroupMemberships(batch: BatchOperation) {
......
......@@ -17,7 +17,7 @@ import at.bitfire.ical4android.*
import net.fortuna.ical4j.model.property.ProdId
import java.util.*
class LocalEvent: AndroidEvent, LocalResource {
class LocalEvent: AndroidEvent, LocalResource<Event> {
companion object {
init {
......
......@@ -56,7 +56,7 @@ class LocalGroup: AndroidGroup, LocalAddress {
// delete all memberships and cached memberships for this group
for (contact in addressBook.getByGroupMembership(id)) {
contact.removeGroupMemberships(batch)
changeContactIDs.add(contact.id!!)
changeContactIDs += contact.id!!
}
// extract list of member UIDs
......@@ -76,7 +76,7 @@ class LocalGroup: AndroidGroup, LocalAddress {
Constants.log.fine("Assigning member: $uid")
addressBook.findContactByUID(uid)?.let { member ->
member.addToGroup(batch, id)
changeContactIDs.add(member.id!!)
changeContactIDs += member.id!!
} ?: Constants.log.warning("Group member not found: $uid")
}
......@@ -230,7 +230,7 @@ class LocalGroup: AndroidGroup, LocalAddress {
null
)?.use { cursor ->
while (cursor.moveToNext())
members.add(cursor.getLong(0))
members += cursor.getLong(0)
}
return members
}
......
......@@ -8,7 +8,9 @@
package at.bitfire.davdroid.resource
interface LocalResource {
import android.net.Uri
interface LocalResource<in TData: Any> {
companion object {
/**
......@@ -34,6 +36,22 @@ interface LocalResource {
fun clearDirty(eTag: String?)
fun updateFlags(flags: Int)
/**
* Adds the data object to the content provider and ensures that the dirty flag is clear.
* @return content URI of the created row (e.g. event URI)
*/
fun add(): Uri
/**
* Updates the data object in the content provider and ensures that the dirty flag is clear.
* @return content URI of the updated row (e.g. event URI)
*/
fun update(data: TData): Uri
/**
* Deletes the data object from the content provider.
* @return number of affected rows
*/
fun delete(): Int
}
\ No newline at end of file
......@@ -10,16 +10,14 @@ package at.bitfire.davdroid.resource
import android.content.ContentProviderOperation
import android.content.ContentValues
import at.bitfire.davdroid.log.Logger
import at.bitfire.ical4android.AndroidTask
import at.bitfire.ical4android.AndroidTaskFactory
import at.bitfire.ical4android.AndroidTaskList
import at.bitfire.ical4android.Task
import org.dmfs.tasks.contract.TaskContract.Tasks
import java.util.*
import java.util.logging.Level
class LocalTask: AndroidTask, LocalResource {
class LocalTask: AndroidTask, LocalResource<Task> {
companion object {
const val COLUMN_ETAG = Tasks.SYNC1
......@@ -57,7 +55,6 @@ class LocalTask: AndroidTask, LocalResource {
builder .withValue(Tasks._SYNC_ID, fileName)
.withValue(COLUMN_ETAG, eTag)
.withValue(COLUMN_FLAGS, flags)
Logger.log.log(Level.FINE, "Built task object", builder.build())
}
......
......@@ -109,9 +109,8 @@ class LocalTaskList private constructor(
}
fun update(info: CollectionInfo, updateColor: Boolean) {
update(valuesFromCollectionInfo(info, updateColor))
}
fun update(info: CollectionInfo, updateColor: Boolean) =
update(valuesFromCollectionInfo(info, updateColor))
override fun findDeleted() = queryTasks("${Tasks._DELETED}!=0", null)
......
......@@ -33,7 +33,7 @@ import okhttp3.HttpUrl
import okhttp3.RequestBody
import java.util.logging.Level
abstract class BaseDavSyncManager<ResourceType: LocalResource, out CollectionType: LocalCollection<ResourceType>, RemoteType: DavCollection>(
abstract class BaseDavSyncManager<ResourceType: LocalResource<*>, out CollectionType: LocalCollection<ResourceType>, RemoteType: DavCollection>(
context: Context,
settings: ISettings,
account: Account,
......@@ -264,7 +264,7 @@ abstract class BaseDavSyncManager<ResourceType: LocalResource, out CollectionTyp
}
protected fun<T: LocalResource?, R> useLocal(local: T, body: (T) -> R): R {
protected fun<T: LocalResource<*>?, R> useLocal(local: T, body: (T) -> R): R {
local?.let { currentLocalResource.push(it) }
val result = body(local)
local?.let { currentLocalResource.pop() }
......
......@@ -388,7 +388,7 @@ class ContactsSyncManager(
if (local is LocalGroup && newData.group) {
// update group
local.eTag = eTag
local.updateFromServer(newData)
local.update(newData)
syncResult.stats.numUpdates++
} else if (local is LocalContact && !newData.group) {
......@@ -408,13 +408,13 @@ class ContactsSyncManager(
if (newData.group) {
Logger.log.log(Level.INFO, "Creating local group", newData)
useLocal(LocalGroup(localCollection, newData, fileName, eTag, LocalResource.FLAG_REMOTELY_PRESENT), {
it.create()
it.add()
local = it
})
} else {
Logger.log.log(Level.INFO, "Creating local contact", newData)
useLocal(LocalContact(localCollection, newData, fileName, eTag, LocalResource.FLAG_REMOTELY_PRESENT), {
it.create()
it.add()
local = it
})
}
......
......@@ -49,7 +49,7 @@ import java.util.*
import java.util.logging.Level
import javax.net.ssl.SSLHandshakeException
abstract class SyncManager<out ResourceType: LocalResource, out CollectionType: LocalCollection<ResourceType>>(
abstract class SyncManager<out ResourceType: LocalResource<*>, out CollectionType: LocalCollection<ResourceType>>(
val context: Context,
val settings: ISettings,
val account: Account,
......@@ -79,7 +79,7 @@ abstract class SyncManager<out ResourceType: LocalResource, out CollectionType:
protected val notificationTag = Companion.notificationTag(authority, mainAccount)
/** Local resource we're currently operating on. Used for error notifications. **/
protected val currentLocalResource = LinkedList<LocalResource>()
protected val currentLocalResource = LinkedList<LocalResource<*>>()
/** Remote resource we're currently operating on. Used for error notifications. **/
protected val currentRemoteResource = LinkedList<DavResource>()
......@@ -419,7 +419,7 @@ abstract class SyncManager<out ResourceType: LocalResource, out CollectionType:
PendingIntent.getService(context, 0, retryIntent, PendingIntent.FLAG_UPDATE_CURRENT))
}
private fun buildViewItemAction(local: LocalResource): NotificationCompat.Action? {
private fun buildViewItemAction(local: LocalResource<*>): NotificationCompat.Action? {
Logger.log.log(Level.FINE, "Adding view action for local resource", local)
val intent = local.id?.let { id ->
when (local) {
......
......@@ -106,7 +106,7 @@ class TasksSyncManager(
}
val toDownload = changes.updated.map { it.location }
Logger.log.info("Downloading ${toDownload.size} resources (${MULTIGET_MAX_RESOURCES} at once)")
Logger.log.info("Downloading ${toDownload.size} resources ($MULTIGET_MAX_RESOURCES at once)")
for (bunch in toDownload.chunked(MULTIGET_MAX_RESOURCES)) {
if (bunch.size == 1)
......@@ -158,7 +158,7 @@ class TasksSyncManager(
// update local task, if it exists
useLocal(localCollection.findByName(fileName), { local ->
if (local != null) {
Logger.log.info("Updating $fileName in local tasklist")
Logger.log.info("Updating $fileName in local task list")
local.eTag = eTag
local.update(newData)
syncResult.stats.numUpdates++
......
Subproject commit d99abf4ca20d78e8d874763e212299708d389fb5
Subproject commit a39a4997d6417ed90887c65e0e5527124ab38b93
Subproject commit 0b1a898fd2cc6d84ea8a7d66984c62aa5e240b10
Subproject commit cbb11f30ceafd57e7976b06deb0a1a3770e472d9
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment