pull/32/head
kunfei 5 years ago
parent 55b8ecf73a
commit d824372a2c
  1. 34
      app/src/main/java/io/legado/app/ui/main/findbook/FindBookAdapter.kt
  2. 2
      app/src/main/res/layout/item_find_book.xml
  3. 7
      app/src/main/res/layout/item_text.xml

@ -4,7 +4,7 @@ import android.graphics.drawable.GradientDrawable
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.TextView import android.widget.GridLayout
import androidx.paging.PagedListAdapter import androidx.paging.PagedListAdapter
import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
@ -12,10 +12,12 @@ import io.legado.app.R
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.lib.theme.ColorUtils import io.legado.app.lib.theme.ColorUtils
import io.legado.app.utils.gone import io.legado.app.utils.gone
import io.legado.app.utils.invisible import io.legado.app.utils.visible
import kotlinx.android.synthetic.main.item_find_book.view.* import kotlinx.android.synthetic.main.item_find_book.view.*
import kotlinx.android.synthetic.main.item_text.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
class FindBookAdapter:PagedListAdapter<BookSource, FindBookAdapter.MyViewHolder>(DIFF_CALLBACK) { class FindBookAdapter:PagedListAdapter<BookSource, FindBookAdapter.MyViewHolder>(DIFF_CALLBACK) {
var exIndex = 0 var exIndex = 0
@ -43,18 +45,34 @@ class FindBookAdapter:PagedListAdapter<BookSource, FindBookAdapter.MyViewHolder>
tv_name.text = bookSource.bookSourceName tv_name.text = bookSource.bookSourceName
ll_title.onClick { ll_title.onClick {
val oldEx = exIndex val oldEx = exIndex
if (exIndex == position) {
exIndex = -1
} else {
exIndex = position exIndex = position
notifyItemChanged(oldEx)
notifyItemChanged(position) notifyItemChanged(position)
} }
notifyItemChanged(oldEx)
}
if (exIndex == position) { if (exIndex == position) {
gl_child.invisible() gl_child.visible()
bookSource.getExploreRule().getExploreKinds(bookSource.bookSourceUrl)?.let { bookSource.getExploreRule().getExploreKinds(bookSource.bookSourceUrl)?.let {
var rowNum = 0
var columnNum = 0
gl_child.removeAllViews()
it.map { kind -> it.map { kind ->
val tv = TextView(context) val tv = LayoutInflater.from(context)
tv.text = kind.title .inflate(R.layout.item_text, gl_child, false)
tv.onClick { } tv.text_view.text = kind.title
gl_child.addView(tv) val rowSpecs = GridLayout.spec(rowNum, 1.0f)
val colSpecs = GridLayout.spec(columnNum, 1.0f)
val params = GridLayout.LayoutParams(rowSpecs, colSpecs)
gl_child.addView(tv, params)
if (columnNum < 2) {
columnNum++
} else {
columnNum = 0
rowNum++
}
} }
} }
} else { } else {

@ -4,7 +4,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:padding="10dp" android:layout_margin="10dp"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout <LinearLayout

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="3dp"
android:textColor="@color/tv_text_secondary" />
Loading…
Cancel
Save