diff --git a/src/main/java/mouamle/generator/annotation/handlers/StringValue.java b/src/main/java/mouamle/generator/annotation/handlers/StringValue.java index 126a319..fdaa133 100644 --- a/src/main/java/mouamle/generator/annotation/handlers/StringValue.java +++ b/src/main/java/mouamle/generator/annotation/handlers/StringValue.java @@ -9,8 +9,13 @@ @Retention(RetentionPolicy.RUNTIME) public @interface StringValue { + int Horizontal = 0; + int Vertical = 1; + String key(); String[] values(); + int orientation() default Horizontal; + } diff --git a/src/main/java/mouamle/generator/annotation/handlers/StringValueHandler.java b/src/main/java/mouamle/generator/annotation/handlers/StringValueHandler.java index 723c5dd..bf42a5f 100644 --- a/src/main/java/mouamle/generator/annotation/handlers/StringValueHandler.java +++ b/src/main/java/mouamle/generator/annotation/handlers/StringValueHandler.java @@ -1,10 +1,11 @@ package mouamle.generator.annotation.handlers; -import mouamle.registry.AnnotationHandler; import mouamle.generator.classes.ButtonHolder; +import mouamle.registry.AnnotationHandler; import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class StringValueHandler implements AnnotationHandler { @@ -16,6 +17,29 @@ public List> generate(StringValue stringValue, Object o, Fiel List> part = new ArrayList<>(); addValueHeader(valueKey, part); + switch (stringValue.orientation()) { + case StringValue.Horizontal: + generateHorizontal(stringValue, field, valueKey, part); + break; + case StringValue.Vertical: + generateVertical(stringValue, field, valueKey, part); + break; + default: + throw new IllegalArgumentException("The orientation must be StringValue.Horizontal or StringValue.Vertical"); + } + + return part; + } + + private void generateVertical(StringValue stringValue, Field field, String valueKey, List> part) { + String[] values = stringValue.values(); + for (String value : values) { + String data = String.format("StringValue;%s;%s;%s", field.getName(), valueKey, value); + part.add(Collections.singletonList(new ButtonHolder(value, data))); + } + } + + private void generateHorizontal(StringValue stringValue, Field field, String valueKey, List> part) { List row = new ArrayList<>(); String[] values = stringValue.values(); @@ -25,7 +49,6 @@ public List> generate(StringValue stringValue, Object o, Fiel } part.add(row); - return part; } } diff --git a/src/test/java/mouamle/keyboard/bot/model/Data.java b/src/test/java/mouamle/keyboard/bot/model/Data.java index b23f243..ac79571 100644 --- a/src/test/java/mouamle/keyboard/bot/model/Data.java +++ b/src/test/java/mouamle/keyboard/bot/model/Data.java @@ -9,7 +9,7 @@ public class Data { @IntValue(key = "Age") private int age; - @StringValue(key = "Color", values = {"r", "g", "b", "a"}) + @StringValue(key = "Color", values = {"r", "g", "b", "a"}, orientation = StringValue.Vertical) private String color; @IntValue(key = "Size")