Răsfoiți Sursa

feat: 书源列表溢出菜单

HapeLee 3 luni în urmă
părinte
comite
3396580c64

+ 18 - 0
app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt

@@ -4,7 +4,11 @@ import androidx.activity.result.contract.ActivityResultContracts
 import androidx.compose.runtime.Composable
 import io.legado.app.base.BaseComposeActivity
 import io.legado.app.ui.association.ImportBookSourceDialog
+import io.legado.app.ui.book.search.SearchActivity
+import io.legado.app.ui.book.search.SearchScope
+import io.legado.app.ui.book.source.debug.BookSourceDebugActivity
 import io.legado.app.ui.book.source.edit.BookSourceEditActivity
+import io.legado.app.ui.login.SourceLoginActivity
 import io.legado.app.utils.showDialogFragment
 import io.legado.app.utils.startActivity
 
@@ -25,6 +29,20 @@ class BookSourceActivity : BaseComposeActivity() {
                     putExtra("sourceUrl", sourceUrl)
                 }
             },
+            onLoginSource = { sourceUrl ->
+                startActivity<SourceLoginActivity> {
+                    putExtra("type", "bookSource")
+                    putExtra("key", sourceUrl)
+                }
+            },
+            onSearchSource = { sourceUrl ->
+                SearchActivity.start(this, null, SearchScope(sourceUrl).toString())
+            },
+            onDebugSource = { sourceUrl ->
+                startActivity<BookSourceDebugActivity> {
+                    putExtra("key", sourceUrl)
+                }
+            },
             onImportLocal = {
                 importDocument.launch(
                     arrayOf(

+ 3 - 0
app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceContract.kt

@@ -17,6 +17,9 @@ data class BookSourceItemUi(
     val name: String,
     val group: String?,
     val enabled: Boolean,
+    val enabledExplore: Boolean,
+    val hasLoginUrl: Boolean,
+    val hasExploreUrl: Boolean,
     val customOrder: Int,
 ) : SelectableItem<String> {
 }

+ 87 - 6
app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceScreen.kt

@@ -17,8 +17,6 @@ import androidx.compose.foundation.lazy.grid.GridItemSpan
 import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
 import androidx.compose.foundation.lazy.rememberLazyListState
 import androidx.compose.foundation.shape.RoundedCornerShape
-import androidx.compose.material.icons.Icons
-import androidx.compose.material.icons.filled.Delete
 import androidx.compose.material3.ExperimentalMaterial3Api
 import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
 import androidx.compose.material3.SnackbarHostState
@@ -51,6 +49,7 @@ import io.legado.app.ui.widget.components.divider.PillDivider
 import io.legado.app.ui.widget.components.icon.AppIcons
 import io.legado.app.ui.widget.components.importComponents.SourceInputDialog
 import io.legado.app.ui.widget.components.lazylist.FastScrollLazyColumn
+import io.legado.app.ui.widget.components.menuItem.RoundDropdownMenu
 import io.legado.app.ui.widget.components.menuItem.RoundDropdownMenuItem
 import io.legado.app.ui.widget.components.modalBottomSheet.AppModalBottomSheet
 import io.legado.app.ui.widget.components.rules.RuleListScaffold
@@ -66,6 +65,9 @@ fun BookSourceRouteScreen(
     onBackClick: () -> Unit,
     onAddSource: () -> Unit,
     onEditSource: (String) -> Unit,
+    onLoginSource: (String) -> Unit,
+    onSearchSource: (String) -> Unit,
+    onDebugSource: (String) -> Unit,
     onImportLocal: () -> Unit,
     onImportOnline: (String) -> Unit,
 ) {
@@ -76,6 +78,9 @@ fun BookSourceRouteScreen(
         onBackClick,
         onAddSource,
         onEditSource,
+        onLoginSource,
+        onSearchSource,
+        onDebugSource,
         onImportLocal,
         onImportOnline
     )
@@ -89,6 +94,9 @@ fun BookSourceScreen(
     onBackClick: () -> Unit,
     onAddSource: () -> Unit,
     onEditSource: (String) -> Unit,
+    onLoginSource: (String) -> Unit,
+    onSearchSource: (String) -> Unit,
+    onDebugSource: (String) -> Unit,
     onImportLocal: () -> Unit,
     onImportOnline: (String) -> Unit,
 ) {
@@ -354,10 +362,25 @@ fun BookSourceScreen(
                             },
                             onClickEdit = { onEditSource(item.id) },
                             trailingAction = {
-                                SmallPlainButton(
-                                    icon = Icons.Default.Delete,
-                                    contentDescription = stringResource(R.string.delete),
-                                    onClick = { deleteIds = setOf(item.id) })
+                                BookSourceItemMenu(
+                                    item = item,
+                                    canMoveToEdge = state.sort == BookSourceSort.Default && !state.groupByDomain,
+                                    onMoveToEdge = { toTop ->
+                                        onIntent(BookSourceIntent.MoveToEdge(setOf(item.id), toTop))
+                                    },
+                                    onLogin = { onLoginSource(item.id) },
+                                    onSearch = { onSearchSource(item.id) },
+                                    onDebug = { onDebugSource(item.id) },
+                                    onDelete = { deleteIds = setOf(item.id) },
+                                    onSetExploreEnabled = { enabled ->
+                                        onIntent(
+                                            BookSourceIntent.SetExploreEnabled(
+                                                setOf(item.id),
+                                                enabled
+                                            )
+                                        )
+                                    },
+                                )
                             })
                     }
                 }
@@ -377,6 +400,64 @@ fun BookSourceScreen(
     }
 }
 
+@Composable
+private fun BookSourceItemMenu(
+    item: BookSourceItemUi,
+    canMoveToEdge: Boolean,
+    onMoveToEdge: (Boolean) -> Unit,
+    onLogin: () -> Unit,
+    onSearch: () -> Unit,
+    onDebug: () -> Unit,
+    onDelete: () -> Unit,
+    onSetExploreEnabled: (Boolean) -> Unit,
+) {
+    var expanded by remember { mutableStateOf(false) }
+    Box {
+        SmallPlainButton(
+            icon = AppIcons.MoreVert,
+            contentDescription = stringResource(R.string.menu),
+            onClick = { expanded = true },
+        )
+        RoundDropdownMenu(
+            expanded = expanded,
+            onDismissRequest = { expanded = false },
+        ) { dismiss ->
+            if (canMoveToEdge) {
+                RoundDropdownMenuItem(stringResource(R.string.to_top), onClick = {
+                    dismiss(); onMoveToEdge(true)
+                })
+                RoundDropdownMenuItem(stringResource(R.string.to_bottom), onClick = {
+                    dismiss(); onMoveToEdge(false)
+                })
+            }
+            if (item.hasLoginUrl) {
+                RoundDropdownMenuItem(stringResource(R.string.login), onClick = {
+                    dismiss(); onLogin()
+                })
+            }
+            RoundDropdownMenuItem(stringResource(R.string.search), onClick = {
+                dismiss(); onSearch()
+            })
+            RoundDropdownMenuItem(stringResource(R.string.debug), onClick = {
+                dismiss(); onDebug()
+            })
+            RoundDropdownMenuItem(stringResource(R.string.delete), onClick = {
+                dismiss(); onDelete()
+            })
+            if (item.hasExploreUrl) {
+                RoundDropdownMenuItem(
+                    text = stringResource(
+                        if (item.enabledExplore) R.string.disable_explore else R.string.enable_explore
+                    ),
+                    onClick = {
+                        dismiss(); onSetExploreEnabled(!item.enabledExplore)
+                    },
+                )
+            }
+        }
+    }
+}
+
 @Composable
 private fun SortMenuItem(
     textRes: Int,

+ 3 - 0
app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceViewModel.kt

@@ -83,6 +83,9 @@ class BookSourceViewModel(
                     name = source.bookSourceName,
                     group = source.bookSourceGroup,
                     enabled = pendingEnabled[source.bookSourceUrl] ?: source.enabled,
+                    enabledExplore = source.enabledExplore,
+                    hasLoginUrl = source.hasLoginUrl,
+                    hasExploreUrl = source.hasExploreUrl,
                     customOrder = source.customOrder,
                 )
             }.toImmutableList(),