[feat] Comic Resume
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.acitelight.aether.view
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
@@ -20,7 +21,9 @@ import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateListOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
@@ -37,28 +40,113 @@ import androidx.navigation.NavHostController
|
||||
import coil3.compose.AsyncImage
|
||||
import coil3.request.ImageRequest
|
||||
import com.acitelight.aether.Global
|
||||
import com.acitelight.aether.ToggleFullScreen
|
||||
import com.acitelight.aether.model.BookMark
|
||||
import com.acitelight.aether.model.Comic
|
||||
import com.acitelight.aether.model.ComicRecordDatabase
|
||||
import com.acitelight.aether.viewModel.ComicGridViewModel
|
||||
import java.util.EnumSet.range
|
||||
import java.util.stream.IntStream.range
|
||||
|
||||
@Composable
|
||||
fun ComicGridView(comicId: String, navController: NavHostController, comicGridViewModel: ComicGridViewModel = viewModel())
|
||||
{
|
||||
fun ComicGridView(comicId: String, navController: NavHostController, comicGridViewModel: ComicGridViewModel = viewModel()) {
|
||||
comicGridViewModel.SetupClient()
|
||||
comicGridViewModel.Resolve(comicId.hexToString())
|
||||
LazyColumn(modifier = Modifier.fillMaxWidth())
|
||||
{
|
||||
items(comicGridViewModel.chapterList)
|
||||
{
|
||||
c ->
|
||||
ChapterCard(comicGridViewModel.comic!!, navController, c, comicGridViewModel)
|
||||
comicGridViewModel.updateProcess(comicId.hexToString()){}
|
||||
ToggleFullScreen(false)
|
||||
|
||||
val context = LocalContext.current
|
||||
val comic by comicGridViewModel.comic
|
||||
val record by comicGridViewModel.record
|
||||
|
||||
if (comic != null) {
|
||||
Column {
|
||||
Box(
|
||||
Modifier
|
||||
.padding(horizontal = 16.dp).padding(top = 36.dp)
|
||||
.background(Color.White.copy(alpha = 0.65f), shape = RoundedCornerShape(12.dp))
|
||||
)
|
||||
{
|
||||
Column {
|
||||
Text(
|
||||
text = comic!!.comic.comic_name,
|
||||
fontSize = 18.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = Color.Black,
|
||||
maxLines = 1,
|
||||
modifier = Modifier.padding(4.dp)
|
||||
)
|
||||
|
||||
Text(
|
||||
text = comic!!.comic.author,
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = Color.Black,
|
||||
maxLines = 1,
|
||||
modifier = Modifier.padding(4.dp).fillMaxWidth()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
LazyColumn(modifier = Modifier.fillMaxWidth().weight(1f).padding(top = 6.dp).clip(RoundedCornerShape(6.dp)))
|
||||
{
|
||||
items(comicGridViewModel.chapterList)
|
||||
{ c ->
|
||||
ChapterCard(comic!!, navController, c, comicGridViewModel)
|
||||
}
|
||||
}
|
||||
|
||||
Box(
|
||||
Modifier
|
||||
.padding(horizontal = 16.dp).padding(top = 6.dp).padding(bottom = 20.dp).heightIn(min = 42.dp)
|
||||
.background(Color.White.copy(alpha = 0.65f), shape = RoundedCornerShape(12.dp))
|
||||
.clickable{
|
||||
comicGridViewModel.updateProcess(comicId.hexToString())
|
||||
{
|
||||
if(record != null) {
|
||||
val k = comic!!.getPageChapterIndex(record!!.position)!!
|
||||
val route = "comic_page_route/${"${comic!!.id}".toHex()}/${
|
||||
comic!!.getPageIndex(k.first.page)
|
||||
}"
|
||||
navController.navigate(route)
|
||||
}else
|
||||
{
|
||||
val route = "comic_page_route/${"${comic!!.id}".toHex()}/${0}"
|
||||
navController.navigate(route)
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
{
|
||||
Row(Modifier.fillMaxWidth().align(Alignment.Center).padding(horizontal = 8.dp)) {
|
||||
if(record != null)
|
||||
{
|
||||
val k = comic!!.getPageChapterIndex(record!!.position)!!
|
||||
|
||||
Text(
|
||||
text = "Last Read Position: ${k.first.name} ${k.second}/${comic!!.getChapterLength(k.first.page)}",
|
||||
fontSize = 20.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = Color.Black,
|
||||
maxLines = 1,
|
||||
modifier = Modifier.padding(4.dp).weight(1f)
|
||||
)
|
||||
}else{
|
||||
Text(
|
||||
text = "Read from scratch",
|
||||
fontSize = 20.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = Color.Black,
|
||||
maxLines = 1,
|
||||
modifier = Modifier.padding(4.dp).weight(1f)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Composable
|
||||
fun ChapterCard(comic: Comic, navController: NavHostController, chapter: BookMark, comicGridViewModel: ComicGridViewModel = viewModel())
|
||||
{
|
||||
@@ -70,7 +158,7 @@ fun ChapterCard(comic: Comic, navController: NavHostController, chapter: BookMar
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.wrapContentHeight()
|
||||
.padding(16.dp),
|
||||
.padding(horizontal = 16.dp).padding(vertical = 6.dp),
|
||||
onClick = {
|
||||
val route = "comic_page_route/${"${comic.id}".toHex()}/${comic.getPageIndex(chapter.page)}"
|
||||
navController.navigate(route)
|
||||
@@ -78,10 +166,10 @@ fun ChapterCard(comic: Comic, navController: NavHostController, chapter: BookMar
|
||||
) {
|
||||
Column(Modifier.fillMaxWidth())
|
||||
{
|
||||
Row(Modifier.padding(12.dp))
|
||||
Row(Modifier.padding(6.dp))
|
||||
{
|
||||
Box(Modifier
|
||||
.height(260.dp)
|
||||
.height(170.dp)
|
||||
.clip(RoundedCornerShape(8.dp))
|
||||
.background(Color(0x44FFFFFF)))
|
||||
{
|
||||
@@ -117,7 +205,7 @@ fun ChapterCard(comic: Comic, navController: NavHostController, chapter: BookMar
|
||||
}
|
||||
|
||||
val r = comic.comic.list.subList(iv, iv + comic.getChapterLength(c.page))
|
||||
LazyRow(modifier = Modifier.fillMaxWidth().padding(8.dp)) {
|
||||
LazyRow(modifier = Modifier.fillMaxWidth().padding(6.dp)) {
|
||||
items(r)
|
||||
{
|
||||
r ->
|
||||
@@ -126,7 +214,7 @@ fun ChapterCard(comic: Comic, navController: NavHostController, chapter: BookMar
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.wrapContentHeight()
|
||||
.height(200.dp)
|
||||
.height(140.dp)
|
||||
.padding(horizontal = 6.dp),
|
||||
onClick = {
|
||||
val route = "comic_page_route/${"${comic.id}".toHex()}/${comic.getPageIndex(r)}"
|
||||
|
||||
@@ -6,6 +6,7 @@ import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
@@ -25,6 +26,7 @@ import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
@@ -44,6 +46,7 @@ import androidx.navigation.NavHostController
|
||||
import coil3.compose.AsyncImage
|
||||
import coil3.request.ImageRequest
|
||||
import com.acitelight.aether.ToggleFullScreen
|
||||
import com.acitelight.aether.model.ComicRecord
|
||||
import com.acitelight.aether.viewModel.ComicPageViewModel
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
@@ -57,122 +60,188 @@ fun ComicPageView(comicId: String, page: String, navController: NavHostControll
|
||||
val pagerState = rememberPagerState(initialPage = page.toInt(), pageCount = { comicPageViewModel.pageList.size })
|
||||
var showPlane by comicPageViewModel.showPlane
|
||||
|
||||
Box()
|
||||
{
|
||||
HorizontalPager(
|
||||
state = pagerState,
|
||||
modifier = Modifier.fillMaxSize().align(Alignment.Center).background(Color.Black).clickable(){
|
||||
showPlane = !showPlane
|
||||
comicPageViewModel.UpdateProcess(pagerState.currentPage)
|
||||
|
||||
val comic by comicPageViewModel.comic
|
||||
comic?.let {
|
||||
Box()
|
||||
{
|
||||
HorizontalPager(
|
||||
state = pagerState,
|
||||
modifier = Modifier.fillMaxSize().align(Alignment.Center).background(Color.Black).clickable{
|
||||
showPlane = !showPlane
|
||||
if(showPlane)
|
||||
{
|
||||
comicPageViewModel.coroutineScope?.launch {
|
||||
comicPageViewModel.listState?.scrollToItem(index = pagerState.currentPage)
|
||||
}
|
||||
}
|
||||
}
|
||||
) {
|
||||
page ->
|
||||
AsyncImage(
|
||||
model = ImageRequest.Builder(LocalContext.current)
|
||||
.data(it.getPage(page))
|
||||
.memoryCacheKey("${it.id}/${page}")
|
||||
.diskCacheKey("${it.id}/${page}")
|
||||
.build(),
|
||||
contentDescription = null,
|
||||
imageLoader = comicPageViewModel.imageLoader!!,
|
||||
modifier = Modifier.padding(8.dp).fillMaxSize(),
|
||||
contentScale = ContentScale.Fit,
|
||||
)
|
||||
}
|
||||
) {
|
||||
page ->
|
||||
AsyncImage(
|
||||
model = ImageRequest.Builder(LocalContext.current)
|
||||
.data(comicPageViewModel.comic!!.getPage(page))
|
||||
.memoryCacheKey("${comicPageViewModel.comic!!.id}/${page}")
|
||||
.diskCacheKey("${comicPageViewModel.comic!!.id}/${page}")
|
||||
.build(),
|
||||
contentDescription = null,
|
||||
imageLoader = comicPageViewModel.imageLoader!!,
|
||||
modifier = Modifier.padding(8.dp).fillMaxSize(),
|
||||
contentScale = ContentScale.Fit,
|
||||
)
|
||||
}
|
||||
|
||||
androidx.compose.animation.AnimatedVisibility(
|
||||
visible = showPlane,
|
||||
enter = slideInVertically(initialOffsetY = { fullHeight -> -fullHeight }),
|
||||
exit = slideOutVertically(targetOffsetY = { fullHeight -> -fullHeight }),
|
||||
modifier = Modifier
|
||||
.align(Alignment.TopCenter)
|
||||
){
|
||||
Box()
|
||||
{
|
||||
Box(modifier = Modifier.height(180.dp).align(Alignment.TopCenter).fillMaxWidth().background(
|
||||
brush = Brush.verticalGradient(
|
||||
colors = listOf(
|
||||
Color.Black.copy(alpha = 0.75f),
|
||||
Color.Transparent,
|
||||
))))
|
||||
|
||||
|
||||
Row(modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(top = 18.dp).padding(horizontal = 12.dp)
|
||||
.height(60.dp)
|
||||
androidx.compose.animation.AnimatedVisibility(
|
||||
visible = showPlane,
|
||||
enter = slideInVertically(initialOffsetY = { fullHeight -> -fullHeight }),
|
||||
exit = slideOutVertically(targetOffsetY = { fullHeight -> -fullHeight }),
|
||||
modifier = Modifier
|
||||
.align(Alignment.TopCenter)
|
||||
.background(Color(0x90FFFFFF), shape = RoundedCornerShape(12.dp)))
|
||||
){
|
||||
Box()
|
||||
{
|
||||
Text(
|
||||
text = title,
|
||||
fontSize = 20.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = Color.Black,
|
||||
maxLines = 1,
|
||||
modifier = Modifier.padding(8.dp).padding(horizontal = 10.dp).weight(1f).align(Alignment.CenterVertically)
|
||||
)
|
||||
Box(modifier = Modifier.height(240.dp).align(Alignment.TopCenter).fillMaxWidth().background(
|
||||
brush = Brush.verticalGradient(
|
||||
colors = listOf(
|
||||
Color.Black.copy(alpha = 0.75f),
|
||||
Color.Transparent,
|
||||
))))
|
||||
|
||||
Text(
|
||||
text = "${pagerState.currentPage + 1}/${pagerState.pageCount}",
|
||||
fontSize = 24.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = Color.Black,
|
||||
maxLines = 1,
|
||||
modifier = Modifier.padding(8.dp).widthIn(120.dp).align(Alignment.CenterVertically)
|
||||
)
|
||||
Column(Modifier.align(Alignment.TopCenter).fillMaxWidth())
|
||||
{
|
||||
Row(modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(top = 18.dp).padding(horizontal = 12.dp)
|
||||
.height(42.dp)
|
||||
.background(Color(0x90FFFFFF), shape = RoundedCornerShape(12.dp)))
|
||||
{
|
||||
Text(
|
||||
text = title,
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = Color.Black,
|
||||
maxLines = 1,
|
||||
modifier = Modifier.padding(8.dp).padding(horizontal = 10.dp).weight(1f).align(Alignment.CenterVertically)
|
||||
)
|
||||
|
||||
Text(
|
||||
text = "${pagerState.currentPage + 1}/${pagerState.pageCount}",
|
||||
fontSize = 18.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = Color.Black,
|
||||
maxLines = 1,
|
||||
modifier = Modifier.padding(8.dp).widthIn(min = 60.dp).align(Alignment.CenterVertically)
|
||||
)
|
||||
}
|
||||
Row(modifier = Modifier
|
||||
.padding(top = 6.dp).padding(horizontal = 12.dp)
|
||||
.height(42.dp)
|
||||
.background(Color(0x90FFFFFF), shape = RoundedCornerShape(12.dp)))
|
||||
{
|
||||
val k = it.getPageChapterIndex(pagerState.currentPage)!!
|
||||
Text(
|
||||
text = k.first.name,
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = Color.Black,
|
||||
maxLines = 1,
|
||||
modifier = Modifier.padding(8.dp).padding(horizontal = 10.dp).align(Alignment.CenterVertically)
|
||||
)
|
||||
|
||||
Text(
|
||||
text = "${k.second}/${it.getChapterLength(k.first.page)}",
|
||||
fontSize = 18.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = Color.Black,
|
||||
maxLines = 1,
|
||||
modifier = Modifier.padding(8.dp).widthIn(min = 60.dp).align(Alignment.CenterVertically)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
androidx.compose.animation.AnimatedVisibility(
|
||||
visible = showPlane,
|
||||
enter = slideInVertically(initialOffsetY = { fullHeight -> fullHeight }),
|
||||
exit = slideOutVertically(targetOffsetY = { fullHeight -> fullHeight }),
|
||||
modifier = Modifier
|
||||
.align(Alignment.BottomCenter)
|
||||
)
|
||||
{
|
||||
Box{
|
||||
Box(modifier = Modifier.height(360.dp).align(Alignment.BottomCenter).fillMaxWidth().background(
|
||||
brush = Brush.verticalGradient(
|
||||
colors = listOf(
|
||||
Color.Transparent,
|
||||
Color.Black.copy(alpha = 0.90f),
|
||||
))))
|
||||
|
||||
LazyRow (state = comicPageViewModel.listState!!, modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(bottom = 18.dp).padding(horizontal = 12.dp)
|
||||
.height(240.dp)
|
||||
androidx.compose.animation.AnimatedVisibility(
|
||||
visible = showPlane,
|
||||
enter = slideInVertically(initialOffsetY = { fullHeight -> fullHeight }),
|
||||
exit = slideOutVertically(targetOffsetY = { fullHeight -> fullHeight }),
|
||||
modifier = Modifier
|
||||
.align(Alignment.BottomCenter)
|
||||
.background(Color(0x90999999), shape = RoundedCornerShape(12.dp)))
|
||||
{
|
||||
items(comicPageViewModel.pageList.size)
|
||||
)
|
||||
{
|
||||
Box{
|
||||
Box(modifier = Modifier.height(360.dp).align(Alignment.BottomCenter).fillMaxWidth().background(
|
||||
brush = Brush.verticalGradient(
|
||||
colors = listOf(
|
||||
Color.Transparent,
|
||||
Color.Black.copy(alpha = 0.90f),
|
||||
))))
|
||||
|
||||
LazyRow (state = comicPageViewModel.listState!!, modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(bottom = 18.dp).padding(horizontal = 12.dp)
|
||||
.height(240.dp)
|
||||
.align(Alignment.BottomCenter)
|
||||
.background(Color(0x90999999), shape = RoundedCornerShape(12.dp)))
|
||||
{
|
||||
r ->
|
||||
Card(
|
||||
shape = RoundedCornerShape(12.dp),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.wrapContentHeight()
|
||||
.padding(horizontal = 6.dp).padding(vertical = 6.dp),
|
||||
onClick = {
|
||||
pagerState.requestScrollToPage(page = r)
|
||||
}
|
||||
){
|
||||
AsyncImage(
|
||||
model = ImageRequest.Builder(LocalContext.current)
|
||||
.data(comicPageViewModel.comic!!.getPage(r))
|
||||
.memoryCacheKey("${comicPageViewModel.comic!!.id}/${r}")
|
||||
.diskCacheKey("${comicPageViewModel.comic!!.id}/${r}")
|
||||
.build(),
|
||||
contentDescription = null,
|
||||
imageLoader = comicPageViewModel.imageLoader!!,
|
||||
items(comicPageViewModel.pageList.size)
|
||||
{
|
||||
r ->
|
||||
Card(
|
||||
shape = RoundedCornerShape(12.dp),
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.clip(RoundedCornerShape(12.dp)),
|
||||
contentScale = ContentScale.Fit,
|
||||
)
|
||||
.fillMaxWidth()
|
||||
.wrapContentHeight()
|
||||
.padding(horizontal = 6.dp).padding(vertical = 6.dp),
|
||||
onClick = {
|
||||
pagerState.requestScrollToPage(page = r)
|
||||
}
|
||||
){
|
||||
Box(Modifier.fillMaxSize())
|
||||
{
|
||||
AsyncImage(
|
||||
model = ImageRequest.Builder(LocalContext.current)
|
||||
.data(it.getPage(r))
|
||||
.memoryCacheKey("${it.id}/${r}")
|
||||
.diskCacheKey("${it.id}/${r}")
|
||||
.build(),
|
||||
contentDescription = null,
|
||||
imageLoader = comicPageViewModel.imageLoader!!,
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.clip(RoundedCornerShape(12.dp))
|
||||
.align(Alignment.Center),
|
||||
contentScale = ContentScale.Fit,
|
||||
)
|
||||
val k = it.getPageChapterIndex(r)!!
|
||||
Box(Modifier
|
||||
.align(Alignment.TopEnd)
|
||||
.padding(6.dp)
|
||||
.background(Color.Black.copy(alpha = 0.65f), shape = RoundedCornerShape(12.dp)))
|
||||
{
|
||||
Row{
|
||||
Text(
|
||||
text = k.first.name,
|
||||
fontSize = 14.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = Color.White,
|
||||
maxLines = 1,
|
||||
modifier = Modifier.padding(4.dp).align(Alignment.CenterVertically)
|
||||
)
|
||||
|
||||
Text(
|
||||
text = "${k.second}/${it.getChapterLength(k.first.page)}",
|
||||
fontSize = 16.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = Color.White,
|
||||
maxLines = 1,
|
||||
modifier = Modifier.padding(4.dp).fillMaxWidth().align(Alignment.CenterVertically)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ fun VideoScreen(videoScreenViewModel: VideoScreenViewModel = viewModel(), navCon
|
||||
TopRow(videoScreenViewModel);
|
||||
|
||||
LazyVerticalGrid(
|
||||
columns = GridCells.Adaptive(200.dp),
|
||||
columns = GridCells.Adaptive(160.dp),
|
||||
contentPadding = PaddingValues(8.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||
|
||||
Reference in New Issue
Block a user