Skip to content

Commit

Permalink
More discreet zoom display
Browse files Browse the repository at this point in the history
  • Loading branch information
RobbWatershed committed Aug 17, 2023
1 parent e0c0487 commit d332f2f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class ReaderPagerFragment : Fragment(R.layout.fragment_reader_pager),
private lateinit var processPositionDebouncer: DebouncerK<Pair<Int, Int>>
private lateinit var rescaleDebouncer: DebouncerK<Float>
private lateinit var adapterRescaleDebouncer: DebouncerK<Float>
private lateinit var zoomLevelDebouncer: DebouncerK<Unit>
private var firstZoom = true

// Starting index management
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/res/layout/fragment_reader_pager.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,24 @@
tools:text="28/255"
tools:visibility="visible" />

<TextView
android:id="@+id/viewer_zoom_text"
style="@style/TextShadowLight"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:clickable="false"
android:focusable="false"
android:gravity="center"
android:padding="8dp"
android:textAlignment="center"
android:textColor="@color/white_opacity_25"
android:textSize="@dimen/caption"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:text="144%"
tools:visibility="visible" />

<ProgressBar
android:id="@+id/progress_bar"
style="@style/Widget.AppCompat.ProgressBar.Horizontal"
Expand Down

0 comments on commit d332f2f

Please sign in to comment.