many improvements and prototype launcher image

This commit is contained in:
sergeych committed 2026-05-18 02:09:21 +03:00
1 parent 11c8f7c6e4
commit 6422f814d1
27 files changed
+530 -232

No files matched your search

@@ -118,7 +118,7 @@ private fun BookReaderApp(onThemeToggle: () -> Unit) {
)
is AppState.Reader -> {
scope.launch { saveActiveReadingFileId(null) }
AppState.Library(current.libraryItems, current.scanPath, current.message)
AppState.Library(emptyList(), current.scanPath, current.message)
}
is AppState.Scan -> AppState.Library(current.items, current.scanPath, current.message)
is AppState.Error -> AppState.LoadingLibrary
@@ -116,6 +116,8 @@ expect suspend fun loadLibraryReadingPosition(fileId: String): ReadingPosition?
expect suspend fun saveLibraryReadingPosition(fileId: String, position: ReadingPosition)
expect suspend fun clearLibraryReadingPosition(fileId: String)
expect suspend fun markLibraryReadingStatus(fileId: String, status: BookReadingStatus): Boolean
expect suspend fun shareLibraryBookFile(fileId: String): Boolean
@@ -146,6 +146,28 @@ internal fun LibraryScreen(
}
}
suspend fun applyReadingStatus(
item: LibraryItem,
status: BookReadingStatus,
successMessage: String,
) {
if (markLibraryReadingStatus(item.fileId, status)) {
val updatedItem = loadLibraryItem(item.fileId) ?: item.copy(readingStatus = status)
items = items.replaceLibraryItem(updatedItem)
searchResults = searchResults.replaceLibraryItem(updatedItem)
message = successMessage
if (searchActive) {
searching = true
searchResults = searchLibraryItems(searchText, SearchResultLimit)
searching = false
} else {
loadPage(reset = true)
}
} else {
message = "Could not update ${item.title}."
}
}
fun rescanAllLibrary() {
settingsMenuOpen = false
scope.launch {
@@ -320,7 +342,13 @@ internal fun LibraryScreen(
readerLibraryItems = readerLibraryItems.replaceLibraryItem(updatedItem)
coverCache[updatedItem.fileId] = loadLibraryItemCover(updatedItem.fileId)
}
markLibraryReadingStatus(item.fileId, BookReadingStatus.READING)
if (markLibraryReadingStatus(item.fileId, BookReadingStatus.READING)) {
val readingItem = loadLibraryItem(item.fileId)
?: item.copy(readingStatus = BookReadingStatus.READING)
items = items.replaceLibraryItem(readingItem)
searchResults = searchResults.replaceLibraryItem(readingItem)
readerLibraryItems = readerLibraryItems.replaceLibraryItem(readingItem)
}
saveActiveReadingFileId(item.fileId)
AppState.Reader(
fileId = item.fileId,
@@ -342,12 +370,7 @@ internal fun LibraryScreen(
scope.launch {
busy = true
try {
if (markLibraryReadingStatus(item.fileId, BookReadingStatus.READ)) {
message = "Marked ${item.title} as read."
refresh()
} else {
message = "Could not update ${item.title}."
}
applyReadingStatus(item, BookReadingStatus.READ, "Marked ${item.title} as read.")
} finally {
busy = false
}
@@ -357,12 +380,7 @@ internal fun LibraryScreen(
scope.launch {
busy = true
try {
if (markLibraryReadingStatus(item.fileId, BookReadingStatus.NEW)) {
message = "Marked ${item.title} as unread."
refresh()
} else {
message = "Could not update ${item.title}."
}
applyReadingStatus(item, BookReadingStatus.NEW, "Marked ${item.title} as unread.")
} finally {
busy = false
}
@@ -372,12 +390,7 @@ internal fun LibraryScreen(
scope.launch {
busy = true
try {
if (markLibraryReadingStatus(item.fileId, BookReadingStatus.NEW)) {
message = "Removed marks from ${item.title}."
refresh()
} else {
message = "Could not update ${item.title}."
}
applyReadingStatus(item, BookReadingStatus.NEW, "Removed marks from ${item.title}.")
} finally {
busy = false
}
@@ -387,12 +400,7 @@ internal fun LibraryScreen(
scope.launch {
busy = true
try {
if (markLibraryReadingStatus(item.fileId, BookReadingStatus.NOT_INTERESTED)) {
message = "Marked ${item.title} as not interested."
refresh()
} else {
message = "Could not update ${item.title}."
}
applyReadingStatus(item, BookReadingStatus.NOT_INTERESTED, "Marked ${item.title} as not interested.")
} finally {
busy = false
}
@@ -438,7 +446,8 @@ internal fun LibraryScreen(
librarySection(
key = "reading",
title = "reading now",
count = readingNow.size,
itemCount = readingNow.size,
displayCount = readingNow.size.takeIf { endReached },
collapsed = readingNowCollapsed,
onCollapsedChange = { readingNowCollapsed = it },
) {
@@ -447,7 +456,8 @@ internal fun LibraryScreen(
librarySection(
key = "library",
title = "my library",
count = myLibrary.size,
itemCount = myLibrary.size,
displayCount = myLibrary.size.takeIf { endReached },
collapsed = myLibraryCollapsed,
onCollapsedChange = { myLibraryCollapsed = it },
) {
@@ -456,7 +466,8 @@ internal fun LibraryScreen(
librarySection(
key = "not-interested",
title = "not interested",
count = notInterested.size,
itemCount = notInterested.size,
displayCount = notInterested.size.takeIf { endReached },
collapsed = notInterestedCollapsed,
onCollapsedChange = { notInterestedCollapsed = it },
) {
@@ -573,16 +584,17 @@ private fun EmptySearchPane(modifier: Modifier = Modifier) {
private fun LazyListScope.librarySection(
key: String,
title: String,
count: Int,
itemCount: Int,
displayCount: Int?,
collapsed: Boolean,
onCollapsedChange: (Boolean) -> Unit,
content: LazyListScope.() -> Unit,
) {
if (count == 0) return
if (itemCount == 0) return
item(key = "section-$key") {
LibrarySectionHeader(
text = title,
count = count,
count = displayCount,
collapsed = collapsed,
onToggle = { onCollapsedChange(!collapsed) },
)
@@ -595,7 +607,7 @@ private fun LazyListScope.librarySection(
@Composable
private fun LibrarySectionHeader(
text: String,
count: Int,
count: Int?,
collapsed: Boolean,
onToggle: () -> Unit,
) {
@@ -614,7 +626,7 @@ private fun LibrarySectionHeader(
modifier = Modifier.size(18.dp),
)
Text(
"$text ($count)",
if (count == null) text else "$text ($count)",
style = MaterialTheme.typography.labelSmall,
color = MaterialTheme.colorScheme.outline,
textAlign = TextAlign.Center,