Skip to content
This repository was archived by the owner on Nov 27, 2025. It is now read-only.

Commit 8cabe68

Browse files
committed
Moved inlinekeyboard builders into a separate class
1 parent aabd24b commit 8cabe68

2 files changed

Lines changed: 34 additions & 20 deletions

File tree

src/main/java/com/didanko228/tghealthreminder/handlers/TextHandler.java

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package com.didanko228.tghealthreminder.handlers;
22

3+
import com.didanko228.tghealthreminder.ui.Keyboards;
34
import com.didanko228.tghealthreminder.utils.Logger;
45
import com.didanko228.tghealthreminder.utils.TranslationManager;
56
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
67
import org.telegram.telegrambots.meta.api.objects.message.Message;
7-
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
8-
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.InlineKeyboardButton;
9-
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.InlineKeyboardRow;
108
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
119
import org.telegram.telegrambots.meta.generics.TelegramClient;
1210

@@ -20,14 +18,7 @@ public static void handle(TelegramClient telegramClient, Message msg) {
2018
.builder()
2119
.chatId(chat_id)
2220
.text(TranslationManager.translate("ru_ru", "ru_ru"))
23-
.replyMarkup(InlineKeyboardMarkup
24-
.builder()
25-
.keyboardRow(new InlineKeyboardRow(InlineKeyboardButton
26-
.builder()
27-
.text(TranslationManager.translate("ru_ru", "ru_ru"))
28-
.callbackData("test")
29-
.build()))
30-
.build())
21+
.replyMarkup(Keyboards.getRuKeyboard())
3122
.build();
3223

3324
try {
@@ -41,20 +32,13 @@ else if (text.equals("en")) {
4132
.builder()
4233
.chatId(chat_id)
4334
.text(TranslationManager.translate("en_us", "en_us"))
44-
.replyMarkup(InlineKeyboardMarkup
45-
.builder()
46-
.keyboardRow(new InlineKeyboardRow(InlineKeyboardButton
47-
.builder()
48-
.text(TranslationManager.translate("en_us", "en_us"))
49-
.callbackData("test")
50-
.build()))
51-
.build())
35+
.replyMarkup(Keyboards.getEnKeyboard())
5236
.build();
5337

5438
try {
5539
telegramClient.execute(message);
5640
} catch (TelegramApiException e) {
57-
throw new RuntimeException(e);
41+
Logger.error("Error sending message", e);
5842
}
5943
}
6044
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.didanko228.tghealthreminder.ui;
2+
3+
import com.didanko228.tghealthreminder.utils.TranslationManager;
4+
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
5+
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.InlineKeyboardButton;
6+
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.InlineKeyboardRow;
7+
8+
public class Keyboards {
9+
public static InlineKeyboardMarkup getRuKeyboard() {
10+
return InlineKeyboardMarkup
11+
.builder()
12+
.keyboardRow(new InlineKeyboardRow(InlineKeyboardButton
13+
.builder()
14+
.text(TranslationManager.translate("ru_ru", "ru_ru"))
15+
.callbackData("test")
16+
.build()))
17+
.build();
18+
}
19+
20+
public static InlineKeyboardMarkup getEnKeyboard() {
21+
return InlineKeyboardMarkup
22+
.builder()
23+
.keyboardRow(new InlineKeyboardRow(InlineKeyboardButton
24+
.builder()
25+
.text(TranslationManager.translate("en_us", "en_us"))
26+
.callbackData("test")
27+
.build()))
28+
.build();
29+
}
30+
}

0 commit comments

Comments
 (0)