| 2 |
| 3 | import android.annotation.SuppressLint |
| 4 | import android.view.View |
| 5 | import org.telegram.ui.ActionBar.ActionBarMenuItem |
| 6 | import org.telegram.ui.ActionBar.Theme |
| 7 |
| 8 | @SuppressLint("ViewConstructor") |
| 9 | class PopupBuilder @JvmOverloads constructor(anchor: View, dialog: Boolean = false) : ActionBarMenuItem(anchor.context, null, Theme.ACTION_BAR_WHITE_SELECTOR_COLOR, -0x4c4c4d) { |
| 10 |
| 11 | init { |
| 12 |
| 13 | setAnchor(anchor) |
| 14 |
| 15 | isShowOnTop = dialog |
| 16 |
| 17 | isVerticalScrollBarEnabled = true |
| 18 |
| 19 | } |
| 20 |
| 21 | fun setItems(items: Array<CharSequence>, listener: (Int,CharSequence) -> Unit) { |
| 22 |
| 23 | removeAllSubItems() |
| 24 |
| 25 | items.forEachIndexed { i, v -> |
| 26 |
| 27 | addSubItem(i, v) |
| 28 |
| 29 | } |
| 30 |
| 31 | setDelegate { |
| 32 |
| 33 | listener(it,items[it]) |
| 34 |
| 35 | } |
| 36 |
| 37 | } |
| 38 |
| 39 | fun show() { |
| 40 |
| 41 | toggleSubMenu() |
| 42 |
| 43 | } |
| 44 |
| 45 | } |