~aleteoryx/muditaos

ref: 3e762ab8d4ce987c08425a64d8050342e290fe42 muditaos/module-apps/application-settings/windows/apps/SoundSelectWindow.cpp -rw-r--r-- 2.4 KiB
3e762ab8 — Lefucjusz [MOS-28] Change alarm sounds and ringtones preview behavior 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
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "SoundSelectWindow.hpp"

#include <application-settings/data/SoundSelectData.hpp>
#include <application-settings/models/apps/SoundsModel.hpp>

#include <ListView.hpp>
#include <i18n/i18n.hpp>

namespace gui
{
    SoundSelectWindow::SoundSelectWindow(app::ApplicationCommon *app,
                                         std::string name,
                                         std::shared_ptr<AbstractSoundsModel> model)
        : AppWindow(app, name), mSoundsModel{std::move(model)}
    {
        buildInterface();
    }

    void SoundSelectWindow::rebuild()
    {
        destroyInterface();
        buildInterface();
    }

    void SoundSelectWindow::buildInterface()
    {
        AppWindow::buildInterface();
        navBar->setText(nav_bar::Side::Center, utils::translate(style::strings::common::select));
        navBar->setText(nav_bar::Side::Right, utils::translate(style::strings::common::back));

        mSoundsList = new gui::ListView(this,
                                        style::window::default_left_margin,
                                        style::window::default_vertical_pos - 1,
                                        style::listview::body_width_with_scroll,
                                        style::window_height - style::window::default_vertical_pos + 1 -
                                            style::nav_bar::height + style::margins::small,
                                        mSoundsModel,
                                        listview::ScrollBarType::Proportional);
        mSoundsList->setBoundaries(Boundaries::Continuous);

        setFocusItem(mSoundsList);
    }

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

    void SoundSelectWindow::onBeforeShow([[maybe_unused]] ShowMode mode, SwitchData *data)
    {
        auto info = dynamic_cast<SoundSelectData *>(data);
        if (info == nullptr) {
            LOG_ERROR("Null switch data pointer!");
            return;
        }

        setTitle(info->get().windowTitle);
        mSoundsModel->createData(application, info->get().audioModel);
    }

    void SoundSelectWindow::onClose(Window::CloseReason reason)
    {
        if (reason == Window::CloseReason::ApplicationClose) {
            mSoundsModel->clearData();
        }
    }
} // namespace gui