pull/32/head
Invinciblelee 6 years ago
parent 5d162ebfa7
commit f8a0e2dbfc
  1. 6
      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. 14
      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.Index
import androidx.room.PrimaryKey
import com.google.gson.Gson
import io.legado.app.constant.AppConst.NOT_AVAILABLE
import io.legado.app.utils.GSON
import io.legado.app.utils.fromJson
import kotlinx.android.parcel.IgnoredOnParcel
import kotlinx.android.parcel.Parcelize
@ -69,7 +69,7 @@ data class Book(
variableMap = if (isEmpty(variable)) {
HashMap()
} 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) {
initVariableMap()
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
callBack?.update(bookSource)
}
iv_more.setOnClickListener {
iv_more.onClick {
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_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.SimpleRecyclerAdapter
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) {
@ -15,13 +14,11 @@ class SearchAdapter(context: Context) : SimpleRecyclerAdapter<SearchBook>(contex
}
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) {
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 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.arrayFromJson(json: String): ArrayList<T>? = run {
return@run attempt {
inline fun <reified T> Gson.fromJsonArray(json: String): ArrayList<T>? {
return attempt {
with(JsonParser().parse(json).asJsonArray) {
val result = ArrayList<T>()
val parser = JsonParser()
val jArray = parser.parse(json).asJsonArray
jArray?.let {
for (obj in it) {
for (obj in this) {
attempt { fromJson(obj, T::class.java) }.value?.run { result.add(this) }
}
}
result
}
}.value
}
Loading…
Cancel
Save