[优化] 优化代码

This commit is contained in:
HapeLee
2026-03-25 12:30:16 +08:00
parent d029f3016e
commit 4888b82876
3 changed files with 12 additions and 39 deletions
-32
View File
@@ -230,38 +230,6 @@ jobs:
if-no-files-found: ignore
path: ${{ github.workspace }}/mapping/mapping.txt
test_Branch:
needs: [ prepare, build ]
runs-on: ubuntu-latest
# 仅在所有者的非 PR 事件时执行(即所有者 push 到 main 分支时)
if: ${{ github.event_name != 'pull_request' && github.actor == 'HapeLee' }}
steps:
- uses: actions/checkout@v5
- uses: actions/download-artifact@v5
with:
pattern: '*-apk-release'
path: apk/
merge-multiple: true
- working-directory: apk/
run: |
# 使用 find 安全地移动文件
find . -type f -name "*.apk" -exec mv {} . \;
# 清理子目录
find . -type d -mindepth 1 -exec rm -rf {} +
- name: Push To "test" Branch
run: |
cd $GITHUB_WORKSPACE/apk/
git init
git checkout -b test
git config --global user.name "github-actions[bot]"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git remote add origin "https://${{ github.actor }}:${{ secrets.ACTIONS_TOKEN }}@github.com/${{ github.actor }}/release"
git add *.apk
git commit -m "${{ needs.prepare.outputs.versionL }}"
git push -f -u origin test
create_release:
needs: [ prepare, build ]
# 仅在所有者的 push 到 main 分支时执行发布
@@ -13,6 +13,7 @@ import io.legado.app.data.entities.BookGroup
import io.legado.app.data.entities.BookSource
import io.legado.app.help.book.isNotShelf
import io.legado.app.ui.main.bookshelf.BookShelfItem
import io.legado.app.ui.main.bookshelf.toBookShelfItem
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
@@ -39,6 +40,12 @@ interface BookDao {
}
}
fun flowBookShelfByGroup(groupId: Long): Flow<List<BookShelfItem>> {
return flowByGroup(groupId).map { list ->
list.map { it.toBookShelfItem() }
}
}
@Query(
"""
select * from books where type & ${BookType.text} > 0
@@ -123,16 +123,15 @@ class BookshelfViewModel(
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5000), emptyList())
private val allBooksFlow = appDb.bookDao.flowBookShelf()
.map { list -> list.map { it.toBookShelfItem() } }
.distinctUntilChanged()
.flowOn(Dispatchers.Default)
@OptIn(ExperimentalCoroutinesApi::class)
val booksFlow = combine(groupIdFlow, refreshTrigger) { groupId, _ -> groupId }
.flatMapLatest { groupId ->
appDb.bookDao.flowByGroup(groupId).map { list ->
appDb.bookDao.flowBookShelfByGroup(groupId).map { list ->
sortBooks(
list.map { it.toBookShelfItem() },
list,
groupsFlow.value.find { it.groupId == groupId })
}
}.distinctUntilChanged().flowOn(Dispatchers.Default)
@@ -310,17 +309,16 @@ class BookshelfViewModel(
@OptIn(ExperimentalCoroutinesApi::class)
fun getBooksFlow(groupId: Long): Flow<List<BookShelfItem>> {
return combine(
appDb.bookDao.flowByGroup(groupId),
appDb.bookDao.flowBookShelfByGroup(groupId),
searchKeyFlow,
groupsFlow,
refreshTrigger
) { books, searchKey, groups, _ ->
val group = groups.find { it.groupId == groupId }
val bookshelfItems = books.map { it.toBookShelfItem() }
val filtered = if (searchKey.isEmpty()) {
bookshelfItems
books
} else {
bookshelfItems.filter {
books.filter {
it.name.contains(searchKey, true) || it.author.contains(searchKey, true)
}
}