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