|
|
@ -10,15 +10,18 @@ import androidx.recyclerview.widget.DiffUtil |
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.data.entities.BookSource |
|
|
|
import io.legado.app.data.entities.BookSource |
|
|
|
|
|
|
|
import io.legado.app.help.coroutine.Coroutine |
|
|
|
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.visible |
|
|
|
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 kotlinx.android.synthetic.main.item_text.view.* |
|
|
|
|
|
|
|
import kotlinx.coroutines.CoroutineScope |
|
|
|
import org.jetbrains.anko.sdk27.listeners.onClick |
|
|
|
import org.jetbrains.anko.sdk27.listeners.onClick |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class FindBookAdapter:PagedListAdapter<BookSource, FindBookAdapter.MyViewHolder>(DIFF_CALLBACK) { |
|
|
|
class FindBookAdapter(private val scope: CoroutineScope) : |
|
|
|
|
|
|
|
PagedListAdapter<BookSource, FindBookAdapter.MyViewHolder>(DIFF_CALLBACK) { |
|
|
|
|
|
|
|
|
|
|
|
var exIndex = 0 |
|
|
|
var exIndex = 0 |
|
|
|
|
|
|
|
|
|
|
@ -58,26 +61,30 @@ class FindBookAdapter:PagedListAdapter<BookSource, FindBookAdapter.MyViewHolder> |
|
|
|
} |
|
|
|
} |
|
|
|
if (exIndex == position) { |
|
|
|
if (exIndex == position) { |
|
|
|
gl_child.visible() |
|
|
|
gl_child.visible() |
|
|
|
bookSource.getExploreRule().getExploreKinds(bookSource.bookSourceUrl)?.let { |
|
|
|
Coroutine.async(scope) { |
|
|
|
var rowNum = 0 |
|
|
|
bookSource.getExploreRule().getExploreKinds(bookSource.bookSourceUrl) |
|
|
|
var columnNum = 0 |
|
|
|
}.onSuccess { |
|
|
|
gl_child.removeAllViews() |
|
|
|
it?.let { |
|
|
|
it.map { kind -> |
|
|
|
var rowNum = 0 |
|
|
|
val tv = LayoutInflater.from(context) |
|
|
|
var columnNum = 0 |
|
|
|
.inflate(R.layout.item_text, gl_child, false) |
|
|
|
gl_child.removeAllViews() |
|
|
|
tv.text_view.text = kind.title |
|
|
|
it.map { kind -> |
|
|
|
val rowSpecs = GridLayout.spec(rowNum, 1.0f) |
|
|
|
val tv = LayoutInflater.from(context) |
|
|
|
val colSpecs = GridLayout.spec(columnNum, 1.0f) |
|
|
|
.inflate(R.layout.item_text, gl_child, false) |
|
|
|
val params = GridLayout.LayoutParams(rowSpecs, colSpecs) |
|
|
|
tv.text_view.text = kind.title |
|
|
|
gl_child.addView(tv, params) |
|
|
|
val rowSpecs = GridLayout.spec(rowNum, 1.0f) |
|
|
|
if (columnNum < 2) { |
|
|
|
val colSpecs = GridLayout.spec(columnNum, 1.0f) |
|
|
|
columnNum++ |
|
|
|
val params = GridLayout.LayoutParams(rowSpecs, colSpecs) |
|
|
|
} else { |
|
|
|
gl_child.addView(tv, params) |
|
|
|
columnNum = 0 |
|
|
|
if (columnNum < 2) { |
|
|
|
rowNum++ |
|
|
|
columnNum++ |
|
|
|
} |
|
|
|
} else { |
|
|
|
tv.onClick { |
|
|
|
columnNum = 0 |
|
|
|
|
|
|
|
rowNum++ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
tv.onClick { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|