pull/32/head
Invinciblelee 6 years ago
parent 5d162ebfa7
commit f8a0e2dbfc
  1. 66
      app/src/main/java/io/legado/app/data/entities/Book.kt
  2. 2
      app/src/main/java/io/legado/app/ui/main/booksource/BookSourceAdapter.kt
  3. 3
      app/src/main/java/io/legado/app/ui/search/SearchAdapter.kt
  4. 16
      app/src/main/java/io/legado/app/utils/GsonExtensions.kt

@ -6,8 +6,8 @@ import androidx.room.Entity
import androidx.room.Ignore import androidx.room.Ignore
import androidx.room.Index import androidx.room.Index
import androidx.room.PrimaryKey import androidx.room.PrimaryKey
import com.google.gson.Gson
import io.legado.app.constant.AppConst.NOT_AVAILABLE import io.legado.app.constant.AppConst.NOT_AVAILABLE
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJson import io.legado.app.utils.fromJson
import kotlinx.android.parcel.IgnoredOnParcel import kotlinx.android.parcel.IgnoredOnParcel
import kotlinx.android.parcel.Parcelize import kotlinx.android.parcel.Parcelize
@ -15,36 +15,36 @@ import kotlinx.android.parcel.Parcelize
@Parcelize @Parcelize
@Entity(tableName = "books", indices = [(Index(value = ["descUrl"], unique = true))]) @Entity(tableName = "books", indices = [(Index(value = ["descUrl"], unique = true))])
data class Book( data class Book(
@PrimaryKey @PrimaryKey
var descUrl: String = "", // 详情页Url(本地书源存储完整文件路径) var descUrl: String = "", // 详情页Url(本地书源存储完整文件路径)
var tocUrl: String = "", // 目录页Url (toc=table of Contents) var tocUrl: String = "", // 目录页Url (toc=table of Contents)
var origin: String = "", // 书源规则id(默认-1,表示本地书籍) var origin: String = "", // 书源规则id(默认-1,表示本地书籍)
var name: String? = null, // 书籍名称(书源获取) var name: String? = null, // 书籍名称(书源获取)
var customName: String? = null, // 书籍名称(用户修改) var customName: String? = null, // 书籍名称(用户修改)
var author: String? = null, // 作者名称(书源获取) var author: String? = null, // 作者名称(书源获取)
var customAuthor: String? = null, // 作者名称(用户修改) var customAuthor: String? = null, // 作者名称(用户修改)
var tag: String? = null, // 分类信息(书源获取) var tag: String? = null, // 分类信息(书源获取)
var customTag: String? = null, // 分类信息(用户修改) var customTag: String? = null, // 分类信息(用户修改)
var coverUrl: String? = null, // 封面Url(书源获取) var coverUrl: String? = null, // 封面Url(书源获取)
var customCoverUrl: String? = null, // 封面Url(用户修改) var customCoverUrl: String? = null, // 封面Url(用户修改)
var description: String? = null, // 简介内容(书源获取) var description: String? = null, // 简介内容(书源获取)
var customDescription: String? = null, // 简介内容(用户修改) var customDescription: String? = null, // 简介内容(用户修改)
var charset: String? = null, // 自定义字符集名称(仅适用于本地书籍) var charset: String? = null, // 自定义字符集名称(仅适用于本地书籍)
var type: Int = 0, // 0: 文本读物, 1: 有声读物 var type: Int = 0, // 0: 文本读物, 1: 有声读物
var group: Int = 0, // 自定义分组索引号 var group: Int = 0, // 自定义分组索引号
var latestChapterTitle: String? = null, // 最新章节标题 var latestChapterTitle: String? = null, // 最新章节标题
var latestChapterTime: Long = 0, // 最新章节标题更新时间 var latestChapterTime: Long = 0, // 最新章节标题更新时间
var lastCheckTime: Long = 0, // 最近一次更新书籍信息的时间 var lastCheckTime: Long = 0, // 最近一次更新书籍信息的时间
var lastCheckCount: Int = 0, // 最近一次发现新章节的数量 var lastCheckCount: Int = 0, // 最近一次发现新章节的数量
var totalChapterNum: Int = 0, // 书籍目录总数 var totalChapterNum: Int = 0, // 书籍目录总数
var durChapterTitle: String? = null, // 当前章节名称 var durChapterTitle: String? = null, // 当前章节名称
var durChapterIndex: Int = 0, // 当前章节索引 var durChapterIndex: Int = 0, // 当前章节索引
var durChapterPos: Int = 0, // 当前阅读的进度(首行字符的索引位置) var durChapterPos: Int = 0, // 当前阅读的进度(首行字符的索引位置)
var durChapterTime: Long = 0, // 最近一次阅读书籍的时间(打开正文的时间) var durChapterTime: Long = 0, // 最近一次阅读书籍的时间(打开正文的时间)
var canUpdate: Boolean = true, // 刷新书架时更新书籍信息 var canUpdate: Boolean = true, // 刷新书架时更新书籍信息
var order: Int = 0, // 手动排序 var order: Int = 0, // 手动排序
var useReplaceRule: Boolean = true, // 正文使用净化替换规则 var useReplaceRule: Boolean = true, // 正文使用净化替换规则
var variable: String? = null // 自定义书籍变量信息(用于书源规则检索书籍信息) var variable: String? = null // 自定义书籍变量信息(用于书源规则检索书籍信息)
) : Parcelable, BaseBook { ) : Parcelable, BaseBook {
@IgnoredOnParcel @IgnoredOnParcel
@Ignore @Ignore
@ -69,7 +69,7 @@ data class Book(
variableMap = if (isEmpty(variable)) { variableMap = if (isEmpty(variable)) {
HashMap() HashMap()
} else { } else {
Gson().fromJson<HashMap<String, String>>(variable!!) GSON.fromJson<HashMap<String, String>>(variable!!)
} }
} }
} }
@ -77,6 +77,6 @@ data class Book(
override fun putVariable(key: String, value: String) { override fun putVariable(key: String, value: String) {
initVariableMap() initVariableMap()
variableMap?.put(key, value) variableMap?.put(key, value)
variable = Gson().toJson(variableMap) variable = GSON.toJson(variableMap)
} }
} }

@ -86,7 +86,7 @@ class BookSourceAdapter : PagedListAdapter<BookSource, BookSourceAdapter.MyViewH
bookSource.isEnabled = sw_enabled.isChecked bookSource.isEnabled = sw_enabled.isChecked
callBack?.update(bookSource) callBack?.update(bookSource)
} }
iv_more.setOnClickListener { iv_more.onClick {
val popupMenu = PopupMenu(context, iv_more) val popupMenu = PopupMenu(context, iv_more)
popupMenu.menu.add(Menu.NONE, R.id.menu_edit, Menu.NONE, R.string.edit) popupMenu.menu.add(Menu.NONE, R.id.menu_edit, Menu.NONE, R.string.edit)
popupMenu.menu.add(Menu.NONE, R.id.menu_del, Menu.NONE, R.string.delete) popupMenu.menu.add(Menu.NONE, R.id.menu_del, Menu.NONE, R.string.delete)

@ -6,7 +6,6 @@ import io.legado.app.base.adapter.ItemViewDelegate
import io.legado.app.base.adapter.ItemViewHolder import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.SearchBook
import kotlinx.android.synthetic.main.item_search.view.*
class SearchAdapter(context: Context) : SimpleRecyclerAdapter<SearchBook>(context, R.layout.item_search) { class SearchAdapter(context: Context) : SimpleRecyclerAdapter<SearchBook>(context, R.layout.item_search) {
@ -15,13 +14,11 @@ class SearchAdapter(context: Context) : SimpleRecyclerAdapter<SearchBook>(contex
} }
override fun convert(holder: ItemViewHolder, item: SearchBook, payloads: MutableList<Any>) { override fun convert(holder: ItemViewHolder, item: SearchBook, payloads: MutableList<Any>) {
holder.itemView.bookName.text = "我欲封天"
} }
internal class TestItemDelegate(context: Context) : ItemViewDelegate<SearchBook>(context, R.layout.item_search) { internal class TestItemDelegate(context: Context) : ItemViewDelegate<SearchBook>(context, R.layout.item_search) {
override fun convert(holder: ItemViewHolder, item: SearchBook, payloads: MutableList<Any>) { override fun convert(holder: ItemViewHolder, item: SearchBook, payloads: MutableList<Any>) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
} }
} }

@ -5,20 +5,18 @@ import com.google.gson.GsonBuilder
import com.google.gson.JsonParser import com.google.gson.JsonParser
import org.jetbrains.anko.attempt import org.jetbrains.anko.attempt
val GSON: Gson = GsonBuilder().create() val GSON: Gson by lazy { GsonBuilder().create() }
inline fun <reified T> Gson.fromJson(json: String): T = fromJson(json, T::class.java) inline fun <reified T> Gson.fromJson(json: String): T = fromJson(json, T::class.java)
inline fun <reified T> Gson.arrayFromJson(json: String): ArrayList<T>? = run { inline fun <reified T> Gson.fromJsonArray(json: String): ArrayList<T>? {
return@run attempt { return attempt {
val result = ArrayList<T>() with(JsonParser().parse(json).asJsonArray) {
val parser = JsonParser() val result = ArrayList<T>()
val jArray = parser.parse(json).asJsonArray for (obj in this) {
jArray?.let {
for (obj in it) {
attempt { fromJson(obj, T::class.java) }.value?.run { result.add(this) } attempt { fromJson(obj, T::class.java) }.value?.run { result.add(this) }
} }
result
} }
result
}.value }.value
} }
Loading…
Cancel
Save