mirror of
https://github.com/aniyomiorg/aniyomi.git
synced 2024-11-23 13:23:28 +03:00
Refactor reader bottom bar to presentation package
This commit is contained in:
parent
90d3dd2242
commit
7c01201055
5 changed files with 141 additions and 81 deletions
|
@ -1,4 +1,4 @@
|
||||||
package eu.kanade.presentation.reader
|
package eu.kanade.presentation.reader.appbars
|
||||||
|
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.isSystemInDarkTheme
|
import androidx.compose.foundation.isSystemInDarkTheme
|
|
@ -1,4 +1,4 @@
|
||||||
package eu.kanade.presentation.reader
|
package eu.kanade.presentation.reader.appbars
|
||||||
|
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
|
@ -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<IntOffset>(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,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -24,12 +24,7 @@ import android.view.animation.Animation
|
||||||
import android.view.animation.AnimationUtils
|
import android.view.animation.AnimationUtils
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.activity.viewModels
|
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.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.material3.AlertDialog
|
import androidx.compose.material3.AlertDialog
|
||||||
import androidx.compose.material3.CircularProgressIndicator
|
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 com.google.android.material.transition.platform.MaterialContainerTransform
|
||||||
import dev.chrisbanes.insetter.applyInsetter
|
import dev.chrisbanes.insetter.applyInsetter
|
||||||
import eu.kanade.domain.base.BasePreferences
|
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.OrientationModeSelectDialog
|
||||||
import eu.kanade.presentation.reader.PageIndicatorText
|
import eu.kanade.presentation.reader.PageIndicatorText
|
||||||
import eu.kanade.presentation.reader.ReaderPageActionsDialog
|
import eu.kanade.presentation.reader.ReaderPageActionsDialog
|
||||||
import eu.kanade.presentation.reader.ReadingModeSelectDialog
|
import eu.kanade.presentation.reader.ReadingModeSelectDialog
|
||||||
|
import eu.kanade.presentation.reader.appbars.ReaderAppBars
|
||||||
import eu.kanade.presentation.reader.settings.ReaderSettingsDialog
|
import eu.kanade.presentation.reader.settings.ReaderSettingsDialog
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
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.ReaderSettingsScreenModel
|
||||||
import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType
|
import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType
|
||||||
import eu.kanade.tachiyomi.ui.reader.viewer.ReaderProgressIndicator
|
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.ui.webview.WebViewActivity
|
||||||
import eu.kanade.tachiyomi.util.system.applySystemAnimatorScale
|
import eu.kanade.tachiyomi.util.system.applySystemAnimatorScale
|
||||||
import eu.kanade.tachiyomi.util.system.hasDisplayCutout
|
import eu.kanade.tachiyomi.util.system.hasDisplayCutout
|
||||||
|
@ -366,9 +359,9 @@ class ReaderActivity : BaseActivity() {
|
||||||
margin(top = true, horizontal = true)
|
margin(top = true, horizontal = true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
binding.readerMenuBottom.applyInsetter {
|
binding.dialogRoot.applyInsetter {
|
||||||
type(navigationBars = true) {
|
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
|
val onDismissRequest = viewModel::closeDialog
|
||||||
when (state.dialog) {
|
when (state.dialog) {
|
||||||
is ReaderViewModel.Dialog.Loading -> {
|
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 {
|
val toolbarBackground = (binding.toolbar.background as MaterialShapeDrawable).apply {
|
||||||
elevation = resources.getDimension(R.dimen.m3_sys_elevation_level2)
|
elevation = resources.getDimension(R.dimen.m3_sys_elevation_level2)
|
||||||
alpha = if (isNightMode()) 230 else 242 // 90% dark 95% light
|
alpha = if (isNightMode()) 230 else 242 // 90% dark 95% light
|
||||||
|
|
|
@ -56,12 +56,6 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:minHeight="?attr/actionBarSize" />
|
android:minHeight="?attr/actionBarSize" />
|
||||||
|
|
||||||
<androidx.compose.ui.platform.ComposeView
|
|
||||||
android:id="@+id/reader_menu_bottom"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="bottom" />
|
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
<androidx.compose.ui.platform.ComposeView
|
<androidx.compose.ui.platform.ComposeView
|
||||||
|
|
Loading…
Reference in a new issue