pull/1814/head
parent
45d55a1b2d
commit
dfcc1c5397
@ -0,0 +1,63 @@ |
||||
package io.legado.app.ui.widget |
||||
|
||||
import android.content.Context |
||||
import android.view.ViewGroup |
||||
import android.widget.PopupWindow |
||||
import io.legado.app.base.adapter.ItemViewHolder |
||||
import io.legado.app.base.adapter.RecyclerAdapter |
||||
import io.legado.app.databinding.ItemTextBinding |
||||
import io.legado.app.databinding.PopupActionBinding |
||||
import io.legado.app.lib.dialogs.SelectItem |
||||
import splitties.systemservices.layoutInflater |
||||
|
||||
class PopupAction(private val context: Context) : |
||||
PopupWindow(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT) { |
||||
|
||||
val binding = PopupActionBinding.inflate(context.layoutInflater) |
||||
val adapter by lazy { |
||||
Adapter(context) |
||||
} |
||||
var onActionClick: ((action: String) -> Unit)? = null |
||||
|
||||
init { |
||||
contentView = binding.root |
||||
|
||||
isTouchable = true |
||||
isOutsideTouchable = true |
||||
isFocusable = false |
||||
|
||||
binding.recyclerView.adapter = adapter |
||||
} |
||||
|
||||
fun setItems(items: List<SelectItem<String>>) { |
||||
adapter.setItems(items) |
||||
} |
||||
|
||||
inner class Adapter(context: Context) : |
||||
RecyclerAdapter<SelectItem<String>, ItemTextBinding>(context) { |
||||
|
||||
override fun getViewBinding(parent: ViewGroup): ItemTextBinding { |
||||
return ItemTextBinding.inflate(inflater, parent, false) |
||||
} |
||||
|
||||
override fun convert( |
||||
holder: ItemViewHolder, |
||||
binding: ItemTextBinding, |
||||
item: SelectItem<String>, |
||||
payloads: MutableList<Any> |
||||
) { |
||||
with(binding) { |
||||
textView.text = item.title |
||||
} |
||||
} |
||||
|
||||
override fun registerListener(holder: ItemViewHolder, binding: ItemTextBinding) { |
||||
holder.itemView.setOnClickListener { |
||||
getItem(holder.layoutPosition)?.let { item -> |
||||
onActionClick?.invoke(item.value) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,21 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:background="@drawable/shape_card_view" |
||||
android:orientation="vertical" |
||||
android:padding="5dp"> |
||||
|
||||
<androidx.recyclerview.widget.RecyclerView |
||||
android:id="@+id/recycler_view" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:layout_gravity="center" |
||||
android:orientation="horizontal" |
||||
app:flexDirection="row" |
||||
app:flexWrap="wrap" |
||||
app:layoutManager="com.google.android.flexbox.FlexboxLayoutManager" /> |
||||
|
||||
</LinearLayout> |
||||
|
Loading…
Reference in new issue