~aleteoryx/muditaos

a21e02f91e176a35edc2a87208b15710962f0a3c — Jakub Pyszczak 5 years ago ab2252e
[EGD-5743] Added phone modes popup

Implementation of phone modes window.
Minor fixes of previous approach.
M image/assets/lang/English.json => image/assets/lang/English.json +1 -0
@@ 84,6 84,7 @@
  "home_modes_connected": "CONNECTED",
  "home_modes_notdisturb": "DO NOT DISTURB",
  "home_modes_offline": "OFFLINE",
  "home_modes_message_only": "Message only",
  "topbar_battery_charging": "Charg",
  "topbar_battery_plugged": "Plug",
  "app_alarm_clock_title_main": "Alarm clock",

M module-apps/Application.cpp => module-apps/Application.cpp +18 -1
@@ 87,18 87,31 @@ namespace app
          default_window(gui::name::window::main_window), windowsStack(this),
          keyTranslator{std::make_unique<gui::KeyInputSimpleTranslation>()}, startInBackground{startInBackground},
          callbackStorage{std::make_unique<CallbackStorage>()}, topBarManager{std::make_unique<TopBarManager>()},
          settings(std::make_unique<settings::Settings>(this))
          settings(std::make_unique<settings::Settings>(this)),
          phoneModeObserver(std::make_unique<sys::phone_modes::Observer>())
    {
        topBarManager->enableIndicators({gui::top_bar::Indicator::Time});
        topBarManager->set(utils::dateAndTimeSettings.isTimeFormat12() ? gui::top_bar::TimeMode::Time12h
                                                                       : gui::top_bar::TimeMode::Time24h);
        bus.channels.push_back(sys::BusChannel::ServiceCellularNotifications);
        bus.channels.push_back(sys::BusChannel::PhoneModeChanges);

        longPressTimer = sys::TimerFactory::createPeriodicTimer(this,
                                                                "LongPress",
                                                                std::chrono::milliseconds{key_timer_ms},
                                                                [this](sys::Timer &) { longPressTimerCallback(); });

        phoneModeObserver->connect(this);
        phoneModeObserver->subscribe(
            [=](sys::phone_modes::PhoneMode phoneMode, sys::phone_modes::Tethering tetheringMode) {
                using namespace gui::popup;
                if (getCurrentWindow()->getName() == window::phone_modes_window) {
                    updateWindow(window::phone_modes_window, std::make_unique<gui::ModesPopupData>(phoneMode));
                }
                else {
                    switchWindow(window::phone_modes_window, std::make_unique<gui::ModesPopupData>(phoneMode));
                }
            });
        connect(typeid(AppRefreshMessage),
                [this](sys::Message *msg) -> sys::MessagePointer { return handleAppRefresh(msg); });
        connect(sevm::BatteryStatusChangeMessage(), [&](sys::Message *) { return handleBatteryStatusChange(); });


@@ 673,6 686,10 @@ namespace app
                });
                break;
            case ID::PhoneModes:
                windowsFactory.attach(window::phone_modes_window, [](Application *app, const std::string &name) {
                    return std::make_unique<gui::HomeModesWindow>(app, window::phone_modes_window);
                });
                break;
            case ID::Brightness:
                break;
            }

M module-apps/Application.hpp => module-apps/Application.hpp +3 -0
@@ 17,6 17,8 @@
#include "bsp/keyboard/key_codes.hpp"      // for bsp
#include "gui/Common.hpp"                  // for ShowMode
#include "projdefs.h"                      // for pdMS_TO_TICKS
#include <PhoneModes/Observer.hpp>

#include <service-appmgr/ApplicationManifest.hpp>
#include <list>                           // for list
#include <map>                            // for allocator, map


@@ 380,6 382,7 @@ namespace app

        /// application's settings
        std::unique_ptr<settings::Settings> settings;
        std::unique_ptr<sys::phone_modes::Observer> phoneModeObserver;

      public:
        void setLockScreenPasscodeOn(bool screenPasscodeOn) noexcept;

M module-apps/CMakeLists.txt => module-apps/CMakeLists.txt +1 -1
@@ 30,8 30,8 @@ set( SOURCES
    "widgets/InputBox.cpp"
    "popups/VolumeWindow.cpp"
    "popups/WindowWithTimer.cpp"
    "popups/HomeModesWindow.cpp"
    "windows/BrightnessWindow.cpp"
    "windows/HomeModesWindow.cpp"
    "widgets/BrightnessBox.cpp"
    "widgets/ModesBox.cpp"
    "widgets/BarGraph.cpp"

M module-apps/application-alarm-clock/ApplicationAlarmClock.cpp => module-apps/application-alarm-clock/ApplicationAlarmClock.cpp +1 -1
@@ 108,7 108,7 @@ namespace app
            style::alarmClock::window::name::dialogYesNo,
            [](Application *app, const std::string &name) { return std::make_unique<gui::DialogYesNo>(app, name); });

        attachPopups({gui::popup::ID::Volume});
        attachPopups({gui::popup::ID::Volume, gui::popup::ID::PhoneModes});
    }

    void ApplicationAlarmClock::destroyUserInterface()

M module-apps/application-antenna/ApplicationAntenna.cpp => module-apps/application-antenna/ApplicationAntenna.cpp +1 -1
@@ 178,7 178,7 @@ namespace app
            return std::make_unique<gui::AlgoParamsWindow>(app);
        });

        attachPopups({gui::popup::ID::Volume});
        attachPopups({gui::popup::ID::Volume, gui::popup::ID::PhoneModes});
    }

    void ApplicationAntenna::destroyUserInterface()

M module-apps/application-calculator/ApplicationCalculator.cpp => module-apps/application-calculator/ApplicationCalculator.cpp +1 -1
@@ 43,7 43,7 @@ namespace app
            return std::make_unique<gui::CalculatorMainWindow>(app, name);
        });

        attachPopups({gui::popup::ID::Volume});
        attachPopups({gui::popup::ID::Volume, gui::popup::ID::PhoneModes});
    }

    void ApplicationCalculator::destroyUserInterface()

M module-apps/application-calendar/ApplicationCalendar.cpp => module-apps/application-calendar/ApplicationCalendar.cpp +1 -1
@@ 143,7 143,7 @@ namespace app
            return std::make_unique<gui::EventReminderWindow>(app, event_reminder_window);
        });

        attachPopups({gui::popup::ID::Volume});
        attachPopups({gui::popup::ID::Volume, gui::popup::ID::PhoneModes});
    }

    void ApplicationCalendar::destroyUserInterface()

M module-apps/application-call/ApplicationCall.cpp => module-apps/application-call/ApplicationCall.cpp +1 -1
@@ 222,7 222,7 @@ namespace app
        windowsFactory.attach(app::window::name_dialogConfirm, [](Application *app, const std::string &name) {
            return std::make_unique<gui::DialogConfirm>(app, name);
        });
        attachPopups({gui::popup::ID::Volume});
        attachPopups({gui::popup::ID::Volume, gui::popup::ID::PhoneModes});
    }

    bool ApplicationCall::showNotification(std::function<bool()> action,

M module-apps/application-calllog/ApplicationCallLog.cpp => module-apps/application-calllog/ApplicationCallLog.cpp +1 -1
@@ 98,7 98,7 @@ namespace app
            return std::make_unique<gui::DialogYesNo>(app, name);
        });

        attachPopups({gui::popup::ID::Volume});
        attachPopups({gui::popup::ID::Volume, gui::popup::ID::PhoneModes});
    }

    void ApplicationCallLog::destroyUserInterface()

M module-apps/application-clock/ApplicationClock.cpp => module-apps/application-clock/ApplicationClock.cpp +1 -1
@@ 86,7 86,7 @@ namespace app
            return std::make_unique<gui::ClockMainWindow>(app, name);
        });

        attachPopups({gui::popup::ID::Volume});
        attachPopups({gui::popup::ID::Volume, gui::popup::ID::PhoneModes});
    }

    void ApplicationClock::destroyUserInterface()

M module-apps/application-desktop/ApplicationDesktop.cpp => module-apps/application-desktop/ApplicationDesktop.cpp +1 -1
@@ 449,7 449,7 @@ namespace app
            return std::make_unique<gui::MmiInternalMsgWindow>(app, desktop_mmi_internal);
        });

        attachPopups({gui::popup::ID::Volume});
        attachPopups({gui::popup::ID::Volume, gui::popup::ID::PhoneModes});
    }

    void ApplicationDesktop::destroyUserInterface()

M module-apps/application-meditation/ApplicationMeditation.cpp => module-apps/application-meditation/ApplicationMeditation.cpp +1 -1
@@ 53,7 53,7 @@ namespace app
            return std::make_unique<gui::PreparationTimeWindow>(app);
        });

        attachPopups({gui::popup::ID::Volume});
        attachPopups({gui::popup::ID::Volume, gui::popup::ID::PhoneModes});
    }

    void ApplicationMeditation::destroyUserInterface()

M module-apps/application-messages/ApplicationMessages.cpp => module-apps/application-messages/ApplicationMessages.cpp +1 -1
@@ 149,7 149,7 @@ namespace app
            return std::make_unique<gui::SearchResults>(app);
        });

        attachPopups({gui::popup::ID::Volume});
        attachPopups({gui::popup::ID::Volume, gui::popup::ID::PhoneModes});
    }

    void ApplicationMessages::destroyUserInterface()

M module-apps/application-music-player/ApplicationMusicPlayer.cpp => module-apps/application-music-player/ApplicationMusicPlayer.cpp +1 -1
@@ 69,7 69,7 @@ namespace app
            return std::make_unique<gui::MusicPlayerEmptyWindow>(app);
        });

        attachPopups({gui::popup::ID::Volume});
        attachPopups({gui::popup::ID::Volume, gui::popup::ID::PhoneModes});
    }

    void ApplicationMusicPlayer::destroyUserInterface()

M module-apps/application-notes/ApplicationNotes.cpp => module-apps/application-notes/ApplicationNotes.cpp +1 -1
@@ 122,7 122,7 @@ namespace app
            utils::localize.get("app_phonebook_options_title"),
            [](Application *app, const std::string &name) { return std::make_unique<gui::OptionWindow>(app, name); });

        attachPopups({gui::popup::ID::Volume});
        attachPopups({gui::popup::ID::Volume, gui::popup::ID::PhoneModes});
    }

    void ApplicationNotes::destroyUserInterface()

M module-apps/application-onboarding/ApplicationOnBoarding.cpp => module-apps/application-onboarding/ApplicationOnBoarding.cpp +1 -1
@@ 126,7 126,7 @@ namespace app
            return std::make_unique<app::onBoarding::SkipDialogWindow>(app);
        });

        attachPopups({gui::popup::ID::Volume});
        attachPopups({gui::popup::ID::Volume, gui::popup::ID::PhoneModes});
    }

    void ApplicationOnBoarding::destroyUserInterface()

M module-apps/application-phonebook/ApplicationPhonebook.cpp => module-apps/application-phonebook/ApplicationPhonebook.cpp +1 -1
@@ 147,7 147,7 @@ namespace app
            return std::make_unique<gui::PhonebookNewContact>(app);
        });

        attachPopups({gui::popup::ID::Volume});
        attachPopups({gui::popup::ID::Volume, gui::popup::ID::PhoneModes});
    }

    void ApplicationPhonebook::destroyUserInterface()

M module-apps/application-settings/ApplicationSettings.cpp => module-apps/application-settings/ApplicationSettings.cpp +1 -1
@@ 163,7 163,7 @@ namespace app
                                  });
        }

        attachPopups({gui::popup::ID::Volume});
        attachPopups({gui::popup::ID::Volume, gui::popup::ID::PhoneModes});
    }

    void ApplicationSettings::destroyUserInterface()

R module-apps/windows/HomeModesWindow.cpp => module-apps/popups/HomeModesWindow.cpp +26 -11
@@ 1,13 1,17 @@
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "HomeModesWindow.hpp"
#include "widgets/ModesBox.hpp"
#include "data/PopupData.hpp"

#include <module-gui/gui/input/InputEvent.hpp>
#include <module-gui/gui/widgets/Arc.hpp>
#include "HomeModesWindow.hpp"
#include <PhoneModes/Common.hpp>

namespace gui
{
    HomeModesWindow::HomeModesWindow(app::Application *app, const std::string &name) : AppWindow(app, name)
    HomeModesWindow::HomeModesWindow(app::Application *app, const std::string &name) : WindowWithTimer(app, name)
    {
        buildInterface();
    }


@@ 15,22 19,33 @@ namespace gui
    void HomeModesWindow::buildInterface()
    {
        AppWindow::buildInterface();
        modesBox = new ModesBox(this, style::window::modes::left_offset, style::window::modes::top_offset);

        bottomBar->setVisible(false);
        topBar->setVisible(false);

        modesBox = new ModesBox(this, 0, style::window::modes::top_offset);
    }

    void HomeModesWindow::rebuild()
    {}

    void HomeModesWindow::destroyInterface()
    void HomeModesWindow::onBeforeShow(ShowMode mode, SwitchData *data)
    {
        erase();
        WindowWithTimer::onBeforeShow(mode, data);
        const auto popupData = dynamic_cast<ModesPopupData *>(data);
        if (popupData != nullptr) {
            const auto currentMode = popupData->getPhoneMode();
            modesBox->update(currentMode);
        }
    }

    HomeModesWindow::~HomeModesWindow()
    bool HomeModesWindow::onInput(const gui::InputEvent &inputEvent)
    {
        destroyInterface();
        if ((inputEvent.isShortPress())) {
            if (inputEvent.keyCode == KeyCode::KEY_RF) {
                return false;
            }
        }
        return AppWindow::onInput(inputEvent);
    }

    void HomeModesWindow::onBeforeShow(ShowMode mode, SwitchData *data)
    {}
} // namespace gui

R module-apps/windows/HomeModesWindow.hpp => module-apps/popups/HomeModesWindow.hpp +6 -15
@@ 1,32 1,23 @@
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "module-apps/Application.hpp"
#include "AppWindow.hpp"
#include "module-apps/widgets/BarGraph.hpp"
#include "module-apps/widgets/ModesBox.hpp"
#include <functional>
#include "popups/WindowWithTimer.hpp"

namespace gui
{
    class HomeModesWindow : public AppWindow
    class ModesBox;
    class HomeModesWindow : public WindowWithTimer
    {
      protected:
        ModesBox *modesBox = nullptr;

      public:
        HomeModesWindow(app::Application *app, const std::string &name);

        ~HomeModesWindow() override;

        void onBeforeShow(ShowMode mode, SwitchData *data) override;

        void rebuild() override;

        void buildInterface() override;

        void destroyInterface() override;
        bool onInput(const gui::InputEvent &inputEvent) override;
    };
}; // namespace gui
} // namespace gui

M module-apps/popups/Popups.hpp => module-apps/popups/Popups.hpp +1 -0
@@ 4,6 4,7 @@
#pragma once

#include <module-apps/popups/VolumeWindow.hpp>
#include <module-apps/popups/HomeModesWindow.hpp>

#include <string>


M module-apps/popups/VolumeWindow.cpp => module-apps/popups/VolumeWindow.cpp +10 -8
@@ 53,14 53,16 @@ namespace gui
    void VolumeWindow::onBeforeShow(ShowMode mode, SwitchData *data)
    {
        WindowWithTimer::onBeforeShow(mode, data);
        const auto popupData = static_cast<VolumePopupData *>(data);
        volume               = popupData->getVolume();
        audioContext         = popupData->getAudioContext();
        if (volumeBar != nullptr) {
            volumeBar->setValue(volume);
        }
        if (volumeText != nullptr) {
            showProperText(audioContext, volume);
        const auto popupData = dynamic_cast<VolumePopupData *>(data);
        if (popupData) {
            volume       = popupData->getVolume();
            audioContext = popupData->getAudioContext();
            if (volumeBar != nullptr) {
                volumeBar->setValue(volume);
            }
            if (volumeText != nullptr) {
                showProperText(audioContext, volume);
            }
        }
    }


M module-apps/popups/VolumeWindow.hpp => module-apps/popups/VolumeWindow.hpp +1 -1
@@ 52,4 52,4 @@ namespace gui
        void buildInterface() override;
        bool onInput(const gui::InputEvent &inputEvent) override;
    };
}; // namespace gui
} // namespace gui

M module-apps/popups/data/PopupData.hpp => module-apps/popups/data/PopupData.hpp +17 -1
@@ 1,9 1,10 @@

// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once
#include <SwitchData.hpp>
#include <module-audio/Audio/AudioCommon.hpp>

namespace gui
{


@@ 30,4 31,19 @@ namespace gui
        const audio::Volume volume;
        const AudioContext audioContext;
    };

    class ModesPopupData : public SwitchData
    {
      public:
        explicit ModesPopupData(const sys::phone_modes::PhoneMode phoneMode) : SwitchData(), phoneMode{phoneMode}
        {}

        [[nodiscard]] auto getPhoneMode() const noexcept -> sys::phone_modes::PhoneMode
        {
            return phoneMode;
        }

      private:
        const sys::phone_modes::PhoneMode phoneMode;
    };
} // namespace gui

M module-apps/widgets/ModesBox.cpp => module-apps/widgets/ModesBox.cpp +85 -37
@@ 1,11 1,20 @@
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <i18n/i18n.hpp>
#include "ModesBox.hpp"

#include <gui/widgets/ImageBox.hpp>
#include <PhoneModes/Common.hpp>
#include <Utils.hpp>

namespace gui
{
    namespace img::dot
    {
        constexpr auto name = "dot_12px_hard_alpha_W_G";
    } // namespace img::dot

    ModesBox::ModesBox(Item *parent, uint32_t x, uint32_t y)
        : VBox(parent, x, y, style::window::modes::width, style::window::modes::height)
    {


@@ 15,43 24,77 @@ namespace gui
        addOffline();
    }

    void ModesBox::update(const sys::phone_modes::PhoneMode &phoneMode)
    {
        using PhoneMode      = sys::phone_modes::PhoneMode;
        auto getUpdateValues = [&phoneMode](const PhoneMode &compare) -> std::pair<std::string, const bool> {
            return (phoneMode == compare) ? std::make_pair(style::window::font::largelight, true)
                                          : std::make_pair(style::window::font::medium, false);
        };
        connected->update(getUpdateValues(PhoneMode::Connected));
        notDisturb->update(getUpdateValues(PhoneMode::DoNotDisturb));
        offline->update(getUpdateValues(PhoneMode::Offline));
        if (phoneMode == PhoneMode::Offline) {
            messageOnly->setVisible(true);
        }
        else {
            messageOnly->setVisible(false);
        }
    }

    void ModesBox::addConnected()
    {
        connected = new ModeRow(this, 0, 0, style::window::modes::width, style::window::modes::connected::height);
        connected = new ModeRow(this,
                                0,
                                0,
                                style::window::modes::width,
                                style::window::modes::height / style::window::modes::number_of_entries);
        connected->addText(utils::localize.get(style::window::modes::connected::title_key),
                           style::window::font::medium,
                           Margins(style::window::modes::connected::margin::left, 0, 0, 0),
                           style::window::modes::connected::width,
                           style::window::modes::connected::height);
        connected->resizeItems();
                           style::window::modes::text::width,
                           style::window::modes::height / style::window::modes::number_of_entries);

        connected->addImage(img::dot::name);
    }

    void ModesBox::addNotDisturb()
    {
        notDisturb = new ModeRow(this, 0, 0, style::window::modes::width, style::window::modes::notdisturb::height);
        notDisturb->addText(
            utils::localize.get(style::window::modes::notdisturb::title_key),
            style::window::font::largelight,
            Margins(
                style::window::modes::notdisturb::margin::left, 0, style::window::modes::notdisturb::margin::right, 0),
            style::window::modes::notdisturb::width,
            style::window::modes::notdisturb::height);
        notDisturb->addImage("dot_12px_hard_alpha_W_G");
        notDisturb->setMargins(Margins(
            0, style::window::modes::notdisturb::margin::top, 0, style::window::modes::notdisturb::margin::bottom));
        notDisturb->resizeItems();
        notDisturb = new ModeRow(this,
                                 0,
                                 0,
                                 style::window::modes::width,
                                 style::window::modes::height / style::window::modes::number_of_entries);

        notDisturb->addText(utils::localize.get(style::window::modes::notdisturb::title_key),
                            style::window::font::medium,
                            style::window::modes::text::width,
                            style::window::modes::height / style::window::modes::number_of_entries);
        notDisturb->addImage(img::dot::name);
    }

    void ModesBox::addOffline()
    {
        offline = new ModeRow(this, 0, 0, style::window::modes::width, style::window::modes::offline::height);

        offline = new ModeRow(this,
                              0,
                              0,
                              style::window::modes::width,
                              style::window::modes::height / style::window::modes::number_of_entries);
        offline->addText(utils::localize.get(style::window::modes::offline::title_key),
                         style::window::font::medium,
                         Margins(style::window::modes::offline::margin::left, 0, 0, 0),
                         style::window::modes::offline::width,
                         style::window::modes::offline::height);
        offline->resizeItems();
                         style::window::modes::text::width,
                         style::window::modes::height / style::window::modes::number_of_entries);
        offline->addImage(img::dot::name);

        messageOnly = new ModeRow(this,
                                  0,
                                  0,
                                  style::window::modes::width,
                                  style::window::modes::height / style::window::modes::number_of_entries);

        messageOnly->addText(utils::localize.get(style::window::modes::offline::description_key),
                             style::window::font::verysmall,
                             style::window::modes::text::width,
                             style::window::modes::height / style::window::modes::number_of_entries);
    }

    ModeRow::ModeRow(Item *parent, uint32_t x, uint32_t y, uint32_t width, uint32_t height)


@@ 60,25 103,30 @@ namespace gui
        this->setEdges(RectangleEdge::None);
    }

    void ModeRow::addText(
        const std::string &text, const std::string &fontSize, const Margins &margin, uint32_t width, uint32_t height)
    void ModeRow::addText(const std::string &text, const std::string &fontSize, uint32_t width, uint32_t height)
    {
        label = new Label(this, 0, 0, width, height);
        label->setMinimumSize(width, height);
        label = new Label(this, 0, 0, width, height, text);
        label->setEdges(gui::RectangleEdge::None);
        label->setAlignment(Alignment(gui::Alignment::Horizontal::Left, gui::Alignment::Vertical::Center));
        label->activeItem = false;
        label->setText(text);
        label->setAlignment(Alignment(gui::Alignment::Horizontal::Right, gui::Alignment::Vertical::Center));
        label->setFont(fontSize);
        label->setMargins(margin);
    }

    void ModeRow::update(std::pair<std::string, const bool> &&params)
    {
        const auto [font, imgVisibility] = params;
        img->setVisible(imgVisibility);
        label->setFont(font);
    }

    void ModeRow::addImage(const std::string &imageName)
    {
        img = new Image(this, 0, 0, 0, 0);
        img->setMinimumSize(style::window::modes::image::width, style::window::modes::image::height);
        img->setAlignment(Alignment(gui::Alignment::Horizontal::Right, gui::Alignment::Vertical::Center));
        img->set(imageName);
        img->setMargins(Margins(style::window::modes::image::margin::left, 0, 0, 0));
        img = new ImageBox(this,
                           0,
                           0,
                           style::window::modes::image::width,
                           style::window::modes::height / style::window::modes::number_of_entries,
                           new Image(imageName));

        img->setAlignment(Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));
    }
} // namespace gui

M module-apps/widgets/ModesBox.hpp => module-apps/widgets/ModesBox.hpp +24 -44
@@ 1,91 1,71 @@
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <BoxLayout.hpp>
#include <Label.hpp>
#include <module-gui/gui/widgets/Image.hpp>
#include <utility>

namespace style::window::modes
namespace sys::phone_modes
{
    constexpr inline auto invision_diff = 26;
    enum class PhoneMode;
} // namespace sys::phone_modes

    constexpr inline auto left_offset   = style::window_width / 4;
namespace style::window::modes
{
    constexpr inline auto top_offset    = 182;
    constexpr inline auto bottom_offset = 257;
    constexpr inline auto bottom_offset     = 235;
    constexpr inline auto height        = style::window_height - top_offset - bottom_offset;
    constexpr inline auto width         = style::window_width - left_offset;

    constexpr inline auto width             = style::window_width;
    constexpr inline auto number_of_entries = 4;
    namespace connected
    {
        constexpr inline auto title_key = "home_modes_connected";
        constexpr inline auto width     = 129;
        constexpr inline auto height    = 33;

        namespace margin
        {
            constexpr inline auto left  = 296 - style::window::modes::left_offset + invision_diff;
            constexpr inline auto right = 20;
        } // namespace margin

    }     // namespace connected

    namespace notdisturb
    {
        constexpr inline auto title_key = "home_modes_notdisturb";
        constexpr inline auto width     = 297 + invision_diff;
        constexpr inline auto height    = 51;

        namespace margin
        {
            constexpr inline auto top    = 20;
            constexpr inline auto left   = 128 - style::window::modes::left_offset;
            constexpr inline auto bottom = 20;
            constexpr inline auto right  = 0;
        } // namespace margin

    }     // namespace notdisturb

    namespace offline
    {
        constexpr inline auto title_key = "home_modes_offline";
        constexpr inline auto width     = 88;
        constexpr inline auto height    = 33;

        namespace margin
        {
            constexpr inline auto left  = 337 - style::window::modes::left_offset + invision_diff;
            constexpr inline auto right = 10;
        } // namespace margin
        constexpr inline auto description_key = "home_modes_message_only";
    }     // namespace offline

    namespace image
    {
        namespace margin
        {
            constexpr inline auto left = 7;
        }
        constexpr inline auto width  = 10;
        constexpr inline auto height = 20;
        constexpr inline auto width = 55;
    } // namespace image

    namespace text
    {
        constexpr inline auto width = style::window::modes::width - style::window::modes::image::width;
    } // namespace text
} // namespace style::window::modes

namespace gui
{
    class ImageBox;

    class ModeRow : public HBox
    {
        Label *label = nullptr;
        Image *img   = nullptr;
        ImageBox *img = nullptr;

      public:
        ModeRow(Item *parent = nullptr, uint32_t x = 0, uint32_t y = 0, uint32_t width = 0, uint32_t height = 0);

        void addText(const std::string &text,
                     const std::string &fontSize,
                     const Margins &margin,
                     uint32_t width,
                     uint32_t height);

        void update(std::pair<std::string, const bool> &&params);
        void addImage(const std::string &imageName);
    };



@@ 94,14 74,14 @@ namespace gui
        ModeRow *connected  = nullptr;
        ModeRow *notDisturb = nullptr;
        ModeRow *offline    = nullptr;
        ModeRow *messageOnly = nullptr;

        void addConnected();

        void addNotDisturb();

        void addOffline();

      public:
        ModesBox(Item *parent = nullptr, uint32_t x = 0, uint32_t y = 0);
        void update(const sys::phone_modes::PhoneMode &phoneMode);
    };
} // namespace gui