mirror of
https://github.com/SimpleMobileTools/Simple-Calendar.git
synced 2025-06-05 21:59:17 +02:00
add some logic to queueing operations
This commit is contained in:
@@ -354,7 +354,7 @@ class DBHelper private constructor(val context: Context) : SQLiteOpenHelper(cont
|
|||||||
} catch (ignored: Exception) {
|
} catch (ignored: Exception) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
context.googleSyncQueue.insert(it.id, OPERATION_DELETE)
|
context.googleSyncQueue.addOperation(it.id, OPERATION_DELETE)
|
||||||
}
|
}
|
||||||
}).start()
|
}).start()
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,7 @@ class GoogleSyncHandler {
|
|||||||
createRemoteGoogleEvent(activity, event)
|
createRemoteGoogleEvent(activity, event)
|
||||||
}).start()
|
}).start()
|
||||||
} else {
|
} else {
|
||||||
activity.googleSyncQueue.insert(event.id, OPERATION_INSERT)
|
activity.googleSyncQueue.addOperation(event.id, OPERATION_INSERT)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -94,7 +94,7 @@ class GoogleSyncHandler {
|
|||||||
}
|
}
|
||||||
}).start()
|
}).start()
|
||||||
} else {
|
} else {
|
||||||
activity.googleSyncQueue.insert(event.id, OPERATION_UPDATE)
|
activity.googleSyncQueue.addOperation(event.id, OPERATION_UPDATE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -38,8 +38,16 @@ class GoogleSyncQueueDB private constructor(val context: Context) : SQLiteOpenHe
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun insert(eventId: Int, operation: Int) {
|
fun addOperation(eventId: Int, operation: Int) {
|
||||||
delete(eventId)
|
if (operation == OPERATION_DELETE) {
|
||||||
|
clearOperationsOf(eventId)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (operation == OPERATION_UPDATE) {
|
||||||
|
if (getOperationOf(eventId)?.operation?.equals(OPERATION_INSERT) == true) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val contentValues = ContentValues().apply {
|
val contentValues = ContentValues().apply {
|
||||||
put(COL_EVENT_ID, eventId)
|
put(COL_EVENT_ID, eventId)
|
||||||
@@ -48,6 +56,21 @@ class GoogleSyncQueueDB private constructor(val context: Context) : SQLiteOpenHe
|
|||||||
mDb.insert(OPERATIONS_TABLE_NAME, null, contentValues)
|
mDb.insert(OPERATIONS_TABLE_NAME, null, contentValues)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getOperationOf(eventId: Int): GoogleOperation? {
|
||||||
|
val selection = "$COL_EVENT_ID = $eventId"
|
||||||
|
val projection = arrayOf(COL_OPERATION)
|
||||||
|
var cursor: Cursor? = null
|
||||||
|
try {
|
||||||
|
cursor = mDb.query(OPERATIONS_TABLE_NAME, projection, selection, null, null, null, null)
|
||||||
|
if (cursor?.moveToFirst() == true) {
|
||||||
|
return GoogleOperation(eventId, cursor.getIntValue(COL_OPERATION))
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
cursor?.close()
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
fun getOperations(): ArrayList<GoogleOperation> {
|
fun getOperations(): ArrayList<GoogleOperation> {
|
||||||
val operations = ArrayList<GoogleOperation>()
|
val operations = ArrayList<GoogleOperation>()
|
||||||
val projection = arrayOf(COL_EVENT_ID, COL_OPERATION)
|
val projection = arrayOf(COL_EVENT_ID, COL_OPERATION)
|
||||||
@@ -67,7 +90,7 @@ class GoogleSyncQueueDB private constructor(val context: Context) : SQLiteOpenHe
|
|||||||
return operations
|
return operations
|
||||||
}
|
}
|
||||||
|
|
||||||
fun delete(eventId: Int) {
|
fun clearOperationsOf(eventId: Int) {
|
||||||
val selection = "$COL_EVENT_ID = $eventId"
|
val selection = "$COL_EVENT_ID = $eventId"
|
||||||
mDb.delete(OPERATIONS_TABLE_NAME, selection, null)
|
mDb.delete(OPERATIONS_TABLE_NAME, selection, null)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user