diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index 81172e00f..0b89b122e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -19,6 +19,7 @@ import android.view.View import android.view.WindowManager import android.view.animation.Animation import android.view.animation.AnimationUtils +import android.widget.SeekBar import androidx.core.view.ViewCompat import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView import eu.kanade.tachiyomi.R @@ -51,6 +52,7 @@ import eu.kanade.tachiyomi.util.view.isDefaultBar import eu.kanade.tachiyomi.util.view.showBar import eu.kanade.tachiyomi.util.view.visible import eu.kanade.tachiyomi.widget.SimpleAnimationListener +import eu.kanade.tachiyomi.widget.SimpleSeekBarListener import java.io.File import java.util.concurrent.TimeUnit import kotlin.math.abs @@ -59,7 +61,6 @@ import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.sample import nucleus.factory.RequiresPresenter -import reactivecircus.flowbinding.android.widget.progressChanges import rx.Observable import rx.android.schedulers.AndroidSchedulers import rx.subscriptions.CompositeSubscription @@ -283,13 +284,13 @@ class ReaderActivity : BaseRxActivity() } // Init listeners on bottom menu - binding.pageSeekbar.progressChanges() - .onEach { - if (viewer != null) { - moveToPageIndex(it) + binding.pageSeekbar.setOnSeekBarChangeListener(object : SimpleSeekBarListener() { + override fun onProgressChanged(seekBar: SeekBar, value: Int, fromUser: Boolean) { + if (viewer != null && fromUser) { + moveToPageIndex(value) } } - .launchIn(scope) + }) binding.leftChapter.setOnClickListener { if (viewer != null) { if (viewer is R2LPagerViewer) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt index d7f909225..c4f5a18e2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.reader import android.graphics.Color import android.view.View import android.view.ViewGroup +import android.widget.SeekBar import androidx.annotation.ColorInt import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetDialog @@ -11,6 +12,7 @@ import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.util.view.gone import eu.kanade.tachiyomi.util.view.visible import eu.kanade.tachiyomi.widget.IgnoreFirstSpinnerListener +import eu.kanade.tachiyomi.widget.SimpleSeekBarListener import kotlin.math.abs import kotlinx.android.synthetic.main.reader_color_filter.brightness_seekbar import kotlinx.android.synthetic.main.reader_color_filter.color_filter_mode @@ -27,13 +29,9 @@ import kotlinx.android.synthetic.main.reader_color_filter.txt_color_filter_green import kotlinx.android.synthetic.main.reader_color_filter.txt_color_filter_red_value import kotlinx.android.synthetic.main.reader_color_filter_sheet.brightness_overlay import kotlinx.android.synthetic.main.reader_color_filter_sheet.color_overlay -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.Job import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.sample -import reactivecircus.flowbinding.android.widget.progressChanges import uy.kohesive.injekt.injectLazy /** @@ -41,8 +39,6 @@ import uy.kohesive.injekt.injectLazy */ class ReaderColorFilterSheet(private val activity: ReaderActivity) : BottomSheetDialog(activity) { - private val scope = CoroutineScope(Job() + Dispatchers.Main) - private val preferences by injectLazy() private var sheetBehavior: BottomSheetBehavior<*>? = null @@ -97,25 +93,45 @@ class ReaderColorFilterSheet(private val activity: ReaderActivity) : BottomSheet } color_filter_mode.setSelection(preferences.colorFilterMode().get(), false) - seekbar_color_filter_alpha.progressChanges() - .onEach { setColorValue(it, ALPHA_MASK, 24) } - .launchIn(scope) + seekbar_color_filter_alpha.setOnSeekBarChangeListener(object : SimpleSeekBarListener() { + override fun onProgressChanged(seekBar: SeekBar, value: Int, fromUser: Boolean) { + if (fromUser) { + setColorValue(value, ALPHA_MASK, 24) + } + } + }) - seekbar_color_filter_red.progressChanges() - .onEach { setColorValue(it, RED_MASK, 16) } - .launchIn(scope) + seekbar_color_filter_red.setOnSeekBarChangeListener(object : SimpleSeekBarListener() { + override fun onProgressChanged(seekBar: SeekBar, value: Int, fromUser: Boolean) { + if (fromUser) { + setColorValue(value, RED_MASK, 16) + } + } + }) - seekbar_color_filter_green.progressChanges() - .onEach { setColorValue(it, GREEN_MASK, 8) } - .launchIn(scope) + seekbar_color_filter_green.setOnSeekBarChangeListener(object : SimpleSeekBarListener() { + override fun onProgressChanged(seekBar: SeekBar, value: Int, fromUser: Boolean) { + if (fromUser) { + setColorValue(value, GREEN_MASK, 8) + } + } + }) - seekbar_color_filter_blue.progressChanges() - .onEach { setColorValue(it, BLUE_MASK, 0) } - .launchIn(scope) + seekbar_color_filter_blue.setOnSeekBarChangeListener(object : SimpleSeekBarListener() { + override fun onProgressChanged(seekBar: SeekBar, value: Int, fromUser: Boolean) { + if (fromUser) { + setColorValue(value, BLUE_MASK, 0) + } + } + }) - brightness_seekbar.progressChanges() - .onEach { preferences.customBrightnessValue().set(it) } - .launchIn(scope) + brightness_seekbar.setOnSeekBarChangeListener(object : SimpleSeekBarListener() { + override fun onProgressChanged(seekBar: SeekBar, value: Int, fromUser: Boolean) { + if (fromUser) { + preferences.customBrightnessValue().set(value) + } + } + }) } override fun onStart() { diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/SimpleSeekBarListener.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/SimpleSeekBarListener.kt new file mode 100644 index 000000000..fdade75f1 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/SimpleSeekBarListener.kt @@ -0,0 +1,14 @@ +package eu.kanade.tachiyomi.widget + +import android.widget.SeekBar + +open class SimpleSeekBarListener : SeekBar.OnSeekBarChangeListener { + override fun onProgressChanged(seekBar: SeekBar, value: Int, fromUser: Boolean) { + } + + override fun onStartTrackingTouch(seekBar: SeekBar) { + } + + override fun onStopTrackingTouch(seekBar: SeekBar) { + } +}