MobileMkch/ui/add_comment_screen.go

108 lines
3.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package ui
import (
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
)
type AddCommentScreen struct {
uiManager *UIManager
content *fyne.Container
boardCode string
threadID int
}
func NewAddCommentScreen(uiManager *UIManager, boardCode string, threadID int) *AddCommentScreen {
acs := &AddCommentScreen{
uiManager: uiManager,
boardCode: boardCode,
threadID: threadID,
content: container.NewVBox(),
}
acs.setupContent()
return acs
}
func (acs *AddCommentScreen) setupContent() {
acs.content.Objects = nil
titleLabel := widget.NewLabel(fmt.Sprintf("Добавить комментарий в тред %d /%s/", acs.threadID, acs.boardCode))
titleLabel.TextStyle = fyne.TextStyle{Bold: true}
acs.content.Add(titleLabel)
textEntry := widget.NewMultiLineEntry()
textEntry.SetPlaceHolder("Текст комментария")
textEntry.Resize(fyne.NewSize(300, 200))
acs.content.Add(textEntry)
passcode := acs.uiManager.GetPasscode()
if passcode != "" {
passcodeLabel := widget.NewLabel("Passcode настроен")
passcodeLabel.TextStyle = fyne.TextStyle{Bold: true}
acs.content.Add(passcodeLabel)
} else {
passcodeLabel := widget.NewLabel("Passcode не настроен - постинг может быть\nограничен и могут быть неожиданные ПРОБЛЕЕМЫ\n(подробнее в настройках)")
passcodeLabel.TextStyle = fyne.TextStyle{Bold: true}
acs.content.Add(passcodeLabel)
}
buttonsContainer := container.NewHBox()
addButton := widget.NewButton("Добавить комментарий", func() {
text := textEntry.Text
if text == "" {
acs.uiManager.ShowError("Ошибка", "Текст не может быть пустым")
return
}
acs.uiManager.ShowInfo("Добавление комментария", "Отправляем комментарий...")
passcode := acs.uiManager.GetPasscode()
err := acs.uiManager.GetAPIClient().AddComment(acs.boardCode, acs.threadID, text, passcode)
if err != nil {
acs.uiManager.ShowError("Ошибка", fmt.Sprintf("Не удалось добавить комментарий: %v", err))
return
}
acs.uiManager.ClearCacheForThread(acs.threadID)
acs.uiManager.ShowInfo("Успех", "Комментарий добавлен успешно!")
acs.uiManager.GoBack()
if threadDetailScreen, ok := acs.uiManager.GetCurrentScreen().(*ThreadDetailScreen); ok {
threadDetailScreen.RefreshThread()
}
})
cancelButton := widget.NewButton("Отмена", func() {
acs.uiManager.GoBack()
})
buttonsContainer.Add(addButton)
buttonsContainer.Add(cancelButton)
acs.content.Add(buttonsContainer)
acs.content.Refresh()
}
func (acs *AddCommentScreen) GetContent() fyne.CanvasObject {
return acs.content
}
func (acs *AddCommentScreen) GetTitle() string {
return fmt.Sprintf("Комментарий в тред %d", acs.threadID)
}
func (acs *AddCommentScreen) OnShow() {
acs.setupContent()
}
func (acs *AddCommentScreen) OnHide() {
// Ничего не делаем при скрытии
}