fix: lag when run tasks dialog is opened

This removes the categories option in run tasks dialog (closes #584)
This commit is contained in:
Akash Yadav
2022-12-21 21:36:00 +05:30
parent 117752ef5f
commit 745fc60cce
8 changed files with 14 additions and 161 deletions
@@ -1,57 +0,0 @@
/*
* This file is part of AndroidIDE.
*
* AndroidIDE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* AndroidIDE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
*/
package com.itsaky.androidide.adapters
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.itsaky.androidide.adapters.RunTasksCategoryAdapter.VH
import com.itsaky.androidide.databinding.LayoutRunTasksCategoryBinding
import com.itsaky.androidide.models.Checkable
import com.itsaky.androidide.models.RunTasksCategory
import com.itsaky.androidide.tooling.api.model.GradleTask
/** @author Akash Yadav */
class RunTasksCategoryAdapter(
val items: List<RunTasksCategory>,
private val onCheckChanged: (Checkable<GradleTask>) -> Unit = {}
) : RecyclerView.Adapter<VH>() {
class VH(val binding: LayoutRunTasksCategoryBinding) : RecyclerView.ViewHolder(binding.root)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH {
return VH(
LayoutRunTasksCategoryBinding.inflate(LayoutInflater.from(parent.context), parent, false)
)
}
override fun getItemCount(): Int {
return items.size
}
fun getItem(index: Int): RunTasksCategory {
return items[index]
}
override fun onBindViewHolder(holder: VH, position: Int) {
val binding = holder.binding
val category = getItem(position)
binding.header.setText(category.title)
binding.tasks.adapter = RunTasksListAdapter(category.tasks, onCheckChanged)
}
}
@@ -53,13 +53,10 @@ constructor(
binding.check.isChecked = data.isChecked
binding.taskPath.text = task.path
binding.taskDesc.text = task.description
binding.root.setOnClickListener {
binding.check.isChecked = !binding.check.isChecked
}
binding.check.addOnCheckedStateChangedListener { checkbox, _ ->
data.isChecked = checkbox.isChecked
binding.root.setOnClickListener {
data.isChecked = !data.isChecked
binding.check.isChecked = data.isChecked
onCheckChanged(data)
}
}
@@ -32,20 +32,17 @@ import androidx.core.view.updateLayoutParams
import androidx.core.view.updateMargins
import androidx.core.view.updatePadding
import androidx.fragment.app.viewModels
import androidx.recyclerview.widget.RecyclerView
import androidx.transition.TransitionManager
import com.blankj.utilcode.util.ThreadUtils
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.google.android.material.transition.MaterialSharedAxis
import com.itsaky.androidide.R.string
import com.itsaky.androidide.adapters.RunTasksCategoryAdapter
import com.itsaky.androidide.adapters.RunTasksListAdapter
import com.itsaky.androidide.databinding.LayoutRunTaskBinding
import com.itsaky.androidide.databinding.LayoutRunTaskDialogBinding
import com.itsaky.androidide.lookup.Lookup
import com.itsaky.androidide.models.Checkable
import com.itsaky.androidide.models.RunTasksCategory
import com.itsaky.androidide.projects.ProjectManager
import com.itsaky.androidide.projects.builder.BuildService
import com.itsaky.androidide.resources.R
@@ -95,10 +92,8 @@ class RunTasksDialogFragment : BottomSheetDialogFragment() {
findViewById<View>(com.google.android.material.R.id.container)?.apply {
doOnApplyWindowInsets { view, insets, _, margins ->
insets.getInsets(statusBars() or navigationBars()).apply {
view.updateLayoutParams<MarginLayoutParams> {
updateMargins(top = margins.top + top)
}
run.categories.apply {
view.updateLayoutParams<MarginLayoutParams> { updateMargins(top = margins.top + top) }
run.tasks.apply {
updatePadding(bottom = bottom)
clipToPadding = false
clipChildren = false
@@ -130,22 +125,8 @@ class RunTasksDialogFragment : BottomSheetDialogFragment() {
}
viewModel.observeQuery(viewLifecycleOwner) {
val adapter = run.categories.adapter
if (adapter !is RunTasksCategoryAdapter) {
return@observeQuery
}
for (index in 0 until viewModel.categories.size) {
val layout =
run.categories.layoutManager
?.findViewByPosition(index)
?.findViewById<RecyclerView>(com.itsaky.androidide.R.id.tasks)
?: continue
val childAdapter = layout.adapter
if (childAdapter !is RunTasksListAdapter) {
continue
}
childAdapter.filter(it)
}
val adapter = run.tasks.adapter as? RunTasksListAdapter? ?: return@observeQuery
adapter.filter(it)
}
run.searchInput.editText?.addTextChangedListener(
@@ -209,13 +190,8 @@ class RunTasksDialogFragment : BottomSheetDialogFragment() {
viewModel.deselect(item.data.path)
}
}
viewModel.categories =
listOf(
RunTasksCategory(R.string.title_common, viewModel.commonTasks),
RunTasksCategory(R.string.title_all_tasks, viewModel.tasks)
)
run.categories.adapter = RunTasksCategoryAdapter(viewModel.categories, onCheckChanged)
run.tasks.adapter = RunTasksListAdapter(viewModel.tasks, onCheckChanged)
}
}
}
@@ -22,7 +22,6 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModel
import com.itsaky.androidide.models.Checkable
import com.itsaky.androidide.models.RunTasksCategory
import com.itsaky.androidide.tooling.api.model.GradleTask
/** @author Akash Yadav */
@@ -41,29 +40,17 @@ class RunTasksViewModel : ViewModel() {
"lintRelease"
)
private val _categories = MutableLiveData(listOf<RunTasksCategory>())
private val _tasks = MutableLiveData(listOf<Checkable<GradleTask>>())
private val _commonTasks = MutableLiveData(listOf<Checkable<GradleTask>>())
private val _selected = MutableLiveData(mutableSetOf<String>())
private val _displayedChild = MutableLiveData(0)
private val _query = MutableLiveData("")
var categories: List<RunTasksCategory>
get() = _categories.value!!
set(value) {
_categories.value = value
}
var tasks: List<Checkable<GradleTask>>
get() = _tasks.value!!
set(value) {
_tasks.value = value
_commonTasks.value = value.filter { _commonTaskNames.contains(it.data.name) }
}
val commonTasks: List<Checkable<GradleTask>>
get() = _commonTasks.value!!
var displayedChild: Int
get() = this._displayedChild.value!!
set(value) {
+2 -2
View File
@@ -37,7 +37,7 @@
</com.google.android.material.textfield.TextInputLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/categories"
android:id="@+id/tasks"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
@@ -45,6 +45,6 @@
android:layout_marginEnd="16dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:itemCount="3"
tools:listitem="@layout/layout_run_tasks_category" />
tools:listitem="@layout/layout_run_task_item" />
</androidx.appcompat.widget.LinearLayoutCompat>
@@ -20,6 +20,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_ripple"
android:clickable="true"
android:descendantFocusability="blocksDescendants"
android:focusable="true">
@@ -29,6 +30,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:clickable="false"
android:focusable="false"
android:gravity="center_vertical"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
@@ -1,53 +0,0 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ This file is part of AndroidIDE.
~
~ AndroidIDE is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ AndroidIDE is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
-->
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="@layout/layout_divider_horizontal" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/header"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:textAppearance="@style/TextAppearance.Material3.BodySmall"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/separator"
tools:text="@string/title_all_tasks" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/tasks"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/header"
tools:itemCount="3"
tools:listitem="@layout/layout_run_task_item" />
</androidx.constraintlayout.widget.ConstraintLayout>
Binary file not shown.