From 5ef907d04629fc5135147c3b5b108fd817c3c406 Mon Sep 17 00:00:00 2001 From: MuhamadSyabitHidayattulloh Date: Thu, 11 Sep 2025 09:36:24 +0700 Subject: [PATCH] fix: Ui not visible if Control Panel show --- .../kotatsu/reader/ui/ReaderActivity.kt | 7 ++++++ .../kotatsu/reader/ui/ReaderViewModel.kt | 8 +++++++ .../ui/pager/webtoon/WebtoonReaderFragment.kt | 24 +++++++++++++++---- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderActivity.kt b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderActivity.kt index c32e46d94..a536bab7e 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderActivity.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderActivity.kt @@ -374,6 +374,9 @@ class ReaderActivity : viewBinding.infoBar.isTimeVisible = isFullscreen updateScrollTimerButton() systemUiController.setSystemUiVisible(isUiVisible || !isFullscreen) + val topOffset = if (isUiVisible) viewBinding.appbarTop.height else 0 + val bottomOffset = if (isUiVisible) (viewBinding.toolbarDocked?.height ?: 0) else 0 + viewModel.setReaderUiOffsets(topOffset, bottomOffset) } } @@ -395,6 +398,10 @@ class ReaderActivity : viewBinding.infoBar.updatePadding( top = systemBars.top, ) + viewModel.setReaderUiOffsets( + (if (viewBinding.appbarTop.isVisible) viewBinding.appbarTop.height else 0) + systemBars.top, + (if (viewBinding.toolbarDocked?.isVisible == true) (viewBinding.toolbarDocked?.height ?: 0) else 0) + systemBars.bottom, + ) return WindowInsetsCompat.Builder(insets) .setInsets(WindowInsetsCompat.Type.systemBars(), Insets.NONE) .build() diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderViewModel.kt index e951521d2..d1804e2f0 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/ReaderViewModel.kt @@ -120,6 +120,9 @@ class ReaderViewModel @Inject constructor( val onAskNsfwIncognito = MutableEventFlow() val uiState = MutableStateFlow(null) + val readerUiTopOffset = MutableStateFlow(0) + val readerUiBottomOffset = MutableStateFlow(0) + val isIncognitoMode = MutableStateFlow(savedStateHandle.get(ReaderIntent.EXTRA_INCOGNITO)) val content = MutableStateFlow(ReaderContent(emptyList(), null)) @@ -227,6 +230,11 @@ class ReaderViewModel @Inject constructor( discordRpc.setIdle() } + fun setReaderUiOffsets(top: Int, bottom: Int) { + readerUiTopOffset.value = top + readerUiBottomOffset.value = bottom + } + fun switchMode(newMode: ReaderMode) { launchJob { val manga = checkNotNull(getMangaOrNull()) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/webtoon/WebtoonReaderFragment.kt b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/webtoon/WebtoonReaderFragment.kt index 15f4325e3..9d22f3292 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/webtoon/WebtoonReaderFragment.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/reader/ui/pager/webtoon/WebtoonReaderFragment.kt @@ -49,6 +49,12 @@ class WebtoonReaderFragment : BaseReaderFragment() super.onViewBindingCreated(binding, savedInstanceState) var canGoPrev = true var canGoNext = true + viewModel.readerUiTopOffset.observe(viewLifecycleOwner) { top -> + binding.feedbackTop.translationY = top.toFloat() + } + viewModel.readerUiBottomOffset.observe(viewLifecycleOwner) { bottom -> + binding.feedbackBottom.translationY = -bottom.toFloat() + } with(binding.recyclerView) { setHasFixedSize(true) adapter = readerAdapter @@ -59,17 +65,17 @@ class WebtoonReaderFragment : BaseReaderFragment() setOnPullGestureListener(object : WebtoonRecyclerView.OnPullGestureListener { override fun onPullProgressTop(progress: Float) { if (canGoPrev) { - binding.feedbackTop.setText(R.string.pull_to_prev_chapter) + setFeedbackText(binding.feedbackTop, getString(R.string.pull_to_prev_chapter)) } else { - binding.feedbackTop.setText(R.string.pull_top_no_prev) + setFeedbackText(binding.feedbackTop, getString(R.string.pull_top_no_prev)) } updateFeedback(binding.feedbackTop, progress) } override fun onPullProgressBottom(progress: Float) { if (canGoNext) { - binding.feedbackBottom.setText(R.string.pull_to_next_chapter) + setFeedbackText(binding.feedbackBottom, getString(R.string.pull_to_next_chapter)) } else { - binding.feedbackBottom.setText(R.string.pull_bottom_no_next) + setFeedbackText(binding.feedbackBottom, getString(R.string.pull_bottom_no_next)) } updateFeedback(binding.feedbackBottom, progress) } @@ -241,3 +247,13 @@ private fun updateFeedback(tv: TextView, progress: Float) { private fun fadeOut(tv: TextView) { tv.animate().alpha(0f).setDuration(150L).start() } + +private fun setFeedbackText(tv: TextView, text: CharSequence) { + if (tv.alpha <= 0f && text.isNotEmpty()) { + tv.alpha = 0f + tv.text = text + tv.animate().alpha(1f).setDuration(120L).start() + } else { + tv.text = text + } +}