eu.vendeli.tgbot.interfaces.KeyboardBuilder.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of telegram-bot Show documentation
Show all versions of telegram-bot Show documentation
Telegram Bot API wrapper, with handy Kotlin DSL.
package eu.vendeli.tgbot.interfaces
abstract class KeyboardBuilder {
protected abstract val buttons: MutableList
/**
* Adds a line break, so that the following buttons will be on a new line.
*/
fun newLine() {
buttons.add(null)
}
/**
* Same as [newLine].
*
* @see [newLine]
*/
fun br() = newLine()
/**
* The function that collects and returns [Keyboard]
*
* @return
*/
internal fun build(): List> {
val builtButtons = mutableListOf>()
val buttonsIterator = buttons.iterator()
var currentLine: MutableList = mutableListOf()
while (buttonsIterator.hasNext()) {
val item = buttonsIterator.next()
if (item == null) {
builtButtons.add(currentLine)
currentLine = mutableListOf()
continue
}
currentLine.add(item)
}
if (currentLine.isNotEmpty()) builtButtons.add(currentLine)
return builtButtons
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy