Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ package com.ichi2.anki.previewer

import android.content.Context
import android.content.Intent
import android.graphics.Rect
import android.os.Bundle
import android.view.KeyEvent
import android.view.Menu
import android.view.MenuItem
import android.view.View
import androidx.appcompat.widget.Toolbar
import androidx.core.os.bundleOf
import androidx.core.view.ViewCompat
import androidx.core.view.doOnLayout
import androidx.core.view.isVisible
import androidx.fragment.app.viewModels
import androidx.lifecycle.flowWithLifecycle
Expand Down Expand Up @@ -133,9 +136,15 @@ class PreviewerFragment :

binding.slider.apply {
valueTo = cardsCount.toFloat()
doOnLayout {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set the gesture exclusion area once the slider has its final size

Copy link
Member

@david-allison david-allison Mar 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer code comments, rather than GitHub comments

If it's useful for reviewers, it'll be useful for future maintainers in the codebase

updateSliderGestureExclusion(this)
}
addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ ->
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the exclusion area again if the slider layout changes later

updateSliderGestureExclusion(this)
}
addOnSliderTouchListener(
object : Slider.OnSliderTouchListener {
override fun onStartTrackingTouch(slider: Slider) {}
override fun onStartTrackingTouch(slider: Slider) = Unit

override fun onStopTrackingTouch(slider: Slider) {
viewModel.onSliderChange(slider.value.toInt())
Expand Down Expand Up @@ -184,6 +193,13 @@ class PreviewerFragment :
bindingMap = BindingMap(sharedPrefs(), PreviewerAction.entries, this)
}

private fun updateSliderGestureExclusion(slider: Slider) {
ViewCompat.setSystemGestureExclusionRects(
slider,
listOf(Rect(0, 0, slider.width, slider.height)),
)
}

private fun setupFlagMenu(menu: Menu) {
val submenu = menu.findItem(R.id.action_flag).subMenu
lifecycleScope.launch {
Expand Down
Loading