* 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
287 lines
11 KiB
Kotlin
287 lines
11 KiB
Kotlin
package com.aryan.reader
|
|
|
|
import com.aryan.reader.data.BookShelfCrossRef
|
|
import com.aryan.reader.data.BookTagCrossRef
|
|
import com.aryan.reader.data.RecentFileItem
|
|
import com.aryan.reader.data.ShelfEntity
|
|
import com.aryan.reader.data.TagEntity
|
|
import com.aryan.reader.shared.BookItem as SharedBookItem
|
|
import com.aryan.reader.shared.BookShelfRef as SharedBookShelfRef
|
|
import com.aryan.reader.shared.EpubAnnotationSerializer
|
|
import com.aryan.reader.shared.FileType as SharedFileType
|
|
import com.aryan.reader.shared.LibraryFilters as SharedLibraryFilters
|
|
import com.aryan.reader.shared.SharedReaderScreenState
|
|
import com.aryan.reader.shared.Shelf as SharedShelf
|
|
import com.aryan.reader.shared.ShelfRecord
|
|
import com.aryan.reader.shared.SyncedFolder as SharedSyncedFolder
|
|
import com.aryan.reader.shared.Tag as SharedTag
|
|
|
|
fun FileType.toSharedFileType(): SharedFileType = this
|
|
|
|
fun SharedFileType.toAndroidFileType(): FileType = this
|
|
|
|
fun LibraryFilters.toSharedLibraryFilters(): SharedLibraryFilters = this
|
|
|
|
fun SharedLibraryFilters.toAndroidLibraryFilters(): LibraryFilters = this
|
|
|
|
fun SyncedFolder.toSharedSyncedFolder(): SharedSyncedFolder = this
|
|
|
|
fun SharedSyncedFolder.toAndroidSyncedFolder(): SyncedFolder = this
|
|
|
|
fun RecentFileItem.toSharedBookItem(): SharedBookItem {
|
|
return SharedBookItem(
|
|
id = bookId,
|
|
path = uriString,
|
|
type = type,
|
|
displayName = customName ?: displayName,
|
|
timestamp = timestamp,
|
|
coverImagePath = coverImagePath,
|
|
title = title,
|
|
author = author,
|
|
description = description,
|
|
originalTitle = originalTitle,
|
|
originalAuthor = originalAuthor,
|
|
originalSeriesName = originalSeriesName,
|
|
originalSeriesIndex = originalSeriesIndex,
|
|
originalDescription = originalDescription,
|
|
progressPercentage = progressPercentage,
|
|
isRecent = isRecent,
|
|
fileSize = fileSize,
|
|
fileContentModifiedTimestamp = fileContentModifiedTimestamp,
|
|
sourceFolder = sourceFolderUri,
|
|
folderTextMetadataParsed = folderTextMetadataParsed,
|
|
seriesName = seriesName,
|
|
seriesIndex = seriesIndex,
|
|
lastPageIndex = lastPage,
|
|
tags = tags.map { it.toSharedTag() },
|
|
readerHighlights = EpubAnnotationSerializer.parseHighlightsJson(highlightsJson)
|
|
)
|
|
}
|
|
|
|
fun RecentFileItem.toSharedProjectionBookItem(): SharedBookItem {
|
|
return toSharedBookItem().copy(displayName = displayName)
|
|
}
|
|
|
|
fun SharedBookItem.toRecentFileItem(
|
|
androidBooksById: Map<String, RecentFileItem> = emptyMap(),
|
|
tagEntitiesById: Map<String, TagEntity> = emptyMap()
|
|
): RecentFileItem {
|
|
val resolvedTags = tags.map { tag -> tagEntitiesById[tag.id] ?: tag.toTagEntity(createdAt = 0L) }
|
|
return androidBooksById[id]?.copy(tags = resolvedTags)
|
|
?.copy(
|
|
uriString = path,
|
|
type = type,
|
|
displayName = androidBooksById[id]?.displayName ?: displayName,
|
|
timestamp = timestamp,
|
|
coverImagePath = coverImagePath,
|
|
title = title,
|
|
author = author,
|
|
description = description,
|
|
originalTitle = originalTitle,
|
|
originalAuthor = originalAuthor,
|
|
originalSeriesName = originalSeriesName,
|
|
originalSeriesIndex = originalSeriesIndex,
|
|
originalDescription = originalDescription,
|
|
lastPage = lastPageIndex,
|
|
progressPercentage = progressPercentage,
|
|
isRecent = isRecent,
|
|
sourceFolderUri = sourceFolder,
|
|
fileSize = fileSize,
|
|
fileContentModifiedTimestamp = fileContentModifiedTimestamp,
|
|
seriesName = seriesName,
|
|
seriesIndex = seriesIndex,
|
|
folderTextMetadataParsed = folderTextMetadataParsed
|
|
)
|
|
?: RecentFileItem(
|
|
bookId = id,
|
|
uriString = path,
|
|
type = type,
|
|
displayName = displayName,
|
|
timestamp = timestamp,
|
|
coverImagePath = coverImagePath,
|
|
title = title,
|
|
author = author,
|
|
description = description,
|
|
originalTitle = originalTitle,
|
|
originalAuthor = originalAuthor,
|
|
originalSeriesName = originalSeriesName,
|
|
originalSeriesIndex = originalSeriesIndex,
|
|
originalDescription = originalDescription,
|
|
lastPage = lastPageIndex,
|
|
progressPercentage = progressPercentage,
|
|
isRecent = isRecent,
|
|
sourceFolderUri = sourceFolder,
|
|
fileSize = fileSize,
|
|
fileContentModifiedTimestamp = fileContentModifiedTimestamp,
|
|
seriesName = seriesName,
|
|
seriesIndex = seriesIndex,
|
|
folderTextMetadataParsed = folderTextMetadataParsed,
|
|
tags = resolvedTags
|
|
)
|
|
}
|
|
|
|
fun TagEntity.toSharedTag(): SharedTag {
|
|
return SharedTag(
|
|
id = id,
|
|
name = name,
|
|
color = color
|
|
)
|
|
}
|
|
|
|
fun SharedTag.toTagEntity(createdAt: Long): TagEntity {
|
|
return TagEntity(
|
|
id = id,
|
|
name = name,
|
|
color = color,
|
|
createdAt = createdAt
|
|
)
|
|
}
|
|
|
|
fun ShelfEntity.toSharedShelfRecord(): ShelfRecord {
|
|
return ShelfRecord(
|
|
id = id,
|
|
name = name,
|
|
isSmart = isSmart,
|
|
smartRulesJson = smartRulesJson
|
|
)
|
|
}
|
|
|
|
fun ShelfRecord.toShelfEntity(createdAt: Long, updatedAt: Long = createdAt): ShelfEntity {
|
|
return ShelfEntity(
|
|
id = id,
|
|
name = name,
|
|
isSmart = isSmart,
|
|
smartRulesJson = smartRulesJson,
|
|
createdAt = createdAt,
|
|
updatedAt = updatedAt
|
|
)
|
|
}
|
|
|
|
fun BookShelfCrossRef.toSharedBookShelfRef(): SharedBookShelfRef {
|
|
return SharedBookShelfRef(
|
|
bookId = bookId,
|
|
shelfId = shelfId,
|
|
addedAt = addedAt
|
|
)
|
|
}
|
|
|
|
fun ReaderScreenState.toSharedReaderScreenState(
|
|
rawBooks: List<RecentFileItem> = rawLibraryFiles,
|
|
dbTags: List<TagEntity> = allTags
|
|
): SharedReaderScreenState {
|
|
return SharedReaderScreenState(
|
|
selectedBookId = selectedBookId,
|
|
selectedUriString = selectedPdfUri?.toString() ?: selectedEpubUri?.toString(),
|
|
selectedFileType = selectedFileType,
|
|
isLoading = isLoading,
|
|
errorMessage = errorMessage,
|
|
renderMode = renderMode,
|
|
sortOrder = sortOrder,
|
|
viewingShelfId = viewingShelfId,
|
|
isAddingBooksToShelf = isAddingBooksToShelf,
|
|
showCreateShelfDialog = showCreateShelfDialog,
|
|
mainScreenStartPage = mainScreenStartPage,
|
|
libraryScreenStartPage = libraryScreenStartPage,
|
|
showRenameShelfDialogFor = showRenameShelfDialogFor,
|
|
showDeleteShelfDialogFor = showDeleteShelfDialogFor,
|
|
addBooksSource = addBooksSource,
|
|
booksSelectedForAdding = booksSelectedForAdding,
|
|
selectedBookIds = contextualActionItems.mapTo(mutableSetOf()) { it.bookId },
|
|
selectedShelfIds = contextualActionShelfIds,
|
|
isProUser = isProUser,
|
|
credits = credits,
|
|
isSyncEnabled = isSyncEnabled,
|
|
isFolderSyncEnabled = isFolderSyncEnabled,
|
|
bannerMessage = bannerMessage,
|
|
downloadingBookIds = downloadingBookIds,
|
|
uploadingBookIds = uploadingBookIds,
|
|
syncedFolders = syncedFolders,
|
|
lastFolderScanTime = lastFolderScanTime,
|
|
hasUnreadFeedback = hasUnreadFeedback,
|
|
searchQuery = searchQuery,
|
|
isSearchActive = isSearchActive,
|
|
isRefreshing = isRefreshing,
|
|
reflowProgress = reflowProgress,
|
|
recentBooks = recentFiles.map { it.toSharedBookItem() },
|
|
libraryBooks = allRecentFiles.map { it.toSharedBookItem() },
|
|
rawLibraryBooks = rawBooks.map { it.toSharedBookItem() },
|
|
pinnedHomeBookIds = pinnedHomeBookIds,
|
|
pinnedLibraryBookIds = pinnedLibraryBookIds,
|
|
libraryFilters = libraryFilters,
|
|
recentFilesLimit = recentFilesLimit,
|
|
isTabsEnabled = isTabsEnabled,
|
|
openTabIds = openTabIds,
|
|
openTabs = openTabs.map { it.toSharedBookItem() },
|
|
activeTabBookId = activeTabBookId,
|
|
showExternalFileSavePromptFor = showExternalFileSavePromptFor,
|
|
externalFileBehavior = externalFileBehavior,
|
|
useStrictFileFilter = useStrictFileFilter,
|
|
usePdfFileNameAsDisplayName = usePdfFileNameAsDisplayName,
|
|
appThemeMode = appThemeMode,
|
|
appContrastOption = appContrastOption,
|
|
appTextDimFactorLight = appTextDimFactorLight,
|
|
appTextDimFactorDark = appTextDimFactorDark,
|
|
appSeedColor = appSeedColor,
|
|
appFontPreference = appFontPreference,
|
|
customAppThemes = customAppThemes,
|
|
allTags = dbTags.map { it.toSharedTag() },
|
|
showTagSelectionDialogFor = showTagSelectionDialogFor
|
|
)
|
|
}
|
|
|
|
fun List<RecentFileItem>.withResolvedTags(
|
|
dbTags: List<TagEntity>,
|
|
tagRefs: List<BookTagCrossRef>
|
|
): List<RecentFileItem> {
|
|
val tagsById = dbTags.associateBy { it.id }
|
|
val bookTagsMap = tagRefs.groupBy { it.bookId }.mapValues { entry ->
|
|
entry.value.mapNotNull { tagsById[it.tagId] }
|
|
}
|
|
return map { item -> item.copy(tags = bookTagsMap[item.bookId].orEmpty()) }
|
|
}
|
|
|
|
fun SharedReaderScreenState.toAndroidReaderScreenState(
|
|
base: ReaderScreenState,
|
|
androidBooksById: Map<String, RecentFileItem>,
|
|
tagEntitiesById: Map<String, TagEntity> = emptyMap()
|
|
): ReaderScreenState {
|
|
val fallbackBooksById = rawLibraryBooks.associateBy { it.id }
|
|
fun SharedBookItem.toAndroidBook(): RecentFileItem {
|
|
return toRecentFileItem(androidBooksById, tagEntitiesById)
|
|
}
|
|
fun bookById(bookId: String): RecentFileItem? {
|
|
return androidBooksById[bookId] ?: fallbackBooksById[bookId]?.toAndroidBook()
|
|
}
|
|
return base.copy(
|
|
recentFiles = recentBooks.map { it.toAndroidBook() },
|
|
allRecentFiles = libraryBooks.map { it.toAndroidBook() },
|
|
rawLibraryFiles = rawLibraryBooks.map { it.toAndroidBook() },
|
|
viewingShelfId = viewingShelfId,
|
|
isAddingBooksToShelf = isAddingBooksToShelf,
|
|
contextualActionShelfIds = selectedShelfIds,
|
|
contextualActionItems = selectedBookIds.mapNotNullTo(mutableSetOf()) { bookById(it) },
|
|
shelves = shelves.map { it.toAndroidShelf(androidBooksById, tagEntitiesById) },
|
|
openTabs = openTabs.map { it.toAndroidBook() },
|
|
openTabIds = openTabIds,
|
|
activeTabBookId = activeTabBookId,
|
|
booksAvailableForAdding = booksAvailableForAdding.map { it.toAndroidBook() },
|
|
allTags = allTags.map { tag -> tagEntitiesById[tag.id] ?: tag.toTagEntity(createdAt = 0L) }
|
|
)
|
|
}
|
|
|
|
fun SharedShelf.toAndroidShelf(
|
|
androidBooksById: Map<String, RecentFileItem> = emptyMap(),
|
|
tagEntitiesById: Map<String, TagEntity> = emptyMap()
|
|
): Shelf {
|
|
return Shelf(
|
|
id = id,
|
|
name = name,
|
|
type = type,
|
|
books = books.map { it.toRecentFileItem(androidBooksById, tagEntitiesById) },
|
|
directBooks = directBooks.map { it.toRecentFileItem(androidBooksById, tagEntitiesById) },
|
|
parentShelfId = parentShelfId,
|
|
childShelfIds = childShelfIds,
|
|
depth = depth,
|
|
sortKey = sortKey
|
|
)
|
|
}
|