Simplify alignment menu logic

This commit is contained in:
davide 2022-08-16 12:02:20 +02:00
parent 00ef93f0c5
commit 32e7a8f19c

View File

@ -150,7 +150,8 @@ class ReaderActivity : AppCompatActivity(), DIAware {
} }
} }
private fun alignmentMenu(showJustify: Boolean) { private fun alignmentMenu() {
val showJustify = activeAlignment == ALIGN_LEFT
toolbarMenu.findItem(R.id.align_left).isVisible = !showJustify toolbarMenu.findItem(R.id.align_left).isVisible = !showJustify
toolbarMenu.findItem(R.id.align_justify).isVisible = showJustify toolbarMenu.findItem(R.id.align_justify).isVisible = showJustify
} }
@ -165,11 +166,7 @@ class ReaderActivity : AppCompatActivity(), DIAware {
} else { } else {
canFavorite() canFavorite()
} }
if (activeAlignment == JUSTIFY) { alignmentMenu()
alignmentMenu(false)
} else {
alignmentMenu(true)
}
binding.pager.registerOnPageChangeCallback( binding.pager.registerOnPageChangeCallback(
object : ViewPager2.OnPageChangeCallback() { object : ViewPager2.OnPageChangeCallback() {
@ -223,19 +220,24 @@ class ReaderActivity : AppCompatActivity(), DIAware {
} }
} }
R.id.align_left -> { R.id.align_left -> {
settings.putInt("text_align", ALIGN_LEFT) activeAlignment = ALIGN_LEFT
alignmentMenu(true) switchAlignmentSetting()
refreshFragment() refreshFragment()
} }
R.id.align_justify -> { R.id.align_justify -> {
settings.putInt("text_align", JUSTIFY) activeAlignment = JUSTIFY
alignmentMenu(false) switchAlignmentSetting()
refreshFragment() refreshFragment()
} }
} }
return super.onOptionsItemSelected(item) return super.onOptionsItemSelected(item)
} }
private fun switchAlignmentSetting() {
settings.putInt("text_align", activeAlignment)
alignmentMenu()
}
private fun refreshFragment() { private fun refreshFragment() {
finish() finish()
overridePendingTransition(0, 0) overridePendingTransition(0, 0)