Просмотр исходного кода

[新增] 新增更多伴生分组:已读、未读、在读等

HapeLee 11 месяцев назад
Родитель
Сommit
2546a8aa5d

+ 35 - 0
app/src/main/java/io/legado/app/data/AppDatabase.kt

@@ -169,12 +169,47 @@ abstract class AppDatabase : RoomDatabase() {
                 """.trimIndent()
                 db.execSQL(insertBookGroupLocalSql)
                 @Language("sql")
+                val insertBookGroupTextSql = """
+                    insert into book_groups(groupId, groupName, 'order', show) 
+                    select ${BookGroup.IdText}, '小说', -26, 1
+                    where not exists (select * from book_groups where groupId = ${BookGroup.IdText})
+                """.trimIndent()
+                db.execSQL(insertBookGroupTextSql)
+                @Language("sql")
+                val insertBookGroupMangaSql = """
+                    insert into book_groups(groupId, groupName, 'order', show) 
+                    select ${BookGroup.IdManga}, '漫画', -25, 1
+                    where not exists (select * from book_groups where groupId = ${BookGroup.IdManga})
+                """.trimIndent()
+                db.execSQL(insertBookGroupMangaSql)
+                @Language("sql")
                 val insertBookGroupMusicSql = """
                     insert into book_groups(groupId, groupName, 'order', show) 
                     select ${BookGroup.IdAudio}, '音频', -8, 1
                     where not exists (select * from book_groups where groupId = ${BookGroup.IdAudio})
                 """.trimIndent()
                 db.execSQL(insertBookGroupMusicSql)
+                Language("sql")
+                val insertGroupReading = """
+                    insert into book_groups(groupId, groupName, 'order', show) 
+                    select ${BookGroup.IdReading}, '在读', -30, 1
+                    where not exists (select * from book_groups where groupId = ${BookGroup.IdReading})
+                """.trimIndent()
+                db.execSQL(insertGroupReading)
+                @Language("sql")
+                val insertGroupUnread = """
+                    insert into book_groups(groupId, groupName, 'order', show) 
+                    select ${BookGroup.IdUnread}, '未读', -29, 1
+                    where not exists (select * from book_groups where groupId = ${BookGroup.IdUnread})
+                """.trimIndent()
+                db.execSQL(insertGroupUnread)
+                @Language("sql")
+                val insertGroupReadFinished = """
+                    insert into book_groups(groupId, groupName, 'order', show) 
+                    select ${BookGroup.IdReadFinished}, '已读', -28, 1
+                    where not exists (select * from book_groups where groupId = ${BookGroup.IdReadFinished})
+                """.trimIndent()
+                db.execSQL(insertGroupReadFinished)
                 @Language("sql")
                 val insertBookGroupNetNoneGroupSql = """
                     insert into book_groups(groupId, groupName, 'order', show) 

+ 20 - 0
app/src/main/java/io/legado/app/data/dao/BookDao.kt

@@ -26,7 +26,12 @@ interface BookDao {
             BookGroup.IdAudio -> flowAudio()
             BookGroup.IdNetNone -> flowNetNoGroup()
             BookGroup.IdLocalNone -> flowLocalNoGroup()
+            BookGroup.IdManga -> flowManga()
+            BookGroup.IdText -> flowText()
             BookGroup.IdError -> flowUpdateError()
+            BookGroup.IdUnread -> flowUnread()
+            BookGroup.IdReading -> flowReading()
+            BookGroup.IdReadFinished -> flowReadFinished()
             else -> flowByUserGroup(groupId)
         }.map { list ->
             list.filterNot { it.isNotShelf }
@@ -77,6 +82,21 @@ interface BookDao {
     @Query("SELECT * FROM books where type & ${BookType.updateError} > 0 order by durChapterTime desc")
     fun flowUpdateError(): Flow<List<Book>>
 
+    @Query("""SELECT * FROM books WHERE durChapterIndex = 0 AND durChapterPos = 0""")
+    fun flowUnread(): Flow<List<Book>>
+
+    @Query("""SELECT * FROM books WHERE totalChapterNum > 0 AND durChapterIndex >= totalChapterNum - 1""")
+    fun flowReadFinished(): Flow<List<Book>>
+
+    @Query("""SELECT * FROM books WHERE totalChapterNum > 0 AND durChapterIndex > 0 AND durChapterIndex < totalChapterNum - 1""")
+    fun flowReading(): Flow<List<Book>>
+
+    @Query("SELECT * FROM books WHERE type & ${BookType.image} > 0")
+    fun flowManga(): Flow<List<Book>>
+
+    @Query("SELECT * FROM books WHERE type & ${BookType.text} > 0")
+    fun flowText(): Flow<List<Book>>
+
     @Query("SELECT * FROM books WHERE (`group` & :group) > 0")
     fun getBooksByGroup(group: Long): List<Book>
 

+ 44 - 24
app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt

@@ -25,33 +25,53 @@ interface BookGroupDao {
 
     @get:Query(
         """
-        with const as (SELECT sum(groupId) sumGroupId FROM book_groups where groupId > 0)
-        SELECT book_groups.* FROM book_groups join const 
-        where show > 0 
-        and (
-            (groupId >= 0  and exists (select 1 from books where `group` & book_groups.groupId > 0))
-            or groupId = -1
-            or (groupId = -2 and exists (select 1 from books where type & ${BookType.local} > 0))
-            or (groupId = -3 and exists (select 1 from books where type & ${BookType.audio} > 0))
-            or (groupId = -11 and exists (select 1 from books where type & ${BookType.updateError} > 0))
-            or (groupId = -4 
-                and exists (
-                    select 1 from books 
-                    where type & ${BookType.audio} = 0
-                    and type & ${BookType.local} = 0
-                    and const.sumGroupId & `group` = 0
-                )
+    with const as (SELECT sum(groupId) sumGroupId FROM book_groups where groupId > 0)
+    SELECT book_groups.* FROM book_groups join const 
+    where show > 0 
+    and (
+        (groupId >= 0  and exists (select 1 from books where `group` & book_groups.groupId > 0))
+        or groupId = ${BookGroup.IdAll}
+        or (groupId = ${BookGroup.IdLocal} and exists (select 1 from books where type & ${BookType.local} > 0))
+        or (groupId = ${BookGroup.IdAudio} and exists (select 1 from books where type & ${BookType.audio} > 0))
+        or (groupId = ${BookGroup.IdManga} and exists (select 1 FROM books where type & ${BookType.image} > 0))
+        or (groupId = ${BookGroup.IdText} and exists (select 1 FROM books where type & ${BookType.text} > 0))
+        or (groupId = ${BookGroup.IdReading} and exists (
+            SELECT 1 FROM books 
+            WHERE totalChapterNum > 0 
+            AND durChapterIndex > 0 
+            AND durChapterIndex < totalChapterNum - 1
+        ))
+        or (groupId = ${BookGroup.IdUnread} and exists (
+            SELECT 1 FROM books 
+            WHERE durChapterIndex = 0 
+            AND durChapterPos = 0
+        ))
+        or (groupId = ${BookGroup.IdReadFinished} and exists (
+            SELECT 1 FROM books 
+            WHERE totalChapterNum > 0 
+            AND durChapterIndex >= totalChapterNum - 1
+        ))
+        
+        or (groupId = ${BookGroup.IdError} and exists (select 1 from books where type & ${BookType.updateError} > 0))
+        
+        or (groupId = ${BookGroup.IdNetNone} 
+            and exists (
+                select 1 from books 
+                where type & ${BookType.audio} = 0
+                and type & ${BookType.local} = 0
+                and const.sumGroupId & `group` = 0
             )
-            or (groupId = -5
-                and exists (
-                    select 1 from books 
-                    where type & ${BookType.audio} = 0
-                    and type & ${BookType.local} > 0
-                    and const.sumGroupId & `group` = 0
-                )
+        )
+        or (groupId = ${BookGroup.IdLocalNone}
+            and exists (
+                select 1 from books 
+                where type & ${BookType.audio} = 0
+                and type & ${BookType.local} > 0
+                and const.sumGroupId & `group` = 0
             )
         )
-        ORDER BY `order`"""
+    )
+    ORDER BY `order`"""
     )
     val show: LiveData<List<BookGroup>>
 

+ 10 - 0
app/src/main/java/io/legado/app/data/entities/BookGroup.kt

@@ -33,7 +33,12 @@ data class BookGroup(
         const val IdAudio = -3L
         const val IdNetNone = -4L
         const val IdLocalNone = -5L
+        const val IdManga = -7L
+        const val IdText = -8L
         const val IdError = -11L
+        const val IdReading = -20L
+        const val IdUnread = -21L
+        const val IdReadFinished = -22L
     }
 
     data class GroupNameInfo(
@@ -48,7 +53,12 @@ data class BookGroup(
             IdLocal -> GroupNameInfo(groupName, context.getString(R.string.local))
             IdNetNone -> GroupNameInfo(groupName, context.getString(R.string.net_no_group))
             IdLocalNone -> GroupNameInfo(groupName, context.getString(R.string.local_no_group))
+            IdManga -> GroupNameInfo(groupName, context.getString(R.string.manga))
+            IdText -> GroupNameInfo(groupName, context.getString(R.string.noval))
             IdError -> GroupNameInfo(groupName, context.getString(R.string.update_book_fail))
+            IdReading -> GroupNameInfo(groupName, context.getString(R.string.is_reading))
+            IdUnread -> GroupNameInfo(groupName, context.getString(R.string.is_unread))
+            IdReadFinished -> GroupNameInfo(groupName, context.getString(R.string.is_read_finished))
             else -> GroupNameInfo(groupName)
         }
     }

+ 1 - 1
app/src/main/res/drawable/bg_gradient_black.xml

@@ -3,6 +3,6 @@
     <gradient
         android:angle="90"
         android:endColor="#00000000"
-        android:startColor="#CC000000"
+        android:startColor="#80000000"
         android:type="linear" />
 </shape>

+ 4 - 0
app/src/main/res/layout/item_bookshelf_grid_compact.xml

@@ -129,6 +129,10 @@
                 android:textColor="@android:color/white"
                 android:textSize="12sp"
                 android:textStyle="bold"
+                android:shadowColor="#80000000"
+                android:shadowDx="0"
+                android:shadowDy="0"
+                android:shadowRadius="4.0"
                 app:layout_constraintBottom_toBottomOf="parent"
                 app:layout_constraintStart_toStartOf="parent"
                 app:layout_constraintEnd_toEndOf="parent" />

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

@@ -1351,4 +1351,9 @@
     <string name="read_change_all">换源按钮默认弹出整书换源</string>
     <string name="read_change_all_s">反之则默认弹出单章换源</string>
     <string name="show_tip">显示书籍类型</string>
+    <string name="is_reading">在读</string>
+    <string name="is_unread">未读</string>
+    <string name="is_read_finished">已读</string>
+    <string name="manga">漫画</string>
+    <string name="noval">小说</string>
 </resources>

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

@@ -1354,4 +1354,9 @@
     <string name="read_change_all">换源按钮默认弹出整书换源</string>
     <string name="read_change_all_s">反之则默认弹出单章换源</string>
     <string name="show_tip">显示书籍类型</string>
+    <string name="is_reading">在读</string>
+    <string name="is_unread">未读</string>
+    <string name="is_read_finished">已读</string>
+    <string name="manga">漫画</string>
+    <string name="noval">小说</string>
 </resources>

+ 1 - 1
app/version.properties

@@ -1,5 +1,5 @@
 VERSION_MAJOR=3
 VERSION_MINOR=26
-VERSION_PATCH=4
+VERSION_PATCH=5
 VERSION_SUFFIX=0
 # 1 = Pre, 0 = Release