|
|
@ -1,10 +1,11 @@ |
|
|
|
package io.legado.app.ui.main.explore |
|
|
|
package io.legado.app.ui.main.explore |
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context |
|
|
|
import android.content.Context |
|
|
|
import android.view.LayoutInflater |
|
|
|
|
|
|
|
import android.view.View |
|
|
|
import android.view.View |
|
|
|
import android.view.ViewGroup |
|
|
|
import android.view.ViewGroup |
|
|
|
import android.widget.PopupMenu |
|
|
|
import android.widget.PopupMenu |
|
|
|
|
|
|
|
import android.widget.TextView |
|
|
|
|
|
|
|
import androidx.core.view.children |
|
|
|
import com.google.android.flexbox.FlexboxLayout |
|
|
|
import com.google.android.flexbox.FlexboxLayout |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.base.adapter.ItemViewHolder |
|
|
|
import io.legado.app.base.adapter.ItemViewHolder |
|
|
@ -25,6 +26,8 @@ import splitties.views.onLongClick |
|
|
|
|
|
|
|
|
|
|
|
class ExploreAdapter(context: Context, private val scope: CoroutineScope, val callBack: CallBack) : |
|
|
|
class ExploreAdapter(context: Context, private val scope: CoroutineScope, val callBack: CallBack) : |
|
|
|
RecyclerAdapter<BookSource, ItemFindBookBinding>(context) { |
|
|
|
RecyclerAdapter<BookSource, ItemFindBookBinding>(context) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private val recycler = arrayListOf<View>() |
|
|
|
private var exIndex = -1 |
|
|
|
private var exIndex = -1 |
|
|
|
private var scrollTo = -1 |
|
|
|
private var scrollTo = -1 |
|
|
|
|
|
|
|
|
|
|
@ -66,27 +69,24 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
binding.ivStatus.setImageResource(R.drawable.ic_arrow_right) |
|
|
|
ivStatus.setImageResource(R.drawable.ic_arrow_right) |
|
|
|
binding.rotateLoading.hide() |
|
|
|
rotateLoading.hide() |
|
|
|
binding.flexbox.gone() |
|
|
|
recyclerFlexbox(flexbox) |
|
|
|
|
|
|
|
flexbox.gone() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun upKindList(flexbox: FlexboxLayout, sourceUrl: String, kinds: List<ExploreKind>) { |
|
|
|
private fun upKindList(flexbox: FlexboxLayout, sourceUrl: String, kinds: List<ExploreKind>) { |
|
|
|
if (!kinds.isNullOrEmpty()) { |
|
|
|
if (!kinds.isNullOrEmpty()) { |
|
|
|
|
|
|
|
recyclerFlexbox(flexbox) |
|
|
|
flexbox.visible() |
|
|
|
flexbox.visible() |
|
|
|
flexbox.removeAllViews() |
|
|
|
kinds.forEach { kind -> |
|
|
|
kinds.map { kind -> |
|
|
|
val tv = getFlexboxChild(flexbox) |
|
|
|
val tv = ItemFilletTextBinding.inflate( |
|
|
|
|
|
|
|
LayoutInflater.from(context), |
|
|
|
|
|
|
|
flexbox, |
|
|
|
|
|
|
|
false |
|
|
|
|
|
|
|
).root |
|
|
|
|
|
|
|
flexbox.addView(tv) |
|
|
|
flexbox.addView(tv) |
|
|
|
tv.text = kind.title |
|
|
|
tv.text = kind.title |
|
|
|
val lp = tv.layoutParams as FlexboxLayout.LayoutParams |
|
|
|
val lp = tv.layoutParams as FlexboxLayout.LayoutParams |
|
|
|
kind.style.let { style -> |
|
|
|
kind.style().let { style -> |
|
|
|
lp.flexGrow = style.layout_flexGrow |
|
|
|
lp.flexGrow = style.layout_flexGrow |
|
|
|
lp.flexShrink = style.layout_flexShrink |
|
|
|
lp.flexShrink = style.layout_flexShrink |
|
|
|
lp.alignSelf = style.alignSelf() |
|
|
|
lp.alignSelf = style.alignSelf() |
|
|
@ -100,6 +100,23 @@ class ExploreAdapter(context: Context, private val scope: CoroutineScope, val ca |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Synchronized |
|
|
|
|
|
|
|
private fun getFlexboxChild(flexbox: FlexboxLayout): TextView { |
|
|
|
|
|
|
|
return if (recycler.isEmpty()) { |
|
|
|
|
|
|
|
ItemFilletTextBinding.inflate(inflater, flexbox, false).root |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
recycler.last().also { |
|
|
|
|
|
|
|
recycler.removeLast() |
|
|
|
|
|
|
|
} as TextView |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Synchronized |
|
|
|
|
|
|
|
private fun recyclerFlexbox(flexbox: FlexboxLayout) { |
|
|
|
|
|
|
|
recycler.addAll(flexbox.children) |
|
|
|
|
|
|
|
flexbox.removeAllViews() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun registerListener(holder: ItemViewHolder, binding: ItemFindBookBinding) { |
|
|
|
override fun registerListener(holder: ItemViewHolder, binding: ItemFindBookBinding) { |
|
|
|
binding.apply { |
|
|
|
binding.apply { |
|
|
|
llTitle.setOnClickListener { |
|
|
|
llTitle.setOnClickListener { |
|
|
|