Use non-blocking daos for collapsing filter groups

pull/1055/head
Alex Baker 4 years ago
parent 22363bcb17
commit 8710dab252

@ -11,6 +11,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.RecyclerView
import com.todoroo.andlib.utility.AndroidUtilities
import com.todoroo.astrid.api.Filter
@ -18,8 +19,8 @@ import com.todoroo.astrid.api.FilterListItem
import com.todoroo.astrid.api.FilterListItem.Type.*
import org.tasks.LocalBroadcastManager
import org.tasks.billing.Inventory
import org.tasks.data.CaldavDaoBlocking
import org.tasks.data.GoogleTaskDaoBlocking
import org.tasks.data.CaldavDao
import org.tasks.data.GoogleTaskDao
import org.tasks.filters.NavigationDrawerSubheader
import org.tasks.locale.Locale
import org.tasks.preferences.Preferences
@ -33,8 +34,8 @@ class FilterAdapter @Inject constructor(
private val inventory: Inventory,
private val colorProvider: ColorProvider,
private val preferences: Preferences,
private val googleTaskDao: GoogleTaskDaoBlocking,
private val caldavDao: CaldavDaoBlocking,
private val googleTaskDao: GoogleTaskDao,
private val caldavDao: CaldavDao,
private val localBroadcastManager: LocalBroadcastManager) : BaseAdapter() {
private var selected: Filter? = null
private var items: List<FilterListItem> = ArrayList()
@ -81,7 +82,7 @@ class FilterAdapter @Inject constructor(
SEPARATOR -> SeparatorViewHolder(newView)
SUBHEADER -> SubheaderViewHolder(
newView,
activity,
activity as AppCompatActivity,
preferences,
googleTaskDao,
caldavDao,

@ -9,6 +9,7 @@ import android.app.Activity
import android.os.Bundle
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import com.todoroo.astrid.api.Filter
@ -18,8 +19,8 @@ import io.reactivex.subjects.PublishSubject
import org.tasks.LocalBroadcastManager
import org.tasks.activities.DragAndDropDiffer
import org.tasks.billing.Inventory
import org.tasks.data.CaldavDaoBlocking
import org.tasks.data.GoogleTaskDaoBlocking
import org.tasks.data.CaldavDao
import org.tasks.data.GoogleTaskDao
import org.tasks.filters.NavigationDrawerSubheader
import org.tasks.locale.Locale
import org.tasks.preferences.Preferences
@ -34,8 +35,8 @@ class NavigationDrawerAdapter @Inject constructor(
private val inventory: Inventory,
private val colorProvider: ColorProvider,
private val preferences: Preferences,
private val googleTaskDao: GoogleTaskDaoBlocking,
private val caldavDao: CaldavDaoBlocking,
private val googleTaskDao: GoogleTaskDao,
private val caldavDao: CaldavDao,
private val localBroadcastManager: LocalBroadcastManager)
: RecyclerView.Adapter<RecyclerView.ViewHolder>(), DragAndDropDiffer<FilterListItem, MutableList<FilterListItem>> {
@ -75,7 +76,12 @@ class NavigationDrawerAdapter @Inject constructor(
FilterListItem.Type.ITEM -> FilterViewHolder(
view, true, locale, activity, inventory, colorProvider) { onClickFilter(it) }
FilterListItem.Type.SUBHEADER -> SubheaderViewHolder(
view, activity, preferences, googleTaskDao, caldavDao, localBroadcastManager)
view,
activity as AppCompatActivity,
preferences,
googleTaskDao,
caldavDao,
localBroadcastManager)
FilterListItem.Type.ACTION -> ActionViewHolder(activity, view) { onClickFilter(it) }
else -> SeparatorViewHolder(view)
}

@ -1,18 +1,20 @@
package com.todoroo.astrid.adapter
import android.app.Activity
import android.content.Intent
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.RecyclerView
import butterknife.BindView
import butterknife.ButterKnife
import butterknife.OnClick
import kotlinx.coroutines.launch
import org.tasks.LocalBroadcastManager
import org.tasks.R
import org.tasks.data.CaldavDaoBlocking
import org.tasks.data.GoogleTaskDaoBlocking
import org.tasks.data.CaldavDao
import org.tasks.data.GoogleTaskDao
import org.tasks.filters.NavigationDrawerSubheader
import org.tasks.filters.NavigationDrawerSubheader.SubheaderType
import org.tasks.preferences.Preferences
@ -21,10 +23,10 @@ import org.tasks.themes.DrawableUtil
internal class SubheaderViewHolder(
itemView: View,
activity: Activity,
private val activity: AppCompatActivity,
private val preferences: Preferences,
private val googleTaskDao: GoogleTaskDaoBlocking,
private val caldavDao: CaldavDaoBlocking,
private val googleTaskDao: GoogleTaskDao,
private val caldavDao: CaldavDao,
private val localBroadcastManager: LocalBroadcastManager)
: RecyclerView.ViewHolder(itemView) {
@ -38,13 +40,15 @@ internal class SubheaderViewHolder(
@OnClick(R.id.subheader_row)
fun onClick() {
val collapsed = !subheader.isCollapsed
when (subheader.subheaderType) {
SubheaderType.PREFERENCE -> preferences.setBoolean(subheader.id.toInt(), collapsed)
SubheaderType.GOOGLE_TASKS -> googleTaskDao.setCollapsed(subheader.id, collapsed)
SubheaderType.CALDAV -> caldavDao.setCollapsed(subheader.id, collapsed)
activity.lifecycleScope.launch {
val collapsed = !subheader.isCollapsed
when (subheader.subheaderType) {
SubheaderType.PREFERENCE -> preferences.setBoolean(subheader.id.toInt(), collapsed)
SubheaderType.GOOGLE_TASKS -> googleTaskDao.setCollapsed(subheader.id, collapsed)
SubheaderType.CALDAV -> caldavDao.setCollapsed(subheader.id, collapsed)
}
localBroadcastManager.broadcastRefreshList()
}
localBroadcastManager.broadcastRefreshList()
}
fun bind(subheader: NavigationDrawerSubheader) {

@ -9,10 +9,6 @@ class CaldavDaoBlocking @Inject constructor(private val dao: CaldavDao) {
return dao.subscribeToCalendars()
}
fun setCollapsed(id: Long, collapsed: Boolean) = runBlocking {
dao.setCollapsed(id, collapsed)
}
fun getCalendars(): List<CaldavCalendar> = runBlocking {
dao.getCalendars()
}

@ -1,10 +0,0 @@
package org.tasks.data
import javax.inject.Inject
@Deprecated("use coroutines")
class GoogleTaskDaoBlocking @Inject constructor(private val dao: GoogleTaskDao) {
fun setCollapsed(id: Long, collapsed: Boolean) = runBlocking {
dao.setCollapsed(id, collapsed)
}
}
Loading…
Cancel
Save