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