From 7c012010558d5e7a2ea32a8aaef3c908fdc52799 Mon Sep 17 00:00:00 2001 From: arkon Date: Thu, 12 Oct 2023 22:42:49 -0400 Subject: [PATCH] Refactor reader bottom bar to presentation package --- .../reader/{ => appbars}/BottomReaderBar.kt | 2 +- .../reader/{ => appbars}/ChapterNavigator.kt | 2 +- .../reader/appbars/ReaderAppBars.kt | 88 +++++++++++++ .../tachiyomi/ui/reader/ReaderActivity.kt | 124 +++++++----------- app/src/main/res/layout/reader_activity.xml | 6 - 5 files changed, 141 insertions(+), 81 deletions(-) rename app/src/main/java/eu/kanade/presentation/reader/{ => appbars}/BottomReaderBar.kt (98%) rename app/src/main/java/eu/kanade/presentation/reader/{ => appbars}/ChapterNavigator.kt (99%) create mode 100644 app/src/main/java/eu/kanade/presentation/reader/appbars/ReaderAppBars.kt diff --git a/app/src/main/java/eu/kanade/presentation/reader/BottomReaderBar.kt b/app/src/main/java/eu/kanade/presentation/reader/appbars/BottomReaderBar.kt similarity index 98% rename from app/src/main/java/eu/kanade/presentation/reader/BottomReaderBar.kt rename to app/src/main/java/eu/kanade/presentation/reader/appbars/BottomReaderBar.kt index e88692ff09..ec6acdd781 100644 --- a/app/src/main/java/eu/kanade/presentation/reader/BottomReaderBar.kt +++ b/app/src/main/java/eu/kanade/presentation/reader/appbars/BottomReaderBar.kt @@ -1,4 +1,4 @@ -package eu.kanade.presentation.reader +package eu.kanade.presentation.reader.appbars import androidx.compose.foundation.background import androidx.compose.foundation.isSystemInDarkTheme diff --git a/app/src/main/java/eu/kanade/presentation/reader/ChapterNavigator.kt b/app/src/main/java/eu/kanade/presentation/reader/appbars/ChapterNavigator.kt similarity index 99% rename from app/src/main/java/eu/kanade/presentation/reader/ChapterNavigator.kt rename to app/src/main/java/eu/kanade/presentation/reader/appbars/ChapterNavigator.kt index 6432b8e1bd..31a9a905fe 100644 --- a/app/src/main/java/eu/kanade/presentation/reader/ChapterNavigator.kt +++ b/app/src/main/java/eu/kanade/presentation/reader/appbars/ChapterNavigator.kt @@ -1,4 +1,4 @@ -package eu.kanade.presentation.reader +package eu.kanade.presentation.reader.appbars import androidx.compose.foundation.background import androidx.compose.foundation.interaction.MutableInteractionSource diff --git a/app/src/main/java/eu/kanade/presentation/reader/appbars/ReaderAppBars.kt b/app/src/main/java/eu/kanade/presentation/reader/appbars/ReaderAppBars.kt new file mode 100644 index 0000000000..1bd4d54ac3 --- /dev/null +++ b/app/src/main/java/eu/kanade/presentation/reader/appbars/ReaderAppBars.kt @@ -0,0 +1,88 @@ +package eu.kanade.presentation.reader.appbars + +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.animation.core.tween +import androidx.compose.animation.slideInVertically +import androidx.compose.animation.slideOutVertically +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.IntOffset +import androidx.compose.ui.unit.dp +import eu.kanade.tachiyomi.ui.reader.setting.OrientationType +import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType +import eu.kanade.tachiyomi.ui.reader.viewer.Viewer +import eu.kanade.tachiyomi.ui.reader.viewer.pager.R2LPagerViewer + +private val animationSpec = tween(200) + +@Composable +fun ReaderAppBars( + visible: Boolean, + viewer: Viewer?, + + onNextChapter: () -> Unit, + enabledNext: Boolean, + onPreviousChapter: () -> Unit, + enabledPrevious: Boolean, + currentPage: Int, + totalPages: Int, + onSliderValueChange: (Int) -> Unit, + + readingMode: ReadingModeType, + onClickReadingMode: () -> Unit, + orientationMode: OrientationType, + onClickOrientationMode: () -> Unit, + cropEnabled: Boolean, + onClickCropBorder: () -> Unit, + onClickSettings: () -> Unit, +) { + val isRtl = viewer is R2LPagerViewer + + Column( + modifier = Modifier.fillMaxHeight(), + verticalArrangement = Arrangement.SpaceBetween, + ) { + Spacer(modifier = Modifier.weight(1f)) + + AnimatedVisibility( + visible = visible, + enter = slideInVertically( + initialOffsetY = { it }, + animationSpec = animationSpec, + ), + exit = slideOutVertically( + targetOffsetY = { it }, + animationSpec = animationSpec, + ), + ) { + Column( + verticalArrangement = Arrangement.spacedBy(8.dp), + ) { + ChapterNavigator( + isRtl = isRtl, + onNextChapter = onNextChapter, + enabledNext = enabledNext, + onPreviousChapter = onPreviousChapter, + enabledPrevious = enabledPrevious, + currentPage = currentPage, + totalPages = totalPages, + onSliderValueChange = onSliderValueChange, + ) + + BottomReaderBar( + readingMode = readingMode, + onClickReadingMode = onClickReadingMode, + orientationMode = orientationMode, + onClickOrientationMode = onClickOrientationMode, + cropEnabled = cropEnabled, + onClickCropBorder = onClickCropBorder, + onClickSettings = onClickSettings, + ) + } + } + } +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index 365ee46d50..8f855a32f2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -24,12 +24,7 @@ import android.view.animation.Animation import android.view.animation.AnimationUtils import android.widget.Toast import androidx.activity.viewModels -import androidx.compose.animation.AnimatedVisibility -import androidx.compose.animation.core.tween -import androidx.compose.animation.slideInVertically -import androidx.compose.animation.slideOutVertically import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.material3.AlertDialog import androidx.compose.material3.CircularProgressIndicator @@ -54,12 +49,11 @@ import com.google.android.material.shape.MaterialShapeDrawable import com.google.android.material.transition.platform.MaterialContainerTransform import dev.chrisbanes.insetter.applyInsetter import eu.kanade.domain.base.BasePreferences -import eu.kanade.presentation.reader.BottomReaderBar -import eu.kanade.presentation.reader.ChapterNavigator import eu.kanade.presentation.reader.OrientationModeSelectDialog import eu.kanade.presentation.reader.PageIndicatorText import eu.kanade.presentation.reader.ReaderPageActionsDialog import eu.kanade.presentation.reader.ReadingModeSelectDialog +import eu.kanade.presentation.reader.appbars.ReaderAppBars import eu.kanade.presentation.reader.settings.ReaderSettingsDialog import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.notification.NotificationReceiver @@ -79,7 +73,6 @@ import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences import eu.kanade.tachiyomi.ui.reader.setting.ReaderSettingsScreenModel import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType import eu.kanade.tachiyomi.ui.reader.viewer.ReaderProgressIndicator -import eu.kanade.tachiyomi.ui.reader.viewer.pager.R2LPagerViewer import eu.kanade.tachiyomi.ui.webview.WebViewActivity import eu.kanade.tachiyomi.util.system.applySystemAnimatorScale import eu.kanade.tachiyomi.util.system.hasDisplayCutout @@ -366,9 +359,9 @@ class ReaderActivity : BaseActivity() { margin(top = true, horizontal = true) } } - binding.readerMenuBottom.applyInsetter { + binding.dialogRoot.applyInsetter { type(navigationBars = true) { - margin(bottom = true, horizontal = true) + margin(vertical = true, horizontal = true) } } @@ -407,6 +400,54 @@ class ReaderActivity : BaseActivity() { ) } + val cropBorderPaged by readerPreferences.cropBorders().collectAsState() + val cropBorderWebtoon by readerPreferences.cropBordersWebtoon().collectAsState() + val isPagerType = ReadingModeType.isPagerType(viewModel.getMangaReadingMode()) + val cropEnabled = if (isPagerType) cropBorderPaged else cropBorderWebtoon + + ReaderAppBars( + visible = state.menuVisible, + viewer = state.viewer, + + onNextChapter = ::loadNextChapter, + enabledNext = state.viewerChapters?.nextChapter != null, + onPreviousChapter = ::loadPreviousChapter, + enabledPrevious = state.viewerChapters?.prevChapter != null, + currentPage = state.currentPage, + totalPages = state.totalPages, + onSliderValueChange = { + isScrollingThroughPages = true + moveToPageIndex(it) + }, + + readingMode = ReadingModeType.fromPreference( + viewModel.getMangaReadingMode( + resolveDefault = false, + ), + ), + onClickReadingMode = viewModel::openReadingModeSelectDialog, + orientationMode = OrientationType.fromPreference( + viewModel.getMangaOrientationType( + resolveDefault = false, + ), + ), + onClickOrientationMode = viewModel::openOrientationModeSelectDialog, + cropEnabled = cropEnabled, + onClickCropBorder = { + val enabled = viewModel.toggleCropBorders() + + menuToggleToast?.cancel() + menuToggleToast = toast( + if (enabled) { + R.string.on + } else { + R.string.off + }, + ) + }, + onClickSettings = viewModel::openSettingsDialog, + ) + val onDismissRequest = viewModel::closeDialog when (state.dialog) { is ReaderViewModel.Dialog.Loading -> { @@ -466,69 +507,6 @@ class ReaderActivity : BaseActivity() { } } - binding.readerMenuBottom.setComposeContent { - val state by viewModel.state.collectAsState() - - if (state.viewer == null) return@setComposeContent - val isRtl = state.viewer is R2LPagerViewer - - val cropBorderPaged by readerPreferences.cropBorders().collectAsState() - val cropBorderWebtoon by readerPreferences.cropBordersWebtoon().collectAsState() - val isPagerType = ReadingModeType.isPagerType(viewModel.getMangaReadingMode()) - val cropEnabled = if (isPagerType) cropBorderPaged else cropBorderWebtoon - - AnimatedVisibility( - visible = state.menuVisible, - enter = slideInVertically( - initialOffsetY = { it }, - animationSpec = tween(200), - ), - exit = slideOutVertically( - targetOffsetY = { it }, - animationSpec = tween(200), - ), - ) { - Column( - verticalArrangement = Arrangement.spacedBy(8.dp), - ) { - ChapterNavigator( - isRtl = isRtl, - onNextChapter = ::loadNextChapter, - enabledNext = state.viewerChapters?.nextChapter != null, - onPreviousChapter = ::loadPreviousChapter, - enabledPrevious = state.viewerChapters?.prevChapter != null, - currentPage = state.currentPage, - totalPages = state.totalPages, - onSliderValueChange = { - isScrollingThroughPages = true - moveToPageIndex(it) - }, - ) - - BottomReaderBar( - readingMode = ReadingModeType.fromPreference(viewModel.getMangaReadingMode(resolveDefault = false)), - onClickReadingMode = viewModel::openReadingModeSelectDialog, - orientationMode = OrientationType.fromPreference(viewModel.getMangaOrientationType(resolveDefault = false)), - onClickOrientationMode = viewModel::openOrientationModeSelectDialog, - cropEnabled = cropEnabled, - onClickCropBorder = { - val enabled = viewModel.toggleCropBorders() - - menuToggleToast?.cancel() - menuToggleToast = toast( - if (enabled) { - R.string.on - } else { - R.string.off - }, - ) - }, - onClickSettings = viewModel::openSettingsDialog, - ) - } - } - } - val toolbarBackground = (binding.toolbar.background as MaterialShapeDrawable).apply { elevation = resources.getDimension(R.dimen.m3_sys_elevation_level2) alpha = if (isNightMode()) 230 else 242 // 90% dark 95% light diff --git a/app/src/main/res/layout/reader_activity.xml b/app/src/main/res/layout/reader_activity.xml index b7e34e9875..ac9b535b05 100644 --- a/app/src/main/res/layout/reader_activity.xml +++ b/app/src/main/res/layout/reader_activity.xml @@ -56,12 +56,6 @@ android:layout_height="wrap_content" android:minHeight="?attr/actionBarSize" /> - -