From d332f2f4fed07e3b756689742ab4e18516a078d9 Mon Sep 17 00:00:00 2001 From: Robb <35880555+robbwatershed@users.noreply.github.com> Date: Thu, 17 Aug 2023 13:49:43 +0200 Subject: [PATCH] More discreet zoom display --- .../fragments/reader/ReaderPagerFragment.kt | 26 ++++++++++++++----- .../main/res/layout/fragment_reader_pager.xml | 18 +++++++++++++ 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/me/devsaki/hentoid/fragments/reader/ReaderPagerFragment.kt b/app/src/main/java/me/devsaki/hentoid/fragments/reader/ReaderPagerFragment.kt index 33de9f23f..5b00d4ea9 100644 --- a/app/src/main/java/me/devsaki/hentoid/fragments/reader/ReaderPagerFragment.kt +++ b/app/src/main/java/me/devsaki/hentoid/fragments/reader/ReaderPagerFragment.kt @@ -142,6 +142,7 @@ class ReaderPagerFragment : Fragment(R.layout.fragment_reader_pager), private lateinit var processPositionDebouncer: DebouncerK> private lateinit var rescaleDebouncer: DebouncerK private lateinit var adapterRescaleDebouncer: DebouncerK + private lateinit var zoomLevelDebouncer: DebouncerK private var firstZoom = true // Starting index management @@ -186,16 +187,14 @@ class ReaderPagerFragment : Fragment(R.layout.fragment_reader_pager), } rescaleDebouncer = DebouncerK(this.lifecycleScope, 100) { scale: Float -> adapter.multiplyScale(scale) - if (!firstZoom) - context?.let { - ToastHelper.toast(it, R.string.percent_no_digits, scale * 100.0) - } + if (!firstZoom) displayZoomLevel(scale) else firstZoom = false } adapterRescaleDebouncer = DebouncerK(this.lifecycleScope, 100) { scale: Float -> - context?.let { - ToastHelper.toast(it, R.string.percent_no_digits, scale * 100.0) - } + displayZoomLevel(scale) + } + zoomLevelDebouncer = DebouncerK(this.lifecycleScope, 500) { + hideZoomLevel() } Preferences.registerPrefsChangedListener(prefsListener) Settings.registerPrefsChangedListener(prefsListener) @@ -265,6 +264,7 @@ class ReaderPagerFragment : Fragment(R.layout.fragment_reader_pager), processPositionDebouncer.clear() rescaleDebouncer.clear() adapterRescaleDebouncer.clear() + zoomLevelDebouncer.clear() navigator.clear() binding?.recyclerView?.adapter = null binding = null @@ -1508,6 +1508,18 @@ class ReaderPagerFragment : Fragment(R.layout.fragment_reader_pager), ToastHelper.toast(R.string.slideshow_stop) } + private fun displayZoomLevel(value: Float) { + binding?.apply { + viewerZoomText.text = resources.getString(R.string.percent_no_digits, value * 100.0) + viewerZoomText.isVisible = true + } + zoomLevelDebouncer.submit(Unit) + } + + private fun hideZoomLevel() { + binding?.viewerZoomText?.isVisible = false + } + companion object { const val KEY_HUD_VISIBLE = "hud_visible" const val KEY_GALLERY_SHOWN = "gallery_shown" diff --git a/app/src/main/res/layout/fragment_reader_pager.xml b/app/src/main/res/layout/fragment_reader_pager.xml index d7148d15c..ab1f712de 100644 --- a/app/src/main/res/layout/fragment_reader_pager.xml +++ b/app/src/main/res/layout/fragment_reader_pager.xml @@ -109,6 +109,24 @@ tools:text="28/255" tools:visibility="visible" /> + +