diff --git a/.github/workflows/build-arm64.yml b/.github/workflows/build-arm64.yml new file mode 100644 index 00000000..46da3a5a --- /dev/null +++ b/.github/workflows/build-arm64.yml @@ -0,0 +1,90 @@ +name: Build arm64-v8a APK + +# Manual run: Actions tab -> "Build arm64-v8a APK" -> Run workflow. +# "debug" needs no secrets and installs on any device (debug-signed, package +# dev.mirutime.app.debug, so it can sit beside an official release). +# "release" signs with your keystore secrets (SIGNING_KEY base64, +# KEY_STORE_PASSWORD, ALIAS, KEY_PASSWORD) and keeps the normal package name. +on: + workflow_dispatch: + inputs: + build_type: + description: Build type + type: choice + options: [debug, release] + default: debug + +permissions: + contents: read + +concurrency: + group: build-arm64-${{ github.ref }} + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-latest + timeout-minutes: 45 + steps: + - name: Checkout + uses: actions/checkout@v7 + + - name: Set up JDK + uses: actions/setup-java@v6 + with: + distribution: temurin + java-version: '21' + + - name: Set up Gradle + uses: gradle/actions/setup-gradle@v6.3.0 + with: + gradle-home-cache-cleanup: true + + - name: Prepare release signing + if: inputs.build_type == 'release' + env: + SIGNING_KEY: ${{ secrets.SIGNING_KEY }} + KEY_STORE_PASSWORD: ${{ secrets.KEY_STORE_PASSWORD }} + ALIAS: ${{ secrets.ALIAS }} + KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }} + run: | + if [ -z "$SIGNING_KEY" ]; then + echo "::error::Release build needs the SIGNING_KEY, KEY_STORE_PASSWORD, ALIAS and KEY_PASSWORD secrets. Use build type 'debug' otherwise." + exit 1 + fi + printf '%s' "$SIGNING_KEY" | base64 --decode > app/storeFile.jks + { + echo "storeFile=$GITHUB_WORKSPACE/app/storeFile.jks" + echo "storePassword=$KEY_STORE_PASSWORD" + echo "keyAlias=$ALIAS" + echo "keyPassword=$KEY_PASSWORD" + } > custom.properties + + - name: Build (arm64-v8a split) + env: + BUILD_TYPE: ${{ inputs.build_type }} + run: | + chmod +x gradlew + if [ "$BUILD_TYPE" = "release" ]; then + ./gradlew --no-daemon --build-cache :app:assembleRelease \ + -PabiSplits=true \ + -PlocalPropertiesFilePath="$GITHUB_WORKSPACE/custom.properties" + else + ./gradlew --no-daemon --build-cache :app:assembleDebug -PabiSplits=true + fi + + - name: Collect arm64-v8a APK + env: + BUILD_TYPE: ${{ inputs.build_type }} + run: | + mkdir -p out + cp "app/build/outputs/apk/$BUILD_TYPE/app-arm64-v8a-$BUILD_TYPE.apk" \ + "out/MiruTime-arm64-v8a-$BUILD_TYPE.apk" + ls -lh out + + - name: Upload APK + uses: actions/upload-artifact@v4 + with: + name: MiruTime-arm64-v8a-${{ inputs.build_type }} + path: out/*.apk + if-no-files-found: error diff --git a/app/src/main/java/dev/mirutime/app/features/library/ui/LibraryScreen.kt b/app/src/main/java/dev/mirutime/app/features/library/ui/LibraryScreen.kt index d3c95216..137a87bd 100644 --- a/app/src/main/java/dev/mirutime/app/features/library/ui/LibraryScreen.kt +++ b/app/src/main/java/dev/mirutime/app/features/library/ui/LibraryScreen.kt @@ -1,5 +1,8 @@ package dev.mirutime.app.features.library.ui +import android.net.Uri +import androidx.activity.compose.rememberLauncherForActivityResult +import androidx.activity.result.contract.ActivityResultContracts import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.core.tween import androidx.compose.animation.fadeIn @@ -83,7 +86,6 @@ import dev.mirutime.uikit.AppBottomSheet import dev.mirutime.app.design.components.BookCover import dev.mirutime.app.design.components.CardStylePicker import dev.mirutime.uikit.MiruSearchBar -import dev.mirutime.uikit.ChipRail import dev.mirutime.uikit.MiruChipFlow import dev.mirutime.uikit.MiruFilterChip import dev.mirutime.uikit.MiruRoundIconButton @@ -190,11 +192,7 @@ fun LibraryScreen( val cardStyle = AppSettings.cardStyle var filterOpen by rememberSaveable { mutableStateOf(false) } - var sourceSheetOpen by rememberSaveable { mutableStateOf(false) } - var genresSheetOpen by rememberSaveable { mutableStateOf(false) } - var sortSheetOpen by rememberSaveable { mutableStateOf(false) } var shelfManagerOpen by remember { mutableStateOf(false) } - var importOpen by remember { mutableStateOf(false) } // True from the picker handoff until importFiles + the library reload // finish; the sheet stays open and shows a blocking progress state. var importing by remember { mutableStateOf(false) } @@ -376,6 +374,12 @@ fun LibraryScreen( } } + // Tabs are single-select now; a multi-selection persisted by an older + // build collapses to its first shelf so the list is never a mixed bag. + LaunchedEffect(Unit) { + if (selShelves.size > 1) selShelves = setOf(selShelves.first()) + } + // If a shelf was deleted externally or restored, prune deleted IDs from the active selection. LaunchedEffect(shelves) { if (shelves.isNotEmpty() && selShelves.isNotEmpty()) { @@ -595,6 +599,104 @@ fun LibraryScreen( } } + // Import opens the system picker directly (no intermediate sheet). One + // picked file or many go through the same importer; the Import button + // shows a busy state until the import and the reload finish. + fun performImport(files: List) { + if (files.isEmpty() || importing) return + importing = true + MiruLog.event("library", "import-start", "files" to files.size) + val wasReading = selShelves.isEmpty() || "reading" in selShelves + ioScope.launch { + try { + val summary = try { + provider.importFiles(files) + } catch (e: CancellationException) { + throw e + } catch (e: Exception) { + MiruLog.w("library", "Import failed", e) + null + } + if (summary == null) { + MiruLog.event("library", "import-result", "ok" to false) + android.widget.Toast.makeText( + context, + resources.getString(R.string.toast_import_failed), + android.widget.Toast.LENGTH_SHORT, + ).show() + } else { + MiruLog.event( + "library", + "import-result", + "ok" to true, + "imported" to summary.imported, + "duplicates" to summary.duplicates, + "failures" to summary.failures, + ) + lastRead = provider.lastRead() + // New books land on Reading; make sure they are visible. + if (selShelves.isNotEmpty() && "reading" !in selShelves) { + selShelves = setOf("reading") + } + reloadMeta() + // A shelf change already starts its own page load. + if (wasReading) refreshPages() + val count = summary.accepted + val reason = summary.failureToReport + val message = if (reason != null) { + importFailureText(resources, reason) + } else if (count > 0 && summary.failures > 0) { + mixedImportText(resources, count, summary.failures) + } else if (count > 0) { + if (count == 1) { + resources.getString(R.string.toast_imported_one) + } else { + resources.getQuantityString(R.plurals.plural_local_books, count, count) + } + } else { + resources.getString(R.string.toast_import_failed) + } + android.widget.Toast.makeText( + context, + message, + android.widget.Toast.LENGTH_SHORT, + ).show() + } + } finally { + importing = false + } + } + } + val importPicker = rememberLauncherForActivityResult( + ActivityResultContracts.OpenMultipleDocuments(), + ) { uris: List -> + val picked = uris.mapNotNull { uri -> + val name = displayNameOf(context, uri) ?: uri.lastPathSegment ?: uri.toString() + dev.mirutime.app.features.library.data.PickedImportFile( + uri = uri.toString(), + fileName = name, + format = formatForFileName(name), + ) + } + if (picked.isNotEmpty()) performImport(picked) + } + fun launchImportPicker() { + if (importing) return + importPicker.launch( + arrayOf( + "application/epub+zip", + "text/plain", + "text/xml", + "application/x-fictionbook+xml", + "application/x-cbz", + "application/x-cbr", + "application/pdf", + "application/x-pdf", + "application/zip", + ), + ) + } + val gridRows = remember(shown, columns) { shown.chunked(columns) } // Scaffold's bottom inset reaches past the tab pill: it also carries the // shell's decorative fade strip and plate top padding. Drop those (owned by @@ -640,11 +742,46 @@ fun LibraryScreen( onSearch = { focusManager.clearFocus() }, modifier = Modifier.weight(1f), ) - MiruRoundIconButton( - icon = Icons.Filled.Tune, - contentDescription = stringResource(R.string.lib_cd_filters), - onClick = { filterOpen = true }, - ) + } + } + + // Compact two-button bar: everything that used to be stacked + // (source, genres, grid/list, sort, count, import banner) now lives + // behind Filter, and Import opens the system file picker directly. + item { + val activeFilters = (if (selSources.isNotEmpty()) 1 else 0) + + (if (genres.isNotEmpty()) 1 else 0) + + (if (type != null) 1 else 0) + Row( + modifier = Modifier + .fillMaxWidth() + .padding(top = MiruSpace.Xs), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(MiruSpace.S), + ) { + Box(modifier = Modifier.weight(1f)) { + MiruCompactButton( + label = if (activeFilters > 0) { + stringResource(R.string.lib_btn_filter_active_fmt, activeFilters) + } else { + stringResource(R.string.lib_btn_filter) + }, + icon = Icons.Filled.Tune, + selected = activeFilters > 0, + onClick = { filterOpen = true }, + modifier = Modifier.fillMaxWidth(), + ) + } + Box(modifier = Modifier.weight(1f)) { + MiruCompactButton( + label = stringResource(R.string.lib_btn_import), + icon = Icons.Filled.UploadFile, + enabled = !importing, + busy = importing, + onClick = { launchImportPicker() }, + modifier = Modifier.fillMaxWidth(), + ) + } } } @@ -655,9 +792,8 @@ fun LibraryScreen( ShelfTabsRow( shelves = shelves, selectedIds = selShelves, - onToggle = { id -> - selShelves = if (id in selShelves) selShelves - id else selShelves + id - }, + // Single-select: a tap switches to that shelf alone. + onToggle = { id -> selShelves = setOf(id) }, onSelectAll = { selShelves = emptySet() }, onManage = { shelfManagerOpen = true }, onTabLongPress = { shelfManagerOpen = true }, @@ -665,28 +801,6 @@ fun LibraryScreen( ) } - item { - // A tight gap below the shelf plate: chip rows already carry - // their own touch-target padding around the visual chip faces. - Box(modifier = Modifier.padding(top = MiruSpace.Xxs, bottom = MiruSpace.Xxs)) { - MiniFilters( - sources = selSources, - genres = genres, - layout = layout, - sort = sort, - sortDir = sortDir, - sortEnabled = sortEnabled, - onSource = { sourceSheetOpen = true }, - onGenres = { genresSheetOpen = true }, - onLayout = { - AppSettings.listLayout = - if (layout == LayoutMode.Grid) "list" else "grid" - }, - onSort = { sortSheetOpen = true }, - ) - } - } - if ( shown.isEmpty() && !pager.firstError && @@ -765,93 +879,6 @@ fun LibraryScreen( } } - // Shelf caption (prototype language): live count on the left, the - // local-import entry on the right. - item { - val largeText = isLargeText() - val count = pager.total ?: shown.size - val countLabel = pluralStringResource(R.plurals.plural_books, count, count) - val countShape = RoundedCornerShape(MiruRadius.Chip) - if (largeText) { - Column( - verticalArrangement = Arrangement.spacedBy(MiruSpace.S), - modifier = Modifier - .fillMaxWidth() - .padding(top = MiruSpace.Xs), - ) { - Box( - modifier = Modifier - .heightIn(min = MiruSize.RowCompact) - .clip(countShape) - .background(miruCardSurface()) - .border(miruCardBorder(), countShape) - .padding(horizontal = MiruSpace.M, vertical = MiruSpace.Xs), - contentAlignment = Alignment.Center, - ) { - Text( - text = countLabel, - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.onSurface, - maxLines = 2, - overflow = TextOverflow.Ellipsis, - ) - } - MiruButton( - onClick = { importOpen = true }, - style = MiruButtonStyle.Secondary, - leadingIcon = Icons.Filled.UploadFile, - modifier = Modifier.fillMaxWidth(), - ) { - Text(text = stringResource(R.string.lib_import)) - } - } - } else { - // Counter row: hug-content mini-pill + compact Import pill on - // the same 32dp visual height grid. - BoxWithConstraints( - modifier = Modifier.fillMaxWidth(), - ) { - val maxCountWidth = maxWidth * 0.45f - Row( - horizontalArrangement = Arrangement.spacedBy(MiruSpace.S), - verticalAlignment = Alignment.CenterVertically, - modifier = Modifier.fillMaxWidth(), - ) { - Box( - modifier = Modifier - .widthIn(max = maxCountWidth) - .heightIn(min = MiruSize.RowCompact) - .clip(countShape) - .background(miruCardSurface()) - .border(miruCardBorder(), countShape) - .padding(horizontal = MiruSpace.M), - contentAlignment = Alignment.Center, - ) { - Text( - text = countLabel, - style = MaterialTheme.typography.bodySmall, - color = MaterialTheme.colorScheme.onSurface, - maxLines = 1, - overflow = TextOverflow.Ellipsis, - ) - } - Box( - modifier = Modifier.weight(1f), - contentAlignment = Alignment.CenterEnd, - ) { - Box(modifier = Modifier.width(IntrinsicSize.Max)) { - MiruCompactButton( - label = stringResource(R.string.lib_import), - icon = Icons.Filled.UploadFile, - onClick = { importOpen = true }, - ) - } - } - } - } - } - } - // Stale-while-revalidate: the previous page stays visible and a // slim spinner says the next page/query is still running. if (pager.refreshing || (searchPending && shown.isNotEmpty())) { @@ -1152,131 +1179,6 @@ fun LibraryScreen( onCardStyle = { AppSettings.cardStyle = it }, ) } - if (sourceSheetOpen) { - AppBottomSheet( - title = stringResource(R.string.lib_source_title), - description = stringResource(R.string.lib_source_desc), - onClose = { sourceSheetOpen = false }, - ) { - SheetSection(title = stringResource(R.string.lib_source_title), collapsible = false) { - SourcesOptions( - selected = selSources, - all = sources, - onToggle = { - selSources = if (it in selSources) selSources - it else selSources + it - }, - onClearAll = { selSources = emptySet() }, - ) - } - } - } - if (genresSheetOpen) { - AppBottomSheet( - title = stringResource(R.string.lib_genres_title), - description = stringResource(R.string.lib_genres_desc), - onClose = { genresSheetOpen = false }, - ) { - SheetSection(title = stringResource(R.string.lib_genres_title), collapsible = false) { - GenresOptions(selected = genres, all = allGenres) { - genres = if (it in genres) genres - it else genres + it - } - } - } - } - if (sortSheetOpen && sortEnabled) { - AppBottomSheet( - title = stringResource(R.string.lib_sort_title), - description = stringResource(R.string.lib_sort_desc), - onClose = { sortSheetOpen = false }, - ) { - SheetSection(title = stringResource(R.string.lib_section_sort), collapsible = false) { - SortOptions(sort = sort, sortDir = sortDir) { option -> - if (option == sort) { - sortDir = sortDir.flip() - } else { - sort = option - sortDir = option.defaultDirection() - } - } - } - } - } - if (importOpen) { - fun performImport(files: List) { - if (files.isEmpty() || importing) return - importing = true - MiruLog.event("library", "import-start", "files" to files.size) - val wasReading = selShelves.isEmpty() || "reading" in selShelves - ioScope.launch { - try { - val summary = try { - provider.importFiles(files) - } catch (e: CancellationException) { - throw e - } catch (e: Exception) { - MiruLog.w("library", "Import failed", e) - null - } - if (summary == null) { - MiruLog.event("library", "import-result", "ok" to false) - android.widget.Toast.makeText( - context, - resources.getString(R.string.toast_import_failed), - android.widget.Toast.LENGTH_SHORT, - ).show() - } else { - MiruLog.event( - "library", - "import-result", - "ok" to true, - "imported" to summary.imported, - "duplicates" to summary.duplicates, - "failures" to summary.failures, - ) - lastRead = provider.lastRead() - // New books land on Reading; make sure they are visible. - if (selShelves.isNotEmpty() && "reading" !in selShelves) { - selShelves = selShelves + "reading" - } - reloadMeta() - // A shelf change already starts its own page load. - if (wasReading) refreshPages() - val count = summary.accepted - val reason = summary.failureToReport - val message = if (reason != null) { - importFailureText(resources, reason) - } else if (count > 0 && summary.failures > 0) { - mixedImportText(resources, count, summary.failures) - } else if (count > 0) { - if (count == 1) { - resources.getString(R.string.toast_imported_one) - } else { - resources.getQuantityString(R.plurals.plural_local_books, count, count) - } - } else { - resources.getString(R.string.toast_import_failed) - } - android.widget.Toast.makeText( - context, - message, - android.widget.Toast.LENGTH_SHORT, - ).show() - } - } finally { - importing = false - // Close only after the import + reload finish: the sheet - // owns the blocking progress state. - importOpen = false - } - } - } - ImportSheet( - busy = importing, - onClose = { if (!importing) importOpen = false }, - onImport = { file -> performImport(listOf(file)) }, - onImportUris = { files -> performImport(files) }, - ) - } if (shelfManagerOpen) { ShelfManagerSheet( shelves = shelves, @@ -1505,94 +1407,6 @@ private fun SkeletonCoverGrid(columns: Int) { } } -private data class MiniChip( - val id: String, - val label: String, - val selected: Boolean, - val onClick: () -> Unit, -) - -// One chip language with the shelf strip above (FilterChip everywhere). -@Composable -private fun MiniFilters( - sources: Set, - genres: Set, - layout: LayoutMode, - sort: LibrarySort, - sortDir: SortDirection, - sortEnabled: Boolean, - onSource: () -> Unit, - onGenres: () -> Unit, - onLayout: () -> Unit, - onSort: () -> Unit, -) { - val allLabel = stringResource(R.string.lib_all) - val sourceLabel = if (sources.isEmpty()) { - allLabel - } else { - stringResource(R.string.lib_picked_fmt, sources.size) - } - val genresLabel = if (genres.isEmpty()) { - allLabel - } else { - stringResource(R.string.lib_picked_fmt, genres.size) - } - val sortLabel = sort.label() - val layoutLabel = if (layout == LayoutMode.Grid) { - stringResource(R.string.lib_layout_grid) - } else { - stringResource(R.string.lib_layout_list) - } - val minis = listOfNotNull( - MiniChip( - id = "source", - label = stringResource(R.string.lib_chip_source_fmt, sourceLabel), - selected = sources.isNotEmpty(), - onClick = onSource, - ), - MiniChip( - id = "genres", - label = stringResource(R.string.lib_chip_genres_fmt, genresLabel), - selected = genres.isNotEmpty(), - onClick = onGenres, - ), - MiniChip( - id = "layout", - label = layoutLabel, - selected = false, - onClick = onLayout, - ), - if (sortEnabled) { - MiniChip( - id = "sort", - label = stringResource( - R.string.lib_chip_sort_fmt, - sortLabel, - sortDir.arrow(), - ), - selected = false, - onClick = onSort, - ) - } else { - null - }, - ) - // Four separate pills straight on the photo — each chip draws its own - // ghost backing, no shared box; classic chips keep their look. The row - // itself adds NO horizontal padding: the LazyColumn item inset (16dp) - // already puts chips on the same left grid line as the cards/resume bar, - // giving a symmetric start→end rhythm. Side inset follows the same rule. - ChipRail { - items(minis, key = { it.id }) { item -> - MiruFilterChip( - selected = item.selected, - onClick = item.onClick, - label = item.label, - ) - } - } -} - @Composable private fun LibrarySort.label(): String = stringResource( when (this) { diff --git a/app/src/main/java/dev/mirutime/app/features/library/ui/ShelfTabs.kt b/app/src/main/java/dev/mirutime/app/features/library/ui/ShelfTabs.kt index 6a2db7eb..dfe8424b 100644 --- a/app/src/main/java/dev/mirutime/app/features/library/ui/ShelfTabs.kt +++ b/app/src/main/java/dev/mirutime/app/features/library/ui/ShelfTabs.kt @@ -28,7 +28,7 @@ import dev.mirutime.uikit.miruPlateBorder // Shelves row: secondary scrollable tabs (M3 pattern) with a segmented-control // look — flat text tabs, the selected ones on a soft accent pill, never chips. // "All" is the leading tab and means no shelf filter (empty selection); a tap -// on a shelf toggles it, so several shelves can be active at once. Long-press +// on a shelf switches to it alone (single-select). Long-press // opens the shelf manager; the manage icon duplicates that entry. // // The tabs sit on their OWN plate: one track for the shelf group, the same diff --git a/app/src/main/java/dev/mirutime/app/shell/MiruShell.kt b/app/src/main/java/dev/mirutime/app/shell/MiruShell.kt index e4b25b85..b1e3c90b 100644 --- a/app/src/main/java/dev/mirutime/app/shell/MiruShell.kt +++ b/app/src/main/java/dev/mirutime/app/shell/MiruShell.kt @@ -616,7 +616,7 @@ fun MiruShell( CompositionLocalProvider(LocalImeBottom provides imeBottom) { NavHost( navController = navController, - startDestination = initialRoute ?: MiruDestination.Dashboard.route, + startDestination = initialRoute ?: MiruDestination.Library.route, // Every destination (not only bottom sheets) lifts above the IME, so // full-screen text forms never have their fields/actions covered. modifier = Modifier.imePadding(), diff --git a/app/src/main/res/values-ar/strings.xml b/app/src/main/res/values-ar/strings.xml index 6a94d6cf..47f9e846 100644 --- a/app/src/main/res/values-ar/strings.xml +++ b/app/src/main/res/values-ar/strings.xml @@ -305,6 +305,9 @@ مرشحات المكتبة التمرير إلى الأعلى استيراد EPUB / FB2 / TXT / PDF + تصفية + تصفية · %1$d + استيراد لا شيء هنا جرّب رفًا أو استعلامًا أو مرشحًا آخر. %1$d/%2$d · %3$s · %4$s diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 9971044b..b83deeb5 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -306,6 +306,9 @@ Bibliotheksfilter Nach oben scrollen EPUB / FB2 / TXT / PDF importieren + Filter + Filter · %1$d + Importieren Hier ist nichts Versuche ein anderes Regal, einen anderen Suchbegriff oder Filter. %1$d/%2$d · %3$s · %4$s diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 5cf69c10..1ae4a035 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -306,6 +306,9 @@ Filtros de la biblioteca Ir arriba Importar EPUB / FB2 / TXT / PDF + Filtrar + Filtrar · %1$d + Importar No hay nada aquí Prueba otra estantería, búsqueda o filtro. %1$d/%2$d · %3$s · %4$s diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index b92b99ed..3ed647ff 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -306,6 +306,9 @@ Filtres de la bibliothèque Revenir en haut Importer EPUB / FB2 / TXT / PDF + Filtrer + Filtrer · %1$d + Importer Rien ici Essayez une autre étagère, requête ou filtre. %1$d/%2$d · %3$s · %4$s diff --git a/app/src/main/res/values-in/strings.xml b/app/src/main/res/values-in/strings.xml index 254fafb1..f5efe4e6 100644 --- a/app/src/main/res/values-in/strings.xml +++ b/app/src/main/res/values-in/strings.xml @@ -306,6 +306,9 @@ Filter perpustakaan Gulir ke atas Impor EPUB / FB2 / TXT / PDF + Filter + Filter · %1$d + Impor Tidak ada apa pun di sini Coba rak, kueri, atau filter lain. %1$d/%2$d · %3$s · %4$s diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 057d19ad..7fa4d7ac 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -306,6 +306,9 @@ Filtri libreria Vai in cima Importa EPUB / FB2 / TXT / PDF + Filtra + Filtra · %1$d + Importa Niente qui Prova un altro scaffale, una ricerca o un filtro. %1$d/%2$d · %3$s · %4$s diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index e933b88c..ec8947b3 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -306,6 +306,9 @@ Filtros da biblioteca Rolar até o topo Importar EPUB / FB2 / TXT / PDF + Filtrar + Filtrar · %1$d + Importar Nada aqui Tente outra estante, busca ou filtro. %1$d/%2$d · %3$s · %4$s diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index f4910007..b2b5e8e5 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -312,6 +312,9 @@ Фильтры библиотеки Наверх Импорт EPUB / FB2 / TXT / PDF + Фильтр + Фильтр · %1$d + Импорт Здесь пусто Попробуйте другую полку, запрос или фильтр. %1$d/%2$d · %3$s · %4$s diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index 73c26d6a..45bdc1f8 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -306,6 +306,9 @@ Kitaplık filtreleri Başa kaydır EPUB / FB2 / TXT / PDF içe aktar + Filtre + Filtre · %1$d + İçe aktar Burada bir şey yok Başka bir raf, arama veya filtre deneyin. %1$d/%2$d · %3$s · %4$s diff --git a/app/src/main/res/values-vi/strings.xml b/app/src/main/res/values-vi/strings.xml index 65fb9e3f..18913dc8 100644 --- a/app/src/main/res/values-vi/strings.xml +++ b/app/src/main/res/values-vi/strings.xml @@ -306,6 +306,9 @@ Bộ lọc thư viện Cuộn lên đầu Nhập EPUB / FB2 / TXT / PDF + Lọc + Lọc · %1$d + Nhập Không có gì ở đây Thử kệ, từ khóa hoặc bộ lọc khác. %1$d/%2$d · %3$s · %4$s diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 484faed8..1507f75a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -316,6 +316,9 @@ Library filters Scroll to top Import EPUB / FB2 / TXT / PDF + Filter + Filter · %1$d + Import Nothing here Try another shelf, query or filter. %1$d/%2$d · %3$s · %4$s diff --git a/app/src/test/java/dev/mirutime/app/features/ui/ChipRailContractTest.kt b/app/src/test/java/dev/mirutime/app/features/ui/ChipRailContractTest.kt index 990e683c..a2d3ffe7 100644 --- a/app/src/test/java/dev/mirutime/app/features/ui/ChipRailContractTest.kt +++ b/app/src/test/java/dev/mirutime/app/features/ui/ChipRailContractTest.kt @@ -31,12 +31,6 @@ class ChipRailContractTest { assertTrue(screen.contains("ChipRail {")) } - @Test - fun `library mini filters use the shared rail`() { - val text = source("src/main/java/dev/mirutime/app/features/library/ui/LibraryScreen.kt") - assertTrue(text.contains("ChipRail {")) - } - // Icons are unconditional: the settings toggle and its key are gone, and // every plugin row renders the shared avatar instead of a letter tile. @Test diff --git a/app/src/test/java/dev/mirutime/app/features/ui/ContentFadeContractTest.kt b/app/src/test/java/dev/mirutime/app/features/ui/ContentFadeContractTest.kt index 84d89f32..d792cd28 100644 --- a/app/src/test/java/dev/mirutime/app/features/ui/ContentFadeContractTest.kt +++ b/app/src/test/java/dev/mirutime/app/features/ui/ContentFadeContractTest.kt @@ -25,10 +25,9 @@ class ContentFadeContractTest { } @Test - fun `library mini filters are not alpha masked`() { + fun `library screen is not alpha masked`() { val text = source("src/main/java/dev/mirutime/app/features/library/ui/LibraryScreen.kt") - val mini = slice(text, "private fun MiniFilters(", "private fun LibrarySort.label()") - assertFalse(mini.contains("miruEdgeFade")) + assertFalse(text.contains("miruEdgeFade")) } @Test diff --git a/feature-reader/src/main/java/dev/mirutime/feature/reader/api/ReaderScreen.kt b/feature-reader/src/main/java/dev/mirutime/feature/reader/api/ReaderScreen.kt index b0f34d1c..99c4d480 100644 --- a/feature-reader/src/main/java/dev/mirutime/feature/reader/api/ReaderScreen.kt +++ b/feature-reader/src/main/java/dev/mirutime/feature/reader/api/ReaderScreen.kt @@ -107,7 +107,7 @@ import dev.mirutime.feature.tts.TtsSession import dev.mirutime.feature.tts.TtsStatus import dev.mirutime.feature.tts.api.TtsHighlight import dev.mirutime.feature.tts.ttsSentencePreviewInfo -import dev.mirutime.feature.tts.ui.TtsFloatingPlayer +import dev.mirutime.feature.tts.ui.TtsClassicBar import dev.mirutime.feature.tts.ui.TtsMiniPlayer import java.io.File import java.util.Locale @@ -1348,45 +1348,17 @@ fun ReaderScreen( ) } - // Optional floating player: the rich in-app surface while the reader is - // on screen. The system overlay takes over only once the whole app goes - // to the background, so the two never show the same session at once. - // Hidden while the chrome or a sheet is open so it never duplicates the - // bottom-menu player or sits under a modal scrim. - if (ttsSessionActive && - ttsSettings.floatingPlayer && - panel == null && - !chromeVisible - ) { - TtsFloatingPlayer( + // QuickNovel-style playback strip while a session runs: rewind, stop, + // play/pause, fast-forward. Hidden while the chrome or a sheet is open + // (the bottom menu carries its own player there). + if (ttsSessionActive && panel == null && !chromeVisible) { + TtsClassicBar( status = ttsState.status, - chapterTitle = chapterTitle, - sentencePreview = ttsPreview, - paragraphText = ttsParagraph, - counterpartText = ttsCounterpart, - spokenIsTranslation = ttsState.translated, - ttsHighlight = ttsHighlight, - sentenceHighlightStart = ttsPreviewInfo?.start ?: 0, - sentenceHighlightEnd = ttsPreviewInfo?.end ?: 0, - sentenceNumber = ttsSentenceNumber, - chunkCount = ttsChunkCount, - chapterNumber = state.activeChapterIndex, - chapterCount = chapterCount, - chapterPercent = chapterPercent, - remainingSeconds = ttsState.estimatedRemainingSeconds, - sleepTimer = graph.tts.sleepTimer, - onSleepTimerClick = { chromeVisible = true; panel = ReaderPanel.Tts }, - atEnd = ttsState.atEnd, - glowColorArgb = style.highlightColor, - settings = ttsSettings, - onSettingsChange = graph.tts::updateSettings, - onToggle = toggleTts, + onPrevious = graph.tts::skipPreviousChunk, onStop = stopTts, - onStartHere = startTtsHere, - onFocus = focusTtsBlock, - onPreviousChunk = graph.tts::skipPreviousChunk, - onNextChunk = graph.tts::skipNextChunk, - onOpenSettings = { panel = ReaderPanel.Tts }, + onToggle = toggleTts, + onNext = graph.tts::skipNextChunk, + modifier = Modifier.align(Alignment.BottomCenter), ) } } diff --git a/feature-reader/src/main/java/dev/mirutime/feature/reader/ui/ReaderFeed.kt b/feature-reader/src/main/java/dev/mirutime/feature/reader/ui/ReaderFeed.kt index fc4f25b8..a4f46208 100644 --- a/feature-reader/src/main/java/dev/mirutime/feature/reader/ui/ReaderFeed.kt +++ b/feature-reader/src/main/java/dev/mirutime/feature/reader/ui/ReaderFeed.kt @@ -22,6 +22,8 @@ import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue import androidx.compose.runtime.remember import androidx.compose.runtime.rememberUpdatedState import androidx.compose.runtime.snapshotFlow @@ -34,6 +36,7 @@ import androidx.compose.ui.platform.LocalLayoutDirection import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import dev.mirutime.feature.reader.R +import dev.mirutime.app.features.reader.document.BlockId import dev.mirutime.app.features.reader.document.ReadingAnchor import dev.mirutime.feature.reader.feedItemKey import dev.mirutime.feature.reader.ChapterLoadStatus @@ -68,12 +71,36 @@ internal fun feedScrollTrigger( topPaddingPx = topPaddingPx, ) -/** True when the spoken block is outside the comfortable band. */ +/** + * QuickNovel-style follow rule: the page stays put while the spoken block is + * fully inside the reading area. It only advances once the block has moved + * off-screen (or is cut by the bottom edge and would fit on one screen). + * A block taller than the screen is left alone while any part of it shows. + */ internal fun ttsFollowNeedsScroll( visible: Boolean, offsetPx: Int, - comfortOffsetPx: Int, -): Boolean = !visible || offsetPx !in 0..comfortOffsetPx + sizePx: Int, + viewportTopPx: Int, + viewportBottomPx: Int, +): Boolean { + if (!visible) return true + if (sizePx > viewportBottomPx - viewportTopPx) return false + return offsetPx < viewportTopPx || offsetPx + sizePx > viewportBottomPx +} + +/** + * The follow only continues while the reader is "attached" to the voice: the + * previously spoken block was still on screen (or there was none, or it has + * left the feed). When the user scrolled away from it, the screen is theirs and + * is never yanked back; scrolling back to the voice (or the Focus button) + * re-attaches. + */ +internal fun ttsFollowAttached( + hadPrevious: Boolean, + previousInFeed: Boolean, + previousVisible: Boolean, +): Boolean = !hadPrevious || !previousInFeed || previousVisible /** Small jumps animate; far chapter jumps should land immediately. */ internal fun ttsFollowUsesAnimation(distance: Int): Boolean = distance <= 5 @@ -151,42 +178,68 @@ internal fun ReaderFeed( // The floating chrome header covers the top of the list. A negative scroll // offset parks the spoken block below it instead of under the title. val ttsFocusInsetPx = with(density) { 72.dp.toPx().toInt() } - // A visible block near the top is already comfortable to read: moving it - // again on every spoken sentence is what made the feed blink. - val ttsComfortOffsetPx = with(density) { 200.dp.toPx().toInt() } + // Advancing parks the spoken block just under the top edge, like turning + // to the next screen of text. + val ttsAdvanceInsetPx = with(density) { 16.dp.toPx().toInt() } + // Block id spoken before the current one; lets the follow tell "the voice + // moved off-screen" apart from "the user scrolled away". + var previousTtsBlockId by remember { mutableStateOf(null) } fun ttsBlockIndex(): Int { val blockId = ttsHighlight?.blockId ?: return -1 return entries.indexOfFirst { it is FeedEntry.Block && it.block.id == blockId } } - // When TTS moves to another paragraph, keep it below the floating header. - // Only block changes trigger this; per-sentence range updates do not. - suspend fun followTtsBlock() { + // The page stays stationary while the spoken block is on screen and the + // reader scrolls freely. Only when TTS moves the spoken block off-screen + // does the view advance, parking it at the top. Per-sentence range updates + // never trigger this; only block changes do. + suspend fun followTtsBlock(previous: BlockId?) { val index = ttsBlockIndex() if (index < 0) return - val visible = listState.layoutInfo.visibleItemsInfo.firstOrNull { it.index == index } + val info = listState.layoutInfo + val previousIndex = if (previous == null) { + -1 + } else { + entries.indexOfFirst { it is FeedEntry.Block && it.block.id == previous } + } + val previousVisible = previousIndex >= 0 && + info.visibleItemsInfo.any { it.index == previousIndex } + if (!ttsFollowAttached( + hadPrevious = previous != null, + previousInFeed = previousIndex >= 0, + previousVisible = previousVisible, + ) + ) { + return + } + val visible = info.visibleItemsInfo.firstOrNull { it.index == index } if (!ttsFollowNeedsScroll( visible = visible != null, offsetPx = visible?.offset ?: 0, - comfortOffsetPx = ttsComfortOffsetPx, + sizePx = visible?.size ?: 0, + viewportTopPx = 0, + viewportBottomPx = info.viewportEndOffset - info.afterContentPadding, ) ) { return } val distance = abs(index - (visible?.index ?: listState.firstVisibleItemIndex)) if (ttsFollowUsesAnimation(distance)) { - listState.animateScrollToItem(index, scrollOffset = -ttsFocusInsetPx) + listState.animateScrollToItem(index, scrollOffset = -ttsAdvanceInsetPx) } else { - listState.scrollToItem(index, scrollOffset = -ttsFocusInsetPx) + listState.scrollToItem(index, scrollOffset = -ttsAdvanceInsetPx) } } LaunchedEffect(ttsHighlight?.blockId) { - followTtsBlock() + val current = ttsHighlight?.blockId + val previous = previousTtsBlockId + previousTtsBlockId = current + if (current != null) followTtsBlock(previous) } // First content only: prepending a previous chapter must not re-follow. LaunchedEffect(entries.isEmpty()) { - if (entries.isNotEmpty()) followTtsBlock() + if (entries.isNotEmpty()) followTtsBlock(null) } // Explicit Focus action: retrigger even when the active block has not // changed since the last auto-follow. diff --git a/feature-reader/src/main/java/dev/mirutime/feature/reader/ui/ReaderText.kt b/feature-reader/src/main/java/dev/mirutime/feature/reader/ui/ReaderText.kt index 04a6b37c..b19a2c26 100644 --- a/feature-reader/src/main/java/dev/mirutime/feature/reader/ui/ReaderText.kt +++ b/feature-reader/src/main/java/dev/mirutime/feature/reader/ui/ReaderText.kt @@ -112,7 +112,7 @@ fun ReaderBlockView( // pre-split paragraph never lights up as several. val splitParagraph = ReaderSplit.shouldSplit(block, style.splitSentences) val activeBlock = ttsHighlight?.blockId == block.id - val blockTint = activeBlock && !splitParagraph + val blockTint = activeBlock && !splitParagraph && ttsHighlight?.rangeEnabled == false val content: @Composable () -> Unit = { Box( Modifier diff --git a/feature-reader/src/test/java/dev/mirutime/feature/reader/ui/FeedScrollTriggerTest.kt b/feature-reader/src/test/java/dev/mirutime/feature/reader/ui/FeedScrollTriggerTest.kt index db914f22..14b40c76 100644 --- a/feature-reader/src/test/java/dev/mirutime/feature/reader/ui/FeedScrollTriggerTest.kt +++ b/feature-reader/src/test/java/dev/mirutime/feature/reader/ui/FeedScrollTriggerTest.kt @@ -57,11 +57,30 @@ class FeedScrollTriggerTest { } @Test - fun `tts follow skips a comfortable visible block`() { - assertFalse(ttsFollowNeedsScroll(visible = true, offsetPx = 0, comfortOffsetPx = 200)) - assertFalse(ttsFollowNeedsScroll(visible = true, offsetPx = 200, comfortOffsetPx = 200)) - assertTrue(ttsFollowNeedsScroll(visible = true, offsetPx = 201, comfortOffsetPx = 200)) - assertTrue(ttsFollowNeedsScroll(visible = false, offsetPx = 0, comfortOffsetPx = 200)) + fun `tts follow keeps the page still while the block is fully on screen`() { + assertFalse(ttsFollowNeedsScroll(true, offsetPx = 0, sizePx = 100, viewportTopPx = 0, viewportBottomPx = 1000)) + assertFalse(ttsFollowNeedsScroll(true, offsetPx = 600, sizePx = 300, viewportTopPx = 0, viewportBottomPx = 1000)) + assertFalse(ttsFollowNeedsScroll(true, offsetPx = 900, sizePx = 100, viewportTopPx = 0, viewportBottomPx = 1000)) + } + + @Test + fun `tts follow advances once the block leaves or is cut by the screen`() { + assertTrue(ttsFollowNeedsScroll(false, offsetPx = 0, sizePx = 0, viewportTopPx = 0, viewportBottomPx = 1000)) + assertTrue(ttsFollowNeedsScroll(true, offsetPx = 950, sizePx = 200, viewportTopPx = 0, viewportBottomPx = 1000)) + assertTrue(ttsFollowNeedsScroll(true, offsetPx = -50, sizePx = 200, viewportTopPx = 0, viewportBottomPx = 1000)) + } + + @Test + fun `tts follow leaves a block taller than the screen alone while it shows`() { + assertFalse(ttsFollowNeedsScroll(true, offsetPx = -300, sizePx = 1500, viewportTopPx = 0, viewportBottomPx = 1000)) + } + + @Test + fun `tts follow never yanks the screen back after the user scrolled away`() { + assertTrue(ttsFollowAttached(hadPrevious = false, previousInFeed = false, previousVisible = false)) + assertTrue(ttsFollowAttached(hadPrevious = true, previousInFeed = true, previousVisible = true)) + assertTrue(ttsFollowAttached(hadPrevious = true, previousInFeed = false, previousVisible = false)) + assertFalse(ttsFollowAttached(hadPrevious = true, previousInFeed = true, previousVisible = false)) } @Test diff --git a/feature-tts/src/main/java/dev/mirutime/feature/tts/ui/TtsClassicBar.kt b/feature-tts/src/main/java/dev/mirutime/feature/tts/ui/TtsClassicBar.kt new file mode 100644 index 00000000..d664b9a7 --- /dev/null +++ b/feature-tts/src/main/java/dev/mirutime/feature/tts/ui/TtsClassicBar.kt @@ -0,0 +1,100 @@ +package dev.mirutime.feature.tts.ui + +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.navigationBarsPadding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.Column +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.FastForward +import androidx.compose.material.icons.filled.FastRewind +import androidx.compose.material.icons.filled.Pause +import androidx.compose.material.icons.filled.PlayArrow +import androidx.compose.material.icons.filled.Stop +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.MaterialTheme +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import dev.mirutime.feature.tts.R +import dev.mirutime.feature.tts.TtsStatus + +/** + * QuickNovel-style TTS bar: one full-width strip with four evenly spaced icon + * buttons: rewind (previous sentence), stop, play/pause, fast-forward (next + * sentence). No text, no cards; the page behind keeps its position. + */ +@Composable +fun TtsClassicBar( + status: TtsStatus, + onPrevious: () -> Unit, + onStop: () -> Unit, + onToggle: () -> Unit, + onNext: () -> Unit, + modifier: Modifier = Modifier, +) { + val playing = status == TtsStatus.Playing || status == TtsStatus.Loading + Column( + modifier = modifier + .fillMaxWidth() + .background(MaterialTheme.colorScheme.surfaceContainer) + .navigationBarsPadding(), + ) { + Row( + modifier = Modifier + .fillMaxWidth() + .height(56.dp), + verticalAlignment = Alignment.CenterVertically, + ) { + ClassicBarButton( + Icons.Filled.FastRewind, + stringResource(R.string.rd_tts_prev_chunk), + Modifier.weight(1f), + onPrevious, + ) + ClassicBarButton( + Icons.Filled.Stop, + stringResource(R.string.rd_tts_stop), + Modifier.weight(1f), + onStop, + ) + ClassicBarButton( + if (playing) Icons.Filled.Pause else Icons.Filled.PlayArrow, + stringResource( + if (playing) R.string.rd_tts_action_pause else R.string.rd_tts_action_play, + ), + Modifier.weight(1f), + onToggle, + ) + ClassicBarButton( + Icons.Filled.FastForward, + stringResource(R.string.rd_tts_next_chunk), + Modifier.weight(1f), + onNext, + ) + } + } +} + +@Composable +private fun ClassicBarButton( + icon: ImageVector, + description: String, + modifier: Modifier, + onClick: () -> Unit, +) { + IconButton(onClick = onClick, modifier = modifier.height(56.dp)) { + Icon( + imageVector = icon, + contentDescription = description, + tint = MaterialTheme.colorScheme.onSurface, + modifier = Modifier.size(28.dp), + ) + } +}