1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
/***************************************************************************************************
* Copyright © All Contributors. See LICENSE and AUTHORS in the root directory for details.
**************************************************************************************************/
package at.bitfire.ical4android.impl
import android.accounts.Account
import android.content.ContentProviderClient
import at.bitfire.ical4android.JtxCollection
import at.bitfire.ical4android.JtxCollectionFactory
import at.bitfire.ical4android.JtxICalObject
import at.bitfire.ical4android.MiscUtils.CursorHelper.toValues
import at.techbee.jtx.JtxContract
import java.util.*
class TestJtxCollection(
account: Account,
provider: ContentProviderClient,
id: Long
): JtxCollection<JtxICalObject>(account, provider, TestJtxIcalObject.Factory, id) {
/**
* Queries [JtxContract.JtxICalObject] from this collection. Adds a WHERE clause that restricts the
* query to [JtxContract.JtxCollection.ID] = [id].
* @param _where selection
* @param _whereArgs arguments for selection
* @return events from this calendar which match the selection
*/
fun queryICalObjects(_where: String? = null, _whereArgs: Array<String>? = null): List<JtxICalObject> {
val where = "(${_where ?: "1"}) AND ${JtxContract.JtxICalObject.ICALOBJECT_COLLECTIONID} = ?"
val whereArgs = (_whereArgs ?: arrayOf()) + id.toString()
val iCalObjects = LinkedList<JtxICalObject>()
client.query(jtxSyncURI(), null, where, whereArgs, null)?.use { cursor ->
while (cursor.moveToNext())
iCalObjects += TestJtxIcalObject.Factory.fromProvider(this, cursor.toValues())
}
return iCalObjects
}
object Factory: JtxCollectionFactory<TestJtxCollection> {
override fun newInstance(
account: Account,
client: ContentProviderClient,
id: Long
): TestJtxCollection = TestJtxCollection(account, client, id)
}
}
|