TelegramAPI/src/de/mrbesen/telegram/objects/TInlineKeyboardMarkup.java

57 lines
1.3 KiB
Java
Raw Normal View History

package de.mrbesen.telegram.objects;
2018-07-18 04:44:04 +02:00
import java.util.ArrayList;
import org.json.JSONArray;
import org.json.JSONObject;
public class TInlineKeyboardMarkup implements TReplyMarkup {
ArrayList<JSONArray> arr_btn = new ArrayList<>();
2018-07-18 22:31:05 +02:00
public TInlineKeyboardMarkup() {
this(1);
}
2018-07-18 04:44:04 +02:00
public TInlineKeyboardMarkup(int rows) {
if(rows < 1)
throw new IllegalArgumentException("You need at least one row.");
arr_btn = new ArrayList<JSONArray>();
for( int row = 0; row < rows; row++ ) {
arr_btn.add(new JSONArray());
2018-07-18 22:31:05 +02:00
}
2018-07-18 04:44:04 +02:00
}
2018-07-18 22:31:05 +02:00
/**
* Insert button in first line
* @param title
* @param url
* @return
*/
public TInlineKeyboardMarkup addUrlButton(String title, String url) {
addUrlButton(title, url, 1);
return this;
}
/**
* Insert button in nth line
* @param title
* @param url
* @param row
* @return
*/
public TInlineKeyboardMarkup addUrlButton(String title, String url, int row) {
2018-07-18 04:44:04 +02:00
arr_btn.get(row-1).put(new JSONObject().put("text", title).put("url", url));
return this;
}
2019-02-06 23:52:15 +01:00
public TInlineKeyboardMarkup addCallbackButton(String title, String callback, int row) {
arr_btn.get(row-1).put(new JSONObject().put("text", title).put("callback_data", callback));
return this;
}
2018-07-18 04:44:04 +02:00
@Override
public String toJSONString() {
2018-07-18 22:31:05 +02:00
return new JSONObject().put("inline_keyboard", new JSONArray(arr_btn)).toString();
2018-07-18 04:44:04 +02:00
}
}