~aleteoryx/muditaos

ref: 5cfd688f510cc32a965d5cb1f052d7025d1d84a3 muditaos/module-apps/application-calllog/widgets/CalllogItem.cpp -rw-r--r-- 3.3 KiB
5cfd688f — Lefucjusz [MOS-1043] Enable VoLTE only for Poland and US 2 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
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "CalllogItem.hpp"
#include "data/CallLogInternals.hpp"
#include <time/time_conversion_factory.hpp>
#include <gui/widgets/BoxLayout.hpp>

#include <Style.hpp>

namespace gui
{
    CalllogItem::CalllogItem(CalllogModel *model) : model{model}
    {
        setMargins(Margins(0, clItemStyle::top_margin, 0, 0));
        setMinimumSize(clItemStyle::w, clItemStyle::h);
        setEdges(RectangleEdge::Bottom | RectangleEdge::Top);

        hBox = new gui::HBox(this, 0, 0, 0, 0);
        hBox->setEdges(gui::RectangleEdge::None);
        hBox->setPenFocusWidth(style::window::default_border_focus_w);
        hBox->setPenWidth(style::window::default_border_rect_no_focus);

        auto newImg = [=](const UTF8 &imageName) -> gui::Image * {
            auto img = new gui::Image(hBox, imageName, gui::ImageTypeSpecifier::W_M);
            img->setAlignment(gui::Alignment{gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center});
            img->setMargins(Margins(0, 0, clItemStyle::internal_margin, 0));
            img->setVisible(false);
            return img;
        };
        imageCallType[calllog::CallLogCallType::IN]     = newImg("calllog_arrow_in");
        imageCallType[calllog::CallLogCallType::OUT]    = newImg("calllog_arrow_out");
        imageCallType[calllog::CallLogCallType::MISSED] = newImg("calllog_arrow_den");

        text = new gui::Label(hBox, 0, 0, 0, 0);
        text->setMinimumHeight(clItemStyle::h);
        text->setMaximumWidth(clItemStyle::w);
        text->setEdges(gui::RectangleEdge::None);
        text->setAlignment(gui::Alignment{gui::Alignment::Horizontal::Left, gui::Alignment::Vertical::Center});
        text->setFont(style::window::font::big);
        text->setTextEllipsisType(TextEllipsis::Right);

        timestamp = new gui::Label(hBox, 0, 0, 0, 0);
        timestamp->setMargins(Margins(0, 0, clItemStyle::right_margin, 0));
        timestamp->setMinimumHeight(clItemStyle::h);
        timestamp->setMinimumWidth(clItemStyle::timestamp::min_w);
        timestamp->setEdges(gui::RectangleEdge::None);
        timestamp->setFont(style::window::font::small);
        timestamp->setAlignment(gui::Alignment{gui::Alignment::Horizontal::Right, gui::Alignment::Vertical::Center});

        dimensionChangedCallback = [&](gui::Item &, const BoundingBox &newDim) -> bool {
            hBox->setArea({0, 0, newDim.w, newDim.h});
            return true;
        };
    }

    void CalllogItem::setCall(std::shared_ptr<CalllogRecord> &call)
    {
        this->call = call;
        if (call->presentation == PresentationType::PR_UNKNOWN) {
            text->setText(utils::translate(callLogStyle::strings::privateNumber));
        }
        else {
            text->setText(call->name);
        }

        auto callType = calllog::toCallLogCallType(call->type);
        if (callType == calllog::CallLogCallType::MISSED) {
            text->setFont(style::window::font::bigbold);
        }

        imageCallType[static_cast<uint32_t>(callType)]->setVisible(true);

        using namespace utils::time;
        timestamp->setText(TimestampFactory().createTimestamp(TimestampType::DateOrTime, call->date)->str());
    }

} /* namespace gui */