| package tw.nekomimi.nekogram |
| 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 | for (item in items) { |
| 26 | if (item == null) continue |
| 27 | addSubItem(items.indexOf(item), item) |
| 28 | } |
| 29 |
| 30 | setDelegate { |
| 31 |
| 32 | listener(it, items[it]!!) |
| 33 |
| 34 | } |
| 35 |
| 36 | } |
| 37 |
| 38 | fun show() { |
| 39 |
| 40 | toggleSubMenu() |
| 41 |
| 42 | } |
| 43 |
| 44 | } |