diff --git a/src/main/java/org/sadtech/social/core/domain/BoxAnswer.java b/src/main/java/org/sadtech/social/core/domain/BoxAnswer.java index 6247fc8..c5fc72e 100644 --- a/src/main/java/org/sadtech/social/core/domain/BoxAnswer.java +++ b/src/main/java/org/sadtech/social/core/domain/BoxAnswer.java @@ -33,4 +33,8 @@ public class BoxAnswer { @Description("Идентификатор стикера") private Integer stickerId; + public static BoxAnswer of(String message) { + return BoxAnswer.builder().message(message).build(); + } + } diff --git a/src/main/java/org/sadtech/social/core/domain/keyboard/button/KeyBoardButtonText.java b/src/main/java/org/sadtech/social/core/domain/keyboard/button/KeyBoardButtonText.java index 21b6bad..3a0fb29 100644 --- a/src/main/java/org/sadtech/social/core/domain/keyboard/button/KeyBoardButtonText.java +++ b/src/main/java/org/sadtech/social/core/domain/keyboard/button/KeyBoardButtonText.java @@ -26,4 +26,8 @@ public class KeyBoardButtonText extends KeyBoardButton { this.label = label; this.color = (color != null) ? color : ButtonColor.DEFAULT; } + + public static KeyBoardButtonText of(String label) { + return KeyBoardButtonText.builder().label(label).build(); + } } diff --git a/src/main/java/org/sadtech/social/core/service/Filter.java b/src/main/java/org/sadtech/social/core/service/Modifiable.java similarity index 86% rename from src/main/java/org/sadtech/social/core/service/Filter.java rename to src/main/java/org/sadtech/social/core/service/Modifiable.java index 427215f..b60caec 100644 --- a/src/main/java/org/sadtech/social/core/service/Filter.java +++ b/src/main/java/org/sadtech/social/core/service/Modifiable.java @@ -9,8 +9,8 @@ import org.sadtech.social.core.domain.content.Message; * @author upagge [08/07/2019] */ @FunctionalInterface -public interface Filter { +public interface Modifiable { - void processing(T content); + void change(T content); } diff --git a/src/main/java/org/sadtech/social/core/utils/KeyBoards.java b/src/main/java/org/sadtech/social/core/utils/KeyBoards.java index 6156ec9..e5878f7 100644 --- a/src/main/java/org/sadtech/social/core/utils/KeyBoards.java +++ b/src/main/java/org/sadtech/social/core/utils/KeyBoards.java @@ -6,6 +6,7 @@ import org.sadtech.social.core.domain.keyboard.KeyBoardButton; import org.sadtech.social.core.domain.keyboard.KeyBoardLine; import org.sadtech.social.core.domain.keyboard.button.KeyBoardButtonText; +import java.util.Arrays; import java.util.List; /** @@ -53,12 +54,7 @@ public class KeyBoards { * @return {@link KeyBoard} */ public static KeyBoard verticalMenuString(String... labelButton) { - KeyBoard.KeyBoardBuilder keyBoard = KeyBoard.builder().oneTime(true); - for (String label : labelButton) { - KeyBoardButton keyBoardButton = KeyBoardButtonText.builder().label(label).payload("{\"button\": \"" + label + "\"}").build(); - keyBoard.lineKeyBoard(KeyBoardLine.builder().buttonKeyBoard(keyBoardButton).build()); - } - return keyBoard.build(); + return verticalMenuString(Arrays.asList(labelButton)); } /** @@ -68,15 +64,30 @@ public class KeyBoards { * @return {@link KeyBoard} */ public static KeyBoard verticalDuoMenuString(String... labelButton) { + return verticalDuoMenuString(Arrays.asList(labelButton)); + } + + /** + * Возвращает клавиатуру формата 2х(N/2), где N - это количество элементов в переданном списке + * + * @param labelButton Список названий для кнопок + * @return {@link KeyBoard} + */ + public static KeyBoard verticalDuoMenuString(List labelButton) { KeyBoard.KeyBoardBuilder keyBoard = KeyBoard.builder().oneTime(true); boolean flag = true; KeyBoardLine.KeyBoardLineBuilder keyBoardLine = KeyBoardLine.builder(); - for (String label : labelButton) { + for (int i = 0; i <= labelButton.size() - 1; i++) { + String label = labelButton.get(i); if (flag) { - keyBoardLine.buttonKeyBoard(KeyBoardButtonText.builder().label(label).build()); - flag = false; + keyBoardLine.buttonKeyBoard(KeyBoardButtonText.of(label)); + if (i == labelButton.size() - 1) { + keyBoard.lineKeyBoard(keyBoardLine.build()); + } else { + flag = false; + } } else { - keyBoardLine.buttonKeyBoard(KeyBoardButtonText.builder().label(label).build()); + keyBoardLine.buttonKeyBoard(KeyBoardButtonText.of(label)); keyBoard.lineKeyBoard(keyBoardLine.build()); keyBoardLine = KeyBoardLine.builder(); flag = true;