Move viewholder callbacks to task list fragment

pull/1043/head
Alex Baker 4 years ago
parent 236f9ae0e0
commit 55c8be04d4

@ -71,10 +71,7 @@ import org.tasks.preferences.Device
import org.tasks.preferences.Preferences
import org.tasks.sync.SyncAdapters
import org.tasks.tags.TagPickerActivity
import org.tasks.tasklist.DragAndDropRecyclerAdapter
import org.tasks.tasklist.PagedListRecyclerAdapter
import org.tasks.tasklist.TaskListRecyclerAdapter
import org.tasks.tasklist.ViewHolderFactory
import org.tasks.tasklist.*
import org.tasks.themes.ColorProvider
import org.tasks.themes.ThemeColor
import org.tasks.ui.TaskListViewModel
@ -85,7 +82,9 @@ import javax.inject.Inject
import kotlin.math.max
@AndroidEntryPoint
class TaskListFragment : Fragment(), OnRefreshListener, Toolbar.OnMenuItemClickListener, MenuItem.OnActionExpandListener, SearchView.OnQueryTextListener, ActionMode.Callback {
class TaskListFragment : Fragment(), OnRefreshListener, Toolbar.OnMenuItemClickListener,
MenuItem.OnActionExpandListener, SearchView.OnQueryTextListener, ActionMode.Callback,
TaskViewHolder.ViewHolderCallbacks {
private val refreshReceiver = RefreshReceiver()
private var disposables: CompositeDisposable? = null
@ -230,13 +229,13 @@ class TaskListFragment : Fragment(), OnRefreshListener, Toolbar.OnMenuItemClickL
if (recyclerAdapter !is PagedListRecyclerAdapter) {
setAdapter(
PagedListRecyclerAdapter(
taskAdapter, recyclerView, viewHolderFactory, this, tasks, taskDao, preferences))
taskAdapter, recyclerView, viewHolderFactory, this, tasks, preferences))
return
}
} else if (recyclerAdapter !is DragAndDropRecyclerAdapter) {
setAdapter(
DragAndDropRecyclerAdapter(
taskAdapter, recyclerView, viewHolderFactory, this, tasks, taskDao, preferences))
taskAdapter, recyclerView, viewHolderFactory, this, tasks, preferences))
return
}
recyclerAdapter!!.submitList(tasks)
@ -736,6 +735,45 @@ class TaskListFragment : Fragment(), OnRefreshListener, Toolbar.OnMenuItemClickL
fun clearCollapsed() = taskAdapter.clearCollapsed()
override fun onCompletedTask(task: TaskContainer, newState: Boolean) {
taskAdapter.onCompletedTask(task, newState)
loadTaskListContent()
}
override fun onClick(taskViewHolder: TaskViewHolder) {
if (isActionModeActive) {
recyclerAdapter?.toggle(taskViewHolder)
} else {
onTaskListItemClicked(taskViewHolder.task.getTask())
}
}
override fun onClick(filter: Filter) {
if (!isActionModeActive) {
val context = activity
context?.startActivity(TaskIntents.getTaskListIntent(context, filter))
}
}
override fun onLongPress(taskViewHolder: TaskViewHolder): Boolean {
if (recyclerAdapter?.dragAndDropEnabled() != true) {
startActionMode()
}
if (isActionModeActive && !taskViewHolder.moving) {
recyclerAdapter?.toggle(taskViewHolder)
}
return true
}
override fun onChangeDueDate(task: TaskContainer) {
showDateTimePicker(task)
}
override fun toggleSubtasks(task: TaskContainer, collapsed: Boolean) {
taskDao.setCollapsed(task.id, collapsed)
broadcastRefresh()
}
companion object {
const val TAGS_METADATA_JOIN = "for_tags" // $NON-NLS-1$
const val GTASK_METADATA_JOIN = "googletask" // $NON-NLS-1$

@ -9,7 +9,6 @@ import androidx.recyclerview.widget.ItemTouchHelper.Callback.makeMovementFlags
import androidx.recyclerview.widget.RecyclerView
import com.todoroo.astrid.activity.TaskListFragment
import com.todoroo.astrid.adapter.TaskAdapter
import com.todoroo.astrid.dao.TaskDaoBlocking
import com.todoroo.astrid.utility.Flags
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.subjects.PublishSubject
@ -26,8 +25,7 @@ class DragAndDropRecyclerAdapter(
viewHolderFactory: ViewHolderFactory,
private val taskList: TaskListFragment,
tasks: List<TaskContainer>,
taskDao: TaskDaoBlocking,
preferences: Preferences) : TaskListRecyclerAdapter(adapter, viewHolderFactory, taskList, taskDao, preferences), DragAndDropDiffer<TaskContainer, SectionedDataSource> {
preferences: Preferences) : TaskListRecyclerAdapter(adapter, viewHolderFactory, taskList, preferences), DragAndDropDiffer<TaskContainer, SectionedDataSource> {
private val disableHeaders = taskList.getFilter().let {
!it.supportsSorting()
|| !preferences.showGroupHeaders()

@ -6,7 +6,6 @@ import androidx.recyclerview.widget.AsyncDifferConfig
import androidx.recyclerview.widget.RecyclerView
import com.todoroo.astrid.activity.TaskListFragment
import com.todoroo.astrid.adapter.TaskAdapter
import com.todoroo.astrid.dao.TaskDaoBlocking
import org.tasks.data.TaskContainer
import org.tasks.preferences.Preferences
@ -16,8 +15,7 @@ class PagedListRecyclerAdapter(
viewHolderFactory: ViewHolderFactory,
taskList: TaskListFragment,
list: List<TaskContainer>,
taskDao: TaskDaoBlocking,
preferences: Preferences) : TaskListRecyclerAdapter(adapter, viewHolderFactory, taskList, taskDao, preferences) {
preferences: Preferences) : TaskListRecyclerAdapter(adapter, viewHolderFactory, taskList, preferences) {
private val differ: AsyncPagedListDiffer<TaskContainer> =
AsyncPagedListDiffer(this, AsyncDifferConfig.Builder(ItemCallback()).build())

@ -6,22 +6,18 @@ import androidx.recyclerview.widget.RecyclerView
import com.todoroo.astrid.activity.TaskListFragment
import com.todoroo.astrid.adapter.TaskAdapter
import com.todoroo.astrid.adapter.TaskAdapterDataSource
import com.todoroo.astrid.api.Filter
import com.todoroo.astrid.dao.TaskDaoBlocking
import org.tasks.data.TaskContainer
import org.tasks.intents.TaskIntents
import org.tasks.preferences.Preferences
import org.tasks.tasklist.TaskViewHolder.ViewHolderCallbacks
abstract class TaskListRecyclerAdapter internal constructor(
private val adapter: TaskAdapter,
internal val viewHolderFactory: ViewHolderFactory,
private val taskList: TaskListFragment,
private val taskDao: TaskDaoBlocking,
internal val preferences: Preferences)
: RecyclerView.Adapter<RecyclerView.ViewHolder>(), ViewHolderCallbacks, ListUpdateCallback, TaskAdapterDataSource {
: RecyclerView.Adapter<RecyclerView.ViewHolder>(), ListUpdateCallback, TaskAdapterDataSource {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder = viewHolderFactory.newViewHolder(parent, this)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder
= viewHolderFactory.newViewHolder(parent, taskList)
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
val sortMode = preferences.sortMode
@ -36,45 +32,6 @@ abstract class TaskListRecyclerAdapter internal constructor(
}
}
override fun onCompletedTask(task: TaskContainer, newState: Boolean) {
adapter.onCompletedTask(task, newState)
taskList.loadTaskListContent()
}
override fun onClick(taskViewHolder: TaskViewHolder) {
if (taskList.isActionModeActive) {
toggle(taskViewHolder)
} else {
taskList.onTaskListItemClicked(taskViewHolder.task.getTask())
}
}
override fun onClick(filter: Filter) {
if (!taskList.isActionModeActive) {
val context = taskList.activity
context?.startActivity(TaskIntents.getTaskListIntent(context, filter))
}
}
override fun onLongPress(taskViewHolder: TaskViewHolder): Boolean {
if (!dragAndDropEnabled()) {
taskList.startActionMode()
}
if (taskList.isActionModeActive && !taskViewHolder.moving) {
toggle(taskViewHolder)
}
return true
}
override fun onChangeDueDate(task: TaskContainer) {
taskList.showDateTimePicker(task)
}
override fun toggleSubtasks(task: TaskContainer, collapsed: Boolean) {
taskDao.setCollapsed(task.id, collapsed)
taskList.broadcastRefresh()
}
fun toggle(taskViewHolder: TaskViewHolder) {
adapter.toggleSelection(taskViewHolder.task)
notifyItemChanged(taskViewHolder.adapterPosition)
@ -85,7 +42,7 @@ abstract class TaskListRecyclerAdapter internal constructor(
}
}
protected abstract fun dragAndDropEnabled(): Boolean
abstract fun dragAndDropEnabled(): Boolean
abstract fun submitList(list: List<TaskContainer>)

Loading…
Cancel
Save