Refactor skipping checkable state animation
This commit is contained in:
@@ -25,6 +25,7 @@ import org.koitharu.kotatsu.favourites.ui.categories.FavouriteCategoriesActivity
|
|||||||
import org.koitharu.kotatsu.parsers.model.SortOrder
|
import org.koitharu.kotatsu.parsers.model.SortOrder
|
||||||
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
||||||
import org.koitharu.kotatsu.utils.ext.getSerializableCompat
|
import org.koitharu.kotatsu.utils.ext.getSerializableCompat
|
||||||
|
import org.koitharu.kotatsu.utils.ext.setChecked
|
||||||
import com.google.android.material.R as materialR
|
import com.google.android.material.R as materialR
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
@@ -112,10 +113,8 @@ class FavouritesCategoryEditActivity :
|
|||||||
selectedSortOrder = category?.order
|
selectedSortOrder = category?.order
|
||||||
val sortText = getString((category?.order ?: SortOrder.NEWEST).titleRes)
|
val sortText = getString((category?.order ?: SortOrder.NEWEST).titleRes)
|
||||||
binding.editSort.setText(sortText, false)
|
binding.editSort.setText(sortText, false)
|
||||||
binding.switchTracker.isChecked = category?.isTrackingEnabled ?: true
|
binding.switchTracker.setChecked(category?.isTrackingEnabled ?: true, false)
|
||||||
binding.switchTracker.jumpDrawablesToCurrentState()
|
binding.switchShelf.setChecked(category?.isVisibleInLibrary ?: true, false)
|
||||||
binding.switchShelf.isChecked = category?.isVisibleInLibrary ?: true
|
|
||||||
binding.switchShelf.jumpDrawablesToCurrentState()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onError(e: Throwable) {
|
private fun onError(e: Throwable) {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.hannesdorfmann.adapterdelegates4.dsl.adapterDelegateViewBinding
|
|||||||
import org.koitharu.kotatsu.R
|
import org.koitharu.kotatsu.R
|
||||||
import org.koitharu.kotatsu.databinding.ItemSourceLocaleBinding
|
import org.koitharu.kotatsu.databinding.ItemSourceLocaleBinding
|
||||||
import org.koitharu.kotatsu.settings.onboard.model.SourceLocale
|
import org.koitharu.kotatsu.settings.onboard.model.SourceLocale
|
||||||
|
import org.koitharu.kotatsu.utils.ext.setChecked
|
||||||
import org.koitharu.kotatsu.utils.ext.textAndVisible
|
import org.koitharu.kotatsu.utils.ext.textAndVisible
|
||||||
|
|
||||||
fun sourceLocaleAD(
|
fun sourceLocaleAD(
|
||||||
@@ -19,9 +20,6 @@ fun sourceLocaleAD(
|
|||||||
bind { payloads ->
|
bind { payloads ->
|
||||||
binding.textViewTitle.text = item.title ?: getString(R.string.different_languages)
|
binding.textViewTitle.text = item.title ?: getString(R.string.different_languages)
|
||||||
binding.textViewDescription.textAndVisible = item.summary
|
binding.textViewDescription.textAndVisible = item.summary
|
||||||
binding.switchToggle.isChecked = item.isChecked
|
binding.switchToggle.setChecked(item.isChecked, payloads.isNotEmpty())
|
||||||
if (payloads.isEmpty()) {
|
|
||||||
binding.switchToggle.jumpDrawablesToCurrentState()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import org.koitharu.kotatsu.databinding.FragmentToolsBinding
|
|||||||
import org.koitharu.kotatsu.download.ui.list.DownloadsActivity
|
import org.koitharu.kotatsu.download.ui.list.DownloadsActivity
|
||||||
import org.koitharu.kotatsu.settings.SettingsActivity
|
import org.koitharu.kotatsu.settings.SettingsActivity
|
||||||
import org.koitharu.kotatsu.settings.about.AppUpdateDialog
|
import org.koitharu.kotatsu.settings.about.AppUpdateDialog
|
||||||
|
import org.koitharu.kotatsu.utils.ext.setChecked
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class ToolsFragment :
|
class ToolsFragment :
|
||||||
@@ -42,10 +43,7 @@ class ToolsFragment :
|
|||||||
binding.memoryUsageView.setManageButtonOnClickListener(this)
|
binding.memoryUsageView.setManageButtonOnClickListener(this)
|
||||||
|
|
||||||
viewModel.isIncognitoModeEnabled.observe(viewLifecycleOwner) {
|
viewModel.isIncognitoModeEnabled.observe(viewLifecycleOwner) {
|
||||||
if (binding.switchIncognito.isChecked != it) {
|
binding.switchIncognito.setChecked(it, false)
|
||||||
binding.switchIncognito.isChecked = it
|
|
||||||
binding.switchIncognito.jumpDrawablesToCurrentState()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
viewModel.storageUsage.observe(viewLifecycleOwner) {
|
viewModel.storageUsage.observe(viewLifecycleOwner) {
|
||||||
binding.memoryUsageView.bind(it)
|
binding.memoryUsageView.bind(it)
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import org.koitharu.kotatsu.R
|
|||||||
import org.koitharu.kotatsu.databinding.ItemCategoryCheckableMultipleBinding
|
import org.koitharu.kotatsu.databinding.ItemCategoryCheckableMultipleBinding
|
||||||
import org.koitharu.kotatsu.databinding.ItemShelfSectionDraggableBinding
|
import org.koitharu.kotatsu.databinding.ItemShelfSectionDraggableBinding
|
||||||
import org.koitharu.kotatsu.shelf.domain.ShelfSection
|
import org.koitharu.kotatsu.shelf.domain.ShelfSection
|
||||||
|
import org.koitharu.kotatsu.utils.ext.setChecked
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
fun shelfSectionAD(
|
fun shelfSectionAD(
|
||||||
@@ -42,10 +43,7 @@ fun shelfSectionAD(
|
|||||||
|
|
||||||
bind { payloads ->
|
bind { payloads ->
|
||||||
binding.textViewTitle.setText(item.section.titleResId)
|
binding.textViewTitle.setText(item.section.titleResId)
|
||||||
binding.switchToggle.isChecked = item.isChecked
|
binding.switchToggle.setChecked(item.isChecked, payloads.isNotEmpty())
|
||||||
if (payloads.isEmpty()) {
|
|
||||||
binding.switchToggle.jumpDrawablesToCurrentState()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,10 +63,7 @@ fun shelfCategoryAD(
|
|||||||
|
|
||||||
bind { payloads ->
|
bind { payloads ->
|
||||||
binding.root.text = item.title
|
binding.root.text = item.title
|
||||||
binding.root.isChecked = item.isChecked
|
binding.root.setChecked(item.isChecked, payloads.isNotEmpty())
|
||||||
if (payloads.isEmpty()) {
|
|
||||||
binding.root.jumpDrawablesToCurrentState()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import android.view.View.MeasureSpec
|
|||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.view.ViewParent
|
import android.view.ViewParent
|
||||||
import android.view.inputmethod.InputMethodManager
|
import android.view.inputmethod.InputMethodManager
|
||||||
|
import android.widget.Checkable
|
||||||
import androidx.core.view.children
|
import androidx.core.view.children
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
@@ -192,3 +193,11 @@ fun View.measureDimension(desiredSize: Int, measureSpec: Int): Int {
|
|||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun <V> V.setChecked(checked: Boolean, animate: Boolean) where V : View, V : Checkable {
|
||||||
|
val skipAnimation = !animate && checked != isChecked
|
||||||
|
isChecked = checked
|
||||||
|
if (skipAnimation) {
|
||||||
|
jumpDrawablesToCurrentState()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user