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();
switch(s) {
case HOBBY:
inlineKeyboardButton.setText(Constants.HOBBY_BTN); inlineKeyboardButton.setText(Constants.HOBBY_BTN);
inlineKeyboardButton.setCallbackData(HashUtils.getCRC32(Constants.HOBBY_BTN.getBytes())); inlineKeyboardButton.setCallbackData(HashUtils.getCRC32(Constants.HOBBY_BTN.getBytes()));
columns.add(Collections.singletonList(inlineKeyboardButton)); columns.add(Collections.singletonList(inlineKeyboardButton));
} break;
if( !infoSections.getIsAgeShowed() ) { case AGE:
InlineKeyboardButton inlineKeyboardButton = new InlineKeyboardButton();
inlineKeyboardButton.setText(Constants.AGE_BTN); inlineKeyboardButton.setText(Constants.AGE_BTN);
inlineKeyboardButton.setCallbackData(HashUtils.getCRC32(Constants.AGE_BTN.getBytes())); inlineKeyboardButton.setCallbackData(HashUtils.getCRC32(Constants.AGE_BTN.getBytes()));
columns.add(Collections.singletonList(inlineKeyboardButton)); columns.add(Collections.singletonList(inlineKeyboardButton));
} break;
if( !infoSections.getIsGenderShowed() ) { case GENDER:
InlineKeyboardButton inlineKeyboardButton = new InlineKeyboardButton();
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;
if( !infoSections.getIsWorkShowed() ) { case WORK:
InlineKeyboardButton inlineKeyboardButton = new InlineKeyboardButton();
inlineKeyboardButton.setText(Constants.WORK_BTN); inlineKeyboardButton.setText(Constants.WORK_BTN);
inlineKeyboardButton.setCallbackData(HashUtils.getCRC32(Constants.WORK_BTN.getBytes())); inlineKeyboardButton.setCallbackData(HashUtils.getCRC32(Constants.WORK_BTN.getBytes()));
columns.add(Collections.singletonList(inlineKeyboardButton)); columns.add(Collections.singletonList(inlineKeyboardButton));
} break;
if( !infoSections.getIsLuggageShowed() ) { case LUGGAGE:
InlineKeyboardButton inlineKeyboardButton = new InlineKeyboardButton();
inlineKeyboardButton.setText(Constants.LUGG_BTN); inlineKeyboardButton.setText(Constants.LUGG_BTN);
inlineKeyboardButton.setCallbackData(HashUtils.getCRC32(Constants.LUGG_BTN.getBytes())); inlineKeyboardButton.setCallbackData(HashUtils.getCRC32(Constants.LUGG_BTN.getBytes()));
columns.add(Collections.singletonList(inlineKeyboardButton)); columns.add(Collections.singletonList(inlineKeyboardButton));
break;
} }
});
inlineKeyboardMarkup.setKeyboard(columns); inlineKeyboardMarkup.setKeyboard(columns);
return inlineKeyboardMarkup; return inlineKeyboardMarkup;
} }