[feat] Comic Bookmark

This commit is contained in:
acite
2025-09-05 12:57:50 +08:00
parent 18d021a8e5
commit 514e99d7db
7 changed files with 161 additions and 50 deletions

View File

@@ -48,13 +48,14 @@ class Comic(
return -1 return -1
} }
fun getPageChapterIndex(page: Int): Pair<BookMark, Int>? fun getPageChapterIndex(page: Int): Pair<BookMark, Int>
{ {
var p = page var p = page
while(p >= 0 && !comic.bookmarks.any{ x -> x.page == comic.list[p] }) while(p >= 0 && !comic.bookmarks.any{ x -> x.page == comic.list[p] })
{ {
p-- p--
} }
if(p < 0) return Pair(BookMark(name="null", page=comic.list[0]), page + 1)
for(i in comic.bookmarks) for(i in comic.bookmarks)
{ {
if(i.page == comic.list[p]) if(i.page == comic.list[p])
@@ -63,6 +64,6 @@ class Comic(
} }
} }
return null return Pair(BookMark(name="null", page=comic.list[0]), page + 1)
} }
} }

View File

@@ -1,5 +1,6 @@
package com.acitelight.aether.service package com.acitelight.aether.service
import com.acitelight.aether.model.BookMark
import com.acitelight.aether.model.ChallengeResponse import com.acitelight.aether.model.ChallengeResponse
import com.acitelight.aether.model.ComicResponse import com.acitelight.aether.model.ComicResponse
import com.acitelight.aether.model.VideoResponse import com.acitelight.aether.model.VideoResponse
@@ -32,6 +33,8 @@ interface ApiInterface {
@GET("api/image/{id}") @GET("api/image/{id}")
suspend fun queryComicInfo(@Path("id") id: String, @Query("token") token: String): ComicResponse suspend fun queryComicInfo(@Path("id") id: String, @Query("token") token: String): ComicResponse
@POST("api/image/{id}/bookmark")
suspend fun postBookmark(@Path("id") id: String, @Query("token") token: String, @Body bookmark: BookMark)
@GET("api/user/{user}") @GET("api/user/{user}")
suspend fun getChallenge( suspend fun getChallenge(

View File

@@ -1,5 +1,6 @@
package com.acitelight.aether.service package com.acitelight.aether.service
import com.acitelight.aether.model.BookMark
import com.acitelight.aether.model.Comic import com.acitelight.aether.model.Comic
import com.acitelight.aether.model.ComicResponse import com.acitelight.aether.model.ComicResponse
import com.acitelight.aether.model.Video import com.acitelight.aether.model.Video
@@ -69,4 +70,15 @@ object MediaManager
return null return null
} }
} }
suspend fun postBookmark(id: String, bookMark: BookMark): Boolean
{
try{
val j = ApiClient.api!!.postBookmark(id, token, bookMark)
return true
}catch (e: Exception)
{
return false
}
}
} }

View File

@@ -0,0 +1,60 @@
package com.acitelight.aether.view
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.window.DialogProperties
@Composable
fun BookmarkPop(
onDismiss: () -> Unit,
onConfirm: (String) -> Unit
)
{
var inputValue by remember { mutableStateOf("") }
AlertDialog(
onDismissRequest = onDismiss,
title = {
Text("Bookmark", style = MaterialTheme.typography.headlineMedium)
},
text = {
Column {
OutlinedTextField(
value = inputValue,
onValueChange = { inputValue = it },
label = { Text("Bookmark") },
modifier = Modifier.fillMaxWidth(),
singleLine = true
)
}
},
confirmButton = {
TextButton(
onClick = { onConfirm(inputValue) },
enabled = inputValue.isNotBlank()
) {
Text("Confirm")
}
},
dismissButton = {
TextButton(onClick = onDismiss) {
Text("Cancel")
}
},
properties = DialogProperties(
dismissOnBackPress = true,
dismissOnClickOutside = true
)
)
}

View File

@@ -2,12 +2,9 @@ package com.acitelight.aether.view
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
@@ -22,36 +19,28 @@ import androidx.compose.material3.Card
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.text.font.FontWeight 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.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController import androidx.navigation.NavHostController
import coil3.compose.AsyncImage import coil3.compose.AsyncImage
import coil3.request.ImageRequest import coil3.request.ImageRequest
import com.acitelight.aether.Global
import com.acitelight.aether.ToggleFullScreen import com.acitelight.aether.ToggleFullScreen
import com.acitelight.aether.model.BookMark import com.acitelight.aether.model.BookMark
import com.acitelight.aether.model.Comic import com.acitelight.aether.model.Comic
import com.acitelight.aether.model.ComicRecordDatabase
import com.acitelight.aether.viewModel.ComicGridViewModel import com.acitelight.aether.viewModel.ComicGridViewModel
import java.util.EnumSet.range
import java.util.stream.IntStream.range
@Composable @Composable
fun ComicGridView(comicId: String, navController: NavHostController, comicGridViewModel: ComicGridViewModel = viewModel()) { fun ComicGridView(comicId: String, navController: NavHostController, comicGridViewModel: ComicGridViewModel = viewModel()) {
comicGridViewModel.SetupClient() comicGridViewModel.SetupClient()
comicGridViewModel.Resolve(comicId.hexToString()) comicGridViewModel.resolve(comicId.hexToString())
comicGridViewModel.updateProcess(comicId.hexToString()){} comicGridViewModel.updateProcess(comicId.hexToString()){}
ToggleFullScreen(false) ToggleFullScreen(false)
@@ -104,9 +93,9 @@ fun ComicGridView(comicId: String, navController: NavHostController, comicGridVi
comicGridViewModel.updateProcess(comicId.hexToString()) comicGridViewModel.updateProcess(comicId.hexToString())
{ {
if(record != null) { if(record != null) {
val k = comic!!.getPageChapterIndex(record!!.position)!! val k = comic!!.getPageChapterIndex(record!!.position)
val route = "comic_page_route/${"${comic!!.id}".toHex()}/${ val route = "comic_page_route/${"${comic!!.id}".toHex()}/${
comic!!.getPageIndex(k.first.page) record!!.position
}" }"
navController.navigate(route) navController.navigate(route)
}else }else
@@ -121,7 +110,7 @@ fun ComicGridView(comicId: String, navController: NavHostController, comicGridVi
Row(Modifier.fillMaxWidth().align(Alignment.Center).padding(horizontal = 8.dp)) { Row(Modifier.fillMaxWidth().align(Alignment.Center).padding(horizontal = 8.dp)) {
if(record != null) if(record != null)
{ {
val k = comic!!.getPageChapterIndex(record!!.position)!! val k = comic!!.getPageChapterIndex(record!!.position)
Text( Text(
text = "Last Read Position: ${k.first.name} ${k.second}/${comic!!.getChapterLength(k.first.page)}", text = "Last Read Position: ${k.first.name} ${k.second}/${comic!!.getChapterLength(k.first.page)}",

View File

@@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
@@ -23,11 +24,17 @@ import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.pager.HorizontalPager import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Bookmarks
import androidx.compose.material.icons.filled.Key
import androidx.compose.material3.Card import androidx.compose.material3.Card
import androidx.compose.material3.Icon
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
@@ -46,7 +53,9 @@ import androidx.navigation.NavHostController
import coil3.compose.AsyncImage import coil3.compose.AsyncImage
import coil3.request.ImageRequest import coil3.request.ImageRequest
import com.acitelight.aether.ToggleFullScreen import com.acitelight.aether.ToggleFullScreen
import com.acitelight.aether.model.BookMark
import com.acitelight.aether.model.ComicRecord import com.acitelight.aether.model.ComicRecord
import com.acitelight.aether.service.MediaManager
import com.acitelight.aether.viewModel.ComicPageViewModel import com.acitelight.aether.viewModel.ComicPageViewModel
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@@ -59,6 +68,7 @@ fun ComicPageView(comicId: String, page: String, navController: NavHostControll
val title by comicPageViewModel.title val title by comicPageViewModel.title
val pagerState = rememberPagerState(initialPage = page.toInt(), pageCount = { comicPageViewModel.pageList.size }) val pagerState = rememberPagerState(initialPage = page.toInt(), pageCount = { comicPageViewModel.pageList.size })
var showPlane by comicPageViewModel.showPlane var showPlane by comicPageViewModel.showPlane
var showBookMarkPop by remember { mutableStateOf(false) }
comicPageViewModel.UpdateProcess(pagerState.currentPage) comicPageViewModel.UpdateProcess(pagerState.currentPage)
@@ -101,7 +111,7 @@ fun ComicPageView(comicId: String, page: String, navController: NavHostControll
){ ){
Box() Box()
{ {
Box(modifier = Modifier.height(240.dp).align(Alignment.TopCenter).fillMaxWidth().background( Box(modifier = Modifier.height(160.dp).align(Alignment.TopCenter).fillMaxWidth().background(
brush = Brush.verticalGradient( brush = Brush.verticalGradient(
colors = listOf( colors = listOf(
Color.Black.copy(alpha = 0.75f), Color.Black.copy(alpha = 0.75f),
@@ -134,29 +144,52 @@ fun ComicPageView(comicId: String, page: String, navController: NavHostControll
modifier = Modifier.padding(8.dp).widthIn(min = 60.dp).align(Alignment.CenterVertically) 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( Row {
text = "${k.second}/${it.getChapterLength(k.first.page)}", Row(modifier = Modifier
fontSize = 18.sp, .padding(top = 6.dp).padding(horizontal = 12.dp)
fontWeight = FontWeight.Bold, .height(42.dp)
color = Color.Black, .background(Color(0x90FFFFFF), shape = RoundedCornerShape(12.dp)))
maxLines = 1, {
modifier = Modifier.padding(8.dp).widthIn(min = 60.dp).align(Alignment.CenterVertically) 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)
)
}
Spacer(Modifier.weight(1f))
Row(modifier = Modifier
.padding(top = 6.dp).padding(horizontal = 12.dp)
.height(42.dp).width(42.dp)
.background(Color(0x90FFFFFF), shape = RoundedCornerShape(12.dp)))
{
Box (Modifier.clickable {
showBookMarkPop = true
}){
Icon(
Icons.Filled.Bookmarks,
tint = Color.Black,
modifier = Modifier
.fillMaxSize()
.padding(8.dp),
contentDescription = "Bookmark")
}
}
} }
} }
} }
@@ -214,7 +247,7 @@ fun ComicPageView(comicId: String, page: String, navController: NavHostControll
.align(Alignment.Center), .align(Alignment.Center),
contentScale = ContentScale.Fit, contentScale = ContentScale.Fit,
) )
val k = it.getPageChapterIndex(r)!! val k = it.getPageChapterIndex(r)
Box(Modifier Box(Modifier
.align(Alignment.TopEnd) .align(Alignment.TopEnd)
.padding(6.dp) .padding(6.dp)
@@ -248,4 +281,18 @@ fun ComicPageView(comicId: String, page: String, navController: NavHostControll
} }
} }
} }
if(showBookMarkPop)
{
BookmarkPop({
showBookMarkPop = false
}, {
s ->
showBookMarkPop = false
comicPageViewModel.coroutineScope?.launch {
MediaManager.postBookmark(comicId.hexToString(), BookMark(name = s, page = comicPageViewModel.pageList[pagerState.currentPage]))
comicPageViewModel.comic.value = MediaManager.queryComicInfo(comicId.hexToString())
}
});
}
} }

View File

@@ -15,7 +15,6 @@ import com.acitelight.aether.model.ComicRecord
import com.acitelight.aether.model.ComicRecordDatabase import com.acitelight.aether.model.ComicRecordDatabase
import com.acitelight.aether.service.ApiClient.createOkHttp import com.acitelight.aether.service.ApiClient.createOkHttp
import com.acitelight.aether.service.MediaManager import com.acitelight.aether.service.MediaManager
import com.acitelight.aether.view.hexToString
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
class ComicGridViewModel : ViewModel() class ComicGridViewModel : ViewModel()
@@ -44,16 +43,16 @@ class ComicGridViewModel : ViewModel()
} }
} }
fun Resolve(id: String) fun resolve(id: String)
{ {
if(comic.value != null) return
viewModelScope.launch { viewModelScope.launch {
comic.value = MediaManager.queryComicInfo(id) if(comic.value == null) {
val c = comic.value!! comic.value = MediaManager.queryComicInfo(id)
for(i in c.comic.bookmarks) val c = comic.value!!
{ for (i in c.comic.bookmarks) {
chapterList.add(i) chapterList.add(i)
} }
}else comic.value = MediaManager.queryComicInfo(id)
} }
} }