mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-07-18 12:04:03 -04:00
Added two new scroll bar types. Fixed for ListView with equal height elements and PreRendered which require whole list render - not recommended for big lists but works with not equal heights elements. Applied new types to all lists in Pure. Various cleanups and refactors inside models and listView.
97 lines
3.3 KiB
C++
97 lines
3.3 KiB
C++
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
|
|
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
|
|
|
|
#include "EventDetailWindow.hpp"
|
|
#include "InputEvent.hpp"
|
|
#include "application-calendar/widgets/CalendarStyle.hpp"
|
|
#include "module-apps/application-calendar/data/CalendarData.hpp"
|
|
#include <gui/widgets/Window.hpp>
|
|
#include <time/time_conversion.hpp>
|
|
|
|
namespace gui
|
|
{
|
|
|
|
EventDetailWindow::EventDetailWindow(app::Application *app, std::string name)
|
|
: AppWindow(app, style::window::calendar::name::details_window), eventDetailModel{
|
|
std::make_shared<EventDetailModel>(app)}
|
|
{
|
|
buildInterface();
|
|
}
|
|
|
|
void EventDetailWindow::rebuild()
|
|
{
|
|
erase();
|
|
buildInterface();
|
|
}
|
|
|
|
void EventDetailWindow::buildInterface()
|
|
{
|
|
AppWindow::buildInterface();
|
|
|
|
bottomBar->setActive(gui::BottomBar::Side::RIGHT, true);
|
|
bottomBar->setActive(gui::BottomBar::Side::LEFT, true);
|
|
bottomBar->setText(gui::BottomBar::Side::RIGHT, utils::localize.get(style::strings::common::back));
|
|
bottomBar->setText(gui::BottomBar::Side::LEFT, utils::localize.get(style::strings::common::options));
|
|
|
|
bodyList = new gui::ListView(this,
|
|
style::window::calendar::listView_x,
|
|
style::window::calendar::listView_y,
|
|
style::window::calendar::listView_w,
|
|
style::window::calendar::listView_h,
|
|
eventDetailModel,
|
|
style::listview::ScrollBarType::PreRendered);
|
|
|
|
setFocusItem(bodyList);
|
|
}
|
|
|
|
void EventDetailWindow::onBeforeShow(gui::ShowMode mode, gui::SwitchData *data)
|
|
{
|
|
if (mode == gui::ShowMode::GUI_SHOW_INIT) {
|
|
bodyList->rebuildList();
|
|
}
|
|
|
|
eventDetailModel->loadData(eventRecord);
|
|
}
|
|
|
|
auto EventDetailWindow::handleSwitchData(SwitchData *data) -> bool
|
|
{
|
|
if (data == nullptr) {
|
|
return false;
|
|
}
|
|
|
|
auto *item = dynamic_cast<EventRecordData *>(data);
|
|
if (item == nullptr) {
|
|
return false;
|
|
}
|
|
|
|
eventRecord = item->getData();
|
|
auto startDate = TimePointToYearMonthDay(eventRecord->date_from);
|
|
std::string monthStr =
|
|
utils::time::Locale::get_month(utils::time::Locale::Month(unsigned(startDate.month()) - 1));
|
|
setTitle(std::to_string(unsigned(startDate.day())) + " " + monthStr);
|
|
|
|
return true;
|
|
}
|
|
|
|
bool EventDetailWindow::onInput(const gui::InputEvent &inputEvent)
|
|
{
|
|
if (AppWindow::onInput(inputEvent)) {
|
|
return true;
|
|
}
|
|
|
|
if (!inputEvent.isShortPress()) {
|
|
return false;
|
|
}
|
|
|
|
if (inputEvent.keyCode == gui::KeyCode::KEY_LF) {
|
|
LOG_DEBUG("Switch to option window");
|
|
auto rec = std::make_unique<EventsRecord>(*eventRecord);
|
|
auto data = std::make_unique<EventRecordData>(std::move(rec));
|
|
application->switchWindow(style::window::calendar::name::events_options, std::move(data));
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
} /* namespace gui */
|