~aleteoryx/muditaos

ref: 29f455d46bbddee9a8f0ea860e84c9b6e5ab38b5 muditaos/module-apps/application-calllog/windows/CallLogMainWindow.cpp -rw-r--r-- 8.0 KiB
29f455d4 — Przemyslaw Brudny [EGD-7998] Pure image assets cleanup and update 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "CallLogMainWindow.hpp"
#include "data/CallLogInternals.hpp"
#include "ApplicationCallLog.hpp"
#include "widgets/CalllogItem.hpp"

#include <service-db/DBCalllogMessage.hpp>
#include <i18n/i18n.hpp>
#include <Label.hpp>
#include <Margins.hpp>
#include <Style.hpp>
#include <InputEvent.hpp>

#include <cassert>
#include <functional>
#include <memory>
#include <service-db/DBNotificationMessage.hpp>

using namespace style;
using namespace callLogStyle;

namespace gui
{

    CallLogMainWindow::CallLogMainWindow(app::ApplicationCommon *app)
        : AppWindow(app, calllog::settings::MainWindowStr), calllogModel{std::make_shared<CalllogModel>(app)}
    {

        buildInterface();
    }

    void CallLogMainWindow::rebuild()
    {
        if (list == nullptr) {
            return;
        }
        list->rebuildList(gui::listview::RebuildType::InPlace);
    }

    void CallLogMainWindow::buildInterface()
    {
        AppWindow::buildInterface();

        setTitle(utils::translate("app_calllog_title_main"));

        navBar->setText(nav_bar::Side::Left, utils::translate(style::strings::common::call));
        navBar->setText(nav_bar::Side::Center, utils::translate(style::strings::common::open));
        navBar->setText(nav_bar::Side::Right, utils::translate(style::strings::common::back));

        list = new gui::ListView(this,
                                 mainWindow::x,
                                 mainWindow::y,
                                 mainWindow::w,
                                 mainWindow::h,
                                 calllogModel,
                                 gui::listview::ScrollBarType::Fixed);

        setFocusItem(list);

        buildInterfaceForEmptyState();

        list->emptyListCallback    = [this]() { onEmptyList(); };
        list->notEmptyListCallback = [this]() { onListFilled(); };
    }

    void CallLogMainWindow::buildInterfaceForEmptyState()
    {
        namespace MyStyle = callLogStyle::detailsWindow::noCalls;
        emptyLayout       = new VBox(this, 0, 0, style::window_width, style::window_height);
        emptyLayout->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Top));

        Text *noCallsInfo = new Text(emptyLayout, 0, 0, 0, 0);
        noCallsInfo->setMinimumSize(mainWindow::w, MyStyle::infoHeight);
        noCallsInfo->setTextType(TextType::SingleLine);
        noCallsInfo->setEditMode(EditMode::Browse);
        noCallsInfo->setEdges(RectangleEdge::None);
        noCallsInfo->setFont(style::window::font::medium);
        noCallsInfo->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));
        noCallsInfo->setRichText(utils::translate("app_calllog_no_calls"));
        noCallsInfo->setMargins(gui::Margins(0, MyStyle::infoTopMargin, 0, 0));

        Rect *divLine = new Rect(emptyLayout, 0, 0, style::window_width, 1);
        divLine->setBorderColor(ColorGrey);
        divLine->setEdges(RectangleEdge::Top);
        divLine->setMargins(gui::Margins(0, MyStyle::divLineTopMargin, 0, 0));

        HBox *noCallsBottom = new HBox(emptyLayout);
        noCallsBottom->setMinimumSize(MyStyle::bottomBoxWidth, MyStyle::bottomBoxHeight);
        noCallsBottom->setEdges(RectangleEdge::None);
        noCallsBottom->setMargins(gui::Margins(0, MyStyle::bottomBoxMargin, 0, 0));
        noCallsBottom->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Left, gui::Alignment::Vertical::Center));

        ImageBox *noCallsImg = new ImageBox(noCallsBottom, new Image("calllog_empty_128px_W_G"));
        noCallsImg->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Left, gui::Alignment::Vertical::Center));
        noCallsImg->setMinimumSizeToFitImage();
        noCallsImg->setMargins(Margins(MyStyle::infoIconMargin, 0, 0, 0));

        VThreeBox<VBox, VBox, VBox> *noCallsIcons = new VThreeBox<VBox, VBox, VBox>(noCallsBottom);
        noCallsIcons->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Center));
        noCallsIcons->setEdges(RectangleEdge::None);
        noCallsIcons->setMinimumSize(MyStyle::descriptionSize, MyStyle::bottomBoxHeight);
        noCallsIcons->setMargins(Margins(MyStyle::descriptionLeftMargin, 0, 0, 0));
        auto imgLambda = [&](const UTF8 imageName) {
            VBox *box = new VBox(noCallsIcons);
            box->setEdges(RectangleEdge::None);
            box->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Center));
            box->setMinimumSize(MyStyle::descriptionSize, MyStyle::descriptionSize);
            box->setMargins(Margins(0, MyStyle::descriptionInternalMargin, 0, MyStyle::descriptionInternalMargin));

            ImageBox *image = new ImageBox(box, new Image(imageName, gui::ImageTypeSpecifier::W_G));
            image->setMinimumSizeToFitImage();
            return box;
        };
        noCallsIcons->firstBox  = imgLambda("calllog_arrow_in");
        noCallsIcons->centerBox = imgLambda("calllog_arrow_out");
        noCallsIcons->lastBox   = imgLambda("calllog_arrow_den");

        VThreeBox<VBox, VBox, VBox> *noCallsDescriptions = new VThreeBox<VBox, VBox, VBox>(noCallsBottom);
        noCallsDescriptions->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Center));
        noCallsDescriptions->setEdges(RectangleEdge::None);
        noCallsDescriptions->setMinimumSize(MyStyle::descriptionTextWidth, MyStyle::bottomBoxHeight);
        auto descLambda = [&](const UTF8 descText) {
            VBox *box = new VBox(noCallsDescriptions);
            box->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Center));
            box->setEdges(RectangleEdge::None);
            box->setMinimumSize(MyStyle::descriptionTextWidth, MyStyle::descriptionSize);
            box->setMargins(Margins(0, MyStyle::descriptionInternalMargin, 0, MyStyle::descriptionInternalMargin));

            Text *desc = new Text(box, 0, 0, 0, 0);
            desc->setMaximumSize(MyStyle::descriptionTextWidth, MyStyle::descriptionSize);
            desc->setEditMode(EditMode::Browse);
            desc->setEdges(RectangleEdge::None);
            desc->setFont(style::window::font::small);
            desc->setRichText(descText);

            return box;
        };
        noCallsDescriptions->firstBox  = descLambda(utils::translate("app_calllog_empty_incoming"));
        noCallsDescriptions->centerBox = descLambda(utils::translate("app_calllog_empty_outgoing"));
        noCallsDescriptions->lastBox   = descLambda(utils::translate("app_calllog_empty_missed"));

        emptyLayout->setVisible(false);
        emptyLayout->resizeItems();
    }

    void CallLogMainWindow::destroyInterface()
    {
        erase();
    }

    void CallLogMainWindow::onBeforeShow(ShowMode mode, SwitchData *data)
    {
        if (mode == ShowMode::GUI_SHOW_INIT) {
            list->rebuildList();
        }
        auto app = dynamic_cast<app::ApplicationCallLog *>(application);
        assert(app != nullptr);
        app->setAllEntriesRead();
    }

    bool CallLogMainWindow::onDatabaseMessage(sys::Message *msg)
    {
        auto notification = dynamic_cast<db::NotificationMessage *>(msg);
        if (notification != nullptr) {
            if (notification->interface == db::Interface::Name::Calllog && notification->dataModified()) {
                rebuild();
                return true;
            }
        }
        return false;
    }

    void CallLogMainWindow::onEmptyList()
    {
        navBar->setActive(gui::nav_bar::Side::Left, false);
        navBar->setActive(gui::nav_bar::Side::Center, false);
        emptyLayout->setVisible(true);
        application->refreshWindow(gui::RefreshModes::GUI_REFRESH_DEEP);
    }

    void CallLogMainWindow::onListFilled()
    {
        navBar->setActive(gui::nav_bar::Side::Left, true);
        navBar->setActive(gui::nav_bar::Side::Center, true);
        emptyLayout->setVisible(false);
        application->refreshWindow(gui::RefreshModes::GUI_REFRESH_DEEP);
    }
} /* namespace gui */