Explorar el Código

feat: 选择模式相关

HapeLee hace 1 mes
padre
commit
2c8be9b293

+ 13 - 0
app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfScreen.kt

@@ -137,6 +137,7 @@ import io.legado.app.ui.widget.components.topbar.GlassMediumFlexibleTopAppBar
 import io.legado.app.ui.widget.components.topbar.GlassTopAppBarDefaults
 import io.legado.app.ui.widget.components.topbar.GlassTopAppBarDefaults
 import io.legado.app.ui.widget.components.topbar.GlassTopAppBarScrollBehavior
 import io.legado.app.ui.widget.components.topbar.GlassTopAppBarScrollBehavior
 import io.legado.app.ui.widget.components.topbar.TopBarActionButton
 import io.legado.app.ui.widget.components.topbar.TopBarActionButton
+import io.legado.app.ui.widget.components.topbar.TopBarNavigationButton
 import kotlinx.collections.immutable.ImmutableList
 import kotlinx.collections.immutable.ImmutableList
 import kotlinx.collections.immutable.ImmutableSet
 import kotlinx.collections.immutable.ImmutableSet
 import kotlinx.collections.immutable.persistentListOf
 import kotlinx.collections.immutable.persistentListOf
@@ -481,6 +482,7 @@ fun BookshelfScreen(
                         ?.let(onNavigateToSearch)
                         ?.let(onNavigateToSearch)
                 },
                 },
                 onClearSearch = { onIntent(BookshelfIntent.SetSearchKey("")) },
                 onClearSearch = { onIntent(BookshelfIntent.SetSearchKey("")) },
+                onExitEditMode = exitEditMode,
                 actions = {
                 actions = {
                     AnimatedVisibility(visible = isEditMode) {
                     AnimatedVisibility(visible = isEditMode) {
                         TopBarActionButton(
                         TopBarActionButton(
@@ -1119,12 +1121,23 @@ private fun BookshelfTopBar(
     onSearchQueryChange: (String) -> Unit,
     onSearchQueryChange: (String) -> Unit,
     onSearchSubmit: (String) -> Unit,
     onSearchSubmit: (String) -> Unit,
     onClearSearch: () -> Unit,
     onClearSearch: () -> Unit,
+    onExitEditMode: () -> Unit,
     actions: @Composable RowScope.() -> Unit = {},
     actions: @Composable RowScope.() -> Unit = {},
     bottomContent: @Composable ColumnScope.() -> Unit = {}
     bottomContent: @Composable ColumnScope.() -> Unit = {}
 ) {
 ) {
     val searchContentDescription = stringResource(R.string.search)
     val searchContentDescription = stringResource(R.string.search)
+    val exitEditModeDescription = stringResource(R.string.cancel_select)
     GlassMediumFlexibleTopAppBar(
     GlassMediumFlexibleTopAppBar(
         modifier = Modifier.fillMaxWidth(),
         modifier = Modifier.fillMaxWidth(),
+        navigationIcon = {
+            if (uiState.isEditMode) {
+                TopBarNavigationButton(
+                    onClick = onExitEditMode,
+                    imageVector = AppIcons.Close,
+                    contentDescription = exitEditModeDescription
+                )
+            }
+        },
         title = if (uiState.isLoading) {
         title = if (uiState.isLoading) {
             stringResource(R.string.loading)
             stringResource(R.string.loading)
         } else {
         } else {

+ 20 - 8
app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt

@@ -16,31 +16,31 @@ import io.legado.app.data.repository.BookRepository
 import io.legado.app.data.repository.BookSourceRepository
 import io.legado.app.data.repository.BookSourceRepository
 import io.legado.app.data.repository.BookshelfRepository
 import io.legado.app.data.repository.BookshelfRepository
 import io.legado.app.data.repository.UploadRepository
 import io.legado.app.data.repository.UploadRepository
+import io.legado.app.domain.gateway.AppShellSettingsGateway
+import io.legado.app.domain.gateway.BookshelfSettingsGateway
+import io.legado.app.domain.gateway.DownloadCacheSettingsGateway
+import io.legado.app.domain.gateway.ThemeSettingsGateway
 import io.legado.app.domain.usecase.AddBookUseCase
 import io.legado.app.domain.usecase.AddBookUseCase
 import io.legado.app.domain.usecase.BatchCacheDownloadUseCase
 import io.legado.app.domain.usecase.BatchCacheDownloadUseCase
 import io.legado.app.domain.usecase.ExportBookshelfUseCase
 import io.legado.app.domain.usecase.ExportBookshelfUseCase
 import io.legado.app.domain.usecase.ImportBookshelfUseCase
 import io.legado.app.domain.usecase.ImportBookshelfUseCase
 import io.legado.app.domain.usecase.RefreshTocUseCase
 import io.legado.app.domain.usecase.RefreshTocUseCase
 import io.legado.app.domain.usecase.UpdateBooksGroupUseCase
 import io.legado.app.domain.usecase.UpdateBooksGroupUseCase
-import io.legado.app.domain.gateway.BookshelfSettingsGateway
-import io.legado.app.domain.gateway.AppShellSettingsGateway
-import io.legado.app.domain.gateway.DownloadCacheSettingsGateway
-import io.legado.app.domain.gateway.ThemeSettingsGateway
 import io.legado.app.exception.NoStackTraceException
 import io.legado.app.exception.NoStackTraceException
 import io.legado.app.help.coroutine.Coroutine
 import io.legado.app.help.coroutine.Coroutine
 import io.legado.app.model.CacheBook
 import io.legado.app.model.CacheBook
 import io.legado.app.model.SourceCallBack
 import io.legado.app.model.SourceCallBack
 import io.legado.app.service.CacheBookService
 import io.legado.app.service.CacheBookService
 import io.legado.app.ui.config.themeConfig.TagColorPair
 import io.legado.app.ui.config.themeConfig.TagColorPair
+import io.legado.app.utils.GSON
 import io.legado.app.utils.eventBus.FlowEventBus
 import io.legado.app.utils.eventBus.FlowEventBus
 import io.legado.app.utils.move
 import io.legado.app.utils.move
 import io.legado.app.utils.onEachParallel
 import io.legado.app.utils.onEachParallel
 import io.legado.app.utils.postEvent
 import io.legado.app.utils.postEvent
-import io.legado.app.utils.GSON
 import kotlinx.collections.immutable.ImmutableList
 import kotlinx.collections.immutable.ImmutableList
 import kotlinx.collections.immutable.ImmutableMap
 import kotlinx.collections.immutable.ImmutableMap
-import kotlinx.collections.immutable.persistentMapOf
 import kotlinx.collections.immutable.persistentListOf
 import kotlinx.collections.immutable.persistentListOf
+import kotlinx.collections.immutable.persistentMapOf
 import kotlinx.collections.immutable.toImmutableList
 import kotlinx.collections.immutable.toImmutableList
 import kotlinx.collections.immutable.toImmutableMap
 import kotlinx.collections.immutable.toImmutableMap
 import kotlinx.collections.immutable.toImmutableSet
 import kotlinx.collections.immutable.toImmutableSet
@@ -55,6 +55,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
 import kotlinx.coroutines.flow.SharedFlow
 import kotlinx.coroutines.flow.SharedFlow
 import kotlinx.coroutines.flow.SharingStarted
 import kotlinx.coroutines.flow.SharingStarted
 import kotlinx.coroutines.flow.StateFlow
 import kotlinx.coroutines.flow.StateFlow
+import kotlinx.coroutines.flow.asSharedFlow
 import kotlinx.coroutines.flow.catch
 import kotlinx.coroutines.flow.catch
 import kotlinx.coroutines.flow.collect
 import kotlinx.coroutines.flow.collect
 import kotlinx.coroutines.flow.combine
 import kotlinx.coroutines.flow.combine
@@ -66,7 +67,6 @@ import kotlinx.coroutines.flow.flowOf
 import kotlinx.coroutines.flow.flowOn
 import kotlinx.coroutines.flow.flowOn
 import kotlinx.coroutines.flow.map
 import kotlinx.coroutines.flow.map
 import kotlinx.coroutines.flow.onEach
 import kotlinx.coroutines.flow.onEach
-import kotlinx.coroutines.flow.asSharedFlow
 import kotlinx.coroutines.flow.shareIn
 import kotlinx.coroutines.flow.shareIn
 import kotlinx.coroutines.flow.stateIn
 import kotlinx.coroutines.flow.stateIn
 import kotlinx.coroutines.isActive
 import kotlinx.coroutines.isActive
@@ -577,7 +577,19 @@ class BookshelfViewModel(
             title = title,
             title = title,
             subtitle = when {
             subtitle = when {
                 interaction.isEditMode -> {
                 interaction.isEditMode -> {
-                    context.getString(R.string.bookshelf_total_count, previews.allBookCount)
+                    val selectedText = context.getString(
+                        R.string.bookshelf_selected_count,
+                        interaction.selectedBookUrls.size
+                    )
+                    val groupTotalText = context.getString(
+                        R.string.bookshelf_total_count,
+                        books.size
+                    )
+                    context.getString(
+                        R.string.bookshelf_edit_subtitle,
+                        selectedText,
+                        groupTotalText
+                    )
                 }
                 }
 
 
                 selectedBooks.isSearchMode -> {
                 selectedBooks.isSearchMode -> {

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -2015,6 +2015,7 @@
     <string name="tool_bar_style">Tool bar style</string>
     <string name="tool_bar_style">Tool bar style</string>
     <string name="bookshelf_total_count">%1$d books</string>
     <string name="bookshelf_total_count">%1$d books</string>
     <string name="bookshelf_selected_count">%1$d selected</string>
     <string name="bookshelf_selected_count">%1$d selected</string>
+    <string name="bookshelf_edit_subtitle">%1$s · %2$s</string>
     <string name="bookshelf_empty_global_search">No books here. Try global search.</string>
     <string name="bookshelf_empty_global_search">No books here. Try global search.</string>
     <string name="global_search">Global search</string>
     <string name="global_search">Global search</string>
     <string name="cache_management">Cache management</string>
     <string name="cache_management">Cache management</string>