Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a7edba607a | |||
| c622f74c62 | |||
| 95b1199f1d | |||
| eca7a3b886 | |||
| ba1b4d2362 | |||
| 023c3bb2f1 | |||
| aec03c6c71 | |||
| c9c119689d | |||
| 38a327cdf6 |
@@ -33,6 +33,11 @@ private val fontFamilies = listOf(
|
||||
MR.strings.pref_text_reader_font_mono to ReaderPreferences.TextFontFamily.MONOSPACE,
|
||||
)
|
||||
|
||||
private val lineBreakModes = listOf(
|
||||
MR.strings.pref_text_reader_line_break_word to ReaderPreferences.TextLineBreakMode.WORD,
|
||||
MR.strings.pref_text_reader_line_break_character to ReaderPreferences.TextLineBreakMode.CHARACTER,
|
||||
)
|
||||
|
||||
@Composable
|
||||
internal fun ColumnScope.TextSettingsPage(viewModel: ReaderSettingsViewModel) {
|
||||
val context = LocalContext.current
|
||||
@@ -90,6 +95,36 @@ internal fun ColumnScope.TextSettingsPage(viewModel: ReaderSettingsViewModel) {
|
||||
pillColor = MaterialTheme.colorScheme.surfaceContainerHighest,
|
||||
)
|
||||
|
||||
val horizontalMarginPref = viewModel.preferences.textHorizontalMargin
|
||||
val horizontalMargin by horizontalMarginPref.collectAsState()
|
||||
SliderItem(
|
||||
label = stringResource(MR.strings.pref_text_reader_horizontal_margin),
|
||||
value = horizontalMargin,
|
||||
valueRange = 0..64,
|
||||
steps = 15,
|
||||
valueString = "$horizontalMargin dp",
|
||||
onChange = { value ->
|
||||
horizontalMarginPref.set(value)
|
||||
viewModel.previewAndRequestTextSettingsReload()
|
||||
},
|
||||
pillColor = MaterialTheme.colorScheme.surfaceContainerHighest,
|
||||
)
|
||||
|
||||
val lineBreakModePref = viewModel.preferences.textLineBreakMode
|
||||
val lineBreakMode by lineBreakModePref.collectAsState()
|
||||
SettingsChipRow(MR.strings.pref_text_reader_line_break_mode) {
|
||||
lineBreakModes.forEach { (label, value) ->
|
||||
FilterChip(
|
||||
selected = lineBreakMode == value,
|
||||
onClick = {
|
||||
lineBreakModePref.set(value)
|
||||
viewModel.previewAndRequestTextSettingsReload()
|
||||
},
|
||||
label = { Text(stringResource(label)) },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val fontFamilyPref = viewModel.preferences.textFontFamily
|
||||
val fontFamily by fontFamilyPref.collectAsState()
|
||||
SettingsChipRow(MR.strings.pref_text_reader_font_family) {
|
||||
|
||||
@@ -20,6 +20,8 @@ import android.view.WindowManager
|
||||
import android.widget.Toast
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.activity.viewModels
|
||||
import androidx.compose.animation.core.animateDpAsState
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
@@ -306,28 +308,56 @@ class ReaderActivity : BaseActivity() {
|
||||
|
||||
AppBars(state = state)
|
||||
|
||||
if (ttsState.active) {
|
||||
IconButton(
|
||||
onClick = ::toggleTts,
|
||||
val showFloatingTts = ttsState.active &&
|
||||
ttsState.readerChapterId == state.currentChapter?.chapter?.id &&
|
||||
state.currentChapter?.pages?.any { it is TextReaderPage } == true
|
||||
if (showFloatingTts) {
|
||||
val floatingTtsBottomPadding by animateDpAsState(
|
||||
targetValue = if (state.menuVisible) 144.dp else 72.dp,
|
||||
animationSpec = tween(durationMillis = 200),
|
||||
label = "floatingTtsBottomPadding",
|
||||
)
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.align(Alignment.BottomEnd)
|
||||
.navigationBarsPadding()
|
||||
.padding(end = 18.dp, bottom = 72.dp)
|
||||
.size(52.dp)
|
||||
.background(
|
||||
color = MaterialTheme.colorScheme.surface.copy(alpha = 0.55f),
|
||||
shape = CircleShape,
|
||||
),
|
||||
.padding(end = 18.dp, bottom = floatingTtsBottomPadding),
|
||||
horizontalArrangement = Arrangement.spacedBy(10.dp),
|
||||
) {
|
||||
Icon(
|
||||
painter = painterResource(
|
||||
if (ttsState.playing) R.drawable.ic_pause_24dp else R.drawable.ic_play_arrow_24dp,
|
||||
),
|
||||
contentDescription = stringResource(
|
||||
if (ttsState.playing) MR.strings.reader_tts_pause else MR.strings.reader_tts_start,
|
||||
),
|
||||
tint = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.92f),
|
||||
)
|
||||
IconButton(
|
||||
onClick = ::toggleTts,
|
||||
modifier = Modifier
|
||||
.size(52.dp)
|
||||
.background(
|
||||
color = MaterialTheme.colorScheme.surface.copy(alpha = 0.55f),
|
||||
shape = CircleShape,
|
||||
),
|
||||
) {
|
||||
Icon(
|
||||
painter = painterResource(
|
||||
if (ttsState.playing) R.drawable.ic_pause_24dp else R.drawable.ic_play_arrow_24dp,
|
||||
),
|
||||
contentDescription = stringResource(
|
||||
if (ttsState.playing) MR.strings.reader_tts_pause else MR.strings.reader_tts_start,
|
||||
),
|
||||
tint = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.92f),
|
||||
)
|
||||
}
|
||||
IconButton(
|
||||
onClick = { ReaderTtsController.stop(this@ReaderActivity) },
|
||||
modifier = Modifier
|
||||
.size(52.dp)
|
||||
.background(
|
||||
color = MaterialTheme.colorScheme.surface.copy(alpha = 0.55f),
|
||||
shape = CircleShape,
|
||||
),
|
||||
) {
|
||||
Icon(
|
||||
painter = painterResource(R.drawable.ic_stop_24dp),
|
||||
contentDescription = stringResource(MR.strings.reader_tts_stop),
|
||||
tint = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.92f),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -738,9 +768,14 @@ class ReaderActivity : BaseActivity() {
|
||||
if (ttsState.playing) {
|
||||
ReaderTtsController.toggle(this)
|
||||
} else {
|
||||
val currentPageIndex = (state.currentPage - 1).coerceAtLeast(0)
|
||||
if (currentPageIndex != ttsState.readerPageIndex) {
|
||||
ReaderTtsController.resumeFromPage(this, currentPageIndex)
|
||||
val currentPage = chapter.pages
|
||||
?.getOrNull((state.currentPage - 1).coerceAtLeast(0)) as? TextReaderPage
|
||||
if (currentPage != null) {
|
||||
ReaderTtsController.resumeFromSource(
|
||||
context = this,
|
||||
documentIndex = currentPage.anchor.documentIndex,
|
||||
sourceOffset = currentPage.anchor.startOffset,
|
||||
)
|
||||
} else {
|
||||
ReaderTtsController.toggle(this)
|
||||
}
|
||||
@@ -842,10 +877,13 @@ class ReaderActivity : BaseActivity() {
|
||||
}
|
||||
|
||||
ttsHighlightedPage = targetPage
|
||||
if (state.currentPage != targetPage.index + 1) {
|
||||
val targetPageIsVisible = state.currentPage == targetPage.index + 1
|
||||
if (ttsState.playing && !targetPageIsVisible) {
|
||||
moveToPageIndex(targetPage.index)
|
||||
}
|
||||
state.viewer?.refreshCurrentPage()
|
||||
if (ttsState.playing || targetPageIsVisible) {
|
||||
state.viewer?.refreshCurrentPage()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,15 +8,20 @@ import android.graphics.Typeface
|
||||
import android.text.Layout
|
||||
import android.text.Spannable
|
||||
import android.text.SpannableString
|
||||
import android.text.SpannableStringBuilder
|
||||
import android.text.StaticLayout
|
||||
import android.text.TextPaint
|
||||
import android.text.style.BackgroundColorSpan
|
||||
import android.text.style.ForegroundColorSpan
|
||||
import android.text.style.LineHeightSpan
|
||||
import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences.TextLineBreakMode
|
||||
import eu.kanade.tachiyomi.ui.reader.setting.TextReaderStyle
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.InputStream
|
||||
import java.io.Reader
|
||||
import java.text.BreakIterator
|
||||
import java.util.Locale
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
internal data class PaginatedTextPage(
|
||||
@@ -26,9 +31,10 @@ internal data class PaginatedTextPage(
|
||||
)
|
||||
|
||||
internal object TextPageRenderer {
|
||||
private const val MARGIN_DP = 32f
|
||||
private const val VERTICAL_MARGIN_DP = 32f
|
||||
private const val STREAM_BUFFER_CHARS = 64 * 1024
|
||||
private const val STREAM_READ_CHARS = 8 * 1024
|
||||
private const val ZERO_WIDTH_SPACE = "\u200B"
|
||||
|
||||
fun paginate(text: String, style: TextReaderStyle): List<PaginatedTextPage> {
|
||||
if (text.isBlank()) return emptyList()
|
||||
@@ -132,7 +138,8 @@ internal object TextPageRenderer {
|
||||
if (text.isEmpty()) return emptyList()
|
||||
|
||||
val metrics = resolveLayoutMetrics(style)
|
||||
val layout = createLayout(text, style, metrics.contentWidth)
|
||||
val builtLayout = createLayout(text, style, metrics.contentWidth)
|
||||
val layout = builtLayout.layout
|
||||
if (layout.lineCount == 0) return listOf(PageSlice(0, text.length))
|
||||
|
||||
val pages = mutableListOf<PageSlice>()
|
||||
@@ -147,8 +154,10 @@ internal object TextPageRenderer {
|
||||
endLine++
|
||||
}
|
||||
|
||||
val start = layout.getLineStart(startLine)
|
||||
val end = layout.getLineEnd(endLine).coerceAtLeast(start + 1).coerceAtMost(text.length)
|
||||
val start = builtLayout.originalOffset(layout.getLineStart(startLine))
|
||||
val end = builtLayout.originalOffset(layout.getLineEnd(endLine))
|
||||
.coerceAtLeast(start + 1)
|
||||
.coerceAtMost(text.length)
|
||||
pages += PageSlice(start, end)
|
||||
startLine = endLine + 1
|
||||
}
|
||||
@@ -174,7 +183,7 @@ internal object TextPageRenderer {
|
||||
contentWidth = metrics.contentWidth,
|
||||
sentenceHighlightRange = sentenceHighlightRange,
|
||||
activeHighlightRange = activeHighlightRange,
|
||||
).draw(canvas)
|
||||
).layout.draw(canvas)
|
||||
canvas.restore()
|
||||
|
||||
val output = ByteArrayOutputStream()
|
||||
@@ -189,7 +198,7 @@ internal object TextPageRenderer {
|
||||
contentWidth: Int,
|
||||
sentenceHighlightRange: IntRange? = null,
|
||||
activeHighlightRange: IntRange? = null,
|
||||
): StaticLayout {
|
||||
): BuiltLayout {
|
||||
val (_, textColor) = resolveColors(style)
|
||||
val paint = TextPaint().apply {
|
||||
isAntiAlias = true
|
||||
@@ -205,8 +214,9 @@ internal object TextPageRenderer {
|
||||
sentenceHighlightRange = sentenceHighlightRange,
|
||||
activeHighlightRange = activeHighlightRange,
|
||||
)
|
||||
return StaticLayout.Builder
|
||||
.obtain(styledText, 0, styledText.length, paint, contentWidth)
|
||||
val preparedText = prepareLineBreakText(text, styledText, style.lineBreakMode)
|
||||
val layout = StaticLayout.Builder
|
||||
.obtain(preparedText.text, 0, preparedText.text.length, paint, contentWidth)
|
||||
.setAlignment(Layout.Alignment.ALIGN_NORMAL)
|
||||
// Page slices are laid out again when rendered. Keeping font padding
|
||||
// here can make the sliced layout taller than the same lines measured
|
||||
@@ -214,14 +224,66 @@ internal object TextPageRenderer {
|
||||
.setIncludePad(false)
|
||||
.setLineSpacing(0f, style.lineSpacingPercent / 100f)
|
||||
.build()
|
||||
return BuiltLayout(layout, preparedText.originalOffsetByPreparedOffset)
|
||||
}
|
||||
|
||||
private fun prepareLineBreakText(
|
||||
originalText: String,
|
||||
styledText: CharSequence,
|
||||
mode: TextLineBreakMode,
|
||||
): PreparedText {
|
||||
if (mode == TextLineBreakMode.WORD || originalText.length < 2) {
|
||||
return PreparedText(styledText, null)
|
||||
}
|
||||
|
||||
val breakIterator = BreakIterator.getCharacterInstance(Locale.ROOT).apply {
|
||||
setText(originalText)
|
||||
}
|
||||
val insertionOffsets = mutableListOf<Int>()
|
||||
var boundary = breakIterator.first()
|
||||
while (true) {
|
||||
boundary = breakIterator.next()
|
||||
if (boundary == BreakIterator.DONE || boundary >= originalText.length) break
|
||||
if (boundary <= 0) continue
|
||||
|
||||
val before = originalText.codePointBefore(boundary)
|
||||
val after = originalText.codePointAt(boundary)
|
||||
if (!Character.isWhitespace(before) && !Character.isWhitespace(after)) {
|
||||
insertionOffsets += boundary
|
||||
}
|
||||
}
|
||||
if (insertionOffsets.isEmpty()) return PreparedText(styledText, null)
|
||||
|
||||
val prepared = SpannableStringBuilder(styledText)
|
||||
insertionOffsets.asReversed().forEach { offset ->
|
||||
prepared.insert(offset, ZERO_WIDTH_SPACE)
|
||||
}
|
||||
|
||||
val insertedAt = BooleanArray(originalText.length + 1)
|
||||
insertionOffsets.forEach { insertedAt[it] = true }
|
||||
val mapping = IntArray(prepared.length + 1)
|
||||
var preparedOffset = 0
|
||||
mapping[0] = 0
|
||||
for (originalOffset in 0 until originalText.length) {
|
||||
if (insertedAt[originalOffset]) {
|
||||
preparedOffset++
|
||||
mapping[preparedOffset] = originalOffset
|
||||
}
|
||||
preparedOffset++
|
||||
mapping[preparedOffset] = originalOffset + 1
|
||||
}
|
||||
return PreparedText(prepared, mapping)
|
||||
}
|
||||
|
||||
private fun resolveLayoutMetrics(style: TextReaderStyle): LayoutMetrics {
|
||||
val pageWidth = style.pageWidthPx.coerceAtLeast(1)
|
||||
val pageHeight = style.pageHeightPx.coerceAtLeast(1)
|
||||
val requestedMargin = (MARGIN_DP * style.density).roundToInt().coerceAtLeast(1)
|
||||
val horizontalMargin = requestedMargin.coerceAtMost(((pageWidth - 1) / 2).coerceAtLeast(0))
|
||||
val verticalMargin = requestedMargin.coerceAtMost(((pageHeight - 1) / 2).coerceAtLeast(0))
|
||||
val requestedHorizontalMargin = (style.horizontalMarginDp * style.density)
|
||||
.roundToInt()
|
||||
.coerceAtLeast(0)
|
||||
val requestedVerticalMargin = (VERTICAL_MARGIN_DP * style.density).roundToInt().coerceAtLeast(1)
|
||||
val horizontalMargin = requestedHorizontalMargin.coerceAtMost(((pageWidth - 1) / 2).coerceAtLeast(0))
|
||||
val verticalMargin = requestedVerticalMargin.coerceAtMost(((pageHeight - 1) / 2).coerceAtLeast(0))
|
||||
|
||||
return LayoutMetrics(
|
||||
pageWidth = pageWidth,
|
||||
@@ -274,13 +336,15 @@ internal object TextPageRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
val darkBackground = resolveColors(style).first == Color.BLACK
|
||||
val (_, baseTextColor) = resolveColors(style)
|
||||
val darkTheme = baseTextColor == Color.WHITE
|
||||
sentenceHighlightRange?.let { range ->
|
||||
applyHighlightSpan(
|
||||
spannable = spannable,
|
||||
textLength = text.length,
|
||||
range = range,
|
||||
color = if (darkBackground) Color.rgb(72, 68, 40) else Color.rgb(255, 249, 196),
|
||||
backgroundColor = if (darkTheme) Color.rgb(77, 66, 25) else Color.rgb(255, 243, 176),
|
||||
foregroundColor = if (darkTheme) Color.WHITE else Color.BLACK,
|
||||
)
|
||||
}
|
||||
activeHighlightRange?.let { range ->
|
||||
@@ -288,7 +352,8 @@ internal object TextPageRenderer {
|
||||
spannable = spannable,
|
||||
textLength = text.length,
|
||||
range = range,
|
||||
color = if (darkBackground) Color.rgb(150, 117, 0) else Color.rgb(255, 193, 7),
|
||||
backgroundColor = if (darkTheme) Color.rgb(255, 193, 7) else Color.rgb(255, 179, 0),
|
||||
foregroundColor = Color.BLACK,
|
||||
)
|
||||
}
|
||||
return spannable
|
||||
@@ -298,14 +363,21 @@ internal object TextPageRenderer {
|
||||
spannable: SpannableString,
|
||||
textLength: Int,
|
||||
range: IntRange,
|
||||
color: Int,
|
||||
backgroundColor: Int,
|
||||
foregroundColor: Int,
|
||||
) {
|
||||
if (range.isEmpty()) return
|
||||
val start = range.first.coerceIn(0, textLength)
|
||||
val endExclusive = (range.last + 1).coerceIn(start, textLength)
|
||||
if (start >= endExclusive) return
|
||||
spannable.setSpan(
|
||||
BackgroundColorSpan(color),
|
||||
BackgroundColorSpan(backgroundColor),
|
||||
start,
|
||||
endExclusive,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE,
|
||||
)
|
||||
spannable.setSpan(
|
||||
ForegroundColorSpan(foregroundColor),
|
||||
start,
|
||||
endExclusive,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE,
|
||||
@@ -326,6 +398,21 @@ internal object TextPageRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
private data class PreparedText(
|
||||
val text: CharSequence,
|
||||
val originalOffsetByPreparedOffset: IntArray?,
|
||||
)
|
||||
|
||||
private data class BuiltLayout(
|
||||
val layout: StaticLayout,
|
||||
val originalOffsetByLayoutOffset: IntArray?,
|
||||
) {
|
||||
fun originalOffset(layoutOffset: Int): Int {
|
||||
val mapping = originalOffsetByLayoutOffset ?: return layoutOffset
|
||||
return mapping[layoutOffset.coerceIn(0, mapping.lastIndex)]
|
||||
}
|
||||
}
|
||||
|
||||
private data class LayoutMetrics(
|
||||
val pageWidth: Int,
|
||||
val pageHeight: Int,
|
||||
|
||||
@@ -120,6 +120,13 @@ class ReaderPreferences(
|
||||
|
||||
val textParagraphSpacing: Preference<Int> = preferenceStore.getInt("reader_text_paragraph_spacing", 4)
|
||||
|
||||
val textHorizontalMargin: Preference<Int> = preferenceStore.getInt("reader_text_horizontal_margin", 32)
|
||||
|
||||
val textLineBreakMode: Preference<TextLineBreakMode> = preferenceStore.getEnum(
|
||||
"reader_text_line_break_mode",
|
||||
TextLineBreakMode.WORD,
|
||||
)
|
||||
|
||||
val textFontFamily: Preference<TextFontFamily> = preferenceStore.getEnum(
|
||||
"reader_text_font_family",
|
||||
TextFontFamily.SYSTEM,
|
||||
@@ -161,6 +168,8 @@ class ReaderPreferences(
|
||||
fontSize = textFontSize.get(),
|
||||
lineSpacingPercent = textLineSpacing.get(),
|
||||
paragraphSpacing = textParagraphSpacing.get(),
|
||||
horizontalMarginDp = textHorizontalMargin.get(),
|
||||
lineBreakMode = textLineBreakMode.get(),
|
||||
fontFamily = textFontFamily.get(),
|
||||
readerTheme = readerTheme.get(),
|
||||
automaticDark = (context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) ==
|
||||
@@ -301,6 +310,11 @@ class ReaderPreferences(
|
||||
MONOSPACE("monospace"),
|
||||
}
|
||||
|
||||
enum class TextLineBreakMode {
|
||||
WORD,
|
||||
CHARACTER,
|
||||
}
|
||||
|
||||
enum class FlashColor {
|
||||
BLACK,
|
||||
WHITE,
|
||||
@@ -435,6 +449,8 @@ data class TextReaderStyle(
|
||||
val fontSize: Int,
|
||||
val lineSpacingPercent: Int,
|
||||
val paragraphSpacing: Int,
|
||||
val horizontalMarginDp: Int,
|
||||
val lineBreakMode: ReaderPreferences.TextLineBreakMode,
|
||||
val fontFamily: ReaderPreferences.TextFontFamily,
|
||||
val readerTheme: Int,
|
||||
val automaticDark: Boolean,
|
||||
|
||||
@@ -51,6 +51,11 @@ class ReaderSettingsViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
fun previewAndRequestTextSettingsReload() {
|
||||
onTextSettingsPreview()
|
||||
requestTextSettingsReload()
|
||||
}
|
||||
|
||||
/**
|
||||
* Theme-only changes do not affect page boundaries, so avoid an unnecessary
|
||||
* full repagination.
|
||||
|
||||
@@ -57,12 +57,17 @@ object ReaderTtsController {
|
||||
)
|
||||
}
|
||||
|
||||
fun resumeFromPage(context: Context, readerPageIndex: Int) {
|
||||
fun resumeFromSource(
|
||||
context: Context,
|
||||
documentIndex: Int,
|
||||
sourceOffset: Long,
|
||||
) {
|
||||
if (!state.value.active) return
|
||||
context.startService(
|
||||
Intent(context, ReaderTtsService::class.java)
|
||||
.setAction(ReaderTtsService.ACTION_RESUME_FROM_PAGE)
|
||||
.putExtra(ReaderTtsService.EXTRA_START_PAGE_INDEX, readerPageIndex),
|
||||
.setAction(ReaderTtsService.ACTION_RESUME_FROM_SOURCE)
|
||||
.putExtra(ReaderTtsService.EXTRA_DOCUMENT_INDEX, documentIndex)
|
||||
.putExtra(ReaderTtsService.EXTRA_SOURCE_OFFSET, sourceOffset),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -46,8 +46,9 @@ class ReaderTtsService : Service() {
|
||||
when (intent?.action) {
|
||||
ACTION_START -> startSession(intent)
|
||||
ACTION_TOGGLE -> if (playing) pausePlayback() else resumePlayback()
|
||||
ACTION_RESUME_FROM_PAGE -> resumeFromPage(
|
||||
intent.getIntExtra(EXTRA_START_PAGE_INDEX, -1),
|
||||
ACTION_RESUME_FROM_SOURCE -> resumeFromSource(
|
||||
documentIndex = intent.getIntExtra(EXTRA_DOCUMENT_INDEX, -1),
|
||||
sourceOffset = intent.getLongExtra(EXTRA_SOURCE_OFFSET, -1L),
|
||||
)
|
||||
ACTION_STOP -> stopPlayback()
|
||||
ACTION_SET_SPEED -> {
|
||||
@@ -207,16 +208,47 @@ class ReaderTtsService : Service() {
|
||||
speakCurrentSegment()
|
||||
}
|
||||
|
||||
private fun resumeFromPage(readerPageIndex: Int) {
|
||||
if (!initialized || readerPageIndex < 0) return
|
||||
private fun resumeFromSource(
|
||||
documentIndex: Int,
|
||||
sourceOffset: Long,
|
||||
) {
|
||||
if (!initialized || documentIndex < 0 || sourceOffset < 0L) return
|
||||
val session = session ?: return
|
||||
val newPagePosition = session.pages.indexOfFirst { it.readerPageIndex >= readerPageIndex }
|
||||
.takeIf { it >= 0 }
|
||||
?: return
|
||||
|
||||
val exactPosition = session.pages.indexOfFirst { entry ->
|
||||
entry.documentIndex == documentIndex &&
|
||||
sourceOffset >= entry.sourceStartOffset &&
|
||||
sourceOffset < entry.sourceEndOffsetExclusive
|
||||
}
|
||||
val nextPosition = if (exactPosition < 0) {
|
||||
session.pages.indexOfFirst { entry ->
|
||||
entry.documentIndex == documentIndex && entry.sourceStartOffset >= sourceOffset
|
||||
}
|
||||
} else {
|
||||
-1
|
||||
}
|
||||
val previousPosition = if (exactPosition < 0 && nextPosition < 0) {
|
||||
session.pages.indexOfLast { entry ->
|
||||
entry.documentIndex == documentIndex && entry.sourceStartOffset <= sourceOffset
|
||||
}
|
||||
} else {
|
||||
-1
|
||||
}
|
||||
val newPagePosition = when {
|
||||
exactPosition >= 0 -> exactPosition
|
||||
nextPosition >= 0 -> nextPosition
|
||||
previousPosition >= 0 -> previousPosition
|
||||
else -> return
|
||||
}
|
||||
val entry = session.pages[newPagePosition]
|
||||
val relativeOffset = (sourceOffset - entry.sourceStartOffset)
|
||||
.coerceAtLeast(0L)
|
||||
.coerceAtMost(Int.MAX_VALUE.toLong())
|
||||
.toInt()
|
||||
|
||||
tts?.stop()
|
||||
pagePosition = newPagePosition
|
||||
pageSpeechStartOffset = 0
|
||||
pageSpeechStartOffset = relativeOffset
|
||||
currentWindow = null
|
||||
currentSegments = emptyList()
|
||||
lookaheadConsumedChars = emptyMap()
|
||||
@@ -225,7 +257,18 @@ class ReaderTtsService : Service() {
|
||||
currentUtteranceBaseOffset = 0
|
||||
currentUtteranceId = null
|
||||
playing = true
|
||||
updatePlaybackState(clearHighlight = true)
|
||||
ReaderTtsController.updateState(
|
||||
ReaderTtsController.State(
|
||||
active = true,
|
||||
playing = true,
|
||||
readerChapterId = readerChapterId,
|
||||
readerPageIndex = entry.readerPageIndex,
|
||||
documentIndex = documentIndex,
|
||||
sourceSentenceStart = sourceOffset,
|
||||
sourceSentenceEndExclusive = sourceOffset,
|
||||
),
|
||||
)
|
||||
refreshNotification()
|
||||
speakCurrentSegment()
|
||||
}
|
||||
|
||||
@@ -721,7 +764,7 @@ class ReaderTtsService : Service() {
|
||||
companion object {
|
||||
const val ACTION_START = "eu.kanade.tachiyomi.reader.tts.START"
|
||||
const val ACTION_TOGGLE = "eu.kanade.tachiyomi.reader.tts.TOGGLE"
|
||||
const val ACTION_RESUME_FROM_PAGE = "eu.kanade.tachiyomi.reader.tts.RESUME_FROM_PAGE"
|
||||
const val ACTION_RESUME_FROM_SOURCE = "eu.kanade.tachiyomi.reader.tts.RESUME_FROM_SOURCE"
|
||||
const val ACTION_STOP = "eu.kanade.tachiyomi.reader.tts.STOP"
|
||||
const val ACTION_SET_SPEED = "eu.kanade.tachiyomi.reader.tts.SET_SPEED"
|
||||
const val ACTION_SET_ENGINE = "eu.kanade.tachiyomi.reader.tts.SET_ENGINE"
|
||||
@@ -729,6 +772,8 @@ class ReaderTtsService : Service() {
|
||||
|
||||
const val EXTRA_SESSION_ID = "session_id"
|
||||
const val EXTRA_START_PAGE_INDEX = "start_page_index"
|
||||
const val EXTRA_DOCUMENT_INDEX = "document_index"
|
||||
const val EXTRA_SOURCE_OFFSET = "source_offset"
|
||||
const val EXTRA_CHAPTER_ID = "chapter_id"
|
||||
const val EXTRA_TITLE = "title"
|
||||
const val EXTRA_SUBTITLE = "subtitle"
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M6,6h12v12H6z" />
|
||||
</vector>
|
||||
@@ -1110,8 +1110,13 @@
|
||||
<string name="pref_text_reader_tts_voice_settings">Voice data settings</string>
|
||||
<string name="reader_tts_start">Start TTS</string>
|
||||
<string name="reader_tts_pause">Pause TTS</string>
|
||||
<string name="reader_tts_stop">Stop TTS</string>
|
||||
<string name="pref_text_reader_line_spacing">Line spacing</string>
|
||||
<string name="pref_text_reader_paragraph_spacing">Paragraph spacing</string>
|
||||
<string name="pref_text_reader_horizontal_margin">Side margins</string>
|
||||
<string name="pref_text_reader_line_break_mode">Line wrapping</string>
|
||||
<string name="pref_text_reader_line_break_word">By word</string>
|
||||
<string name="pref_text_reader_line_break_character">By character</string>
|
||||
<string name="pref_text_reader_font_family">Font</string>
|
||||
<string name="pref_text_reader_font_system">System</string>
|
||||
<string name="pref_text_reader_font_sans">Sans-serif</string>
|
||||
|
||||
@@ -918,8 +918,13 @@
|
||||
<string name="pref_text_reader_tts_voice_settings">음성 데이터 설정</string>
|
||||
<string name="reader_tts_start">TTS 시작</string>
|
||||
<string name="reader_tts_pause">TTS 일시정지</string>
|
||||
<string name="reader_tts_stop">TTS 정지</string>
|
||||
<string name="pref_text_reader_line_spacing">행간</string>
|
||||
<string name="pref_text_reader_paragraph_spacing">문단 간격</string>
|
||||
<string name="pref_text_reader_horizontal_margin">좌우 여백</string>
|
||||
<string name="pref_text_reader_line_break_mode">줄바꿈</string>
|
||||
<string name="pref_text_reader_line_break_word">단어 단위</string>
|
||||
<string name="pref_text_reader_line_break_character">글자 단위</string>
|
||||
<string name="pref_text_reader_font_family">글꼴</string>
|
||||
<string name="pref_text_reader_font_system">시스템</string>
|
||||
<string name="pref_text_reader_font_sans">고딕</string>
|
||||
|
||||
Reference in New Issue
Block a user