96 lines
1.9 KiB
Java
96 lines
1.9 KiB
Java
package de.mrbesen.telegram.objects;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import org.json.JSONArray;
|
|
import org.json.JSONObject;
|
|
|
|
public class TReplyKeyboardMarkup implements TReplyMarkup {
|
|
|
|
boolean isOneTimeKeyboard = false;
|
|
boolean isResizeKeyboard = false;
|
|
boolean isSelective = true;
|
|
|
|
ArrayList<JSONArray> arr_btn = new ArrayList<>();
|
|
|
|
/**
|
|
* One line ReplyKeyboard
|
|
*/
|
|
public TReplyKeyboardMarkup() {
|
|
this(1);
|
|
}
|
|
|
|
/**
|
|
* multi-line ReplyKeyboard
|
|
* @param rows
|
|
*/
|
|
public TReplyKeyboardMarkup(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());
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public String toJSONString() {
|
|
return new JSONObject().put("keyboard", new JSONArray(arr_btn))
|
|
.put("one_time_keyboard", isOneTimeKeyboard)
|
|
.put("resize_keyboard", isResizeKeyboard)
|
|
.put("selective", isSelective)
|
|
.toString();
|
|
}
|
|
|
|
/**
|
|
* Insert button in first line
|
|
* @param title
|
|
* @param url
|
|
* @return
|
|
*/
|
|
public TReplyKeyboardMarkup addButton(String title) {
|
|
addButton(title, 1);
|
|
return this;
|
|
}
|
|
/**
|
|
* Insert button in nth line
|
|
* @param title
|
|
* @param url
|
|
* @param row
|
|
* @return
|
|
*/
|
|
public TReplyKeyboardMarkup addButton(String title, int row) {
|
|
arr_btn.get(row-1).put(title);
|
|
return this;
|
|
}
|
|
|
|
public boolean isOneTimeKeyboard() {
|
|
return isOneTimeKeyboard;
|
|
}
|
|
|
|
public TReplyKeyboardMarkup setOneTimeKeyboard(boolean isOneTimeKeyboard) {
|
|
this.isOneTimeKeyboard = isOneTimeKeyboard;
|
|
return this;
|
|
}
|
|
|
|
public boolean isResizeKeyboard() {
|
|
return isResizeKeyboard;
|
|
}
|
|
|
|
public TReplyKeyboardMarkup setResizeKeyboard(boolean isResizeKeyboard) {
|
|
this.isResizeKeyboard = isResizeKeyboard;
|
|
return this;
|
|
}
|
|
|
|
public boolean isSelective() {
|
|
return isSelective;
|
|
}
|
|
|
|
public TReplyKeyboardMarkup setSelective(boolean isSelective) {
|
|
this.isSelective = isSelective;
|
|
return this;
|
|
}
|
|
|
|
}
|