From 32e7a8f19cc4faa3a0b16fe4ff1fbe17363a6bce Mon Sep 17 00:00:00 2001 From: davide Date: Tue, 16 Aug 2022 12:02:20 +0200 Subject: [PATCH] Simplify alignment menu logic --- .../android/ReaderActivity.kt | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ReaderActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ReaderActivity.kt index 021ffde..f4eb03d 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ReaderActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ReaderActivity.kt @@ -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)