From 41b6df457c3c674b40539ea4e36b202bb49f6bc3 Mon Sep 17 00:00:00 2001 From: Adam Dobrowolski Date: Mon, 9 Dec 2019 10:08:55 +0100 Subject: [PATCH] [EGD-2392] SMS Feed window added --- .../ApplicationMessages.cpp | 6 +- .../widgets/ThreadModel.cpp | 21 +- .../windows/ThreadViewWindow.cpp | 203 +++++++++++++----- .../windows/ThreadViewWindow.hpp | 59 +++-- module-gui/gui/widgets/Alignment.cpp | 8 +- module-gui/gui/widgets/Alignment.hpp | 3 +- module-gui/gui/widgets/Label.cpp | 11 + module-gui/gui/widgets/Label.hpp | 41 +++- module-gui/gui/widgets/Rect.cpp | 1 + module-gui/gui/widgets/Style.cpp | 1 + module-gui/gui/widgets/Style.hpp | 11 +- 11 files changed, 270 insertions(+), 95 deletions(-) diff --git a/module-apps/application-messages/ApplicationMessages.cpp b/module-apps/application-messages/ApplicationMessages.cpp index 061f88bb7..d91f957dd 100644 --- a/module-apps/application-messages/ApplicationMessages.cpp +++ b/module-apps/application-messages/ApplicationMessages.cpp @@ -12,6 +12,7 @@ #include "windows/MessagesMainWindow.hpp" #include "ApplicationMessages.hpp" +#include "windows/ThreadViewWindow.hpp" namespace app { @@ -79,9 +80,8 @@ void ApplicationMessages::createUserInterface() { gui::AppWindow *window = nullptr; window = new gui::MessagesMainWindow(this); - windows.insert( - std::pair(window->getName(), window)); - + windows.insert(std::pair(window->getName(), window)); + windows.insert({gui::name::window::thread_view, new gui::ThreadViewWindow(this)}); } void ApplicationMessages::destroyUserInterface() { diff --git a/module-apps/application-messages/widgets/ThreadModel.cpp b/module-apps/application-messages/widgets/ThreadModel.cpp index d8208c839..bb5e68c34 100644 --- a/module-apps/application-messages/widgets/ThreadModel.cpp +++ b/module-apps/application-messages/widgets/ThreadModel.cpp @@ -11,6 +11,7 @@ #include "Application.hpp" #include "../MessagesStyle.hpp" +#include "../windows/ThreadViewWindow.hpp" // for name of window #include "service-db/api/DBServiceAPI.hpp" ThreadModel::ThreadModel(app::Application *app) : @@ -55,11 +56,19 @@ gui::ListItem* ThreadModel::getItem(int index, int fistElement, int prevElement, if (item != nullptr) { item->setThreadItem(thread); item->setID(index); - item->activatedCallback = [=](gui::Item &item) { - LOG_INFO("ThreadItem ActivatedCallback"); - return true; - }; - return item; - } + item->activatedCallback = [=](gui::Item &item) { + LOG_INFO("ThreadItem ActivatedCallback"); + if (application) + { + application->switchWindow(gui::name::window::thread_view, nullptr); + } + else + { + LOG_ERROR("No application!"); + } + return true; + }; + return item; + } return nullptr; } diff --git a/module-apps/application-messages/windows/ThreadViewWindow.cpp b/module-apps/application-messages/windows/ThreadViewWindow.cpp index e722a4f08..d867fa20f 100644 --- a/module-apps/application-messages/windows/ThreadViewWindow.cpp +++ b/module-apps/application-messages/windows/ThreadViewWindow.cpp @@ -27,68 +27,175 @@ #include "../widgets/ThreadModel.hpp" +#include +#include +#include +#include -namespace gui { - -ThreadViewWindow::ThreadViewWindow(app::Application *app) : - AppWindow(app, "ThreadViewWindow") -// phonebookModel{ new PhonebookModel(app)} +namespace gui { - setSize(480, 600); - buildInterface(); + class LolListItem : public gui::ListItem + { + gui::Label *body = nullptr; -} + public: + LolListItem(int i = 0) + { + { // copied from ThreadItem + minWidth = 431; + minHeight = 100; + maxWidth = 431; + maxHeight = 100; + setRadius(0); + setEdges(RectangleEdgeFlags::GUI_RECT_EDGE_BOTTOM | RectangleEdgeFlags::GUI_RECT_EDGE_TOP); + setPenWidth(0); + setPenFocusWidth(2); + } -void ThreadViewWindow::rebuild() { - destroyInterface(); - buildInterface(); -} -void ThreadViewWindow::buildInterface() { + setID(i); + body = new gui::Label(this, gui::meta::Label({0, 0, 0, 0})); + body->setText("Text: " + std::to_string(i)); + } - AppWindow::buildInterface(); + // this won't work - copying label and other crap + LolListItem(const LolListItem &) = default; -// list = new gui::PhonebookListView(this, 11, 105, 480-22, 600-105-50 ); -// list->setMaxElements(7); -// list->setPageSize(7); -// list->setPenFocusWidth(0); -// list->setPenWidth(0); -// list->setProvider( phonebookModel ); -// list->setApplication( application ); + bool onDimensionChanged(const gui::BoundingBox &oldDim, const gui::BoundingBox &newDim) override + { + LOG_INFO("Dim changed! %s : %d", body->getText().c_str(), getID()); + LOG_INFO("%x", body); + body->setPosition(newDim.x, newDim.y); + body->setSize(newDim.w, newDim.h); + return true; + } - bottomBar->setActive(BottomBar::Side::LEFT, true); - bottomBar->setActive(BottomBar::Side::CENTER, true); - bottomBar->setActive(BottomBar::Side::RIGHT, true); - bottomBar->setText(BottomBar::Side::LEFT, utils::localize.get("common_options")); - bottomBar->setText(BottomBar::Side::CENTER, utils::localize.get("common_open")); - bottomBar->setText(BottomBar::Side::RIGHT, utils::localize.get("common_back")); + virtual bool onFocus(bool state) override + { + ListItem::onFocus(state); + LOG_INFO("Focus changed for! %s", body->getText().c_str()); + return true; + } + }; +}; // namespace gui - topBar->setActive(TopBar::Elements::TIME, true); +class Provider : public gui::ListItemProvider +{ + std::map items; - setTitle(utils::localize.get("app_messages_title_main")); -} -void ThreadViewWindow::destroyInterface() { - AppWindow::destroyInterface(); - children.clear(); -} + public: + Provider(app::Application *app) + { + } -ThreadViewWindow::~ThreadViewWindow() { - destroyInterface(); -} + virtual ~Provider() = default; + gui::ListItem *getItem(int index, int firstElement, int prevIndex, uint32_t count, int remaining, bool topDown) override + { + LOG_INFO("getItem"); + if (index > getItemCount()) + { + return nullptr; + } + if (items.find(index) == items.end()) + { + items[index] = new gui::LolListItem(index); + } + // copy as getItem will push element onto list with parent.. + return new gui::LolListItem(*items[index]); + } -void ThreadViewWindow::onBeforeShow(ShowMode mode, SwitchData *data) { -} + int getItemCount() const override + { + return 11; + }; +}; -bool ThreadViewWindow::onInput(const InputEvent &inputEvent) { - return AppWindow::onInput( inputEvent ); -} +namespace gui +{ -bool ThreadViewWindow::onDatabaseMessage( sys::Message* msgl ) { -// DBContactResponseMessage* msg = reinterpret_cast( msgl ); -// if( phonebookModel->updateRecords( std::move(msg->records), msg->offset, msg->limit, msg->count, msg->favourite ) ) -// return true; + ThreadViewWindow::ThreadViewWindow(app::Application *app) : AppWindow(app, name::window::thread_view) + { + AppWindow::buildInterface(); + setTitle(utils::localize.get("app_messages_title_main")); + topBar->setActive(TopBar::Elements::TIME, true); + bottomBar->setActive(BottomBar::Side::LEFT, true); + bottomBar->setActive(BottomBar::Side::CENTER, true); + bottomBar->setActive(BottomBar::Side::RIGHT, true); + bottomBar->setText(BottomBar::Side::LEFT, utils::localize.get("common_options")); + bottomBar->setText(BottomBar::Side::CENTER, utils::localize.get("common_send")); + bottomBar->setText(BottomBar::Side::RIGHT, utils::localize.get("common_back")); + body = new gui::VBox(this, 0, title->offset_h(), this->getWidth(), bottomBar->getY() - title->offset_h()); + body->setPenWidth(0); + body->setPenFocusWidth(0); - return false; -} + // dummy new text + auto text = new gui::Text(nullptr, 0, 0, 480, 100, "", gui::Text::ExpandMode::EXPAND_UP); + text->setInputMode(new InputMode({InputMode::ABC, InputMode::abc})); + text->setPenFocusWidth(2); + text->setPenWidth(2); + text->setEdges(gui::RectangleEdgeFlags::GUI_RECT_EDGE_BOTTOM); + body->tryAddWidget(text); + + /// dummy sms thread - TODO TODO load from db + /// this is not 'static' do it on window focus (on swtich window) + auto labelmeta = gui::meta::Label({0, 0, 480, 100}); + labelmeta.edges = RectangleEdgeFlags::GUI_RECT_ALL_EDGES; + labelmeta.radius = 3; + labelmeta.focus = 3; + labelmeta.no_focus = 1; + auto label = new gui::Label(nullptr, labelmeta); + label->setText("Dummy text"); + body->tryAddWidget(label); + label = new gui::Label(nullptr, gui::meta::Label({0, 0, 480, 100})); + label->setText("Dummy text2"); + body->tryAddWidget(label); + label = new gui::Label(nullptr, gui::meta::Label({0, 0, 480, 100})); + label->setText("Dummy text3"); + body->tryAddWidget(label); + + /// setup + body->setReverseOrder(true); + body->setVisible(true); + setFocusItem(body); + } + + void ThreadViewWindow::rebuild() + { + destroyInterface(); + buildInterface(); + } + + void ThreadViewWindow::buildInterface() + { + } + + void ThreadViewWindow::destroyInterface() + { + AppWindow::destroyInterface(); + children.clear(); + } + + ThreadViewWindow::~ThreadViewWindow() + { + destroyInterface(); + } + + void ThreadViewWindow::onBeforeShow(ShowMode mode, SwitchData *data) + { + } + + bool ThreadViewWindow::onInput(const InputEvent &inputEvent) + { + return AppWindow::onInput(inputEvent); + } + + bool ThreadViewWindow::onDatabaseMessage(sys::Message *msgl) + { + // DBContactResponseMessage* msg = reinterpret_cast( msgl ); + // if( phonebookModel->updateRecords( std::move(msg->records), msg->offset, msg->limit, msg->count, msg->favourite ) ) + // return true; + + return false; + } } /* namespace gui */ diff --git a/module-apps/application-messages/windows/ThreadViewWindow.hpp b/module-apps/application-messages/windows/ThreadViewWindow.hpp index e7ecdb61d..9fe94c552 100644 --- a/module-apps/application-messages/windows/ThreadViewWindow.hpp +++ b/module-apps/application-messages/windows/ThreadViewWindow.hpp @@ -1,47 +1,44 @@ -/* - * @file ThreadViewWindow.hpp - * @author Robert Borzecki (robert.borzecki@mudita.com) - * @date 25 wrz 2019 - * @brief - * @copyright Copyright (C) 2019 mudita.com - * @details - */ -#ifndef MODULE_APPS_APPLICATION_MESSAGES_WINDOWS_THREADVIEWWINDOW_HPP_ -#define MODULE_APPS_APPLICATION_MESSAGES_WINDOWS_THREADVIEWWINDOW_HPP_ +#pragma once #include #include #include "AppWindow.hpp" +#include "ListView.hpp" #include "gui/widgets/Image.hpp" #include "gui/widgets/Label.hpp" #include "gui/widgets/Window.hpp" -#include "ListView.hpp" +#include -namespace gui { +namespace gui +{ -/* - * - */ -class ThreadViewWindow: public AppWindow { -public: - ThreadViewWindow(app::Application *app); - virtual ~ThreadViewWindow(); + namespace name + { + namespace window + { + inline std::string thread_view = "ThreadViewWindow"; + }; + }; // namespace name - // virtual methods - bool onInput(const InputEvent &inputEvent) override; - void onBeforeShow(ShowMode mode, SwitchData *data) override; + class ThreadViewWindow : public AppWindow + { + private: + gui::VBox *body = nullptr; - bool onDatabaseMessage( sys::Message* msgl ) override; + public: + ThreadViewWindow(app::Application *app); + virtual ~ThreadViewWindow(); - void rebuild() override; - void buildInterface() override; - void destroyInterface() override; + // virtual methods + bool onInput(const InputEvent &inputEvent) override; + void onBeforeShow(ShowMode mode, SwitchData *data) override; -private: - ListView* list; -}; + bool onDatabaseMessage(sys::Message *msgl) override; + + void rebuild() override; + void buildInterface() override; + void destroyInterface() override; + }; } /* namespace gui */ - -#endif /* MODULE_APPS_APPLICATION_MESSAGES_WINDOWS_THREADVIEWWINDOW_HPP_ */ diff --git a/module-gui/gui/widgets/Alignment.cpp b/module-gui/gui/widgets/Alignment.cpp index edd01d48c..06b944203 100644 --- a/module-gui/gui/widgets/Alignment.cpp +++ b/module-gui/gui/widgets/Alignment.cpp @@ -13,8 +13,12 @@ Alignment::Alignment() : alignment{Alignment::ALIGN_HORIZONTAL_LEFT | ALIGN_VERTICAL_TOP } { } -Alignment::Alignment( const uint32_t valH, const uint32_t valV ) : - alignment {valH | valV} { +Alignment::Alignment(const uint32_t align) : alignment{align} +{ +} + +Alignment::Alignment(const uint32_t valH, const uint32_t valV) : Alignment(valH | valV) +{ } Alignment::~Alignment() { diff --git a/module-gui/gui/widgets/Alignment.hpp b/module-gui/gui/widgets/Alignment.hpp index ebcbc4d86..dde85f757 100644 --- a/module-gui/gui/widgets/Alignment.hpp +++ b/module-gui/gui/widgets/Alignment.hpp @@ -25,7 +25,8 @@ public: Alignment(); Alignment( const uint32_t valH, const uint32_t valV ); - virtual ~Alignment(); + Alignment(const uint32_t align); + virtual ~Alignment(); bool setHorizontal( const uint32_t val ); bool setVertical( const uint32_t val ); diff --git a/module-gui/gui/widgets/Label.cpp b/module-gui/gui/widgets/Label.cpp index d52e10f05..595fa75dc 100644 --- a/module-gui/gui/widgets/Label.cpp +++ b/module-gui/gui/widgets/Label.cpp @@ -40,6 +40,17 @@ Label::Label( Item* parent, const uint32_t& x, const uint32_t& y, const uint32_t setFont(style::window::font::medium); } +Label::Label(Item *parent, meta::Label label) : Label(parent, label.x, label.y, label.w, label.h, label.text) +{ + setPenFocusWidth(label.focus); + setPenWidth(label.no_focus); + setFont(label.font); + setDotsMode(label.dots); + setAlignement(label.align); + setRadius(label.radius); + setEdges(label.edges); +} + Label::~Label() { } diff --git a/module-gui/gui/widgets/Label.hpp b/module-gui/gui/widgets/Label.hpp index aa7e63509..5f3f98140 100644 --- a/module-gui/gui/widgets/Label.hpp +++ b/module-gui/gui/widgets/Label.hpp @@ -20,10 +20,48 @@ #include "Alignment.hpp" #include "Rect.hpp" +#include "Style.hpp" #include "utf8/UTF8.hpp" namespace gui { + namespace meta + { + struct Meta + { + }; + + struct Item : public Meta + { + uint32_t radius = 0; + }; + + struct Rect : public Item + { + Rect &operator()(std::array xywh) + { + x = xywh[0], y = xywh[1], w = xywh[2], h = xywh[3]; + return *this; + } + uint32_t x = 0, y = 0, w = 0, h = 0; + int32_t no_focus = style::window::default_border_no_focus_w; + int32_t focus = style::window::default_border_no_focus_w; + std::string font = style::window::font::medium; + bool dots = true; + uint32_t align = gui::Alignment::ALIGN_HORIZONTAL_LEFT | gui::Alignment::ALIGN_VERTICAL_CENTER; + RectangleEdgeFlags edges = gui::RectangleEdgeFlags::GUI_RECT_EDGE_TOP | gui::RectangleEdgeFlags::GUI_RECT_EDGE_BOTTOM; + }; + + struct Label : public Rect + { + const UTF8 text; + Label(std::array xywh) + { + operator()(xywh); + } + }; + }; // namespace meta + class Label: public Rect { protected: UTF8 text; @@ -59,8 +97,9 @@ protected: public: Label(); Label( Item* parent, const uint32_t& x, const uint32_t& y, const uint32_t& w, const uint32_t& h, const UTF8& text = UTF8{} ); + Label(Item *parent, meta::Label label); - virtual ~Label(); + virtual ~Label(); //Label's specific methods virtual void setText( const UTF8& text ); virtual void clear(); diff --git a/module-gui/gui/widgets/Rect.cpp b/module-gui/gui/widgets/Rect.cpp index 9eae80144..d54746832 100644 --- a/module-gui/gui/widgets/Rect.cpp +++ b/module-gui/gui/widgets/Rect.cpp @@ -37,6 +37,7 @@ Rect::Rect(Item *parent, const uint32_t &x, const uint32_t &y, const uint32_t &w { parent->addWidget(this); } + setPosition(x, y); setSize(w, h); setMaxSize(w, h); diff --git a/module-gui/gui/widgets/Style.cpp b/module-gui/gui/widgets/Style.cpp index f8b583157..5a0df4fc6 100644 --- a/module-gui/gui/widgets/Style.cpp +++ b/module-gui/gui/widgets/Style.cpp @@ -1,4 +1,5 @@ #include "Style.hpp" +#include namespace style::window { diff --git a/module-gui/gui/widgets/Style.hpp b/module-gui/gui/widgets/Style.hpp index b211480ab..2bdaa1690 100644 --- a/module-gui/gui/widgets/Style.hpp +++ b/module-gui/gui/widgets/Style.hpp @@ -1,9 +1,14 @@ #pragma once -#include -#include -#include #include +#include +#include +#include + +namespace gui +{ + class Label; +}; namespace style { const inline uint32_t window_height = 600;