[feat] Comic Reader

This commit is contained in:
acite
2025-09-01 20:41:28 +08:00
parent ea574895ab
commit daa66a9ecc
12 changed files with 703 additions and 41 deletions

View File

@@ -0,0 +1,154 @@
package com.acitelight.aether.view
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
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.mutableStateListOf
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController
import coil3.compose.AsyncImage
import coil3.request.ImageRequest
import com.acitelight.aether.Global
import com.acitelight.aether.model.BookMark
import com.acitelight.aether.model.Comic
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())
{
comicGridViewModel.SetupClient()
comicGridViewModel.Resolve(comicId.hexToString())
LazyColumn(modifier = Modifier.fillMaxWidth())
{
items(comicGridViewModel.chapterList)
{
c ->
ChapterCard(comicGridViewModel.comic!!, navController, c, comicGridViewModel)
}
}
}
@Composable
fun ChapterCard(comic: Comic, navController: NavHostController, chapter: BookMark, comicGridViewModel: ComicGridViewModel = viewModel())
{
val c = chapter
val iv = comic.getPageIndex(c.page)
Card(
shape = RoundedCornerShape(6.dp),
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight()
.padding(16.dp),
onClick = {
val route = "comic_page_route/${"${comic.id}".toHex()}/${comic.getPageIndex(chapter.page)}"
navController.navigate(route)
}
) {
Column(Modifier.fillMaxWidth())
{
Row(Modifier.padding(12.dp))
{
Box(Modifier
.height(260.dp)
.clip(RoundedCornerShape(8.dp))
.background(Color(0x44FFFFFF)))
{
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data(comic.getPage(c.page))
.memoryCacheKey("${comic.id}/${c.page}")
.diskCacheKey("${comic.id}/${c.page}")
.build(),
contentDescription = null,
imageLoader = comicGridViewModel.imageLoader!!,
modifier = Modifier.padding(8.dp),
contentScale = ContentScale.Fit,
)
}
Column(modifier = Modifier.padding(horizontal = 12.dp)) {
Text(
text = chapter.name,
fontSize = 18.sp,
fontWeight = FontWeight.Bold,
maxLines = 5,
modifier = Modifier.padding(8.dp).background(Color.Transparent)
)
Text(
text = "${comic.getChapterLength(chapter.page)} Pages",
fontSize = 14.sp,
fontWeight = FontWeight.Bold,
maxLines = 1,
modifier = Modifier.padding(8.dp).background(Color.Transparent)
)
}
}
val r = comic.comic.list.subList(iv, iv + comic.getChapterLength(c.page))
LazyRow(modifier = Modifier.fillMaxWidth().padding(8.dp)) {
items(r)
{
r ->
Card(
shape = RoundedCornerShape(12.dp),
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight()
.height(200.dp)
.padding(horizontal = 6.dp),
onClick = {
val route = "comic_page_route/${"${comic.id}".toHex()}/${comic.getPageIndex(r)}"
navController.navigate(route)
}
){
AsyncImage(
model = ImageRequest.Builder(LocalContext.current)
.data(comic.getPage(r))
.memoryCacheKey("${comic.id}/${r}")
.diskCacheKey("${comic.id}/${r}")
.build(),
contentDescription = null,
imageLoader = comicGridViewModel.imageLoader!!,
modifier = Modifier
.fillMaxSize()
.clip(RoundedCornerShape(12.dp)),
contentScale = ContentScale.Crop,
)
}
}
}
}
}
}