~aleteoryx/muditaos

ref: 3cc3f50f7b9364ffac38349238cd6d9aa243dc23 muditaos/module-apps/apps-common/popups/presenter/WallpaperPresenter.cpp -rw-r--r-- 3.1 KiB
3cc3f50f — Maciej Gibowicz [BH-1809][BH-1835] Add date format setting 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "WallpaperPresenter.hpp"
#include <service-appmgr/ServiceApplicationManagerName.hpp>

namespace gui
{
    WallpaperPresenter::WallpaperPresenter(app::ApplicationCommon *app)
        : AsyncCallbackReceiver(app), application(app),
          notificationsModel(std::make_shared<NotificationsModel>(NotificationsListPlacement::LockedScreen))
    {}

    void WallpaperPresenter::setupWallpaper(Item *parent)
    {
        buildWallpapers(parent);

        auto request = std::make_unique<app::manager::GetWallpaperOptionRequest>();
        auto task    = app::AsyncRequest::createFromMessage(std::move(request), service::name::appmgr);
        auto cb      = [&](auto response) {
            auto result = dynamic_cast<app::manager::GetWallpaperOptionResponse *>(response);
            if (!clockWallpaperForced) {
                switchWallpaper(result->getWallpaperOption());
            }
            selectedOption = result->getWallpaperOption();
            return true;
        };
        task->execute(application, this, cb);
    }

    void WallpaperPresenter::switchWallpaper(WallpaperOption option)
    {
        switch (option) {
        case WallpaperOption::Clock:
            notificationsModel->attachPresenter(clockWallpaper->getNotificationsPresenter());
            clockWallpaper->show();
            quoteWallpaper->hide();
            logoWallpaper->hide();
            break;
        case WallpaperOption::Quote:
            notificationsModel->attachPresenter(quoteWallpaper->getNotificationsPresenter());
            clockWallpaper->hide();
            quoteWallpaper->show();
            logoWallpaper->hide();
            break;
        case WallpaperOption::Logo:
            notificationsModel->attachPresenter(logoWallpaper->getNotificationsPresenter());
            clockWallpaper->hide();
            quoteWallpaper->hide();
            logoWallpaper->show();
            break;
        }
    }

    void WallpaperPresenter::buildWallpapers(Item *parent)
    {
        clockWallpaper = std::make_shared<WallpaperClock>(parent);
        quoteWallpaper = std::make_shared<WallpaperQuote>(application, parent);
        logoWallpaper  = std::make_shared<WallpaperLogo>(parent);
    }

    std::shared_ptr<gui::NotificationsModel> WallpaperPresenter::getNotificationsModel()
    {
        return notificationsModel;
    }

    bool WallpaperPresenter::updateWallpaper()
    {
        if (selectedOption == WallpaperOption::Clock || clockWallpaperForced) {
            if (clockWallpaper) {
                clockWallpaper->updateTime();
            }
            return true;
        }
        return false;
    }

    void WallpaperPresenter::forceClockWallpaper()
    {
        switchWallpaper(WallpaperOption::Clock);
        clockWallpaperForced = true;
    }

    bool WallpaperPresenter::switchBackWallpaper()
    {
        if (clockWallpaperForced) {
            clockWallpaperForced = false;
            switchWallpaper(selectedOption);
            return true;
        }
        else {
            return false;
        }
    }

} // namespace gui