Skip to content

Commit 42e82f4

Browse files
authored
Disallow subclassing of DmfsTaskList (#160)
1 parent 0c6602c commit 42e82f4

File tree

5 files changed

+28
-74
lines changed

5 files changed

+28
-74
lines changed

lib/src/androidTest/kotlin/at/bitfire/ical4android/DmfsTaskListTest.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import android.content.ContentUris
1111
import android.content.ContentValues
1212
import android.database.DatabaseUtils
1313
import android.provider.CalendarContract
14-
import at.bitfire.ical4android.impl.TestTaskList
1514
import net.fortuna.ical4j.model.property.RelatedTo
1615
import org.dmfs.tasks.contract.TaskContract
1716
import org.dmfs.tasks.contract.TaskContract.Properties
@@ -28,7 +27,7 @@ class DmfsTaskListTest(providerName: TaskProvider.ProviderName):
2827
private val testAccount = Account(javaClass.name, CalendarContract.ACCOUNT_TYPE_LOCAL)
2928

3029

31-
private fun createTaskList(): TestTaskList {
30+
private fun createTaskList(): DmfsTaskList {
3231
val info = ContentValues()
3332
info.put(TaskContract.TaskLists.LIST_NAME, "Test Task List")
3433
info.put(TaskContract.TaskLists.LIST_COLOR, 0xffff0000)
@@ -39,7 +38,7 @@ class DmfsTaskListTest(providerName: TaskProvider.ProviderName):
3938
val uri = DmfsTaskList.create(testAccount, provider.client, providerName, info)
4039
assertNotNull(uri)
4140

42-
return DmfsTaskList.findByID(testAccount, provider.client, providerName, TestTaskList.Factory, ContentUris.parseId(uri))
41+
return DmfsTaskList.findByID(testAccount, provider.client, providerName, ContentUris.parseId(uri))
4342
}
4443

4544

lib/src/androidTest/kotlin/at/bitfire/ical4android/DmfsTaskTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class DmfsTaskTest(
6666
private val testAccount = Account(javaClass.name, CalendarContract.ACCOUNT_TYPE_LOCAL)
6767

6868
private lateinit var taskListUri: Uri
69-
private var taskList: TestTaskList? = null
69+
private var taskList: DmfsTaskList? = null
7070

7171
@Before
7272
override fun prepare() {

lib/src/androidTest/kotlin/at/bitfire/ical4android/impl/TestTaskList.kt

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,47 +7,26 @@
77
package at.bitfire.ical4android.impl
88

99
import android.accounts.Account
10-
import android.content.ContentProviderClient
1110
import android.content.ContentUris
1211
import android.content.ContentValues
1312
import at.bitfire.ical4android.DmfsTaskList
14-
import at.bitfire.ical4android.DmfsTaskListFactory
1513
import at.bitfire.ical4android.TaskProvider
1614
import org.dmfs.tasks.contract.TaskContract
1715

18-
class TestTaskList(
19-
account: Account,
20-
provider: ContentProviderClient,
21-
providerName: TaskProvider.ProviderName,
22-
id: Long
23-
) : DmfsTaskList(account, provider, providerName, id) {
16+
object TestTaskList {
2417

25-
companion object {
18+
fun create(
19+
account: Account,
20+
provider: TaskProvider,
21+
): DmfsTaskList {
22+
val values = ContentValues(4)
23+
values.put(TaskContract.TaskListColumns.LIST_NAME, "Test Task List")
24+
values.put(TaskContract.TaskListColumns.LIST_COLOR, 0xffff0000)
25+
values.put(TaskContract.TaskListColumns.SYNC_ENABLED, 1)
26+
values.put(TaskContract.TaskListColumns.VISIBLE, 1)
27+
val uri = DmfsTaskList.create(account, provider.client, provider.name, values)
2628

27-
fun create(
28-
account: Account,
29-
provider: TaskProvider,
30-
): TestTaskList {
31-
val values = ContentValues(4)
32-
values.put(TaskContract.TaskListColumns.LIST_NAME, "Test Task List")
33-
values.put(TaskContract.TaskListColumns.LIST_COLOR, 0xffff0000)
34-
values.put(TaskContract.TaskListColumns.SYNC_ENABLED, 1)
35-
values.put(TaskContract.TaskListColumns.VISIBLE, 1)
36-
val uri = create(account, provider.client, provider.name, values)
37-
38-
return TestTaskList(account, provider.client, provider.name, ContentUris.parseId(uri))
39-
}
40-
41-
}
42-
43-
44-
object Factory : DmfsTaskListFactory<TestTaskList> {
45-
override fun newInstance(
46-
account: Account,
47-
provider: ContentProviderClient,
48-
providerName: TaskProvider.ProviderName,
49-
id: Long
50-
) = TestTaskList(account, provider, providerName, id)
29+
return DmfsTaskList(account, provider.client, provider.name, ContentUris.parseId(uri))
5130
}
5231

5332
}

lib/src/main/kotlin/at/bitfire/ical4android/DmfsTaskList.kt

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import java.util.logging.Logger
3333
* Represents a locally stored task list, containing [DmfsTask]s (tasks).
3434
* Communicates with tasks.org-compatible content providers (currently tasks.org and OpenTasks) to store the tasks.
3535
*/
36-
open class DmfsTaskList(
36+
class DmfsTaskList(
3737
val account: Account,
3838
val provider: ContentProviderClient,
3939
val providerName: TaskProvider.ProviderName,
@@ -200,13 +200,12 @@ open class DmfsTaskList(
200200
?: throw LocalStorageException("Couldn't create task list (empty result from provider)")
201201
}
202202

203-
fun <T : DmfsTaskList> findByID(
203+
fun findByID(
204204
account: Account,
205205
provider: ContentProviderClient,
206206
providerName: TaskProvider.ProviderName,
207-
factory: DmfsTaskListFactory<T>,
208207
id: Long
209-
): T {
208+
): DmfsTaskList {
210209
provider.query(
211210
ContentUris.withAppendedId(TaskLists.getContentUri(providerName.authority), id).asSyncAdapter(account),
212211
null,
@@ -215,23 +214,22 @@ open class DmfsTaskList(
215214
null
216215
)?.use { cursor ->
217216
if (cursor.moveToNext()) {
218-
val taskList = factory.newInstance(account, provider, providerName, id)
217+
val taskList = DmfsTaskList(account, provider, providerName, id)
219218
taskList.populate(cursor.toContentValues())
220219
return taskList
221220
}
222221
}
223222
throw FileNotFoundException()
224223
}
225224

226-
fun <T : DmfsTaskList> find(
225+
fun find(
227226
account: Account,
228-
factory: DmfsTaskListFactory<T>,
229227
provider: ContentProviderClient,
230228
providerName: TaskProvider.ProviderName,
231229
where: String?,
232230
whereArgs: Array<String>?
233-
): List<T> {
234-
val taskLists = LinkedList<T>()
231+
): List<DmfsTaskList> {
232+
val taskLists = LinkedList<DmfsTaskList>()
235233
provider.query(
236234
TaskLists.getContentUri(providerName.authority).asSyncAdapter(account),
237235
null,
@@ -241,8 +239,12 @@ open class DmfsTaskList(
241239
)?.use { cursor ->
242240
while (cursor.moveToNext()) {
243241
val values = cursor.toContentValues()
244-
val taskList =
245-
factory.newInstance(account, provider, providerName, values.getAsLong(TaskLists._ID))
242+
val taskList = DmfsTaskList(
243+
account = account,
244+
provider = provider,
245+
providerName = providerName,
246+
id = values.getAsLong(TaskLists._ID)
247+
)
246248
taskList.populate(values)
247249
taskLists += taskList
248250
}
@@ -252,14 +254,4 @@ open class DmfsTaskList(
252254

253255
}
254256

255-
// default factory (will be removed as soon as DmfsTaskList is not open anymore)
256-
object Factory : DmfsTaskListFactory<DmfsTaskList> {
257-
override fun newInstance(
258-
account: Account,
259-
provider: ContentProviderClient,
260-
providerName: TaskProvider.ProviderName,
261-
id: Long
262-
): DmfsTaskList = DmfsTaskList(account, provider, providerName, id)
263-
}
264-
265257
}

lib/src/main/kotlin/at/bitfire/ical4android/DmfsTaskListFactory.kt

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)