Loading src/androidTest/java/at/bitfire/ical4android/AndroidTaskTest.java +1 −5 Original line number Diff line number Diff line Loading @@ -51,11 +51,7 @@ public class AndroidTaskTest extends InstrumentationTestCase { // helpers private Uri syncAdapterURI(Uri uri) { return uri.buildUpon() .appendQueryParameter(TaskContract.ACCOUNT_TYPE, testAccount.type) .appendQueryParameter(TaskContract.ACCOUNT_NAME, testAccount.name) .appendQueryParameter(TaskContract.CALLER_IS_SYNCADAPTER, "true") .build(); return TaskProvider.syncAdapterUri(uri, testAccount); } Loading src/main/java/at/bitfire/ical4android/AndroidTask.kt +3 −3 Original line number Diff line number Diff line Loading @@ -159,7 +159,7 @@ abstract class AndroidTask( @Throws(CalendarStorageException::class) fun add(): Uri? { val batch = BatchOperation(taskList.provider.client) val builder = ContentProviderOperation.newInsert(taskList.syncAdapterURI(taskList.provider.tasksUri())) val builder = ContentProviderOperation.newInsert(taskList.tasksSyncUri()) buildTask(builder, false) batch.enqueue(BatchOperation.Operation(builder)) batch.commit() Loading @@ -171,7 +171,7 @@ abstract class AndroidTask( @Throws(CalendarStorageException::class) fun update(task: Task) { this.task = task; this.task = task val batch = BatchOperation(taskList.provider.client) val builder = ContentProviderOperation.newUpdate(taskSyncURI()) Loading Loading @@ -282,7 +282,7 @@ abstract class AndroidTask( protected fun taskSyncURI(): Uri { val id = requireNotNull(id) return taskList.syncAdapterURI(ContentUris.withAppendedId(taskList.provider.tasksUri(), id)) return ContentUris.withAppendedId(taskList.tasksSyncUri(), id) } Loading src/main/java/at/bitfire/ical4android/AndroidTaskList.kt +8 −19 Original line number Diff line number Diff line Loading @@ -70,7 +70,7 @@ abstract class AndroidTaskList<out T: AndroidTask>( Constants.log.info("Creating local task list: " + info.toString()) try { return provider.client.insert(syncAdapterURI(provider.taskListsUri(), account), info) return provider.client.insert(TaskProvider.syncAdapterUri(provider.taskListsUri(), account), info) } catch(e: Exception) { throw CalendarStorageException("Couldn't create local task list", e) } Loading @@ -80,7 +80,7 @@ abstract class AndroidTaskList<out T: AndroidTask>( @Throws(FileNotFoundException::class, CalendarStorageException::class) fun<T: AndroidTaskList<AndroidTask>> findByID(account: Account, provider: TaskProvider, factory: AndroidTaskListFactory<T>, id: Long): T { try { provider.client.query(syncAdapterURI(ContentUris.withAppendedId(provider.taskListsUri(), id), account), null, null, null, null)?.use { cursor -> provider.client.query(TaskProvider.syncAdapterUri(ContentUris.withAppendedId(provider.taskListsUri(), id), account), null, null, null, null)?.use { cursor -> if (cursor.moveToNext()) { val taskList = factory.newInstance(account, provider, id) val values = ContentValues(cursor.columnCount) Loading @@ -100,7 +100,7 @@ abstract class AndroidTaskList<out T: AndroidTask>( fun<T: AndroidTaskList<AndroidTask>> find(account: Account, provider: TaskProvider, factory: AndroidTaskListFactory<T>, where: String?, whereArgs: Array<String>?): List<T> { val taskLists = LinkedList<T>() try { provider.client.query(syncAdapterURI(provider.taskListsUri(), account), null, where, whereArgs, null)?.use { cursor -> provider.client.query(TaskProvider.syncAdapterUri(provider.taskListsUri(), account), null, where, whereArgs, null)?.use { cursor -> while (cursor.moveToNext()) { val values = ContentValues(cursor.columnCount) DatabaseUtils.cursorRowToContentValues(cursor, values) Loading @@ -115,13 +115,6 @@ abstract class AndroidTaskList<out T: AndroidTask>( return taskLists } @JvmStatic fun syncAdapterURI(uri: Uri, account: Account) = uri.buildUpon() .appendQueryParameter(TaskContract.ACCOUNT_NAME, account.name) .appendQueryParameter(TaskContract.ACCOUNT_TYPE, account.type) .appendQueryParameter(TaskContract.CALLER_IS_SYNCADAPTER, "true") .build()!! } protected fun populate(values: ContentValues) { Loading Loading @@ -159,7 +152,7 @@ abstract class AndroidTaskList<out T: AndroidTask>( val tasks = LinkedList<T>() try { provider.client.query( syncAdapterURI(provider.tasksUri()), tasksSyncUri(), taskBaseInfoColumns(), where, whereArgs, null)?.use { cursor -> while (cursor.moveToNext()) { Loading @@ -174,14 +167,10 @@ abstract class AndroidTaskList<out T: AndroidTask>( return tasks } fun syncAdapterURI(uri: Uri) = uri.buildUpon() .appendQueryParameter(TaskContract.ACCOUNT_NAME, account.name) .appendQueryParameter(TaskContract.ACCOUNT_TYPE, account.type) .appendQueryParameter(TaskContract.CALLER_IS_SYNCADAPTER, "true") .build()!! fun taskListSyncUri() = syncAdapterURI(ContentUris.withAppendedId(provider.taskListsUri(), id)) TaskProvider.syncAdapterUri(ContentUris.withAppendedId(provider.taskListsUri(), id), account) fun tasksSyncUri() = TaskProvider.syncAdapterUri(provider.tasksUri(), account) } src/main/java/at/bitfire/ical4android/TaskProvider.kt +13 −2 Original line number Diff line number Diff line Loading @@ -8,10 +8,12 @@ package at.bitfire.ical4android import android.accounts.Account import android.annotation.SuppressLint import android.content.ContentProviderClient import android.content.Context import android.content.pm.PackageManager import android.net.Uri import android.os.Build import org.dmfs.tasks.contract.TaskContract import java.io.Closeable Loading Loading @@ -40,9 +42,10 @@ class TaskProvider private constructor( /** * Acquires a content provider for a given task provider. The content provider will * be released when the TaskProvider is closed. * @param resolver will be used to acquire the content provider client * @param context will be used to acquire the content provider client * @param name task provider to acquire content provider for * @return content provider for the given task provider (may be {@code null}) * @throws [ProviderTooOldException] if the tasks provider is installed, but doesn't meet the minimum version requirement */ @SuppressLint("Recycle") @JvmStatic Loading Loading @@ -74,7 +77,7 @@ class TaskProvider private constructor( /** * Checks the version code of an installed tasks provider. * @throws PackageManager.NameNotFoundException if the tasks provider is not installed * @throws IllegalArgumentException if the tasks provider is installed, but doesn't meet the minimum version requirement * @throws [ProviderTooOldException] if the tasks provider is installed, but doesn't meet the minimum version requirement * */ private fun checkVersion(context: Context, name: ProviderName) { // check whether package is available with required minimum version Loading @@ -86,6 +89,13 @@ class TaskProvider private constructor( } } @JvmStatic fun syncAdapterUri(uri: Uri, account: Account) = uri.buildUpon() .appendQueryParameter(TaskContract.ACCOUNT_NAME, account.name) .appendQueryParameter(TaskContract.ACCOUNT_TYPE, account.type) .appendQueryParameter(TaskContract.CALLER_IS_SYNCADAPTER, "true") .build()!! } Loading @@ -93,6 +103,7 @@ class TaskProvider private constructor( fun tasksUri() = TaskContract.Tasks.getContentUri(name.authority)!! //fun alarmsUri() = TaskContract.Alarms.getContentUri(name.authority)!! override fun close() { if (Build.VERSION.SDK_INT >= 24) client.close() Loading Loading
src/androidTest/java/at/bitfire/ical4android/AndroidTaskTest.java +1 −5 Original line number Diff line number Diff line Loading @@ -51,11 +51,7 @@ public class AndroidTaskTest extends InstrumentationTestCase { // helpers private Uri syncAdapterURI(Uri uri) { return uri.buildUpon() .appendQueryParameter(TaskContract.ACCOUNT_TYPE, testAccount.type) .appendQueryParameter(TaskContract.ACCOUNT_NAME, testAccount.name) .appendQueryParameter(TaskContract.CALLER_IS_SYNCADAPTER, "true") .build(); return TaskProvider.syncAdapterUri(uri, testAccount); } Loading
src/main/java/at/bitfire/ical4android/AndroidTask.kt +3 −3 Original line number Diff line number Diff line Loading @@ -159,7 +159,7 @@ abstract class AndroidTask( @Throws(CalendarStorageException::class) fun add(): Uri? { val batch = BatchOperation(taskList.provider.client) val builder = ContentProviderOperation.newInsert(taskList.syncAdapterURI(taskList.provider.tasksUri())) val builder = ContentProviderOperation.newInsert(taskList.tasksSyncUri()) buildTask(builder, false) batch.enqueue(BatchOperation.Operation(builder)) batch.commit() Loading @@ -171,7 +171,7 @@ abstract class AndroidTask( @Throws(CalendarStorageException::class) fun update(task: Task) { this.task = task; this.task = task val batch = BatchOperation(taskList.provider.client) val builder = ContentProviderOperation.newUpdate(taskSyncURI()) Loading Loading @@ -282,7 +282,7 @@ abstract class AndroidTask( protected fun taskSyncURI(): Uri { val id = requireNotNull(id) return taskList.syncAdapterURI(ContentUris.withAppendedId(taskList.provider.tasksUri(), id)) return ContentUris.withAppendedId(taskList.tasksSyncUri(), id) } Loading
src/main/java/at/bitfire/ical4android/AndroidTaskList.kt +8 −19 Original line number Diff line number Diff line Loading @@ -70,7 +70,7 @@ abstract class AndroidTaskList<out T: AndroidTask>( Constants.log.info("Creating local task list: " + info.toString()) try { return provider.client.insert(syncAdapterURI(provider.taskListsUri(), account), info) return provider.client.insert(TaskProvider.syncAdapterUri(provider.taskListsUri(), account), info) } catch(e: Exception) { throw CalendarStorageException("Couldn't create local task list", e) } Loading @@ -80,7 +80,7 @@ abstract class AndroidTaskList<out T: AndroidTask>( @Throws(FileNotFoundException::class, CalendarStorageException::class) fun<T: AndroidTaskList<AndroidTask>> findByID(account: Account, provider: TaskProvider, factory: AndroidTaskListFactory<T>, id: Long): T { try { provider.client.query(syncAdapterURI(ContentUris.withAppendedId(provider.taskListsUri(), id), account), null, null, null, null)?.use { cursor -> provider.client.query(TaskProvider.syncAdapterUri(ContentUris.withAppendedId(provider.taskListsUri(), id), account), null, null, null, null)?.use { cursor -> if (cursor.moveToNext()) { val taskList = factory.newInstance(account, provider, id) val values = ContentValues(cursor.columnCount) Loading @@ -100,7 +100,7 @@ abstract class AndroidTaskList<out T: AndroidTask>( fun<T: AndroidTaskList<AndroidTask>> find(account: Account, provider: TaskProvider, factory: AndroidTaskListFactory<T>, where: String?, whereArgs: Array<String>?): List<T> { val taskLists = LinkedList<T>() try { provider.client.query(syncAdapterURI(provider.taskListsUri(), account), null, where, whereArgs, null)?.use { cursor -> provider.client.query(TaskProvider.syncAdapterUri(provider.taskListsUri(), account), null, where, whereArgs, null)?.use { cursor -> while (cursor.moveToNext()) { val values = ContentValues(cursor.columnCount) DatabaseUtils.cursorRowToContentValues(cursor, values) Loading @@ -115,13 +115,6 @@ abstract class AndroidTaskList<out T: AndroidTask>( return taskLists } @JvmStatic fun syncAdapterURI(uri: Uri, account: Account) = uri.buildUpon() .appendQueryParameter(TaskContract.ACCOUNT_NAME, account.name) .appendQueryParameter(TaskContract.ACCOUNT_TYPE, account.type) .appendQueryParameter(TaskContract.CALLER_IS_SYNCADAPTER, "true") .build()!! } protected fun populate(values: ContentValues) { Loading Loading @@ -159,7 +152,7 @@ abstract class AndroidTaskList<out T: AndroidTask>( val tasks = LinkedList<T>() try { provider.client.query( syncAdapterURI(provider.tasksUri()), tasksSyncUri(), taskBaseInfoColumns(), where, whereArgs, null)?.use { cursor -> while (cursor.moveToNext()) { Loading @@ -174,14 +167,10 @@ abstract class AndroidTaskList<out T: AndroidTask>( return tasks } fun syncAdapterURI(uri: Uri) = uri.buildUpon() .appendQueryParameter(TaskContract.ACCOUNT_NAME, account.name) .appendQueryParameter(TaskContract.ACCOUNT_TYPE, account.type) .appendQueryParameter(TaskContract.CALLER_IS_SYNCADAPTER, "true") .build()!! fun taskListSyncUri() = syncAdapterURI(ContentUris.withAppendedId(provider.taskListsUri(), id)) TaskProvider.syncAdapterUri(ContentUris.withAppendedId(provider.taskListsUri(), id), account) fun tasksSyncUri() = TaskProvider.syncAdapterUri(provider.tasksUri(), account) }
src/main/java/at/bitfire/ical4android/TaskProvider.kt +13 −2 Original line number Diff line number Diff line Loading @@ -8,10 +8,12 @@ package at.bitfire.ical4android import android.accounts.Account import android.annotation.SuppressLint import android.content.ContentProviderClient import android.content.Context import android.content.pm.PackageManager import android.net.Uri import android.os.Build import org.dmfs.tasks.contract.TaskContract import java.io.Closeable Loading Loading @@ -40,9 +42,10 @@ class TaskProvider private constructor( /** * Acquires a content provider for a given task provider. The content provider will * be released when the TaskProvider is closed. * @param resolver will be used to acquire the content provider client * @param context will be used to acquire the content provider client * @param name task provider to acquire content provider for * @return content provider for the given task provider (may be {@code null}) * @throws [ProviderTooOldException] if the tasks provider is installed, but doesn't meet the minimum version requirement */ @SuppressLint("Recycle") @JvmStatic Loading Loading @@ -74,7 +77,7 @@ class TaskProvider private constructor( /** * Checks the version code of an installed tasks provider. * @throws PackageManager.NameNotFoundException if the tasks provider is not installed * @throws IllegalArgumentException if the tasks provider is installed, but doesn't meet the minimum version requirement * @throws [ProviderTooOldException] if the tasks provider is installed, but doesn't meet the minimum version requirement * */ private fun checkVersion(context: Context, name: ProviderName) { // check whether package is available with required minimum version Loading @@ -86,6 +89,13 @@ class TaskProvider private constructor( } } @JvmStatic fun syncAdapterUri(uri: Uri, account: Account) = uri.buildUpon() .appendQueryParameter(TaskContract.ACCOUNT_NAME, account.name) .appendQueryParameter(TaskContract.ACCOUNT_TYPE, account.type) .appendQueryParameter(TaskContract.CALLER_IS_SYNCADAPTER, "true") .build()!! } Loading @@ -93,6 +103,7 @@ class TaskProvider private constructor( fun tasksUri() = TaskContract.Tasks.getContentUri(name.authority)!! //fun alarmsUri() = TaskContract.Alarms.getContentUri(name.authority)!! override fun close() { if (Build.VERSION.SDK_INT >= 24) client.close() Loading