From 8f07d5bcd39a1387aac57eef8b1ce8f1d0f71274 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 23 Sep 2022 21:19:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=AA=E5=88=86=E7=BB=84=E5=88=86=E4=B8=BA?= =?UTF-8?q?=E7=BD=91=E7=BB=9C=E6=9C=AA=E5=88=86=E7=BB=84=E5=92=8C=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E6=9C=AA=E5=88=86=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/constant/AppConst.kt | 3 ++- .../java/io/legado/app/data/AppDatabase.kt | 9 +++++++-- .../java/io/legado/app/data/dao/BookDao.kt | 12 ++++++++++-- .../io/legado/app/data/dao/BookGroupDao.kt | 19 ++++++++++++++----- .../io/legado/app/data/entities/BookGroup.kt | 3 ++- .../legado/app/ui/book/cache/CacheActivity.kt | 3 ++- .../ui/book/manage/BookshelfManageActivity.kt | 5 +++-- .../bookshelf/style1/books/BooksFragment.kt | 3 ++- .../bookshelf/style2/BookshelfFragment2.kt | 3 ++- app/src/main/res/values-es-rES/strings.xml | 2 ++ app/src/main/res/values-ja-rJP/strings.xml | 2 ++ app/src/main/res/values-pt-rBR/strings.xml | 2 ++ app/src/main/res/values-zh-rHK/strings.xml | 2 ++ app/src/main/res/values-zh-rTW/strings.xml | 2 ++ app/src/main/res/values-zh/strings.xml | 2 ++ app/src/main/res/values/strings.xml | 2 ++ 16 files changed, 58 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/legado/app/constant/AppConst.kt b/app/src/main/java/io/legado/app/constant/AppConst.kt index 51090ee9f..8a6339bdf 100644 --- a/app/src/main/java/io/legado/app/constant/AppConst.kt +++ b/app/src/main/java/io/legado/app/constant/AppConst.kt @@ -41,7 +41,8 @@ object AppConst { const val bookGroupAllId = -1L const val bookGroupLocalId = -2L const val bookGroupAudioId = -3L - const val bookGroupNoneId = -4L + const val bookGroupNetNoneId = -4L + const val bookGroupLocalNoneId = -5L const val notificationIdRead = -1122391 const val notificationIdAudio = -1122392 diff --git a/app/src/main/java/io/legado/app/data/AppDatabase.kt b/app/src/main/java/io/legado/app/data/AppDatabase.kt index 82631303c..b9be414db 100644 --- a/app/src/main/java/io/legado/app/data/AppDatabase.kt +++ b/app/src/main/java/io/legado/app/data/AppDatabase.kt @@ -98,8 +98,13 @@ abstract class AppDatabase : RoomDatabase() { ) db.execSQL( """insert into book_groups(groupId, groupName, 'order', show) - select ${AppConst.bookGroupNoneId}, '未分组', -7, 1 - where not exists (select * from book_groups where groupId = ${AppConst.bookGroupNoneId})""" + select ${AppConst.bookGroupNetNoneId}, '网络未分组', -7, 1 + where not exists (select * from book_groups where groupId = ${AppConst.bookGroupNetNoneId})""" + ) + db.execSQL( + """insert into book_groups(groupId, groupName, 'order', show) + select ${AppConst.bookGroupLocalNoneId}, '本地未分组', -8, 0 + where not exists (select * from book_groups where groupId = ${AppConst.bookGroupLocalNoneId})""" ) db.execSQL("update book_sources set loginUi = null where loginUi = 'null'") db.execSQL("update rssSources set loginUi = null where loginUi = 'null'") diff --git a/app/src/main/java/io/legado/app/data/dao/BookDao.kt b/app/src/main/java/io/legado/app/data/dao/BookDao.kt index ff150b5c3..d95853a41 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookDao.kt @@ -14,7 +14,7 @@ interface BookDao { select * from books where type != ${BookType.audio} and origin != '${BookType.local}' and ((SELECT sum(groupId) FROM book_groups where groupId > 0) & `group`) = 0 - and (select show from book_groups where groupId = ${AppConst.bookGroupNoneId}) != 1 + and (select show from book_groups where groupId = ${AppConst.bookGroupNetNoneId}) != 1 """ ) fun flowRoot(): Flow> @@ -34,7 +34,15 @@ interface BookDao { and ((SELECT sum(groupId) FROM book_groups where groupId > 0) & `group`) = 0 """ ) - fun flowNoGroup(): Flow> + fun flowNetNoGroup(): Flow> + + @Query( + """ + select * from books where type != ${BookType.audio} and origin != '${BookType.local}' + and ((SELECT sum(groupId) FROM book_groups where groupId > 0) & `group`) = 0 + """ + ) + fun flowLocalNoGroup(): Flow> @Query("SELECT bookUrl FROM books WHERE origin = '${BookType.local}'") fun flowLocalUri(): Flow> diff --git a/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt b/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt index e8a3983a6..cfac470f0 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt @@ -20,18 +20,27 @@ interface BookGroupDao { @get:Query( """ - SELECT * FROM book_groups where (groupId >= 0 and show > 0) + with const as (SELECT sum(groupId) sumGroupId FROM book_groups where groupId > 0) + SELECT book_groups.* FROM book_groups, const where (groupId >= 0 and show > 0) + or (groupId = -1 and show > 0) + or (groupId = -2 and show > 0 and (select count(bookUrl) from books where origin = '${BookType.local}') > 0) + or (groupId = -3 and show > 0 and (select count(bookUrl) from books where type = ${BookType.audio}) > 0) or (groupId = -4 and show > 0 and ( select count(bookUrl) from books where type != '${BookType.audio}' and origin != '${BookType.local}' - and ((SELECT sum(groupId) FROM book_groups where groupId > 0) & `group`) = 0 + and const.sumGroupId & `group` = 0 + ) > 0 + ) + or (groupId = -5 and show > 0 + and ( + select count(bookUrl) from books + where type != '${BookType.audio}' + and origin = '${BookType.local}' + and const.sumGroupId & `group` = 0 ) > 0 ) - or (groupId = -3 and show > 0 and (select count(bookUrl) from books where type = ${BookType.audio}) > 0) - or (groupId = -2 and show > 0 and (select count(bookUrl) from books where origin = '${BookType.local}') > 0) - or (groupId = -1 and show > 0) ORDER BY `order`""" ) val show: LiveData> diff --git a/app/src/main/java/io/legado/app/data/entities/BookGroup.kt b/app/src/main/java/io/legado/app/data/entities/BookGroup.kt index f19f5f05c..c1f7cf7df 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookGroup.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookGroup.kt @@ -24,7 +24,8 @@ data class BookGroup( AppConst.bookGroupAllId -> "$groupName(${context.getString(R.string.all)})" AppConst.bookGroupAudioId -> "$groupName(${context.getString(R.string.audio)})" AppConst.bookGroupLocalId -> "$groupName(${context.getString(R.string.local)})" - AppConst.bookGroupNoneId -> "$groupName(${context.getString(R.string.no_group)})" + AppConst.bookGroupNetNoneId -> "$groupName(${context.getString(R.string.net_no_group)})" + AppConst.bookGroupLocalNoneId -> "$groupName(${context.getString(R.string.local_no_group)})" else -> groupName } } diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt index 36a6ad667..b63eb9e7e 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheActivity.kt @@ -159,7 +159,8 @@ class CacheActivity : VMBaseActivity() AppConst.bookGroupAllId -> appDb.bookDao.flowAll() AppConst.bookGroupLocalId -> appDb.bookDao.flowLocal() AppConst.bookGroupAudioId -> appDb.bookDao.flowAudio() - AppConst.bookGroupNoneId -> appDb.bookDao.flowNoGroup() + AppConst.bookGroupNetNoneId -> appDb.bookDao.flowNetNoGroup() + AppConst.bookGroupLocalNoneId -> appDb.bookDao.flowLocalNoGroup() else -> appDb.bookDao.flowByGroup(groupId) }.conflate().map { books -> val booksDownload = books.filter { diff --git a/app/src/main/java/io/legado/app/ui/book/manage/BookshelfManageActivity.kt b/app/src/main/java/io/legado/app/ui/book/manage/BookshelfManageActivity.kt index f96bca25b..897ed6758 100644 --- a/app/src/main/java/io/legado/app/ui/book/manage/BookshelfManageActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/manage/BookshelfManageActivity.kt @@ -140,11 +140,12 @@ class BookshelfManageActivity : booksFlowJob?.cancel() booksFlowJob = launch { when (groupId) { - AppConst.rootGroupId -> appDb.bookDao.flowNoGroup() + AppConst.rootGroupId -> appDb.bookDao.flowNetNoGroup() AppConst.bookGroupAllId -> appDb.bookDao.flowAll() AppConst.bookGroupLocalId -> appDb.bookDao.flowLocal() AppConst.bookGroupAudioId -> appDb.bookDao.flowAudio() - AppConst.bookGroupNoneId -> appDb.bookDao.flowNoGroup() + AppConst.bookGroupNetNoneId -> appDb.bookDao.flowNetNoGroup() + AppConst.bookGroupLocalNoneId -> appDb.bookDao.flowLocalNoGroup() else -> appDb.bookDao.flowByGroup(groupId) }.conflate().map { books -> when (getPrefInt(PreferKey.bookshelfSort)) { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksFragment.kt index 2e836422b..a7f2002aa 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksFragment.kt @@ -112,7 +112,8 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books), AppConst.bookGroupAllId -> appDb.bookDao.flowAll() AppConst.bookGroupLocalId -> appDb.bookDao.flowLocal() AppConst.bookGroupAudioId -> appDb.bookDao.flowAudio() - AppConst.bookGroupNoneId -> appDb.bookDao.flowNoGroup() + AppConst.bookGroupNetNoneId -> appDb.bookDao.flowNetNoGroup() + AppConst.bookGroupLocalNoneId -> appDb.bookDao.flowLocalNoGroup() else -> appDb.bookDao.flowByGroup(groupId) }.conflate().map { list -> when (getPrefInt(PreferKey.bookshelfSort)) { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt index cfa2c4304..bb554a84e 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BookshelfFragment2.kt @@ -124,7 +124,8 @@ class BookshelfFragment2 : BaseBookshelfFragment(R.layout.fragment_bookshelf1), AppConst.bookGroupAllId -> appDb.bookDao.flowAll() AppConst.bookGroupLocalId -> appDb.bookDao.flowLocal() AppConst.bookGroupAudioId -> appDb.bookDao.flowAudio() - AppConst.bookGroupNoneId -> appDb.bookDao.flowNoGroup() + AppConst.bookGroupNetNoneId -> appDb.bookDao.flowNetNoGroup() + AppConst.bookGroupLocalNoneId -> appDb.bookDao.flowLocalNoGroup() else -> appDb.bookDao.flowByGroup(groupId) }.conflate().map { list -> when (getPrefInt(PreferKey.bookshelfSort)) { diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index 1fb6af765..6b7844633 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -1033,4 +1033,6 @@ 允许与其他应用同时播放音频 刷新分类 Decode Cover Js(coverDecodeJs) + 网络为分组 + 本地未分组 diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index e0e27038f..86659c2fd 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -1036,4 +1036,6 @@ 允许与其他应用同时播放音频 刷新分类 Decode Cover Js(coverDecodeJs) + 网络为分组 + 本地未分组 diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index afaca31d4..46004fcb8 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -1036,4 +1036,6 @@ 允许与其他应用同时播放音频 刷新分类 Decode Cover Js(coverDecodeJs) + 网络为分组 + 本地未分组 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index af865ca72..6eaa0b020 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -1033,4 +1033,6 @@ 允许与其他应用同时播放音频 刷新分类 封面解密(coverDecodeJs) + 网络为分组 + 本地未分组 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 17bbd385e..af1a24b4d 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -1035,4 +1035,6 @@ 允许与其他应用同时播放音频 刷新分类 封面解密(coverDecodeJs) + 网络为分组 + 本地未分组 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index be99bd644..edfc0df15 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -1035,4 +1035,6 @@ 允许与其他应用同时播放音频 刷新分类 封面解密(coverDecodeJs) + 网络为分组 + 本地未分组 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cbce0bd2d..eb031f4b2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1036,4 +1036,6 @@ 允许与其他应用同时播放音频 刷新分类 Decode Cover Js(coverDecodeJs) + 网络为分组 + 本地未分组