diff --git a/app/src/main/java/io/legado/app/ui/main/findbook/FindBookAdapter.kt b/app/src/main/java/io/legado/app/ui/main/findbook/FindBookAdapter.kt index ff89cf48a..c6a217109 100644 --- a/app/src/main/java/io/legado/app/ui/main/findbook/FindBookAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/findbook/FindBookAdapter.kt @@ -4,7 +4,7 @@ import android.graphics.drawable.GradientDrawable import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.TextView +import android.widget.GridLayout import androidx.paging.PagedListAdapter import androidx.recyclerview.widget.DiffUtil 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.lib.theme.ColorUtils 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_text.view.* import org.jetbrains.anko.sdk27.listeners.onClick + class FindBookAdapter:PagedListAdapter(DIFF_CALLBACK) { var exIndex = 0 @@ -43,18 +45,34 @@ class FindBookAdapter:PagedListAdapter tv_name.text = bookSource.bookSourceName ll_title.onClick { val oldEx = exIndex - exIndex = position + if (exIndex == position) { + exIndex = -1 + } else { + exIndex = position + notifyItemChanged(position) + } notifyItemChanged(oldEx) - notifyItemChanged(position) } if (exIndex == position) { - gl_child.invisible() + gl_child.visible() bookSource.getExploreRule().getExploreKinds(bookSource.bookSourceUrl)?.let { + var rowNum = 0 + var columnNum = 0 + gl_child.removeAllViews() it.map { kind -> - val tv = TextView(context) - tv.text = kind.title - tv.onClick { } - gl_child.addView(tv) + val tv = LayoutInflater.from(context) + .inflate(R.layout.item_text, gl_child, false) + tv.text_view.text = kind.title + 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 { diff --git a/app/src/main/res/layout/item_find_book.xml b/app/src/main/res/layout/item_find_book.xml index 0439c293a..be691c1f6 100644 --- a/app/src/main/res/layout/item_find_book.xml +++ b/app/src/main/res/layout/item_find_book.xml @@ -4,7 +4,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" xmlns:app="http://schemas.android.com/apk/res-auto" - android:padding="10dp" + android:layout_margin="10dp" android:orientation="vertical"> + \ No newline at end of file