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

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

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

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