Resume TTS from current reader position
Build & Test / Build & Test App (push) Has been cancelled
Release / Extract tag name (push) Has been cancelled
Update website / update_website (release) Has been cancelled
Release / Build (push) Has been cancelled
Release / Build (FOSS) (push) Has been cancelled
Release / Create GitHub Release (push) Has been cancelled
Build & Test / Build & Test App (push) Has been cancelled
Release / Extract tag name (push) Has been cancelled
Update website / update_website (release) Has been cancelled
Release / Build (push) Has been cancelled
Release / Build (FOSS) (push) Has been cancelled
Release / Create GitHub Release (push) Has been cancelled
This commit is contained in:
@@ -20,13 +20,20 @@ import android.view.WindowManager
|
|||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.activity.enableEdgeToEdge
|
import androidx.activity.enableEdgeToEdge
|
||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.navigationBarsPadding
|
import androidx.compose.foundation.layout.navigationBarsPadding
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
import androidx.compose.material3.AlertDialog
|
import androidx.compose.material3.AlertDialog
|
||||||
import androidx.compose.material3.CircularProgressIndicator
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.IconButton
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.collectAsState
|
import androidx.compose.runtime.collectAsState
|
||||||
@@ -34,6 +41,7 @@ import androidx.compose.runtime.getValue
|
|||||||
import androidx.compose.runtime.remember
|
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.res.painterResource
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.core.content.getSystemService
|
import androidx.core.content.getSystemService
|
||||||
import androidx.core.graphics.Insets
|
import androidx.core.graphics.Insets
|
||||||
@@ -271,6 +279,7 @@ class ReaderActivity : BaseActivity() {
|
|||||||
private fun ReaderActivityBinding.setComposeOverlay(): Unit = composeOverlay.setComposeContent {
|
private fun ReaderActivityBinding.setComposeOverlay(): Unit = composeOverlay.setComposeContent {
|
||||||
val state by viewModel.state.collectAsState()
|
val state by viewModel.state.collectAsState()
|
||||||
val showPageNumber by readerPreferences.showPageNumber.collectAsState()
|
val showPageNumber by readerPreferences.showPageNumber.collectAsState()
|
||||||
|
val ttsState by ReaderTtsController.state.collectAsState()
|
||||||
val settingsviewModel = remember {
|
val settingsviewModel = remember {
|
||||||
ReaderSettingsViewModel(
|
ReaderSettingsViewModel(
|
||||||
readerState = viewModel.state,
|
readerState = viewModel.state,
|
||||||
@@ -296,6 +305,31 @@ class ReaderActivity : BaseActivity() {
|
|||||||
ContentOverlay(state = state)
|
ContentOverlay(state = state)
|
||||||
|
|
||||||
AppBars(state = state)
|
AppBars(state = state)
|
||||||
|
|
||||||
|
if (ttsState.active) {
|
||||||
|
IconButton(
|
||||||
|
onClick = ::toggleTts,
|
||||||
|
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,
|
||||||
|
),
|
||||||
|
) {
|
||||||
|
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),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val onDismissRequest = viewModel::closeDialog
|
val onDismissRequest = viewModel::closeDialog
|
||||||
@@ -701,7 +735,16 @@ class ReaderActivity : BaseActivity() {
|
|||||||
val ttsState = ReaderTtsController.state.value
|
val ttsState = ReaderTtsController.state.value
|
||||||
|
|
||||||
if (ttsState.active && ttsState.readerChapterId == chapterId) {
|
if (ttsState.active && ttsState.readerChapterId == chapterId) {
|
||||||
ReaderTtsController.toggle(this)
|
if (ttsState.playing) {
|
||||||
|
ReaderTtsController.toggle(this)
|
||||||
|
} else {
|
||||||
|
val currentPageIndex = (state.currentPage - 1).coerceAtLeast(0)
|
||||||
|
if (currentPageIndex != ttsState.readerPageIndex) {
|
||||||
|
ReaderTtsController.resumeFromPage(this, currentPageIndex)
|
||||||
|
} else {
|
||||||
|
ReaderTtsController.toggle(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,15 @@ object ReaderTtsController {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun resumeFromPage(context: Context, readerPageIndex: Int) {
|
||||||
|
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),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fun stop(context: Context) {
|
fun stop(context: Context) {
|
||||||
if (!state.value.active) return
|
if (!state.value.active) return
|
||||||
context.startService(
|
context.startService(
|
||||||
|
|||||||
@@ -46,6 +46,9 @@ class ReaderTtsService : Service() {
|
|||||||
when (intent?.action) {
|
when (intent?.action) {
|
||||||
ACTION_START -> startSession(intent)
|
ACTION_START -> startSession(intent)
|
||||||
ACTION_TOGGLE -> if (playing) pausePlayback() else resumePlayback()
|
ACTION_TOGGLE -> if (playing) pausePlayback() else resumePlayback()
|
||||||
|
ACTION_RESUME_FROM_PAGE -> resumeFromPage(
|
||||||
|
intent.getIntExtra(EXTRA_START_PAGE_INDEX, -1),
|
||||||
|
)
|
||||||
ACTION_STOP -> stopPlayback()
|
ACTION_STOP -> stopPlayback()
|
||||||
ACTION_SET_SPEED -> {
|
ACTION_SET_SPEED -> {
|
||||||
playbackSpeed = intent.getFloatExtra(EXTRA_SPEED, playbackSpeed).coerceIn(MIN_SPEED, MAX_SPEED)
|
playbackSpeed = intent.getFloatExtra(EXTRA_SPEED, playbackSpeed).coerceIn(MIN_SPEED, MAX_SPEED)
|
||||||
@@ -204,6 +207,28 @@ class ReaderTtsService : Service() {
|
|||||||
speakCurrentSegment()
|
speakCurrentSegment()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun resumeFromPage(readerPageIndex: Int) {
|
||||||
|
if (!initialized || readerPageIndex < 0) return
|
||||||
|
val session = session ?: return
|
||||||
|
val newPagePosition = session.pages.indexOfFirst { it.readerPageIndex >= readerPageIndex }
|
||||||
|
.takeIf { it >= 0 }
|
||||||
|
?: return
|
||||||
|
|
||||||
|
tts?.stop()
|
||||||
|
pagePosition = newPagePosition
|
||||||
|
pageSpeechStartOffset = 0
|
||||||
|
currentWindow = null
|
||||||
|
currentSegments = emptyList()
|
||||||
|
lookaheadConsumedChars = emptyMap()
|
||||||
|
segmentPosition = 0
|
||||||
|
segmentSpeechOffset = 0
|
||||||
|
currentUtteranceBaseOffset = 0
|
||||||
|
currentUtteranceId = null
|
||||||
|
playing = true
|
||||||
|
updatePlaybackState(clearHighlight = true)
|
||||||
|
speakCurrentSegment()
|
||||||
|
}
|
||||||
|
|
||||||
private fun speakCurrentSegment() {
|
private fun speakCurrentSegment() {
|
||||||
if (!playing || !initialized) return
|
if (!playing || !initialized) return
|
||||||
|
|
||||||
@@ -419,8 +444,16 @@ class ReaderTtsService : Service() {
|
|||||||
active = true,
|
active = true,
|
||||||
playing = playing,
|
playing = playing,
|
||||||
readerChapterId = readerChapterId,
|
readerChapterId = readerChapterId,
|
||||||
readerPageIndex = page.readerPageIndex,
|
readerPageIndex = if (!clearHighlight && previous.readerPageIndex >= 0) {
|
||||||
documentIndex = page.documentIndex,
|
previous.readerPageIndex
|
||||||
|
} else {
|
||||||
|
page.readerPageIndex
|
||||||
|
},
|
||||||
|
documentIndex = if (!clearHighlight && previous.documentIndex >= 0) {
|
||||||
|
previous.documentIndex
|
||||||
|
} else {
|
||||||
|
page.documentIndex
|
||||||
|
},
|
||||||
sourceSentenceStart = if (clearHighlight) -1L else previous.sourceSentenceStart,
|
sourceSentenceStart = if (clearHighlight) -1L else previous.sourceSentenceStart,
|
||||||
sourceSentenceEndExclusive = if (clearHighlight) -1L else previous.sourceSentenceEndExclusive,
|
sourceSentenceEndExclusive = if (clearHighlight) -1L else previous.sourceSentenceEndExclusive,
|
||||||
sourceHighlightStart = if (clearHighlight) -1L else previous.sourceHighlightStart,
|
sourceHighlightStart = if (clearHighlight) -1L else previous.sourceHighlightStart,
|
||||||
@@ -688,6 +721,7 @@ class ReaderTtsService : Service() {
|
|||||||
companion object {
|
companion object {
|
||||||
const val ACTION_START = "eu.kanade.tachiyomi.reader.tts.START"
|
const val ACTION_START = "eu.kanade.tachiyomi.reader.tts.START"
|
||||||
const val ACTION_TOGGLE = "eu.kanade.tachiyomi.reader.tts.TOGGLE"
|
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_STOP = "eu.kanade.tachiyomi.reader.tts.STOP"
|
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_SPEED = "eu.kanade.tachiyomi.reader.tts.SET_SPEED"
|
||||||
const val ACTION_SET_ENGINE = "eu.kanade.tachiyomi.reader.tts.SET_ENGINE"
|
const val ACTION_SET_ENGINE = "eu.kanade.tachiyomi.reader.tts.SET_ENGINE"
|
||||||
|
|||||||
Reference in New Issue
Block a user