Add ContentProviderDao

pull/1025/head
Alex Baker 4 years ago
parent f0bf3713e6
commit 1a0697c2b0

@ -42,6 +42,7 @@ abstract class Database : RoomDatabase() {
abstract val taskDao: TaskDao
abstract val caldavDao: CaldavDao
abstract val deletionDao: DeletionDao
abstract val contentProviderDao: ContentProviderDao
/** @return human-readable database name for debugging
*/

@ -240,12 +240,6 @@ abstract class TaskDao(private val database: Database) {
task.id = insert
}
@Query("SELECT * FROM tasks "
+ "WHERE completed = 0 AND deleted = 0 AND hideUntil < (strftime('%s','now')*1000) "
+ "ORDER BY (CASE WHEN (dueDate=0) THEN (strftime('%s','now')*1000)*2 ELSE ((CASE WHEN (dueDate / 1000) % 60 > 0 THEN dueDate ELSE (dueDate + 43140000) END)) END) + 172800000 * importance ASC "
+ "LIMIT 100")
abstract fun getAstrid2TaskProviderTasks(): List<Task>
fun count(filter: Filter): Int {
val query = getQuery(filter.sqlQuery, Field.COUNT)
val start = if (BuildConfig.DEBUG) DateUtilities.now() else 0

@ -13,7 +13,6 @@ import android.database.Cursor
import android.database.MatrixCursor
import android.net.Uri
import androidx.annotation.ColorRes
import com.todoroo.astrid.dao.TaskDao
import dagger.hilt.EntryPoint
import dagger.hilt.InstallIn
import dagger.hilt.android.EntryPointAccessors
@ -21,8 +20,7 @@ import dagger.hilt.android.components.ApplicationComponent
import org.tasks.BuildConfig
import org.tasks.R
import org.tasks.analytics.Firebase
import org.tasks.data.TagDao
import org.tasks.data.TagDataDao
import org.tasks.data.ContentProviderDao
import timber.log.Timber
import java.math.BigInteger
import java.security.MessageDigest
@ -41,9 +39,7 @@ class Astrid2TaskProvider : ContentProvider() {
@EntryPoint
@InstallIn(ApplicationComponent::class)
interface Astrid2TaskProviderEntryPoint {
val tagDataDao: TagDataDao
val taskDao: TaskDao
val tagDao: TagDao
val contentProviderDao: ContentProviderDao
val firebase: Firebase
}
@ -121,7 +117,7 @@ class Astrid2TaskProvider : ContentProvider() {
*/
private val tags: Cursor
get() {
val tags = hilt().tagDataDao.tagDataOrderedByName()
val tags = hilt().contentProviderDao.tagDataOrderedByName()
val ret = MatrixCursor(TAGS_FIELD_LIST)
for (tag in tags) {
val values = arrayOfNulls<Any>(2)
@ -163,7 +159,7 @@ class Astrid2TaskProvider : ContentProvider() {
get() {
val hilt = hilt()
hilt.firebase.logEvent(R.string.event_query_legacy_content_provider)
val tasks = hilt.taskDao.getAstrid2TaskProviderTasks()
val tasks = hilt.contentProviderDao.getAstrid2TaskProviderTasks()
val ret = MatrixCursor(TASK_FIELD_LIST)
for (task in tasks) {
val taskTags = getTagsAsString(task.id, TAG_SEPARATOR)
@ -204,5 +200,5 @@ class Astrid2TaskProvider : ContentProvider() {
* @return empty string if no tags, otherwise string
*/
private fun getTagsAsString(taskId: Long, separator: String) =
hilt().tagDao.getTagNames(taskId).joinToString(separator)
hilt().contentProviderDao.getTagNames(taskId).joinToString(separator)
}

@ -0,0 +1,29 @@
package org.tasks.data
import androidx.room.Dao
import androidx.room.Query
import com.todoroo.astrid.data.Task
@Dao
interface ContentProviderDao {
@Query("SELECT name FROM tags WHERE task = :taskId ORDER BY UPPER(name) ASC")
fun getTagNames(taskId: Long): List<String>
@Query("""
SELECT *
FROM tasks
WHERE completed = 0
AND deleted = 0
AND hideUntil < (strftime('%s', 'now') * 1000)
ORDER BY (CASE
WHEN (dueDate = 0) THEN
(strftime('%s', 'now') * 1000) * 2
ELSE ((CASE WHEN (dueDate / 1000) % 60 > 0 THEN dueDate ELSE (dueDate + 43140000) END)) END) +
172800000 * importance
ASC
LIMIT 100""")
fun getAstrid2TaskProviderTasks(): List<Task>
@Query("SELECT * FROM tagdata WHERE name IS NOT NULL AND name != '' ORDER BY UPPER(name) ASC")
fun tagDataOrderedByName(): List<TagData>
}

@ -17,9 +17,6 @@ abstract class TagDao {
@Query("DELETE FROM tags WHERE task = :taskId AND tag_uid in (:tagUids)")
abstract fun deleteTags(taskId: Long, tagUids: List<String>)
@Query("SELECT name FROM tags WHERE task = :taskId ORDER BY UPPER(name) ASC")
abstract fun getTagNames(taskId: Long): List<String>
@Query("SELECT * FROM tags WHERE tag_uid = :tagUid")
abstract fun getByTagUid(tagUid: String): List<Tag>

@ -91,6 +91,10 @@ class ApplicationModule {
@Singleton
fun getDeletionDao(db: Database): DeletionDao = db.deletionDao
@Provides
@Singleton
fun getContentProviderDao(db: Database): ContentProviderDao = db.contentProviderDao
@Provides
fun getBillingClient(@ApplicationContext context: Context, inventory: Inventory, firebase: Firebase): BillingClient
= BillingClientImpl(context, inventory, firebase)

Loading…
Cancel
Save