diff --git a/app/src/main/java/io/legado/app/constant/BookType.kt b/app/src/main/java/io/legado/app/constant/BookType.kt new file mode 100644 index 000000000..7b1e05c60 --- /dev/null +++ b/app/src/main/java/io/legado/app/constant/BookType.kt @@ -0,0 +1,7 @@ +package io.legado.app.constant + +object BookType { + const val default = 0 + const val audio = 1 + const val local = "Local" +} \ No newline at end of file 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 cd7b359d1..310f8506d 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 @@ -6,6 +6,7 @@ import androidx.room.Dao import androidx.room.Insert import androidx.room.OnConflictStrategy import androidx.room.Query +import io.legado.app.constant.BookType import io.legado.app.data.entities.Book @Dao @@ -14,6 +15,12 @@ interface BookDao { @Query("SELECT * FROM books") fun observeAll(): DataSource.Factory + @Query("SELECT * FROM books WHERE type = ${BookType.audio}") + fun observeAudio(): DataSource.Factory + + @Query("SELECT * FROM books WHERE origin = ${BookType.local}") + fun observeLocal(): DataSource.Factory + @Query("SELECT * FROM books WHERE `group` = :group") fun observeByGroup(group: Int): DataSource.Factory diff --git a/app/src/main/java/io/legado/app/data/entities/Book.kt b/app/src/main/java/io/legado/app/data/entities/Book.kt index faf5bd9a5..80804ce79 100644 --- a/app/src/main/java/io/legado/app/data/entities/Book.kt +++ b/app/src/main/java/io/legado/app/data/entities/Book.kt @@ -18,7 +18,7 @@ data class Book( @PrimaryKey var descUrl: String = "", // 详情页Url(本地书源存储完整文件路径) var tocUrl: String = "", // 目录页Url (toc=table of Contents) - var origin: String = "", // 书源规则id(默认-1,表示本地书籍) + var origin: String = "", // 书源URL(默认BookType.local) var name: String? = null, // 书籍名称(书源获取) var customName: String? = null, // 书籍名称(用户修改) var author: String? = null, // 作者名称(书源获取) @@ -30,7 +30,7 @@ data class Book( var description: String? = null, // 简介内容(书源获取) var customDescription: String? = null, // 简介内容(用户修改) var charset: String? = null, // 自定义字符集名称(仅适用于本地书籍) - var type: Int = 0, // 0: 文本读物, 1: 有声读物 + var type: Int = 0, // @BookType var group: Int = 0, // 自定义分组索引号 var latestChapterTitle: String? = null, // 最新章节标题 var latestChapterTime: Long = 0, // 最新章节标题更新时间 diff --git a/app/src/main/java/io/legado/app/ui/bookshelf/BookshelfActivity.kt b/app/src/main/java/io/legado/app/ui/bookshelf/BookshelfActivity.kt index 61baf35bb..6ba11119f 100644 --- a/app/src/main/java/io/legado/app/ui/bookshelf/BookshelfActivity.kt +++ b/app/src/main/java/io/legado/app/ui/bookshelf/BookshelfActivity.kt @@ -52,10 +52,12 @@ class BookshelfActivity : BaseActivity() { LivePagedListBuilder(App.db.bookDao().observeAll(), 10).build() } -2 -> { - + bookshelfLiveData = + LivePagedListBuilder(App.db.bookDao().observeLocal(), 10).build() } -3 -> { - + bookshelfLiveData = + LivePagedListBuilder(App.db.bookDao().observeAudio(), 10).build() } else -> { bookshelfLiveData =