Merge branch 'TerminusMKB-master' into dev

This commit is contained in:
Rubenlagus 2016-04-17 16:56:54 +02:00
commit c1a0b25c9c
3 changed files with 59 additions and 91 deletions

View File

@ -1,5 +1,6 @@
package org.telegram.telegrambots.api.methods;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
@ -24,8 +25,11 @@ public class AnswerCallbackQuery extends BotApiMethod<Boolean> {
private static final String TEXT_FIELD = "text";
private static final String SHOWALERT_FIELD = "show_alert";
@JsonProperty(CALLBACKQUERYID_FIELD)
private String callbackQueryId; ///< Unique identifier for the query to be answered
@JsonProperty(TEXT_FIELD)
private String text; ///< Text of the notification. If not specified, nothing will be shown to the user
@JsonProperty(SHOWALERT_FIELD)
private Boolean showAlert; ///< Optional. If true, an alert will be shown by the client instead of a notificaiton at the top of the chat screen. Defaults to false.
@ -33,6 +37,30 @@ public class AnswerCallbackQuery extends BotApiMethod<Boolean> {
super();
}
public String getCallbackQueryId() {
return this.callbackQueryId;
}
public void setCallbackQueryId(String callbackQueryId) {
this.callbackQueryId = callbackQueryId;
}
public String getText() {
return this.text;
}
public void setText(String text) {
this.text = text;
}
public Boolean getShowAlert() {
return this.showAlert;
}
public void setShowAlert(Boolean showAlert) {
this.showAlert = showAlert;
}
@Override
public JSONObject toJson() {
JSONObject jsonObject = new JSONObject();

View File

@ -51,6 +51,22 @@ public class CallbackQuery implements IBotApiObject {
super();
}
public String getId() {
return this.id;
}
public User getFrom() {
return this.from;
}
public Message getMessage() {
return this.getMessage();
}
public String getInlineMessageId() {
return this.inlineMessageId;
}
public CallbackQuery(JSONObject jsonObject) {
super();
this.id = jsonObject.getString(ID_FIELD);

View File

@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.jsontype.TypeSerializer;
import org.json.JSONArray;
import org.json.JSONObject;
import org.telegram.telegrambots.api.objects.replykeyboard.buttons.InlineKeyboardButton;
import java.io.IOException;
import java.util.ArrayList;
@ -23,107 +24,42 @@ import java.util.List;
*/
public class InlineKeyboardMarkup implements ReplyKeyboard {
private static final String KEYBOARD_FIELD = "keyboard";
private static final String RESIZEKEYBOARD_FIELD = "resize_keyboard";
private static final String ONETIMEKEYBOARD_FIELD = "one_time_keyboard";
private static final String SELECTIVE_FIELD = "selective";
private static final String KEYBOARD_FIELD = "inline_keyboard";
@JsonProperty(KEYBOARD_FIELD)
private List<List<String>> keyboard; ///< Array of button rows, each represented by an Array of Strings
@JsonProperty(RESIZEKEYBOARD_FIELD)
private Boolean resizeKeyboard; ///< Optional. Requests clients to resize the keyboard vertically for optimal fit (e.g., make the keyboard smaller if there are just two rows of buttons). Defaults to false.
@JsonProperty(ONETIMEKEYBOARD_FIELD)
private Boolean oneTimeKeyboad; ///< Optional. Requests clients to hide the keyboard as soon as it's been used. Defaults to false.
/**
* Optional. Use this parameter if you want to show the keyboard to specific users only.
* Targets: 1) users that are @mentioned in the text of the Message object; 2) if the bot's
* message is a reply (has reply_to_message_id), sender of the original message.
*/
private Boolean selective;
private List<List<InlineKeyboardButton>> keyboard; ///< Array of button rows, each represented by an Array of Strings
public InlineKeyboardMarkup() {
super();
keyboard = new ArrayList<List<String>>();
keyboard = new ArrayList<>();
}
public InlineKeyboardMarkup(JSONObject jsonObject) {
super();
this.keyboard = new ArrayList<List<String>>();
JSONArray keyboard = jsonObject.getJSONArray(KEYBOARD_FIELD);
for (int i = 0; i < keyboard.length(); i++) {
JSONArray keyboardRow = keyboard.getJSONArray(i);
List<String> row = new ArrayList<String>();
for (int j = 0; j < keyboardRow.length(); j++) {
row.add(keyboardRow.getString(j));
}
this.keyboard.add(row);
}
if (jsonObject.has(RESIZEKEYBOARD_FIELD)) {
this.resizeKeyboard = jsonObject.getBoolean(RESIZEKEYBOARD_FIELD);
}
if (jsonObject.has(ONETIMEKEYBOARD_FIELD)) {
this.oneTimeKeyboad = jsonObject.getBoolean(ONETIMEKEYBOARD_FIELD);
}
if (jsonObject.has(SELECTIVE_FIELD)) {
this.selective = jsonObject.getBoolean(SELECTIVE_FIELD);
}
this.keyboard = new ArrayList<>();
}
public List<List<String>> getKeyboard() {
public List<List<InlineKeyboardButton>> getKeyboard() {
return keyboard;
}
public void setKeyboard(List<List<String>> keyboard) {
public void setKeyboard(List<List<InlineKeyboardButton>> keyboard) {
this.keyboard = keyboard;
}
public Boolean getResizeKeyboard() {
return resizeKeyboard;
}
public void setResizeKeyboard(Boolean resizeKeyboard) {
this.resizeKeyboard = resizeKeyboard;
}
public Boolean getOneTimeKeyboad() {
return oneTimeKeyboad;
}
public void setOneTimeKeyboad(Boolean oneTimeKeyboad) {
this.oneTimeKeyboad = oneTimeKeyboad;
}
public Boolean getSelective() {
return selective;
}
public void setSelective(Boolean selective) {
this.selective = selective;
}
@Override
public JSONObject toJson() {
JSONObject jsonObject = new JSONObject();
JSONArray jsonkeyboard = new JSONArray();
for (List<String> innerRow : this.keyboard) {
for (List<InlineKeyboardButton> innerRow : this.keyboard) {
JSONArray innerJSONKeyboard = new JSONArray();
for (String element : innerRow) {
innerJSONKeyboard.put(element);
for (InlineKeyboardButton element : innerRow) {
innerJSONKeyboard.put(element.toJson());
}
jsonkeyboard.put(innerJSONKeyboard);
}
jsonObject.put(InlineKeyboardMarkup.KEYBOARD_FIELD, jsonkeyboard);
if (this.oneTimeKeyboad != null) {
jsonObject.put(InlineKeyboardMarkup.ONETIMEKEYBOARD_FIELD, this.oneTimeKeyboad);
}
if (this.resizeKeyboard != null) {
jsonObject.put(InlineKeyboardMarkup.RESIZEKEYBOARD_FIELD, this.resizeKeyboard);
}
if (this.selective != null) {
jsonObject.put(InlineKeyboardMarkup.SELECTIVE_FIELD, this.selective);
}
return jsonObject;
}
@ -131,23 +67,14 @@ public class InlineKeyboardMarkup implements ReplyKeyboard {
public void serialize(JsonGenerator gen, SerializerProvider serializers) throws IOException {
gen.writeStartObject();
gen.writeArrayFieldStart(KEYBOARD_FIELD);
for (List<String> innerRow : keyboard) {
for (List<InlineKeyboardButton> innerRow : keyboard) {
gen.writeStartArray();
for (String element : innerRow) {
gen.writeString(element);
for (InlineKeyboardButton element : innerRow) {
gen.writeObject(element);
}
gen.writeEndArray();
}
gen.writeEndArray();
if (this.oneTimeKeyboad != null) {
gen.writeBooleanField(ONETIMEKEYBOARD_FIELD, oneTimeKeyboad);
}
if (this.resizeKeyboard != null) {
gen.writeBooleanField(RESIZEKEYBOARD_FIELD, resizeKeyboard);
}
if (this.selective != null) {
gen.writeBooleanField(SELECTIVE_FIELD, selective);
}
gen.writeEndObject();
gen.flush();
}
@ -159,11 +86,8 @@ public class InlineKeyboardMarkup implements ReplyKeyboard {
@Override
public String toString() {
return "ReplyKeyboardMarkup{" +
"keyboard=" + keyboard +
", resizeKeyboard=" + resizeKeyboard +
", oneTimeKeyboad=" + oneTimeKeyboad +
", selective=" + selective +
return "InlineKeyboardMarkup{" +
"inline_keyboard=" + keyboard +
'}';
}
}