~aleteoryx/muditaos

ref: f361257528674efa640f07170c61638c419fc6bc muditaos/module-apps/application-calllog/windows/CallLogMainWindow.cpp -rw-r--r-- 9.9 KiB
f3612575 — Dawid Wojtas [BH-1933] Perform a deep refresh in settings 1 year, 8 months 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
// Copyright (c) 2017-2023, 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 <DialogMetadata.hpp>
#include <DialogMetadataMessage.hpp>

#include <service-appmgr/Controller.hpp>
#include <queries/calllog/QueryCalllogDeleteAll.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"));

        header->navigationIndicatorAdd((deleteAction = new gui::header::DeleteAction()),
                                       gui::header::BoxSelection::Right);

        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);
        list->setBoundaries(Boundaries::Continuous);
        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->setMargins(gui::Margins(0, MyStyle::infoTopMargin, 0, 0));
        noCallsInfo->setFont(style::window::font::medium);
        noCallsInfo->setEditMode(EditMode::Browse);
        noCallsInfo->setTextType(TextType::SingleLine);
        noCallsInfo->setEdges(RectangleEdge::None);
        noCallsInfo->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));
        noCallsInfo->setRichText(utils::translate("app_calllog_no_calls"));

        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));
        const 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);
        const 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) {
            return false;
        }

        if (notification->interface != db::Interface::Name::Calllog) {
            return false;
        }

        if (notification->type != db::Query::Type::Create && notification->type != db::Query::Type::Update) {
            return false;
        }

        rebuild();
        return true;
    }

    void CallLogMainWindow::onEmptyList()
    {
        header->navigationIndicatorRemove(gui::header::BoxSelection::Right);

        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()
    {
        header->navigationIndicatorAdd((deleteAction = new gui::header::DeleteAction()),
                                       gui::header::BoxSelection::Right);

        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);
    }

    bool CallLogMainWindow::isEmpty() const
    {
        return list->isEmpty();
    }

    bool CallLogMainWindow::onInput(InputEvent const &inputEvent)
    {
        if (inputEvent.getKeyCode() != gui::KeyCode::KEY_RIGHT || !inputEvent.isKeyRelease()) {
            return AppWindow::onInput(inputEvent);
        }

        if (isEmpty()) {
            return false;
        }

        auto dialogMetadata = gui::DialogMetadata{
            utils::translate("app_calllog_delete_all_calls"),
            "delete_128px_W_G",
            utils::translate("app_calllog_delete_all_calls_confirmation"),
            "",
            [&]() -> bool {
                DBServiceAPI::GetQuery(
                    application, db::Interface::Name::Calllog, std::make_unique<db::query::calllog::DeleteAll>());
                app::manager::Controller::sendAction(application, app::manager::actions::ShowCallLog);
                return true;
            }};
        auto metaData = std::make_unique<gui::DialogMetadataMessage>(dialogMetadata);

        application->switchWindow(calllog::settings::DialogYesNoStr, std::move(metaData));
        return false;
    }
} /* namespace gui */