57 lines
1.3 KiB
Java
57 lines
1.3 KiB
Java
package de.mrbesen.telegram.objects;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import org.json.JSONArray;
|
|
import org.json.JSONObject;
|
|
|
|
public class TInlineKeyboardMarkup implements TReplyMarkup {
|
|
|
|
ArrayList<JSONArray> arr_btn = new ArrayList<>();
|
|
|
|
public TInlineKeyboardMarkup() {
|
|
this(1);
|
|
}
|
|
|
|
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());
|
|
}
|
|
}
|
|
/**
|
|
* 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) {
|
|
arr_btn.get(row-1).put(new JSONObject().put("text", title).put("url", url));
|
|
return this;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
@Override
|
|
public String toJSONString() {
|
|
return new JSONObject().put("inline_keyboard", new JSONArray(arr_btn)).toString();
|
|
}
|
|
}
|