* Added PDF top tab strip visibility toggle and fixed WebView hit test NPE * Refactored desktop reader screens and state management into specialized components * Added image gallery to reader sidebar and refactored desktop PDF UI components * Implemented EPUB image gallery * Refactored reader and library models to use shared common types, centralizing file type resolution and texture management while removing redundant mapping logic * Standardized UI styling and refactored app navigation layout * Implemented auto-hiding reader chrome and activity tracking in desktop * Refactored reader panels into distinct left and right modal layers with platform-specific sizing and keyboard navigation support. * Added PPTX support for desktop and refactored parsing into a shared module * Implement paid AI features and account management for the desktop application. * Implement AI Hub and enhanced Cloud TTS integration for Desktop * Implement streaming support for AI definition and summarization features * Implement support for password-protected PDFs and file actions in the desktop reader. * Implement cloud synchronization for desktop using Firestore and Google Drive * Implement PDF reflow and "Text View" for the desktop reader * Refactor OPDS logic to use SharedOpdsController * Optimize PDF tile rendering performance * Implement two-page spread support for PDF pagination * Implement two-page spread support for the PDF viewer * Improved shared spread zoom in PDF viewer * Improve PDF spread navigation with fling support and configurable page gaps * Add brightness control to PDF and EPUB readers * Refactor folder synchronization to use shared logic engine * Implement safe string formatting and validation for localized resources * Implement TTS chunk skip navigation * Implement deep-linking and playback controls for TTS media sessions * Implement start index for TTS playback * Improve TTS navigation, prefetching, and notification duration reporting * Implement TTS mini playback bar for background reading * Implement multi-window reader support for the desktop application * Improve desktop modal window management and visibility syncing * Implement localized string support for Desktop and shared UI * Implement language selection and persistence for Desktop * Implement plural string support for Desktop and migrate hardcoded counts to plurals.xml * Implement localized banner messages and UI strings using resource-backed SharedText * Implement compact badge styling for small book covers * Refactor PDF native interaction and improve HTML import memory safety * fix language persistence * Refactor reader overflow menus to use section-based logic * Refactor PDF layout remapping and improve text box interaction * Improve CFI resolution and TTS resume accuracy using dynamic chunk offsets * Centralize PDF annotation export mapping and improve metadata handling * Add support for threaded comments in PDF highlight annotations * Flatten highlight comments into a single thread for PDF export and allow author editing * Integrate page slider into reader chrome and persist toggle state * Handle fragments and queries in EPUB chapter paths * Implement dynamic, theme-aware coloring for the reader slider * Implement customizable app-wide font preference * Implement one-hand zoom gestures in the PDF viewer * Implement File Information dialog for PDF and EPUB readers * Bump version to 1.0.49 (53) * Refactor PDF reader logic into modular components * Add ProGuard rules to prevent R8 optimization issues in EPUB reader screens * Add option to use PDF filenames as display names * Fix preservation of PDF filename display preference in library projection
198 lines
7.6 KiB
Kotlin
198 lines
7.6 KiB
Kotlin
package com.aryan.reader.tts
|
|
|
|
import androidx.compose.foundation.BorderStroke
|
|
import androidx.compose.foundation.clickable
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
import androidx.compose.foundation.layout.Box
|
|
import androidx.compose.foundation.layout.Column
|
|
import androidx.compose.foundation.layout.Row
|
|
import androidx.compose.foundation.layout.Spacer
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
import androidx.compose.foundation.layout.heightIn
|
|
import androidx.compose.foundation.layout.padding
|
|
import androidx.compose.foundation.layout.size
|
|
import androidx.compose.foundation.layout.width
|
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
|
import androidx.compose.material.icons.Icons
|
|
import androidx.compose.material.icons.filled.SkipNext
|
|
import androidx.compose.material.icons.filled.SkipPrevious
|
|
import androidx.compose.material3.CircularProgressIndicator
|
|
import androidx.compose.material3.FilledIconButton
|
|
import androidx.compose.material3.Icon
|
|
import androidx.compose.material3.IconButton
|
|
import androidx.compose.material3.IconButtonDefaults
|
|
import androidx.compose.material3.MaterialTheme
|
|
import androidx.compose.material3.Surface
|
|
import androidx.compose.material3.Text
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.runtime.remember
|
|
import androidx.compose.ui.Alignment
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.draw.clip
|
|
import androidx.compose.ui.res.painterResource
|
|
import androidx.compose.ui.res.stringResource
|
|
import androidx.compose.ui.text.style.TextOverflow
|
|
import androidx.compose.ui.unit.dp
|
|
import androidx.media3.common.util.UnstableApi
|
|
import com.aryan.reader.R
|
|
import com.aryan.reader.tts.TtsPlaybackManager.TtsState
|
|
|
|
private const val TTS_MINI_BAR_EDGE_PADDING_DP = 16
|
|
private const val TTS_MINI_BAR_MAIN_BOTTOM_PADDING_DP = 96
|
|
|
|
internal fun shouldShowReaderTtsMiniBar(
|
|
ttsState: TtsState,
|
|
isOnReaderRoute: Boolean
|
|
): Boolean {
|
|
if (isOnReaderRoute) return false
|
|
if (ttsState.playbackSource != "READER") return false
|
|
if (ttsState.sessionEndedByStop || ttsState.sessionFinished) return false
|
|
return ttsState.isLoading || !ttsState.currentText.isNullOrBlank()
|
|
}
|
|
|
|
internal fun readerTtsMiniBarBottomPaddingDp(isOnMainRoute: Boolean): Int {
|
|
return if (isOnMainRoute) {
|
|
TTS_MINI_BAR_MAIN_BOTTOM_PADDING_DP
|
|
} else {
|
|
TTS_MINI_BAR_EDGE_PADDING_DP
|
|
}
|
|
}
|
|
|
|
@androidx.annotation.OptIn(UnstableApi::class)
|
|
@Composable
|
|
fun ReaderTtsMiniBar(
|
|
ttsController: TtsController,
|
|
ttsState: TtsState,
|
|
onOpenReader: () -> Unit,
|
|
modifier: Modifier = Modifier
|
|
) {
|
|
val canOpenReader = !ttsState.bookId.isNullOrBlank()
|
|
val canSkipPreviousChunk = !ttsState.isLoading &&
|
|
ttsState.currentChunkIndex > 0 &&
|
|
ttsState.totalChunks > 0
|
|
val canSkipNextChunk = !ttsState.isLoading &&
|
|
ttsState.currentChunkIndex >= 0 &&
|
|
ttsState.currentChunkIndex < ttsState.totalChunks - 1
|
|
val chunkLabel = remember(ttsState.currentChunkIndex, ttsState.totalChunks) {
|
|
if (ttsState.currentChunkIndex >= 0 && ttsState.totalChunks > 0) {
|
|
"Chunk ${ttsState.currentChunkIndex + 1}/${ttsState.totalChunks}"
|
|
} else {
|
|
null
|
|
}
|
|
}
|
|
val title = ttsState.bookTitle
|
|
?.takeIf { it.isNotBlank() }
|
|
?: stringResource(R.string.action_read_aloud)
|
|
val subtitle = remember(title, ttsState.chapterTitle, chunkLabel) {
|
|
listOfNotNull(
|
|
ttsState.chapterTitle
|
|
?.takeIf { it.isNotBlank() && it != title },
|
|
chunkLabel
|
|
).joinToString(" - ")
|
|
}
|
|
|
|
Surface(
|
|
shape = RoundedCornerShape(24.dp),
|
|
color = MaterialTheme.colorScheme.surfaceContainerHigh,
|
|
contentColor = MaterialTheme.colorScheme.onSurface,
|
|
tonalElevation = 0.dp,
|
|
shadowElevation = 8.dp,
|
|
border = BorderStroke(1.dp, MaterialTheme.colorScheme.outlineVariant),
|
|
modifier = modifier
|
|
) {
|
|
Row(
|
|
modifier = Modifier
|
|
.fillMaxWidth()
|
|
.heightIn(min = 64.dp)
|
|
.padding(horizontal = 8.dp, vertical = 8.dp),
|
|
verticalAlignment = Alignment.CenterVertically
|
|
) {
|
|
Column(
|
|
modifier = Modifier
|
|
.weight(1f)
|
|
.clip(RoundedCornerShape(16.dp))
|
|
.clickable(enabled = canOpenReader, onClick = onOpenReader)
|
|
.padding(horizontal = 10.dp, vertical = 6.dp),
|
|
verticalArrangement = Arrangement.Center
|
|
) {
|
|
Text(
|
|
text = title,
|
|
style = MaterialTheme.typography.labelLarge,
|
|
maxLines = 1,
|
|
overflow = TextOverflow.Ellipsis
|
|
)
|
|
if (subtitle.isNotBlank()) {
|
|
Text(
|
|
text = subtitle,
|
|
style = MaterialTheme.typography.labelSmall,
|
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
|
maxLines = 1,
|
|
overflow = TextOverflow.Ellipsis
|
|
)
|
|
}
|
|
}
|
|
|
|
Spacer(Modifier.width(4.dp))
|
|
|
|
IconButton(
|
|
enabled = canSkipPreviousChunk,
|
|
onClick = ttsController::skipToPreviousChunk,
|
|
modifier = Modifier.size(40.dp)
|
|
) {
|
|
Icon(
|
|
imageVector = Icons.Default.SkipPrevious,
|
|
contentDescription = stringResource(R.string.content_desc_tts_previous_chunk),
|
|
modifier = Modifier.size(24.dp)
|
|
)
|
|
}
|
|
|
|
Box(modifier = Modifier.size(48.dp), contentAlignment = Alignment.Center) {
|
|
FilledIconButton(
|
|
onClick = {
|
|
if (ttsState.isPlaying) {
|
|
ttsController.pause()
|
|
} else {
|
|
ttsController.resume()
|
|
}
|
|
},
|
|
modifier = Modifier.size(44.dp),
|
|
colors = IconButtonDefaults.filledIconButtonColors(
|
|
containerColor = MaterialTheme.colorScheme.primaryContainer,
|
|
contentColor = MaterialTheme.colorScheme.onPrimaryContainer
|
|
)
|
|
) {
|
|
Icon(
|
|
painter = painterResource(if (ttsState.isPlaying) R.drawable.pause else R.drawable.play),
|
|
contentDescription = stringResource(
|
|
if (ttsState.isPlaying) {
|
|
R.string.content_desc_pause_tts
|
|
} else {
|
|
R.string.content_desc_resume_tts
|
|
}
|
|
),
|
|
modifier = Modifier.size(22.dp)
|
|
)
|
|
}
|
|
if (ttsState.isLoading) {
|
|
CircularProgressIndicator(
|
|
modifier = Modifier.size(48.dp),
|
|
color = MaterialTheme.colorScheme.primary,
|
|
strokeWidth = 2.dp
|
|
)
|
|
}
|
|
}
|
|
|
|
IconButton(
|
|
enabled = canSkipNextChunk,
|
|
onClick = ttsController::skipToNextChunk,
|
|
modifier = Modifier.size(40.dp)
|
|
) {
|
|
Icon(
|
|
imageVector = Icons.Default.SkipNext,
|
|
contentDescription = stringResource(R.string.content_desc_tts_next_chunk),
|
|
modifier = Modifier.size(24.dp)
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|