All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.stormbit.vksdk.objects.keyboard.ButtonsBuilder.kt Maven / Gradle / Ivy

The newest version!
package com.github.stormbit.vksdk.objects.keyboard

import com.github.stormbit.vksdk.objects.models.Keyboard
import com.github.stormbit.vksdk.objects.models.Keyboard.Button.*
import com.github.stormbit.vksdk.objects.models.MessagePayload
import com.github.stormbit.vksdk.vkapi.ContextDsl
import java.io.Serializable
import java.util.*

@Suppress("unused")
@ContextDsl
class ButtonsBuilder : Serializable {
    private var buttons = ArrayList()

    fun primaryButton(label: String, payload: MessagePayload = MessagePayload(""), type: Action.Type = Action.Type.TEXT): ButtonsBuilder {
        addButton(label, payload, ButtonColor.PRIMARY, type)
        return this
    }

    fun defaultButton(label: String, payload: MessagePayload = MessagePayload(""), type: Action.Type = Action.Type.TEXT): ButtonsBuilder {
        addButton(label, payload, ButtonColor.DEFAULT, type)
        return this
    }

    fun positiveButton(label: String, payload: MessagePayload = MessagePayload(""), type: Action.Type = Action.Type.TEXT): ButtonsBuilder {
        addButton(label, payload, ButtonColor.POSITIVE, type)
        return this
    }

    fun negativeButton(label: String, payload: MessagePayload = MessagePayload(""), type: Action.Type = Action.Type.TEXT): ButtonsBuilder {
        addButton(label, payload, ButtonColor.NEGATIVE, type)
        return this
    }

    private fun addButton(label: String, payload: MessagePayload, color: ButtonColor, type: Action.Type) {
        buttons.add(Keyboard.Button(
            color = color,
            action = Action(
                type = type,
                label = label,
                payload = payload
            )
        ))
    }

    fun getButtons(): ArrayList {
        return buttons
    }

    fun setButtons(buttons: ArrayList) {
        this.buttons = buttons
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy