diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/AppSettings.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/AppSettings.kt index 1d85d4f6d..fba3fbe70 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/AppSettings.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/prefs/AppSettings.kt @@ -138,12 +138,10 @@ class AppSettings @Inject constructor(@ApplicationContext context: Context) { get() = prefs.getBoolean(KEY_READER_DOUBLE_PAGES, false) set(value) = prefs.edit { putBoolean(KEY_READER_DOUBLE_PAGES, value) } - val readerDoublePagesSensitivity: Float - get() = prefs.getFloat(KEY_READER_DOUBLE_PAGES_SENSITIVITY, 12f) / 10f - - fun setReaderDoublePagesSensitivity(value: Float) { - prefs.edit { putFloat(KEY_READER_DOUBLE_PAGES_SENSITIVITY, value) } - } + @get:FloatRange(0.0, 1.0) + var readerDoublePagesSensitivity: Float + get() = prefs.getFloat(KEY_READER_DOUBLE_PAGES_SENSITIVITY, 0.5f) + set(@FloatRange(0.0, 1.0) value) = prefs.edit { putFloat(KEY_READER_DOUBLE_PAGES_SENSITIVITY, value) } val readerScreenOrientation: Int get() = prefs.getString(KEY_READER_ORIENTATION, null)?.toIntOrNull() diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/config/ReaderConfigSheet.kt b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/config/ReaderConfigSheet.kt index 60d89885f..cd8c3080a 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/config/ReaderConfigSheet.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/config/ReaderConfigSheet.kt @@ -5,13 +5,13 @@ import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.CompoundButton -import android.widget.SeekBar import androidx.core.view.WindowInsetsCompat import androidx.core.view.isGone import androidx.core.view.isVisible import androidx.core.view.updatePadding import androidx.fragment.app.activityViewModels import com.google.android.material.button.MaterialButtonToggleGroup +import com.google.android.material.slider.Slider import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach @@ -26,7 +26,9 @@ import org.koitharu.kotatsu.core.ui.sheet.BaseAdaptiveSheet import org.koitharu.kotatsu.core.util.ext.consume import org.koitharu.kotatsu.core.util.ext.findParentCallback import org.koitharu.kotatsu.core.util.ext.observe +import org.koitharu.kotatsu.core.util.ext.setValueRounded import org.koitharu.kotatsu.core.util.ext.viewLifecycleScope +import org.koitharu.kotatsu.core.util.progress.IntPercentLabelFormatter import org.koitharu.kotatsu.databinding.SheetReaderConfigBinding import org.koitharu.kotatsu.reader.domain.PageLoader import org.koitharu.kotatsu.reader.ui.ReaderViewModel @@ -38,7 +40,8 @@ class ReaderConfigSheet : BaseAdaptiveSheet(), View.OnClickListener, MaterialButtonToggleGroup.OnButtonCheckedListener, - CompoundButton.OnCheckedChangeListener { + CompoundButton.OnCheckedChangeListener, + Slider.OnChangeListener { private val viewModel by activityViewModels() @@ -92,7 +95,8 @@ class ReaderConfigSheet : binding.textSensitivity.isVisible = settings.isReaderDoubleOnLandscape binding.seekbarSensitivity.isVisible = settings.isReaderDoubleOnLandscape - binding.seekbarSensitivity.progress = (settings.readerDoublePagesSensitivity * 100).toInt() + binding.seekbarSensitivity.setValueRounded(settings.readerDoublePagesSensitivity * 100f) + binding.seekbarSensitivity.setLabelFormatter(IntPercentLabelFormatter(binding.root.context)) binding.checkableGroup.addOnButtonCheckedListener(this) binding.buttonSavePage.setOnClickListener(this) @@ -104,16 +108,7 @@ class ReaderConfigSheet : binding.buttonBookmark.setOnClickListener(this) binding.switchDoubleReader.setOnCheckedChangeListener(this) binding.switchPullGesture.setOnCheckedChangeListener(this) - - binding.seekbarSensitivity.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { - override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { - settings.setReaderDoublePagesSensitivity(progress / 10f) - } - - override fun onStartTrackingTouch(seekBar: SeekBar?) {} - - override fun onStopTrackingTouch(seekBar: SeekBar?) {} - }) + binding.seekbarSensitivity.addOnChangeListener(this) viewModel.isBookmarkAdded.observe(viewLifecycleOwner) { binding.buttonBookmark.setText(if (it) R.string.bookmark_remove else R.string.bookmark_add) @@ -199,6 +194,10 @@ class ReaderConfigSheet : } } + override fun onValueChange(slider: Slider, value: Float, fromUser: Boolean) { + settings.readerDoublePagesSensitivity = value / 100f + } + override fun onButtonChecked( group: MaterialButtonToggleGroup?, checkedId: Int, diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/doublepage/DoublePageSnapHelper.kt b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/doublepage/DoublePageSnapHelper.kt index 697ba5eef..b967b42cf 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/doublepage/DoublePageSnapHelper.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/doublepage/DoublePageSnapHelper.kt @@ -251,7 +251,7 @@ class DoublePageSnapHelper(private val settings: AppSettings) : SnapHelper() { equal to zero. */ fun getPositionsToMove(llm: LinearLayoutManager, scroll: Int, itemSize: Int): Int { - val sensitivity = settings.readerDoublePagesSensitivity + val sensitivity = settings.readerDoublePagesSensitivity.coerceIn(0f, 1f) * 2.5 var positionsToMove = (scroll.toDouble() / (itemSize * (2.5 - sensitivity))).roundToInt() // Apply a maximum threshold diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/discord/ui/DiscordRpc.kt b/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/discord/ui/DiscordRpc.kt index d72b0ff2d..ef5cf2a36 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/discord/ui/DiscordRpc.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/scrobbling/discord/ui/DiscordRpc.kt @@ -37,7 +37,7 @@ import javax.inject.Inject private const val STATUS_ONLINE = "online" private const val STATUS_IDLE = "idle" private const val BUTTON_TEXT_LIMIT = 32 -private const val DEBOUNCE_TIMEOUT = 6_000L // 6 sec +private const val DEBOUNCE_TIMEOUT = 16_000L // 16 sec @ViewModelScoped class DiscordRpc @Inject constructor( diff --git a/app/src/main/res/layout/sheet_reader_config.xml b/app/src/main/res/layout/sheet_reader_config.xml index 3149729ac..f7a7929d9 100644 --- a/app/src/main/res/layout/sheet_reader_config.xml +++ b/app/src/main/res/layout/sheet_reader_config.xml @@ -138,14 +138,16 @@ android:text="@string/two_page_scroll_sensitivity" android:textAppearance="@style/TextAppearance.Kotatsu.GridTitle" /> - + android:valueFrom="0" + android:valueTo="100" + app:labelBehavior="floating" + tools:value="50" />