* 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
137 lines
4.6 KiB
Kotlin
137 lines
4.6 KiB
Kotlin
package com.aryan.reader
|
|
|
|
import android.content.Context
|
|
import androidx.compose.ui.graphics.Color
|
|
import androidx.compose.ui.graphics.luminance
|
|
import androidx.core.content.edit
|
|
import kotlin.math.max
|
|
import kotlin.math.min
|
|
|
|
private const val READER_SLIDER_CHROME_PREFS = "reader_slider_chrome_prefs"
|
|
private const val READER_SLIDER_TOGGLE_PREFIX = "reader_slider_toggle_"
|
|
private const val MIN_SLIDER_ACCENT_CONTRAST = 3f
|
|
private const val MIN_SLIDER_CONTENT_CONTRAST = 4.5f
|
|
|
|
internal data class ReaderSliderBookmarkPosition(
|
|
val startPage: Int,
|
|
val currentPage: Float
|
|
)
|
|
|
|
internal data class ReaderSliderToggleState(
|
|
val isToggledOn: Boolean,
|
|
val bookmarkPosition: ReaderSliderBookmarkPosition
|
|
)
|
|
|
|
internal data class ReaderSliderChromeColors(
|
|
val activeTrackColor: Color,
|
|
val inactiveTrackColor: Color,
|
|
val thumbColor: Color,
|
|
val bookmarkColor: Color,
|
|
val contentColor: Color,
|
|
val thumbnailSurfaceColor: Color,
|
|
val thumbnailContentColor: Color
|
|
)
|
|
|
|
internal fun readerSliderBookmarkPosition(currentPage: Int): ReaderSliderBookmarkPosition {
|
|
val sanitizedPage = currentPage.coerceAtLeast(0)
|
|
return ReaderSliderBookmarkPosition(
|
|
startPage = sanitizedPage,
|
|
currentPage = sanitizedPage.toFloat()
|
|
)
|
|
}
|
|
|
|
internal fun readerSliderToggleState(
|
|
isCurrentlyToggledOn: Boolean,
|
|
currentPage: Int
|
|
): ReaderSliderToggleState {
|
|
return ReaderSliderToggleState(
|
|
isToggledOn = !isCurrentlyToggledOn,
|
|
bookmarkPosition = readerSliderBookmarkPosition(currentPage)
|
|
)
|
|
}
|
|
|
|
internal fun shouldRenderReaderSlider(
|
|
isToggledOn: Boolean,
|
|
isBottomChromeVisible: Boolean,
|
|
isSearchActive: Boolean
|
|
): Boolean = isToggledOn && isBottomChromeVisible && !isSearchActive
|
|
|
|
internal fun readerSliderTogglePreferenceKey(bookId: String): String =
|
|
READER_SLIDER_TOGGLE_PREFIX + bookId
|
|
|
|
internal fun loadReaderSliderToggled(context: Context, bookId: String): Boolean {
|
|
return context
|
|
.getSharedPreferences(READER_SLIDER_CHROME_PREFS, Context.MODE_PRIVATE)
|
|
.getBoolean(readerSliderTogglePreferenceKey(bookId), false)
|
|
}
|
|
|
|
internal fun saveReaderSliderToggled(
|
|
context: Context,
|
|
bookId: String,
|
|
isToggledOn: Boolean
|
|
) {
|
|
context
|
|
.getSharedPreferences(READER_SLIDER_CHROME_PREFS, Context.MODE_PRIVATE)
|
|
.edit { putBoolean(readerSliderTogglePreferenceKey(bookId), isToggledOn) }
|
|
}
|
|
|
|
internal fun readerSliderChromeColors(
|
|
pageBackground: Color,
|
|
pageText: Color,
|
|
themePrimary: Color
|
|
): ReaderSliderChromeColors {
|
|
val background = specifiedColorOr(pageBackground, Color.White)
|
|
val fallbackContent = highContrastColorFor(background)
|
|
val content = specifiedColorOr(pageText, fallbackContent)
|
|
.takeIf { contrastRatio(it, background) >= MIN_SLIDER_CONTENT_CONTRAST }
|
|
?: fallbackContent
|
|
val active = specifiedColorOr(themePrimary, content)
|
|
.takeIf { contrastRatio(it, background) >= MIN_SLIDER_ACCENT_CONTRAST }
|
|
?: content
|
|
val inactiveAlpha = if (background.luminance() > 0.5f) 0.44f else 0.52f
|
|
val thumbnailSurface = blendColors(
|
|
foreground = content,
|
|
background = background,
|
|
alpha = if (background.luminance() > 0.5f) 0.08f else 0.12f
|
|
).copy(alpha = 0.96f)
|
|
|
|
return ReaderSliderChromeColors(
|
|
activeTrackColor = active,
|
|
inactiveTrackColor = content.copy(alpha = inactiveAlpha),
|
|
thumbColor = active,
|
|
bookmarkColor = active,
|
|
contentColor = content,
|
|
thumbnailSurfaceColor = thumbnailSurface,
|
|
thumbnailContentColor = content
|
|
)
|
|
}
|
|
|
|
private fun specifiedColorOr(color: Color, fallback: Color): Color {
|
|
return if (color == Color.Unspecified) fallback else color
|
|
}
|
|
|
|
private fun highContrastColorFor(background: Color): Color {
|
|
return if (contrastRatio(Color.Black, background) >= contrastRatio(Color.White, background)) {
|
|
Color.Black
|
|
} else {
|
|
Color.White
|
|
}
|
|
}
|
|
|
|
private fun contrastRatio(first: Color, second: Color): Float {
|
|
val firstLuminance = first.luminance()
|
|
val secondLuminance = second.luminance()
|
|
val lighter = max(firstLuminance, secondLuminance)
|
|
val darker = min(firstLuminance, secondLuminance)
|
|
return (lighter + 0.05f) / (darker + 0.05f)
|
|
}
|
|
|
|
private fun blendColors(foreground: Color, background: Color, alpha: Float): Color {
|
|
val clampedAlpha = alpha.coerceIn(0f, 1f)
|
|
return Color(
|
|
red = foreground.red * clampedAlpha + background.red * (1f - clampedAlpha),
|
|
green = foreground.green * clampedAlpha + background.green * (1f - clampedAlpha),
|
|
blue = foreground.blue * clampedAlpha + background.blue * (1f - clampedAlpha),
|
|
alpha = 1f
|
|
)
|
|
}
|