pull/32/head
kunfei 5 years ago
parent 3a9478db8d
commit 30d5153ffc
  1. 4
      app/src/main/java/io/legado/app/data/dao/BookDao.kt
  2. 4
      app/src/main/java/io/legado/app/data/entities/Book.kt
  3. 2
      app/src/main/java/io/legado/app/data/entities/BookChapter.kt
  4. 4
      app/src/main/java/io/legado/app/data/entities/SearchBook.kt
  5. 8
      app/src/main/java/io/legado/app/help/storage/Restore.kt
  6. 5
      app/src/main/java/io/legado/app/model/webbook/BookList.kt
  7. 8
      app/src/main/java/io/legado/app/ui/bookshelf/BookshelfAdapter.kt
  8. 4
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt

@ -24,13 +24,13 @@ interface BookDao {
@Query("SELECT * FROM books WHERE `group` = :group")
fun observeByGroup(group: Int): DataSource.Factory<Int, Book>
@Query("SELECT descUrl FROM books WHERE `group` = :group")
@Query("SELECT bookUrl FROM books WHERE `group` = :group")
fun observeUrlsByGroup(group: Int): LiveData<List<String>>
@Query("SELECT * FROM books WHERE `name` in (:names)")
fun findByName(vararg names: String): List<Book>
@get:Query("SELECT descUrl FROM books")
@get:Query("SELECT bookUrl FROM books")
val allBookUrls: List<String>
@get:Query("SELECT COUNT(*) FROM books")

@ -13,10 +13,10 @@ import kotlinx.android.parcel.Parcelize
import kotlin.math.max
@Parcelize
@Entity(tableName = "books", indices = [(Index(value = ["descUrl"], unique = true))])
@Entity(tableName = "books", indices = [(Index(value = ["bookUrl"], unique = true))])
data class Book(
@PrimaryKey
var descUrl: String = "", // 详情页Url(本地书源存储完整文件路径)
var bookUrl: String = "", // 详情页Url(本地书源存储完整文件路径)
var tocUrl: String = "", // 目录页Url (toc=table of Contents)
var origin: String = "", // 书源URL(默认BookType.local)
var name: String? = null, // 书籍名称(书源获取)

@ -14,7 +14,7 @@ import kotlinx.android.parcel.Parcelize
indices = [(Index(value = ["bookUrl"], unique = true)), (Index(value = ["bookUrl", "index"], unique = true))],
foreignKeys = [(ForeignKey(
entity = Book::class,
parentColumns = ["descUrl"],
parentColumns = ["bookUrl"],
childColumns = ["bookUrl"],
onDelete = ForeignKey.CASCADE
))]

@ -12,10 +12,10 @@ import kotlinx.android.parcel.IgnoredOnParcel
import kotlinx.android.parcel.Parcelize
@Parcelize
@Entity(tableName = "searchBooks", indices = [(Index(value = ["descUrl"], unique = true))])
@Entity(tableName = "searchBooks", indices = [(Index(value = ["bookUrl"], unique = true))])
data class SearchBook(
@PrimaryKey
var descUrl: String = "",
var bookUrl: String = "",
var origin: String = "", // 书源规则id(默认-1,表示本地书籍)
var name: String? = null,
var author: String? = null,

@ -45,16 +45,16 @@ object Restore {
for (item in items) {
val jsonItem = jsonPath.parse(item)
val book = Book()
book.descUrl = jsonItem.readString("$.noteUrl") ?: ""
if (book.descUrl.isBlank()) continue
book.bookUrl = jsonItem.readString("$.noteUrl") ?: ""
if (book.bookUrl.isBlank()) continue
book.name = jsonItem.readString("$.bookInfoBean.name")
if (book.descUrl in existingBooks) {
if (book.bookUrl in existingBooks) {
Log.d(AppConst.APP_TAG, "Found existing book: ${book.name}")
continue
}
book.author = jsonItem.readString("$.bookInfoBean.author")
book.type = if (jsonItem.readString("$.bookInfoBean.bookSourceType") == "AUDIO") 1 else 0
book.tocUrl = jsonItem.readString("$.bookInfoBean.chapterUrl") ?: book.descUrl
book.tocUrl = jsonItem.readString("$.bookInfoBean.chapterUrl") ?: book.bookUrl
book.coverUrl = jsonItem.readString("$.bookInfoBean.coverUrl")
book.customCoverUrl = jsonItem.readString("$.customCoverPath")
book.lastCheckTime = jsonItem.readLong("$.bookInfoBean.finalRefreshData") ?: 0

@ -31,7 +31,7 @@ class BookList {
analyzer.setContent(body, baseUrl)
bookSource.bookUrlPattern?.let {
if (baseUrl.matches(it.toRegex())) {
getItem(analyzer, bookSource)?.let { searchBook ->
getItem(analyzer, bookSource, baseUrl)?.let { searchBook ->
searchBook.bookInfoHtml = body
bookList.add(searchBook)
}
@ -41,7 +41,7 @@ class BookList {
return bookList
}
private fun getItem(analyzeRule: AnalyzeRule, bookSource: BookSource): SearchBook? {
private fun getItem(analyzeRule: AnalyzeRule, bookSource: BookSource, baseUrl: String): SearchBook? {
val searchBook = SearchBook()
analyzeRule.setBook(searchBook)
with(bookSource.getBookInfoRule()) {
@ -52,6 +52,7 @@ class BookList {
if (!searchBook.name.isNullOrEmpty()) {
searchBook.author = analyzeRule.getString(author ?: "")
searchBook.coverUrl = analyzeRule.getString(coverUrl ?: "")
searchBook.bookUrl = baseUrl
return searchBook
}
}

@ -1,21 +1,17 @@
package io.legado.app.ui.bookshelf
import android.text.TextUtils.isEmpty
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.paging.PagedListAdapter
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import io.legado.app.R
import io.legado.app.data.entities.Book
import io.legado.app.help.ImageLoader
import io.legado.app.lib.theme.ThemeStore
import kotlinx.android.synthetic.main.item_bookshelf_list.view.*
import kotlinx.android.synthetic.main.item_relace_rule.view.tv_name
import java.io.File
class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(DIFF_CALLBACK) {
@ -23,10 +19,10 @@ class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(D
@JvmField
val DIFF_CALLBACK = object : DiffUtil.ItemCallback<Book>() {
override fun areItemsTheSame(oldItem: Book, newItem: Book): Boolean =
oldItem.descUrl == newItem.descUrl
oldItem.bookUrl == newItem.bookUrl
override fun areContentsTheSame(oldItem: Book, newItem: Book): Boolean =
oldItem.descUrl == newItem.descUrl
oldItem.bookUrl == newItem.bookUrl
&& oldItem.durChapterTitle == newItem.durChapterTitle
&& oldItem.latestChapterTitle == newItem.latestChapterTitle
}

@ -19,10 +19,10 @@ class BookshelfAdapter : PagedListAdapter<Book, BookshelfAdapter.MyViewHolder>(D
@JvmField
val DIFF_CALLBACK = object : DiffUtil.ItemCallback<Book>() {
override fun areItemsTheSame(oldItem: Book, newItem: Book): Boolean =
oldItem.descUrl == newItem.descUrl
oldItem.bookUrl == newItem.bookUrl
override fun areContentsTheSame(oldItem: Book, newItem: Book): Boolean =
oldItem.descUrl == newItem.descUrl
oldItem.bookUrl == newItem.bookUrl
&& oldItem.durChapterTitle == newItem.durChapterTitle
&& oldItem.latestChapterTitle == newItem.latestChapterTitle
}

Loading…
Cancel
Save