Advertisement
Mouamle

InlineKeyboardBuilder

Jan 18th, 2019
393
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
  2. import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.InlineKeyboardButton;
  3.  
  4. import java.util.ArrayList;
  5. import java.util.List;
  6.  
  7.  
  8. /**
  9.  *
  10.  * @author Mouamle H. Hameed
  11.  */
  12. public class InlineKeyboardBuilder {
  13.  
  14.  
  15.     private List<List<InlineKeyboardButton>> mKeyboard = new ArrayList<>();
  16.     private List<InlineKeyboardButton> row = null;
  17.  
  18.     private InlineKeyboardBuilder() { }
  19.  
  20.  
  21.     public static InlineKeyboardBuilder create() {
  22.         return new InlineKeyboardBuilder();
  23.     }
  24.  
  25.     public InlineKeyboardBuilder row() {
  26.         this.row = new ArrayList<>();
  27.         return this;
  28.     }
  29.  
  30.     public InlineKeyboardBuilder button(String text, String callbackData) {
  31.         row.add(new InlineKeyboardButton().setText(text).setCallbackData(callbackData));
  32.         return this;
  33.     }
  34.  
  35.     public InlineKeyboardBuilder button(InlineKeyboardButton button) {
  36.         row.add(button);
  37.         return this;
  38.     }
  39.  
  40.     public InlineKeyboardBuilder endRow() {
  41.         this.mKeyboard.add(this.row);
  42.         this.row = null;
  43.         return this;
  44.     }
  45.  
  46.     public InlineKeyboardMarkup build() {
  47.         return new InlineKeyboardMarkup().setKeyboard(mKeyboard);
  48.     }
  49.  
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement