Minor code cleanup

This commit is contained in:
arkon 2021-03-20 15:43:02 -04:00
parent 5a7f2684b3
commit 78285bdf37
4 changed files with 24 additions and 35 deletions

View File

@ -91,7 +91,7 @@ class SearchController(
) )
return MaterialDialog(activity!!) return MaterialDialog(activity!!)
.message(R.string.migration_dialog_what_to_include) .title(R.string.migration_dialog_what_to_include)
.listItemsMultiChoice( .listItemsMultiChoice(
items = MigrationFlags.titles.map { resources?.getString(it) as CharSequence }, items = MigrationFlags.titles.map { resources?.getString(it) as CharSequence },
initialSelection = preselected.toIntArray() initialSelection = preselected.toIntArray()

View File

@ -10,7 +10,6 @@ import android.view.View
import android.view.ViewPropertyAnimator import android.view.ViewPropertyAnimator
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.view.isVisible import androidx.core.view.isVisible
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation
import kotlin.math.abs import kotlin.math.abs
@ -34,7 +33,7 @@ class ReaderNavigationOverlayView(context: Context, attributeSet: AttributeSet)
viewPropertyAnimator = animate() viewPropertyAnimator = animate()
.alpha(1f) .alpha(1f)
.setDuration(1000L) .setDuration(FADE_DURATION)
.withStartAction { .withStartAction {
isVisible = true isVisible = true
} }
@ -44,6 +43,8 @@ class ReaderNavigationOverlayView(context: Context, attributeSet: AttributeSet)
viewPropertyAnimator?.start() viewPropertyAnimator?.start()
} }
private val regionPaint = Paint()
private val textPaint = Paint().apply { private val textPaint = Paint().apply {
textAlign = Paint.Align.CENTER textAlign = Paint.Align.CENTER
color = Color.WHITE color = Color.WHITE
@ -62,16 +63,14 @@ class ReaderNavigationOverlayView(context: Context, attributeSet: AttributeSet)
if (navigation == null) return if (navigation == null) return
navigation?.regions?.forEach { region -> navigation?.regions?.forEach { region ->
val paint = paintForRegion(region.type)
val rect = region.rectF val rect = region.rectF
canvas?.save() canvas?.save()
// Scale rect from 1f,1f to screen width and height // Scale rect from 1f,1f to screen width and height
canvas?.scale(width.toFloat(), height.toFloat()) canvas?.scale(width.toFloat(), height.toFloat())
canvas?.drawRect(rect, paint) regionPaint.color = ContextCompat.getColor(context, region.type.colorRes)
canvas?.drawRect(rect, regionPaint)
canvas?.restore() canvas?.restore()
// Don't want scale anymore because it messes with drawText // Don't want scale anymore because it messes with drawText
@ -86,42 +85,20 @@ class ReaderNavigationOverlayView(context: Context, attributeSet: AttributeSet)
// Calculate center of rect height on screen // Calculate center of rect height on screen
val y = height * (abs(rect.top - rect.bottom) / 2) val y = height * (abs(rect.top - rect.bottom) / 2)
canvas?.drawText(region.type.name, x, y, textBorderPaint) canvas?.drawText(context.getString(region.type.nameRes), x, y, textBorderPaint)
canvas?.drawText(region.type.name, x, y, textPaint) canvas?.drawText(context.getString(region.type.nameRes), x, y, textPaint)
canvas?.restore() canvas?.restore()
} }
} }
private fun paintForRegion(type: ViewerNavigation.NavigationRegion): Paint {
return Paint().apply {
when (type) {
ViewerNavigation.NavigationRegion.NEXT -> {
color = ContextCompat.getColor(context, R.color.navigation_next)
}
ViewerNavigation.NavigationRegion.PREV -> {
color = ContextCompat.getColor(context, R.color.navigation_prev)
}
ViewerNavigation.NavigationRegion.MENU -> {
color = ContextCompat.getColor(context, R.color.navigation_menu)
}
ViewerNavigation.NavigationRegion.RIGHT -> {
color = ContextCompat.getColor(context, R.color.navigation_right)
}
ViewerNavigation.NavigationRegion.LEFT -> {
color = ContextCompat.getColor(context, R.color.navigation_left)
}
}
}
}
override fun performClick(): Boolean { override fun performClick(): Boolean {
super.performClick() super.performClick()
if (viewPropertyAnimator == null && isVisible) { if (viewPropertyAnimator == null && isVisible) {
viewPropertyAnimator = animate() viewPropertyAnimator = animate()
.alpha(0f) .alpha(0f)
.setDuration(1000L) .setDuration(FADE_DURATION)
.withEndAction { .withEndAction {
isVisible = false isVisible = false
viewPropertyAnimator = null viewPropertyAnimator = null
@ -138,3 +115,5 @@ class ReaderNavigationOverlayView(context: Context, attributeSet: AttributeSet)
return super.onTouchEvent(event) return super.onTouchEvent(event)
} }
} }
private const val FADE_DURATION = 1000L

View File

@ -2,13 +2,19 @@ package eu.kanade.tachiyomi.ui.reader.viewer
import android.graphics.PointF import android.graphics.PointF
import android.graphics.RectF import android.graphics.RectF
import androidx.annotation.StringRes
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferenceValues import eu.kanade.tachiyomi.data.preference.PreferenceValues
import eu.kanade.tachiyomi.util.lang.invert import eu.kanade.tachiyomi.util.lang.invert
abstract class ViewerNavigation { abstract class ViewerNavigation {
enum class NavigationRegion { sealed class NavigationRegion(@StringRes val nameRes: Int, val colorRes: Int) {
NEXT, PREV, MENU, RIGHT, LEFT object MENU : NavigationRegion(R.string.action_menu, R.color.navigation_menu)
object PREV : NavigationRegion(R.string.nav_zone_prev, R.color.navigation_prev)
object NEXT : NavigationRegion(R.string.nav_zone_next, R.color.navigation_next)
object LEFT : NavigationRegion(R.string.nav_zone_left, R.color.navigation_left)
object RIGHT : NavigationRegion(R.string.nav_zone_right, R.color.navigation_right)
} }
data class Region( data class Region(

View File

@ -253,7 +253,7 @@
<!-- Reader section --> <!-- Reader section -->
<string name="pref_fullscreen">Fullscreen</string> <string name="pref_fullscreen">Fullscreen</string>
<string name="pref_show_navigation_mode">Show navigation layout overlay</string> <string name="pref_show_navigation_mode">Show navigation layout overlay</string>
<string name="pref_show_navigation_mode_summary">Show overlay when reader is opened</string> <string name="pref_show_navigation_mode_summary">Briefly show tap zones when reader is opened</string>
<string name="pref_dual_page_split">Dual page split (ALPHA)</string> <string name="pref_dual_page_split">Dual page split (ALPHA)</string>
<string name="pref_dual_page_invert">Invert dual page split placement</string> <string name="pref_dual_page_invert">Invert dual page split placement</string>
<string name="pref_dual_page_invert_summary">If the placement of the dual page split doesn\'t match reading direction</string> <string name="pref_dual_page_invert_summary">If the placement of the dual page split doesn\'t match reading direction</string>
@ -300,6 +300,10 @@
<string name="kindlish_nav">Kindle-ish</string> <string name="kindlish_nav">Kindle-ish</string>
<string name="edge_nav">Edge</string> <string name="edge_nav">Edge</string>
<string name="right_and_left_nav">Right and Left</string> <string name="right_and_left_nav">Right and Left</string>
<string name="nav_zone_prev">Prev</string>
<string name="nav_zone_next">Next</string>
<string name="nav_zone_left">Left</string>
<string name="nav_zone_right">Right</string>
<string name="left_to_right_viewer">Left to right</string> <string name="left_to_right_viewer">Left to right</string>
<string name="right_to_left_viewer">Right to left</string> <string name="right_to_left_viewer">Right to left</string>
<string name="vertical_viewer">Vertical</string> <string name="vertical_viewer">Vertical</string>