Refactoring stuff x3

This commit is contained in:
Michael Wain 2024-07-04 20:34:19 +03:00
parent cc55257cd4
commit aa3d778026

View File

@ -2,6 +2,7 @@ package com.alterdekim.javabot.util;
import com.alterdekim.javabot.Constants; import com.alterdekim.javabot.Constants;
import com.alterdekim.javabot.bot.InfoSections; import com.alterdekim.javabot.bot.InfoSections;
import com.alterdekim.javabot.bot.SectionType;
import com.alterdekim.javabot.components.RandomComponent; import com.alterdekim.javabot.components.RandomComponent;
import com.alterdekim.javabot.entities.ActionScript; import com.alterdekim.javabot.entities.ActionScript;
import com.alterdekim.javabot.service.TextDataValService; import com.alterdekim.javabot.service.TextDataValService;
@ -35,42 +36,43 @@ public class BotUtils {
public static InlineKeyboardMarkup getShowKeyboard(InfoSections infoSections) { public static InlineKeyboardMarkup getShowKeyboard(InfoSections infoSections) {
InlineKeyboardMarkup inlineKeyboardMarkup = new InlineKeyboardMarkup(); InlineKeyboardMarkup inlineKeyboardMarkup = new InlineKeyboardMarkup();
List<List<InlineKeyboardButton>> columns = new ArrayList<>(); List<List<InlineKeyboardButton>> columns = new ArrayList<>();
if( !infoSections.getIsHobbyShowed() ) { List<SectionType> sectionTypes = Arrays.asList(SectionType.values());
infoSections.getSections().forEach(s -> sectionTypes.remove(s.getType()));
sectionTypes.forEach(s -> {
InlineKeyboardButton inlineKeyboardButton = new InlineKeyboardButton(); InlineKeyboardButton inlineKeyboardButton = new InlineKeyboardButton();
inlineKeyboardButton.setText(Constants.HOBBY_BTN); switch(s) {
inlineKeyboardButton.setCallbackData(HashUtils.getCRC32(Constants.HOBBY_BTN.getBytes())); case HOBBY:
columns.add(Collections.singletonList(inlineKeyboardButton)); inlineKeyboardButton.setText(Constants.HOBBY_BTN);
} inlineKeyboardButton.setCallbackData(HashUtils.getCRC32(Constants.HOBBY_BTN.getBytes()));
if( !infoSections.getIsAgeShowed() ) { columns.add(Collections.singletonList(inlineKeyboardButton));
InlineKeyboardButton inlineKeyboardButton = new InlineKeyboardButton(); break;
inlineKeyboardButton.setText(Constants.AGE_BTN); case AGE:
inlineKeyboardButton.setCallbackData(HashUtils.getCRC32(Constants.AGE_BTN.getBytes())); inlineKeyboardButton.setText(Constants.AGE_BTN);
columns.add(Collections.singletonList(inlineKeyboardButton)); inlineKeyboardButton.setCallbackData(HashUtils.getCRC32(Constants.AGE_BTN.getBytes()));
} columns.add(Collections.singletonList(inlineKeyboardButton));
if( !infoSections.getIsGenderShowed() ) { break;
InlineKeyboardButton inlineKeyboardButton = new InlineKeyboardButton(); case GENDER:
inlineKeyboardButton.setText(Constants.GENDER_BTN); inlineKeyboardButton.setText(Constants.GENDER_BTN);
inlineKeyboardButton.setCallbackData(HashUtils.getCRC32(Constants.GENDER_BTN.getBytes())); inlineKeyboardButton.setCallbackData(HashUtils.getCRC32(Constants.GENDER_BTN.getBytes()));
columns.add(Collections.singletonList(inlineKeyboardButton)); columns.add(Collections.singletonList(inlineKeyboardButton));
} break;
if( !infoSections.getIsHealthShowed() ) { case HEALTH:
InlineKeyboardButton inlineKeyboardButton = new InlineKeyboardButton(); inlineKeyboardButton.setText(Constants.HEALTH_BTN);
inlineKeyboardButton.setText(Constants.HEALTH_BTN); inlineKeyboardButton.setCallbackData(HashUtils.getCRC32(Constants.HEALTH_BTN.getBytes()));
inlineKeyboardButton.setCallbackData(HashUtils.getCRC32(Constants.HEALTH_BTN.getBytes())); columns.add(Collections.singletonList(inlineKeyboardButton));
columns.add(Collections.singletonList(inlineKeyboardButton)); break;
} case WORK:
if( !infoSections.getIsWorkShowed() ) { inlineKeyboardButton.setText(Constants.WORK_BTN);
InlineKeyboardButton inlineKeyboardButton = new InlineKeyboardButton(); inlineKeyboardButton.setCallbackData(HashUtils.getCRC32(Constants.WORK_BTN.getBytes()));
inlineKeyboardButton.setText(Constants.WORK_BTN); columns.add(Collections.singletonList(inlineKeyboardButton));
inlineKeyboardButton.setCallbackData(HashUtils.getCRC32(Constants.WORK_BTN.getBytes())); break;
columns.add(Collections.singletonList(inlineKeyboardButton)); case LUGGAGE:
} inlineKeyboardButton.setText(Constants.LUGG_BTN);
if( !infoSections.getIsLuggageShowed() ) { inlineKeyboardButton.setCallbackData(HashUtils.getCRC32(Constants.LUGG_BTN.getBytes()));
InlineKeyboardButton inlineKeyboardButton = new InlineKeyboardButton(); columns.add(Collections.singletonList(inlineKeyboardButton));
inlineKeyboardButton.setText(Constants.LUGG_BTN); break;
inlineKeyboardButton.setCallbackData(HashUtils.getCRC32(Constants.LUGG_BTN.getBytes())); }
columns.add(Collections.singletonList(inlineKeyboardButton)); });
}
inlineKeyboardMarkup.setKeyboard(columns); inlineKeyboardMarkup.setKeyboard(columns);
return inlineKeyboardMarkup; return inlineKeyboardMarkup;
} }