* Added support for AI and Cloud credits in the Pro flavor. * Implemented credit-based authentication and authorization for AI features and Cloud TTS. * Updated AI feature access and purchase handling to a credit-based system. * Refactored and enhanced the Text-to-Speech (TTS) system with persistent caching and a redesigned UI. * Improved TTS cache management by organizing audio files by book title and adding a detailed cache storage UI. * Refactored the TTS service to use a WebSocket-based Gemini Live connection for cloud audio generation. * Removed the TTS cache settings tab and simplified voice sample playback by removing local caching logic. * Implemented a low-latency streaming mechanism for Cloud TTS using a custom `ConcurrentInputStream` and `ExoPlayer` data source. * Improved cloud TTS stability and prefetching logic in `TtsService` and `TtsPlaybackManager`. * Implemented AI summarization caching and cost tracking in the EPUB reader. * Enhanced chapter summary caching and UI feedback. * limit summaries for pro users to 10 per day * Implemented local caching for Cloud TTS audio chunks. * Removed the Free tier tab from `ProScreen` and simplified the subscription interface. Updated tab logic to focus on Pro and Credits, including a new cost breakdown section for AI and Cloud TTS features. * Refactored HTML parsing to include all child nodes during content chunking and semantic block parsing. * Improved image rendering consistency in epub pagination reader * Improved HTML parsing in `HtmlParser.kt` to better handle complex nested structures * Improved CSS styling support in the epub paginated reader for word spacing and text decorations. * Implemented scroll throttling in `epub_reader.js` to improve performance during scroll events * Improved CFI resolution and scrolling reliability in EPUB reader * Optimized PaginatedReader performance by caching text decorations. * Implemented batching for recent file database operations to handle large datasets and introduced `RecentFileSummary` to optimize data retrieval by excluding heavy JSON columns. * Improved navigation stability by wrapping `navController.navigate` and `popBackStack` calls in a try-catch block to handle `IllegalStateException` during concurrent transitions. Additionally, refined the backstack check for the main route to prevent redundant pops. * feat(tts): redesign TTS controls with overlay UI and cache management * Expanded and improved the TTS (Text-to-Speech) capabilities, particularly for Cloud voices. * Improved TTS playback control and cache management. * Integrated the TTS cache manager into the settings sheet and improved the TTS configuration UI. * Updated `DeviceVoicesTab` to respect the current TTS mode, disabling voice selection when not in `BASE` mode. * Improved error handling and state management for Cloud TTS in `TtsService` and `TtsPlaybackManager`. * Improved TTS voice selection UI and sample playback logic. * Updated `TtsUtils` and `TtsService` to remove `chunkIndex` from TTS cache filenames. Refined the cache file naming convention to rely on text and speaker hashes, and updated the cache file filter logic to correctly identify speakers in both legacy and new filename formats. * Optimized tile rendering and state propagation in PDF viewer * Added "Expand All", "Collapse All", and "Locate" functionality to the Table of Contents in both EPUB and PDF readers. * Added sign-in requirement for credit purchases and improved purchase migration logic. * Updated `EpubReaderTts` to support authenticated TTS requests by passing an auth token provider. The `ttsController.start` method now includes an `authToken` retrieved via `getAuthToken` and explicitly sets the `playbackSource` to "READER". * feat(ai): replace summarization popup with a comprehensive AI Hub Bottom Sheet * Improved locator logic and block traversal in `BookPaginator`. * Updated AI features and Cloud TTS logic. * Added manual clear and auto-reset functionality for AI summaries and recaps * Optimized file importing, EPUB parsing, and TTS playback concurrency. * Restricted TTS mode to BASE in OSS flavor and fixed TTS mode persistence in PDF viewer * Bump version to 1.0.43(44)
189 lines
No EOL
6.7 KiB
Kotlin
189 lines
No EOL
6.7 KiB
Kotlin
/*
|
|
* Episteme Reader - A native Android document reader.
|
|
* Copyright (C) 2026 Episteme
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
* License, or (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Affero General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*
|
|
* mail: epistemereader@gmail.com
|
|
*/
|
|
package com.aryan.reader.data
|
|
|
|
import android.net.Uri
|
|
import com.aryan.reader.FileType
|
|
import androidx.core.net.toUri
|
|
|
|
data class RecentFileItem(
|
|
val bookId: String,
|
|
val uriString: String?,
|
|
val type: FileType,
|
|
val displayName: String,
|
|
val timestamp: Long,
|
|
val coverImagePath: String? = null,
|
|
val title: String? = null,
|
|
val author: String? = null,
|
|
val lastChapterIndex: Int? = null,
|
|
val lastPage: Int? = null,
|
|
val lastPositionCfi: String? = null,
|
|
val locatorBlockIndex: Int? = null,
|
|
val locatorCharOffset: Int? = null,
|
|
val progressPercentage: Float? = null,
|
|
val isRecent: Boolean = true,
|
|
val isAvailable: Boolean = true,
|
|
val lastModifiedTimestamp: Long = 0L,
|
|
val isDeleted: Boolean = false,
|
|
val bookmarksJson: String? = null,
|
|
val sourceFolderUri: String? = null,
|
|
val isReflowPreferred: Boolean = false,
|
|
val customName: String? = null,
|
|
val highlightsJson: String? = null,
|
|
val fileSize: Long = 0L
|
|
) {
|
|
fun getUri(): Uri? = uriString?.toUri()
|
|
}
|
|
|
|
fun RecentFileEntity.toRecentFileItem(): RecentFileItem {
|
|
return RecentFileItem(
|
|
bookId = this.bookId,
|
|
uriString = this.uriString,
|
|
type = this.type,
|
|
displayName = this.displayName,
|
|
timestamp = this.timestamp,
|
|
coverImagePath = this.coverImagePath,
|
|
title = this.title,
|
|
author = this.author,
|
|
lastChapterIndex = this.lastChapterIndex,
|
|
locatorBlockIndex = this.locatorBlockIndex,
|
|
locatorCharOffset = this.locatorCharOffset,
|
|
lastPage = this.lastPage,
|
|
lastPositionCfi = this.lastPositionCfi,
|
|
progressPercentage = this.progressPercentage,
|
|
isRecent = this.isRecent,
|
|
isAvailable = this.isAvailable,
|
|
lastModifiedTimestamp = this.lastModifiedTimestamp,
|
|
isDeleted = this.isDeleted,
|
|
bookmarksJson = this.bookmarks,
|
|
sourceFolderUri = this.sourceFolderUri,
|
|
isReflowPreferred = this.isReflowPreferred,
|
|
customName = this.customName,
|
|
highlightsJson = this.highlights,
|
|
fileSize = this.fileSize
|
|
)
|
|
}
|
|
|
|
fun RecentFileItem.toRecentFileEntity(): RecentFileEntity {
|
|
return RecentFileEntity(
|
|
bookId = this.bookId,
|
|
uriString = this.uriString,
|
|
type = this.type,
|
|
displayName = this.displayName,
|
|
timestamp = this.timestamp,
|
|
coverImagePath = this.coverImagePath,
|
|
title = this.title,
|
|
author = this.author,
|
|
lastChapterIndex = this.lastChapterIndex,
|
|
locatorBlockIndex = this.locatorBlockIndex,
|
|
locatorCharOffset = this.locatorCharOffset,
|
|
lastPage = this.lastPage,
|
|
lastPositionCfi = this.lastPositionCfi,
|
|
progressPercentage = this.progressPercentage,
|
|
isRecent = this.isRecent,
|
|
isAvailable = this.isAvailable,
|
|
lastModifiedTimestamp = this.lastModifiedTimestamp,
|
|
isDeleted = this.isDeleted,
|
|
bookmarks = this.bookmarksJson,
|
|
sourceFolderUri = this.sourceFolderUri,
|
|
isReflowPreferred = this.isReflowPreferred,
|
|
customName = this.customName,
|
|
highlights = this.highlightsJson,
|
|
fileSize = this.fileSize
|
|
)
|
|
}
|
|
|
|
fun RecentFileItem.toBookMetadata(): BookMetadata {
|
|
return BookMetadata(
|
|
bookId = this.bookId,
|
|
title = this.title,
|
|
author = this.author,
|
|
displayName = this.displayName,
|
|
type = this.type.name,
|
|
lastPositionCfi = this.lastPositionCfi,
|
|
lastChapterIndex = this.lastChapterIndex,
|
|
locatorBlockIndex = this.locatorBlockIndex,
|
|
locatorCharOffset = this.locatorCharOffset,
|
|
lastPage = this.lastPage,
|
|
progressPercentage = this.progressPercentage,
|
|
isRecent = this.isRecent,
|
|
isDeleted = this.isDeleted,
|
|
lastModifiedTimestamp = this.lastModifiedTimestamp,
|
|
bookmarksJson = this.bookmarksJson,
|
|
hasAnnotations = false,
|
|
customName = this.customName,
|
|
highlightsJson = this.highlightsJson
|
|
)
|
|
}
|
|
|
|
fun BookMetadata.toRecentFileItem(): RecentFileItem {
|
|
return RecentFileItem(
|
|
bookId = this.bookId,
|
|
uriString = null,
|
|
type = try { FileType.valueOf(this.type) } catch (_: Exception) { FileType.EPUB },
|
|
displayName = this.displayName,
|
|
timestamp = this.lastModifiedTimestamp,
|
|
coverImagePath = null,
|
|
title = this.title,
|
|
author = this.author,
|
|
lastChapterIndex = this.lastChapterIndex,
|
|
locatorBlockIndex = this.locatorBlockIndex,
|
|
locatorCharOffset = this.locatorCharOffset,
|
|
lastPositionCfi = this.lastPositionCfi,
|
|
lastPage = this.lastPage,
|
|
progressPercentage = this.progressPercentage,
|
|
isRecent = this.isRecent,
|
|
isAvailable = false,
|
|
lastModifiedTimestamp = this.lastModifiedTimestamp,
|
|
isDeleted = this.isDeleted,
|
|
bookmarksJson = this.bookmarksJson,
|
|
customName = this.customName,
|
|
highlightsJson = this.highlightsJson
|
|
)
|
|
}
|
|
|
|
fun RecentFileSummary.toRecentFileItem(): RecentFileItem {
|
|
return RecentFileItem(
|
|
bookId = this.bookId,
|
|
uriString = this.uriString,
|
|
type = this.type,
|
|
displayName = this.displayName,
|
|
timestamp = this.timestamp,
|
|
coverImagePath = this.coverImagePath,
|
|
title = this.title,
|
|
author = this.author,
|
|
lastChapterIndex = this.lastChapterIndex,
|
|
locatorBlockIndex = this.locatorBlockIndex,
|
|
locatorCharOffset = this.locatorCharOffset,
|
|
lastPage = this.lastPage,
|
|
lastPositionCfi = this.lastPositionCfi,
|
|
progressPercentage = this.progressPercentage,
|
|
isRecent = this.isRecent,
|
|
isAvailable = this.isAvailable,
|
|
lastModifiedTimestamp = this.lastModifiedTimestamp,
|
|
isDeleted = this.isDeleted,
|
|
bookmarksJson = null,
|
|
sourceFolderUri = this.sourceFolderUri,
|
|
isReflowPreferred = this.isReflowPreferred,
|
|
customName = this.customName,
|
|
highlightsJson = null,
|
|
fileSize = this.fileSize
|
|
)
|
|
} |