V1.0.43 oss (#202)
* 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)
This commit is contained in:
parent
e8f6be2800
commit
46620fa71a
41 changed files with 4412 additions and 2406 deletions
|
|
@ -113,6 +113,7 @@ import java.util.UUID
|
|||
import java.util.concurrent.CancellationException
|
||||
import java.util.concurrent.TimeUnit
|
||||
import androidx.core.graphics.createBitmap
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
|
||||
private const val KEY_RENDER_MODE = "render_mode"
|
||||
private const val KEY_FOLDER_SYNC_ENABLED = "folder_sync_enabled"
|
||||
|
|
@ -214,6 +215,7 @@ data class ReaderScreenState(
|
|||
val currentUser: UserData? = null,
|
||||
val isAuthMenuExpanded: Boolean = false,
|
||||
val isProUser: Boolean = false,
|
||||
val credits: Int = 0,
|
||||
val isSyncEnabled: Boolean = false,
|
||||
val isFolderSyncEnabled: Boolean = false,
|
||||
val bannerMessage: BannerMessage? = null,
|
||||
|
|
@ -269,7 +271,6 @@ open class MainViewModel(application: Application) : AndroidViewModel(applicatio
|
|||
private val cloudflareRepository = CloudflareRepository()
|
||||
private val remoteConfigRepository = RemoteConfigRepository()
|
||||
private var userProfileListener: Any? = null
|
||||
private val migrationAttempted = MutableStateFlow(false)
|
||||
private val _prefsUpdateFlow = MutableStateFlow(0L)
|
||||
private val prefsListener: SharedPreferences.OnSharedPreferenceChangeListener
|
||||
private val feedbackRepository = FeedbackRepository(appContext)
|
||||
|
|
@ -800,9 +801,8 @@ open class MainViewModel(application: Application) : AndroidViewModel(applicatio
|
|||
_internalState.update { it.copy(hasUnreadFeedback = hasUnread) }
|
||||
}
|
||||
|
||||
userProfileListener =
|
||||
firestoreRepository.listenToUserProfile(newUserData.uid) { isProFromBackend ->
|
||||
_internalState.update { it.copy(isProUser = isProFromBackend) }
|
||||
userProfileListener = firestoreRepository.listenToUserProfile(newUserData.uid) { isProFromBackend, creditsFromBackend ->
|
||||
_internalState.update { it.copy(isProUser = isProFromBackend, credits = creditsFromBackend) }
|
||||
|
||||
if (isProFromBackend) {
|
||||
verifyDeviceForProUser()
|
||||
|
|
@ -823,13 +823,27 @@ open class MainViewModel(application: Application) : AndroidViewModel(applicatio
|
|||
}
|
||||
}
|
||||
}
|
||||
triggerLegacyPurchaseMigration()
|
||||
}
|
||||
} else {
|
||||
_internalState.update { it.copy(isProUser = false, hasUnreadFeedback = false) }
|
||||
_internalState.update { it.copy(isProUser = false, credits = 0, isSyncEnabled = false, hasUnreadFeedback = false) }
|
||||
}
|
||||
}
|
||||
}
|
||||
viewModelScope.launch {
|
||||
combine(
|
||||
billingClientWrapper.proUpgradeState.map { it.activePurchases },
|
||||
_internalState.map { it.currentUser?.uid }
|
||||
) { purchases, uid ->
|
||||
Pair(purchases, uid)
|
||||
}
|
||||
.distinctUntilChanged()
|
||||
.collect { (purchases, uid) ->
|
||||
if (uid != null && purchases.isNotEmpty()) {
|
||||
Timber.d("Active purchases or User changed, triggering migration check")
|
||||
triggerLegacyPurchaseMigration()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getDisplayPathFromUri(context: Context, uriString: String): String {
|
||||
|
|
@ -1010,40 +1024,45 @@ open class MainViewModel(application: Application) : AndroidViewModel(applicatio
|
|||
purchase: PurchaseEntity, isSilentMigrationCheck: Boolean = false
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
if (!purchase.products.contains(BillingClientWrapper.PRO_LIFETIME_PRODUCT_ID)) {
|
||||
val productId = purchase.products.firstOrNull()
|
||||
|
||||
if (productId == null || (!productId.startsWith("credits_") && productId != BillingClientWrapper.PRO_LIFETIME_PRODUCT_ID)) {
|
||||
Timber.e("Purchase verification failed: Incorrect product ID.")
|
||||
if (!isSilentMigrationCheck) {
|
||||
_internalState.update {
|
||||
it.copy(
|
||||
bannerMessage = BannerMessage(appContext.getString(R.string.error_purchase_general), isError = true)
|
||||
)
|
||||
}
|
||||
_internalState.update { it.copy(bannerMessage = BannerMessage(appContext.getString(R.string.error_purchase_general), isError = true)) }
|
||||
}
|
||||
billingClientWrapper.clearVerificationState()
|
||||
return@launch
|
||||
}
|
||||
|
||||
val result = cloudflareRepository.verifyPurchase(purchase.purchaseToken)
|
||||
val result = cloudflareRepository.verifyPurchase(purchase.purchaseToken, productId)
|
||||
|
||||
if (result.isSuccess) {
|
||||
Timber.i("Backend verification successful. Firestore will update the app.")
|
||||
_internalState.update {
|
||||
it.copy(bannerMessage = BannerMessage(appContext.getString(R.string.banner_upgrade_success)))
|
||||
|
||||
if (productId.startsWith("credits_")) {
|
||||
billingClientWrapper.consumePurchase(purchase.purchaseToken)
|
||||
if (!isSilentMigrationCheck) {
|
||||
_internalState.update { it.copy(bannerMessage = BannerMessage("Credits successfully added!")) }
|
||||
}
|
||||
} else {
|
||||
if (!isSilentMigrationCheck) {
|
||||
_internalState.update { it.copy(bannerMessage = BannerMessage(appContext.getString(R.string.banner_upgrade_success))) }
|
||||
}
|
||||
verifyDeviceForProUser()
|
||||
}
|
||||
verifyDeviceForProUser()
|
||||
} else {
|
||||
val exception = result.exceptionOrNull()
|
||||
if (exception?.message?.contains("already claimed") == true) {
|
||||
Timber.i(
|
||||
"Migration check: Purchase token is already claimed by another account. Silently ignoring."
|
||||
)
|
||||
Timber.i("Migration/Refresh check: Purchase token is already claimed. Silently ignoring.")
|
||||
if (productId.startsWith("credits_")) {
|
||||
billingClientWrapper.consumePurchase(purchase.purchaseToken)
|
||||
}
|
||||
} else {
|
||||
val errorMessage = appContext.getString(R.string.error_purchase_verification)
|
||||
Timber.e(exception, "Backend verification failed")
|
||||
if (!isSilentMigrationCheck) {
|
||||
_internalState.update {
|
||||
it.copy(bannerMessage = BannerMessage(errorMessage, isError = true))
|
||||
}
|
||||
_internalState.update { it.copy(bannerMessage = BannerMessage(errorMessage, isError = true)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2004,27 +2023,14 @@ open class MainViewModel(application: Application) : AndroidViewModel(applicatio
|
|||
|
||||
private fun triggerLegacyPurchaseMigration() {
|
||||
val user = _internalState.value.currentUser
|
||||
val isProOnBackend = _internalState.value.isProUser
|
||||
val localPurchases = billingClientWrapper.proUpgradeState.value.activePurchases
|
||||
|
||||
val checkedUids = prefs.getStringSet(KEY_MIGRATION_CHECKED_UIDS, emptySet()) ?: emptySet()
|
||||
if (user != null && user.uid in checkedUids) {
|
||||
Timber.d(
|
||||
"Migration check for user ${user.uid} already performed on this device. Skipping."
|
||||
)
|
||||
return // Already checked, do nothing.
|
||||
}
|
||||
if (user != null && localPurchases.isNotEmpty()) {
|
||||
Timber.i("Checking for unconsumed purchases or legacy pro statuses...")
|
||||
|
||||
if (user != null && !isProOnBackend && localPurchases.isNotEmpty() && !migrationAttempted.value) {
|
||||
migrationAttempted.value = true
|
||||
Timber.i(
|
||||
"MIGRATION: Found legacy user with local purchase. Verifying with backend silently..."
|
||||
)
|
||||
val purchaseToVerify = localPurchases.first()
|
||||
|
||||
verifyPurchaseWithBackend(purchaseToVerify, isSilentMigrationCheck = true)
|
||||
|
||||
prefs.edit { putStringSet(KEY_MIGRATION_CHECKED_UIDS, checkedUids + user.uid) }
|
||||
localPurchases.forEach { purchase ->
|
||||
verifyPurchaseWithBackend(purchase, isSilentMigrationCheck = true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -2136,9 +2142,9 @@ open class MainViewModel(application: Application) : AndroidViewModel(applicatio
|
|||
}
|
||||
}
|
||||
|
||||
fun launchPurchaseFlow(activity: android.app.Activity) {
|
||||
Timber.d("Attempting to launch purchase flow. Pro state is: ${proUpgradeState.value}")
|
||||
billingClientWrapper.launchPurchaseFlow(activity)
|
||||
fun launchPurchaseFlow(activity: android.app.Activity, productId: String = BillingClientWrapper.PRO_LIFETIME_PRODUCT_ID) {
|
||||
Timber.d("Attempting to launch purchase flow for $productId. Pro state is: ${proUpgradeState.value}")
|
||||
billingClientWrapper.launchPurchaseFlow(activity, productId)
|
||||
}
|
||||
|
||||
fun clearBillingError() {
|
||||
|
|
@ -4485,6 +4491,10 @@ open class MainViewModel(application: Application) : AndroidViewModel(applicatio
|
|||
_internalState.update { it.copy(useStrictFileFilter = enabled) }
|
||||
}
|
||||
|
||||
suspend fun getAuthToken(): String? {
|
||||
return authRepository.getIdToken()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val KEY_SORT_ORDER = "sort_order"
|
||||
internal const val KEY_SHELVES = "shelf_names"
|
||||
|
|
@ -4494,7 +4504,6 @@ open class MainViewModel(application: Application) : AndroidViewModel(applicatio
|
|||
private const val KEY_ADD_BOOKS_SOURCE = "add_books_source"
|
||||
private const val KEY_SYNC_ENABLED = "sync_enabled"
|
||||
private const val KEY_LAST_SYNC_TIMESTAMP = "last_sync_timestamp"
|
||||
private const val KEY_MIGRATION_CHECKED_UIDS = "migration_checked_uids"
|
||||
private const val KEY_INSTALLATION_ID = "installation_id"
|
||||
private const val KEY_APP_OPEN_COUNT = "app_open_count"
|
||||
internal const val KEY_SYNCED_FOLDER_URI = "synced_folder_uri"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue