From 7f45efed00cf91db7d08ccdbcf7cfcfa9d23aa6d Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 18 Oct 2020 16:52:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=AA=E5=88=86=E7=BB=84=E6=8E=92=E9=99=A4?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E5=92=8C=E9=9F=B3=E9=A2=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/data/dao/BookDao.kt | 16 ++++++++++------ .../io/legado/app/data/entities/BookGroup.kt | 17 ++++++++++++++++- 2 files changed, 26 insertions(+), 7 deletions(-) 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 cbb1ec990..b421c3ffa 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 @@ -18,18 +18,22 @@ interface BookDao { @Query("SELECT * FROM books WHERE origin = '${BookType.local}'") fun observeLocal(): LiveData> + @Query( + """ + select * from books where ((SELECT sum(groupId) FROM book_groups where groupId > 0) & `group`) = 0 and type != ${BookType.audio} and origin != '${BookType.local}' + """ + ) + fun observeNoGroup(): LiveData> + + @Query("select count(bookUrl) from books where (SELECT sum(groupId) FROM book_groups where groupId > 0) & `group` = 0") + fun observeNoGroupSize(): LiveData + @Query("SELECT bookUrl FROM books WHERE origin = '${BookType.local}'") fun observeLocalUri(): LiveData> @Query("SELECT * FROM books WHERE (`group` & :group) > 0") fun observeByGroup(group: Long): LiveData> - @Query("select * from books where (SELECT sum(groupId) FROM book_groups where groupId > 0) & `group` = 0") - fun observeNoGroup(): LiveData> - - @Query("select count(bookUrl) from books where (SELECT sum(groupId) FROM book_groups where groupId > 0) & `group` = 0") - fun observeNoGroupSize(): LiveData - @Query("SELECT * FROM books WHERE name like '%'||:key||'%' or author like '%'||:key||'%'") fun liveDataSearch(key: String): 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 20a8263a3..4a24e9acb 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 @@ -1,8 +1,11 @@ package io.legado.app.data.entities +import android.content.Context import android.os.Parcelable import androidx.room.Entity import androidx.room.PrimaryKey +import io.legado.app.R +import io.legado.app.constant.AppConst import kotlinx.android.parcel.Parcelize @Parcelize @@ -13,4 +16,16 @@ data class BookGroup( var groupName: String, var order: Int = 0, var show: Boolean = true -) : Parcelable \ No newline at end of file +) : Parcelable { + + fun getDefaultName(context: Context): String { + return when (groupId) { + AppConst.bookGroupAllId -> context.getString(R.string.all) + AppConst.bookGroupAudioId -> context.getString(R.string.audio) + AppConst.bookGroupLocalId -> context.getString(R.string.local) + AppConst.bookGroupNoneId -> context.getString(R.string.no_group) + else -> groupName + } + } + +} \ No newline at end of file