mirror of
https://github.com/Suwayomi/TachideskJUI.git
synced 2025-12-13 08:12:02 +01:00
Add chapter url opening to browser
This commit is contained in:
@@ -12,7 +12,7 @@ import kotlinx.serialization.Serializable
|
||||
@Serializable
|
||||
@Immutable
|
||||
data class Chapter(
|
||||
val id: Long = -1, // todo remove default
|
||||
val id: Long,
|
||||
val url: String,
|
||||
val name: String,
|
||||
val uploadDate: Long,
|
||||
@@ -24,6 +24,7 @@ data class Chapter(
|
||||
val lastPageRead: Int,
|
||||
val index: Int,
|
||||
val fetchedAt: Long,
|
||||
val realUrl: String?,
|
||||
val chapterCount: Int?,
|
||||
val pageCount: Int?,
|
||||
val lastReadAt: Int?,
|
||||
|
||||
@@ -32,6 +32,7 @@ data class Manga(
|
||||
val status: MangaStatus,
|
||||
val inLibrary: Boolean,
|
||||
val source: Source?,
|
||||
val updateStrategy: UpdateStrategy,
|
||||
val freshData: Boolean,
|
||||
val meta: MangaMeta,
|
||||
val realUrl: String?,
|
||||
@@ -67,3 +68,10 @@ enum class MangaStatus(@Transient val res: StringResource) {
|
||||
CANCELLED(MR.strings.status_cancelled),
|
||||
ON_HIATUS(MR.strings.status_on_hiatus);
|
||||
}
|
||||
|
||||
@Serializable
|
||||
@Stable
|
||||
enum class UpdateStrategy {
|
||||
ALWAYS_UPDATE,
|
||||
ONLY_FETCH_ONCE
|
||||
}
|
||||
@@ -44,7 +44,7 @@
|
||||
<string name="action_searching">Search…</string>
|
||||
<string name="action_more_actions">More actions</string>
|
||||
<string name="action_ok">Ok</string>
|
||||
<string name="action_browser">Browser</string>
|
||||
<string name="action_open_in_browser">Open in Browser</string>
|
||||
<string name="action_filter">Filter</string>
|
||||
<string name="action_mark_as_read">Mark as read</string>
|
||||
<string name="action_mark_as_unread">Mark as unread</string>
|
||||
|
||||
@@ -33,7 +33,7 @@ import androidx.compose.material.icons.rounded.Favorite
|
||||
import androidx.compose.material.icons.rounded.FavoriteBorder
|
||||
import androidx.compose.material.icons.rounded.FlipToBack
|
||||
import androidx.compose.material.icons.rounded.Label
|
||||
import androidx.compose.material.icons.rounded.OpenInBrowser
|
||||
import androidx.compose.material.icons.rounded.Public
|
||||
import androidx.compose.material.icons.rounded.Refresh
|
||||
import androidx.compose.material.icons.rounded.RemoveDone
|
||||
import androidx.compose.material.icons.rounded.SelectAll
|
||||
@@ -347,8 +347,8 @@ private fun getActionItems(
|
||||
).toImmutableList()
|
||||
),
|
||||
ActionItem(
|
||||
name = stringResource(MR.strings.action_browser),
|
||||
icon = Icons.Rounded.OpenInBrowser,
|
||||
name = stringResource(MR.strings.action_open_in_browser),
|
||||
icon = Icons.Rounded.Public,
|
||||
enabled = openInBrowserEnabled,
|
||||
doAction = openInBrowser
|
||||
)
|
||||
|
||||
@@ -39,6 +39,7 @@ import androidx.compose.material.Surface
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.rounded.ChevronRight
|
||||
import androidx.compose.material.icons.rounded.Public
|
||||
import androidx.compose.material.icons.rounded.Settings
|
||||
import androidx.compose.material.rememberModalBottomSheetState
|
||||
import androidx.compose.runtime.Composable
|
||||
@@ -64,6 +65,7 @@ import androidx.compose.ui.input.key.onKeyEvent
|
||||
import androidx.compose.ui.input.key.type
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.platform.LocalUriHandler
|
||||
import androidx.compose.ui.unit.dp
|
||||
import ca.gosyer.jui.core.lang.withIOContext
|
||||
import ca.gosyer.jui.domain.reader.model.Direction
|
||||
@@ -409,7 +411,24 @@ fun ThinReaderMenu(
|
||||
closable = true,
|
||||
onClose = onCloseRequest,
|
||||
actions = {
|
||||
listOf(
|
||||
val uriHandler = LocalUriHandler.current
|
||||
listOfNotNull(
|
||||
if (chapter.chapter.realUrl != null) {
|
||||
ActionItem(
|
||||
stringResource(MR.strings.action_open_in_browser),
|
||||
Icons.Rounded.Public,
|
||||
doAction = {
|
||||
uriHandler.openUri(
|
||||
chapter.chapter.realUrl ?: return@ActionItem
|
||||
)
|
||||
scope.launch {
|
||||
sheetState.show()
|
||||
}
|
||||
}
|
||||
)
|
||||
} else {
|
||||
null
|
||||
},
|
||||
ActionItem(
|
||||
stringResource(MR.strings.location_settings),
|
||||
Icons.Rounded.Settings,
|
||||
@@ -418,7 +437,7 @@ fun ThinReaderMenu(
|
||||
sheetState.show()
|
||||
}
|
||||
}
|
||||
)
|
||||
),
|
||||
).toImmutableList()
|
||||
}
|
||||
)
|
||||
|
||||
@@ -93,25 +93,25 @@ class ReaderMenuViewModel @Inject constructor(
|
||||
private val _state = MutableStateFlow<ReaderChapter.State>(ReaderChapter.State.Wait)
|
||||
val state = _state.asStateFlow()
|
||||
|
||||
val pages = viewerChapters.flatMapLatest {
|
||||
val previousChapterPages = it.prevChapter
|
||||
val pages = viewerChapters.flatMapLatest { viewerChapters ->
|
||||
val previousChapterPages = viewerChapters.prevChapter
|
||||
?.pages
|
||||
?.map { (it as? PagesState.Success)?.pages }
|
||||
?: flowOf(null)
|
||||
val chapterPages = it.currChapter
|
||||
val chapterPages = viewerChapters.currChapter
|
||||
?.pages
|
||||
?.map { (it as? PagesState.Success)?.pages }
|
||||
?: flowOf(null)
|
||||
val nextChapterPages = it.nextChapter
|
||||
val nextChapterPages = viewerChapters.nextChapter
|
||||
?.pages
|
||||
?.map { (it as? PagesState.Success)?.pages }
|
||||
?: flowOf(null)
|
||||
combine(previousChapterPages, chapterPages, nextChapterPages) { prev, cur, next ->
|
||||
(
|
||||
prev.orEmpty() +
|
||||
ReaderPageSeparator(it.prevChapter, it.currChapter) +
|
||||
ReaderPageSeparator(viewerChapters.prevChapter, viewerChapters.currChapter) +
|
||||
cur.orEmpty() +
|
||||
ReaderPageSeparator(it.currChapter, it.nextChapter) +
|
||||
ReaderPageSeparator(viewerChapters.currChapter, viewerChapters.nextChapter) +
|
||||
next.orEmpty()
|
||||
).toImmutableList()
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ import androidx.compose.material.ProgressIndicatorDefaults
|
||||
import androidx.compose.material.Slider
|
||||
import androidx.compose.material.Surface
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.material.TextButton
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.rounded.ChevronLeft
|
||||
import androidx.compose.material.icons.rounded.NavigateBefore
|
||||
@@ -48,6 +49,7 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.rotate
|
||||
import androidx.compose.ui.platform.LocalUriHandler
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import ca.gosyer.jui.core.util.replace
|
||||
@@ -82,11 +84,13 @@ fun ReaderSideMenu(
|
||||
Column(Modifier.fillMaxSize()) {
|
||||
val pageCount = chapter.chapter.pageCount!!
|
||||
ReaderMenuToolbar(onCloseSideMenuClicked = onCloseSideMenuClicked)
|
||||
Spacer(Modifier.height(4.dp))
|
||||
ReaderModeSetting(
|
||||
readerModes = readerModes,
|
||||
selectedMode = selectedMode,
|
||||
onSetReaderMode = onSetReaderMode
|
||||
)
|
||||
Spacer(Modifier.height(4.dp))
|
||||
ReaderProgressSlider(
|
||||
pages = pages,
|
||||
currentPage = currentPage,
|
||||
@@ -94,6 +98,16 @@ fun ReaderSideMenu(
|
||||
onNewPageClicked = onNewPageClicked,
|
||||
isRtL = false
|
||||
)
|
||||
Spacer(Modifier.height(4.dp))
|
||||
val uriHandler = LocalUriHandler.current
|
||||
TextButton(
|
||||
onClick = { uriHandler.openUri(chapter.chapter.realUrl ?: return@TextButton) },
|
||||
enabled = chapter.chapter.realUrl != null,
|
||||
modifier = Modifier.fillMaxWidth().padding(horizontal = 4.dp)
|
||||
) {
|
||||
Text(stringResource(MR.strings.action_open_in_browser))
|
||||
}
|
||||
Spacer(Modifier.height(4.dp))
|
||||
NavigateChapters(
|
||||
loadPrevChapter = onPrevChapterClicked,
|
||||
loadNextChapter = onNextChapterClicked
|
||||
@@ -214,7 +228,7 @@ fun ReaderSheet(
|
||||
selectedMode: String,
|
||||
onSetReaderMode: (String) -> Unit
|
||||
) {
|
||||
Column(Modifier.fillMaxWidth()) {
|
||||
Column(Modifier.fillMaxSize()) {
|
||||
ReaderModeSetting(readerModes, selectedMode, onSetReaderMode)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user