Scope task list view model to task list fragment

pull/1051/head
Alex Baker 4 years ago
parent 9dd479744f
commit 1fa17583c0

@ -21,6 +21,7 @@ import androidx.appcompat.widget.Toolbar
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.viewModels
import androidx.lifecycle.Observer
import androidx.lifecycle.lifecycleScope
import androidx.paging.PagedList
@ -126,7 +127,7 @@ class TaskListFragment : Fragment(), OnRefreshListener, Toolbar.OnMenuItemClickL
@BindView(R.id.recycler_view)
lateinit var recyclerView: RecyclerView
private val listViewModel: TaskListViewModel by activityViewModels()
private val listViewModel: TaskListViewModel by viewModels()
private lateinit var taskAdapter: TaskAdapter
private var recyclerAdapter: TaskListRecyclerAdapter? = null
private lateinit var filter: Filter

@ -120,8 +120,6 @@ abstract class TaskDao(private val database: Database) {
@Transaction
open suspend fun fetchTasks(callback: (SubtaskInfo) -> List<String>, subtasks: SubtaskInfo): List<TaskContainer> {
assertNotMainThread()
val start = if (BuildConfig.DEBUG) DateUtilities.now() else 0
val queries = callback.invoke(subtasks)
val db = database.openHelper.writableDatabase

@ -90,9 +90,6 @@ class NavigationDrawerFragment : Fragment() {
}
}
})
if (item is Filter) {
ViewModelProvider(requireActivity()).get(TaskListViewModel::class.java).setFilter((item as Filter?)!!)
}
close()
}

@ -15,8 +15,8 @@ import android.view.inputmethod.InputMethodManager
import android.widget.EditText
import android.widget.LinearLayout
import androidx.core.widget.addTextChangedListener
import androidx.fragment.app.viewModels
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.LinearLayoutManager
@ -69,14 +69,13 @@ class SubtaskControlSet : TaskEditControlFragment(), SubtaskViewHolder.Callbacks
@Inject lateinit var checkBoxProvider: CheckBoxProvider
@Inject lateinit var chipProvider: ChipProvider
private lateinit var listViewModel: TaskListViewModel
private val listViewModel: TaskListViewModel by viewModels()
private val refreshReceiver = RefreshReceiver()
private var remoteList: Filter? = null
private var googleTask: GoogleTask? = null
private lateinit var recyclerAdapter: SubtasksRecyclerAdapter
override fun createView(savedInstanceState: Bundle?) {
listViewModel = ViewModelProvider(this).get(TaskListViewModel::class.java)
viewModel.newSubtasks.forEach { addSubtask(it) }
recyclerAdapter = SubtasksRecyclerAdapter(activity, chipProvider, checkBoxProvider, this)
viewModel.task?.let {

@ -8,10 +8,9 @@ import androidx.sqlite.db.SimpleSQLiteQuery
import com.todoroo.andlib.utility.AndroidUtilities
import com.todoroo.andlib.utility.DateUtilities
import com.todoroo.astrid.api.Filter
import com.todoroo.astrid.dao.TaskDaoBlocking
import com.todoroo.astrid.dao.TaskDao
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.tasks.BuildConfig
import org.tasks.data.SubtaskInfo
import org.tasks.data.TaskContainer
@ -21,7 +20,7 @@ import timber.log.Timber
class TaskListViewModel @ViewModelInject constructor(
private val preferences: Preferences,
private val taskDao: TaskDaoBlocking) : ViewModel(), Observer<PagedList<TaskContainer>> {
private val taskDao: TaskDao) : ViewModel(), Observer<PagedList<TaskContainer>> {
private var tasks = MutableLiveData<List<TaskContainer>>()
private var filter: Filter? = null
@ -70,11 +69,9 @@ class TaskListViewModel @ViewModelInject constructor(
}
private suspend fun performNonPagedQuery(subtasks: SubtaskInfo) {
tasks.value = withContext(Dispatchers.IO) {
taskDao.fetchTasks(
{ s: SubtaskInfo? -> getQuery(preferences, filter!!, s!!) },
subtasks)
}
tasks.value = taskDao.fetchTasks(
{ s: SubtaskInfo? -> getQuery(preferences, filter!!, s!!) },
subtasks)
}
private fun performPagedListQuery() {

Loading…
Cancel
Save