Support imagescale in the reader

This commit is contained in:
Syer10
2021-05-28 19:00:40 -04:00
parent c05e9bfbf2
commit db5f95ff48
3 changed files with 26 additions and 3 deletions

View File

@@ -29,6 +29,7 @@ import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import ca.gosyer.common.di.AppScope
import ca.gosyer.data.reader.model.ImageScale
import ca.gosyer.data.reader.model.NavigationMode
import ca.gosyer.data.ui.UiPreferences
import ca.gosyer.data.ui.model.WindowSettings
@@ -164,10 +165,12 @@ fun ReaderMenu(chapterIndex: Int, mangaId: Long, setHotkeys: (List<KeyboardShort
if (continuous) {
ContinuousReader(
pages,
currentPage,
previousChapter,
chapter,
nextChapter,
pageModifier,
imageScale.toContentScale(),
vm.pageEmitter,
vm::retry,
vm::progress
@@ -181,6 +184,7 @@ fun ReaderMenu(chapterIndex: Int, mangaId: Long, setHotkeys: (List<KeyboardShort
chapter,
nextChapter,
pageModifier,
imageScale.toContentScale(),
vm.pageEmitter,
vm::retry,
vm::progress
@@ -254,3 +258,12 @@ fun NavigationMode.toNavigation() = when (this) {
NavigationMode.LNavigation -> LNavigation()
NavigationMode.EdgeNavigation -> EdgeNavigation()
}
fun ImageScale.toContentScale() = when (this) {
ImageScale.FitScreen -> ContentScale.Inside
ImageScale.FitHeight -> ContentScale.FillHeight
ImageScale.FitWidth -> ContentScale.FillHeight
ImageScale.OriginalSize -> ContentScale.None
ImageScale.SmartFit -> ContentScale.Fit
ImageScale.Stretch -> ContentScale.FillBounds
}

View File

@@ -15,6 +15,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import ca.gosyer.ui.reader.ChapterSeperator
import ca.gosyer.ui.reader.ReaderImage
import ca.gosyer.ui.reader.model.MoveTo
@@ -27,16 +28,18 @@ import kotlinx.coroutines.flow.mapLatest
@Composable
fun ContinuousReader(
pages: List<ReaderPage>,
currentPage: Int,
previousChapter: ReaderChapter?,
currentChapter: ReaderChapter,
nextChapter: ReaderChapter?,
pageModifier: Modifier,
pageContentScale: ContentScale,
pageEmitter: SharedFlow<Pair<MoveTo, Int>>,
retry: (ReaderPage) -> Unit,
progress: (Int) -> Unit
) {
BoxWithConstraints {
val state = rememberLazyListState(1)
val state = rememberLazyListState(currentPage)
LaunchedEffect(Unit) {
pageEmitter
.mapLatest { (moveTo) ->
@@ -69,7 +72,8 @@ fun ContinuousReader(
loadingModifier = pageModifier,
retry = { pageIndex ->
pages.find { it.index == pageIndex }?.let { retry(it) }
}
},
contentScale = pageContentScale
)
}
item {

View File

@@ -10,6 +10,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import ca.gosyer.data.reader.model.Direction
import ca.gosyer.ui.reader.ChapterSeperator
import ca.gosyer.ui.reader.ReaderImage
@@ -32,6 +33,7 @@ fun PagerReader(
currentChapter: ReaderChapter,
nextChapter: ReaderChapter?,
pageModifier: Modifier,
pageContentScale: ContentScale,
pageEmitter: SharedFlow<Pair<MoveTo, Int>>,
retry: (ReaderPage) -> Unit,
progress: (Int) -> Unit
@@ -65,6 +67,7 @@ fun PagerReader(
currentChapter,
nextChapter,
pageModifier,
pageContentScale,
retry
)
}
@@ -77,6 +80,7 @@ fun PagerReader(
currentChapter,
nextChapter,
pageModifier,
pageContentScale,
retry
)
}
@@ -91,6 +95,7 @@ fun HandlePager(
currentChapter: ReaderChapter,
nextChapter: ReaderChapter?,
pageModifier: Modifier,
pageContentScale: ContentScale,
retry: (ReaderPage) -> Unit,
) {
when (page) {
@@ -107,7 +112,8 @@ fun HandlePager(
loadingModifier = pageModifier,
retry = { pageIndex ->
pages.find { it.index == pageIndex }?.let { retry(it) }
}
},
contentScale = pageContentScale
)
}
}