添加更新失败分组

pull/2437/head
kunfei 2 years ago
parent c7e01ee373
commit 7c29f4cdaf
  1. 1
      app/src/main/java/io/legado/app/constant/AppConst.kt
  2. 13
      app/src/main/java/io/legado/app/constant/BookType.kt
  3. 7
      app/src/main/java/io/legado/app/data/AppDatabase.kt
  4. 3
      app/src/main/java/io/legado/app/data/dao/BookDao.kt
  5. 1
      app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt
  6. 39
      app/src/main/java/io/legado/app/help/book/BookExtensions.kt
  7. 1
      app/src/main/java/io/legado/app/ui/book/manage/BookshelfManageActivity.kt
  8. 2
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt
  9. 6
      app/src/main/java/io/legado/app/ui/main/MainViewModel.kt
  10. 1
      app/src/main/java/io/legado/app/ui/main/bookshelf/style1/books/BooksFragment.kt

@ -43,6 +43,7 @@ object AppConst {
const val bookGroupAudioId = -3L
const val bookGroupNetNoneId = -4L
const val bookGroupLocalNoneId = -5L
const val bookGroupErrorId = -11L
const val notificationIdRead = -1122391
const val notificationIdAudio = -1122392

@ -1,7 +1,5 @@
package io.legado.app.constant
import androidx.annotation.IntDef
/**
* 以二进制位来区分,可能一本书籍包含多个类型,每一位代表一个类型,数值为2的n次方
* 以二进制位来区分,数据库查询更高效, 数值>=8和老版本类型区分开
@ -12,6 +10,11 @@ object BookType {
*/
const val text = 0b1000
/**
* 16 更新失败
*/
const val updateError = 0b10000
/**
* 32 音频
*/
@ -32,12 +35,6 @@ object BookType {
*/
const val local = 0b100000000
@Target(AnnotationTarget.VALUE_PARAMETER)
@Retention(AnnotationRetention.SOURCE)
@IntDef(text, audio, image, webFile)
annotation class Type
/**
* 本地书籍书源标志
*/

@ -105,9 +105,14 @@ abstract class AppDatabase : RoomDatabase() {
)
db.execSQL(
"""insert into book_groups(groupId, groupName, 'order', show)
select ${AppConst.bookGroupLocalNoneId}, '本地未分组', -8, 0
select ${AppConst.bookGroupLocalNoneId}, '本地未分组', -6, 0
where not exists (select * from book_groups where groupId = ${AppConst.bookGroupLocalNoneId})"""
)
db.execSQL(
"""insert into book_groups(groupId, groupName, 'order', show)
select ${AppConst.bookGroupErrorId}, '更新失败', -1, 1
where not exists (select * from book_groups where groupId = ${AppConst.bookGroupErrorId})"""
)
db.execSQL("update book_sources set loginUi = null where loginUi = 'null'")
db.execSQL("update rssSources set loginUi = null where loginUi = 'null'")
db.execSQL("update httpTTS set loginUi = null where loginUi = 'null'")

@ -53,6 +53,9 @@ interface BookDao {
@Query("SELECT * FROM books WHERE name like '%'||:key||'%' or author like '%'||:key||'%'")
fun flowSearch(key: String): Flow<List<Book>>
@Query("SELECT * FROM books where type & ${BookType.updateError} > 0 order by durChapterTime desc")
fun flowUpdateError(): Flow<List<Book>>
@Query("SELECT * FROM books WHERE (`group` & :group) > 0")
fun getBooksByGroup(group: Long): List<Book>

@ -25,6 +25,7 @@ interface BookGroupDao {
or (groupId = -1 and show > 0)
or (groupId = -2 and show > 0 and (select count(*) from books where type & ${BookType.local} > 0) > 0)
or (groupId = -3 and show > 0 and (select count(*) from books where type & ${BookType.audio} > 0) > 0)
or (groupId = -11 and show > 0 and (select count(*) from books where type & ${BookType.updateError} > 0) > 0)
or (groupId = -4 and show > 0
and (
select count(*) from books

@ -1,3 +1,5 @@
@file:Suppress("unused")
package io.legado.app.help.book
import android.net.Uri
@ -6,12 +8,12 @@ import io.legado.app.constant.BookSourceType
import io.legado.app.constant.BookType
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookSource
import io.legado.app.help.config.AppConfig.defaultBookTreeUri
import io.legado.app.exception.NoStackTraceException
import io.legado.app.utils.isContentScheme
import io.legado.app.help.config.AppConfig.defaultBookTreeUri
import io.legado.app.utils.getFile
import java.io.File
import io.legado.app.utils.isContentScheme
import splitties.init.appCtx
import java.io.File
val Book.isAudio: Boolean
@ -54,11 +56,11 @@ val Book.isOnLineTxt: Boolean
fun Book.getLocalUri(): Uri {
if (isLocal) {
val originBookUri = if (bookUrl.isContentScheme()) {
Uri.parse(bookUrl)
} else {
Uri.fromFile(File(bookUrl))
}
val originBookUri = if (bookUrl.isContentScheme()) {
Uri.parse(bookUrl)
} else {
Uri.fromFile(File(bookUrl))
}
//不同的设备书籍保存路径可能不一样 优先尝试寻找当前保存路径下的文件
defaultBookTreeUri ?: return originBookUri
val treeUri = Uri.parse(defaultBookTreeUri)
@ -84,6 +86,27 @@ fun Book.getRemoteUrl(): String? {
return null
}
fun Book.setType(vararg types: Int) {
type = 0
addType(*types)
}
fun Book.addType(vararg types: Int) {
types.forEach {
type = type or it
}
}
fun Book.removeType(vararg types: Int) {
types.forEach {
type = type and it.inv()
}
}
fun Book.clearType() {
type = 0
}
fun Book.upType() {
if (type < 8) {
type = when (type) {

@ -184,6 +184,7 @@ class BookshelfManageActivity :
AppConst.bookGroupAudioId -> appDb.bookDao.flowAudio()
AppConst.bookGroupNetNoneId -> appDb.bookDao.flowNetNoGroup()
AppConst.bookGroupLocalNoneId -> appDb.bookDao.flowLocalNoGroup()
AppConst.bookGroupErrorId -> appDb.bookDao.flowUpdateError()
else -> appDb.bookDao.flowByGroup(viewModel.groupId)
}.conflate().map { list ->
val books = if (searchKey.isNullOrBlank()) {

@ -193,7 +193,7 @@ class SearchContentActivity :
}
}
val isLocalBook: Boolean
private val isLocalBook: Boolean
get() = viewModel.book?.isLocal == true
override fun openSearchResult(searchResult: SearchResult, index: Int) {

@ -5,6 +5,7 @@ import androidx.lifecycle.viewModelScope
import io.legado.app.base.BaseViewModel
import io.legado.app.constant.AppConst
import io.legado.app.constant.AppLog
import io.legado.app.constant.BookType
import io.legado.app.constant.EventBus
import io.legado.app.data.appDb
import io.legado.app.data.entities.Book
@ -12,7 +13,9 @@ import io.legado.app.data.entities.BookSource
import io.legado.app.help.AppWebDav
import io.legado.app.help.DefaultData
import io.legado.app.help.book.BookHelp
import io.legado.app.help.book.addType
import io.legado.app.help.book.isLocal
import io.legado.app.help.book.removeType
import io.legado.app.help.config.AppConfig
import io.legado.app.help.config.LocalConfig
import io.legado.app.model.CacheBook
@ -126,6 +129,7 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
WebBook.getBookInfoAwait(source, book)
}
val toc = WebBook.getChapterListAwait(source, book).getOrThrow()
book.removeType(BookType.updateError)
if (book.bookUrl == bookUrl) {
appDb.bookDao.update(book)
} else {
@ -137,6 +141,8 @@ class MainViewModel(application: Application) : BaseViewModel(application) {
appDb.bookChapterDao.insert(*toc.toTypedArray())
addDownload(source, book)
}.onError(upTocPool) {
book.addType(BookType.updateError)
appDb.bookDao.update(book)
AppLog.put("${book.name} 更新目录失败\n${it.localizedMessage}", it)
}.onCancel(upTocPool) {
upTocCancel(bookUrl)

@ -118,6 +118,7 @@ class BooksFragment() : BaseFragment(R.layout.fragment_books),
AppConst.bookGroupAudioId -> appDb.bookDao.flowAudio()
AppConst.bookGroupNetNoneId -> appDb.bookDao.flowNetNoGroup()
AppConst.bookGroupLocalNoneId -> appDb.bookDao.flowLocalNoGroup()
AppConst.bookGroupErrorId -> appDb.bookDao.flowUpdateError()
else -> appDb.bookDao.flowByGroup(groupId)
}.conflate().map { list ->
when (getPrefInt(PreferKey.bookshelfSort)) {

Loading…
Cancel
Save