~aleteoryx/muditaos

7f8fd25e9edee0f05df77490fca59dd15c953585 — Mateusz Grzegorzek 4 years ago c8c8121
[BH-831] Show popup on Alarm activation - part I

Handle Deep press up when not on Home Screen.
M module-apps/apps-common/Application.cpp => module-apps/apps-common/Application.cpp +3 -0
@@ 814,6 814,9 @@ namespace app
                    return std::make_unique<gui::SimNotReadyWindow>(app, window::sim_not_ready_window);
                });
                break;
            case ID::AlarmActivated:
                LOG_DEBUG("TODO");
                break;
            }
        }
    }

M module-apps/apps-common/Application.hpp => module-apps/apps-common/Application.hpp +1 -1
@@ 348,7 348,7 @@ namespace app

        /// Method used to attach popups windows to application
        void attachPopups(const std::vector<gui::popup::ID> &popupsList);
        void showPopup(gui::popup::ID id, const gui::PopupRequestParams *params);
        virtual void showPopup(gui::popup::ID id, const gui::PopupRequestParams *params);
        void abortPopup(gui::popup::ID id);

      public:

M module-apps/apps-common/popups/Popups.cpp => module-apps/apps-common/popups/Popups.cpp +2 -0
@@ 32,6 32,8 @@ namespace gui::popup
            return gui::popup::window::sim_info_window;
        case ID::SimNotReady:
            return gui::popup::window::sim_not_ready_window;
        case ID::AlarmActivated:
            return gui::popup::window::alarm_activated_window;
        }

        return {};

M module-apps/apps-common/popups/Popups.hpp => module-apps/apps-common/popups/Popups.hpp +2 -0
@@ 23,6 23,7 @@ namespace gui
            SimLock,
            SimInfo,
            SimNotReady,
            AlarmActivated
        };

        namespace window


@@ 41,6 42,7 @@ namespace gui
            inline constexpr auto sim_unlock_window                 = "SimUnlockPopup";
            inline constexpr auto sim_info_window                   = "SimInfoPopup";
            inline constexpr auto sim_not_ready_window              = "SimNotReadyPopup";
            inline constexpr auto alarm_activated_window            = "AlarmActivatedPopup";
        } // namespace window

        std::string resolveWindowName(ID id);

M module-sys/Service/Common.hpp => module-sys/Service/Common.hpp +3 -0
@@ 24,6 24,7 @@ namespace sys
        ServiceEvtmgrNotifications,
        PhoneModeChanges,
        PhoneLockChanges,
        AlarmChanges,
    };

    enum class ServicePriority


@@ 121,6 122,8 @@ inline const char *c_str(sys::BusChannel channel)
        return "PhoneModeChanges";
    case sys::BusChannel::PhoneLockChanges:
        return "PhoneLockChanges";
    case sys::BusChannel::AlarmChanges:
        return "AlarmChanges";
    }
    return "";
}

M products/BellHybrid/CMakeLists.txt => products/BellHybrid/CMakeLists.txt +3 -2
@@ 86,7 86,8 @@ add_version_json(BellHybrid)
add_standalone_image(BellHybrid)
add_update_package(BellHybrid)

add_subdirectory(services)
add_subdirectory(alarms)
add_subdirectory(sys)
add_subdirectory(apps)
add_subdirectory(keymap)
add_subdirectory(services)
add_subdirectory(sys)

M products/BellHybrid/alarms/CMakeLists.txt => products/BellHybrid/alarms/CMakeLists.txt +4 -0
@@ 4,6 4,10 @@ target_sources(alarms
    PRIVATE
        BellAlarmHandler.cpp
        AlarmHandlerActions.cpp
        include/AlarmHandlerActions.hpp
        include/BellAlarmHandler.hpp
    PUBLIC
        include/popups/AlarmPopupRequestParams.hpp
)

target_include_directories(alarms

A products/BellHybrid/alarms/include/popups/AlarmPopupRequestParams.hpp => products/BellHybrid/alarms/include/popups/AlarmPopupRequestParams.hpp +16 -0
@@ 0,0 1,16 @@
// 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 <apps-common/popups/data/PopupRequestParams.hpp>

namespace gui
{
    class AlarmPopupRequestParams : public PopupRequestParams
    {
      public:
        AlarmPopupRequestParams() : PopupRequestParams{gui::popup::ID::AlarmActivated}
        {}
    };
} // namespace gui

M products/BellHybrid/apps/application-bell-main/ApplicationBellMain.cpp => products/BellHybrid/apps/application-bell-main/ApplicationBellMain.cpp +17 -0
@@ 62,4 62,21 @@ namespace app
        }
        return std::make_shared<sys::ResponseMessage>();
    }

    void ApplicationBellMain::showPopup(gui::popup::ID id, const gui::PopupRequestParams *params)
    {
        if (id == gui::popup::ID::AlarmActivated) {
            if (not isHomeScreenFocused()) {
                switchWindow(gui::popup::resolveWindowName(id));
            }
        }
        else {
            Application::showPopup(id, params);
        }
    }

    auto ApplicationBellMain::isHomeScreenFocused() -> bool
    {
        return GetName() == app::applicationBellName && getCurrentWindow()->getName() == gui::name::window::main_window;
    }
} // namespace app

M products/BellHybrid/apps/application-bell-main/CMakeLists.txt => products/BellHybrid/apps/application-bell-main/CMakeLists.txt +1 -1
@@ 21,7 21,6 @@ target_sources(application-bell-main
        models/TimeModel.hpp

        presenters/HomeScreenPresenter.hpp
        presenters/KeyMap.hpp
        presenters/StateController.hpp

    PUBLIC


@@ 42,6 41,7 @@ target_link_libraries(application-bell-main
        apps-common
        bellgui
        i18n
        keymap
        module-gui
        service-gui
        time

M products/BellHybrid/apps/application-bell-main/include/application-bell-main/ApplicationBellMain.hpp => products/BellHybrid/apps/application-bell-main/include/application-bell-main/ApplicationBellMain.hpp +4 -0
@@ 36,6 36,10 @@ namespace app
        {
            return sys::ReturnCodes::Success;
        }

      private:
        void showPopup(gui::popup::ID id, const gui::PopupRequestParams *params) override;
        auto isHomeScreenFocused() -> bool;
    };

    template <> struct ManifestTraits<ApplicationBellMain>

M products/BellHybrid/apps/application-bell-main/presenters/StateController.cpp => products/BellHybrid/apps/application-bell-main/presenters/StateController.cpp +2 -1
@@ 3,10 3,11 @@

#include "StateController.hpp"
#include "HomeScreenPresenter.hpp"
#include "KeyMap.hpp"
#include "models/AlarmModel.hpp"
#include "models/TimeModel.hpp"

#include <keymap/KeyMap.hpp>

#include <boost/sml.hpp>
#include <time/time_conversion.hpp>


A products/BellHybrid/keymap/CMakeLists.txt => products/BellHybrid/keymap/CMakeLists.txt +11 -0
@@ 0,0 1,11 @@
add_library(keymap INTERFACE)

target_sources(keymap
    PUBLIC
        include/keymap/KeyMap.hpp
)

target_include_directories(keymap
    INTERFACE
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

R products/BellHybrid/apps/application-bell-main/presenters/KeyMap.hpp => products/BellHybrid/keymap/include/keymap/KeyMap.hpp +14 -17
@@ 5,22 5,19 @@

#include <gui/input/InputEvent.hpp>

namespace app::home_screen
/// Key mapping structure to ease translation between PureOS key definitions and nomenclature used throughout the
/// GUI design
enum class KeyMap
{
    /// Key mapping structure to ease translation between PureOS key definitions and nomenclature used throughout the
    /// GUI design
    enum class KeyMap
    {
        Back          = static_cast<int>(gui::KeyCode::KEY_RF),
        LightPress    = static_cast<int>(gui::KeyCode::KEY_ENTER),
        RotateLeft    = static_cast<int>(gui::KeyCode::KEY_DOWN),
        RotateRight   = static_cast<int>(gui::KeyCode::KEY_UP),
        DeepPressUp   = static_cast<int>(gui::KeyCode::KEY_LEFT),
        DeepPressDown = static_cast<int>(gui::KeyCode::KEY_RIGHT),
    };
    Back          = static_cast<int>(gui::KeyCode::KEY_RF),
    LightPress    = static_cast<int>(gui::KeyCode::KEY_ENTER),
    RotateLeft    = static_cast<int>(gui::KeyCode::KEY_DOWN),
    RotateRight   = static_cast<int>(gui::KeyCode::KEY_UP),
    DeepPressUp   = static_cast<int>(gui::KeyCode::KEY_LEFT),
    DeepPressDown = static_cast<int>(gui::KeyCode::KEY_RIGHT),
};

    inline static KeyMap mapKey(gui::KeyCode key)
    {
        return KeyMap{key};
    }
} // namespace app::home_screen
inline static KeyMap mapKey(gui::KeyCode key)
{
    return KeyMap{key};
}

M products/BellHybrid/services/appmgr/ApplicationManager.cpp => products/BellHybrid/services/appmgr/ApplicationManager.cpp +18 -0
@@ 3,8 3,19 @@

#include <appmgr/ApplicationManager.hpp>

#include <evtmgr/messages/AlarmMessage.hpp>

namespace app::manager
{
    ApplicationManager::ApplicationManager(const ApplicationName &serviceName,
                                           std::vector<std::unique_ptr<app::ApplicationLauncher>> &&launchers,
                                           const ApplicationName &_rootApplicationName)
        : ApplicationManagerCommon(serviceName, std::move(launchers), _rootApplicationName)
    {
        bus.channels.push_back(sys::BusChannel::AlarmChanges);
        registerMessageHandlers();
    }

    auto ApplicationManager::startApplication(ApplicationHandle &app) -> bool
    {
        if (not ApplicationManagerCommon::startApplication(app)) {


@@ 18,4 29,11 @@ namespace app::manager
    {
        return rootApplicationName;
    }
    void ApplicationManager::registerMessageHandlers()
    {
        ApplicationManagerCommon::registerMessageHandlers();

        auto convertibleToActionHandler = [this](sys::Message *request) { return handleMessageAsAction(request); };
        connect(typeid(AlarmActivated), convertibleToActionHandler);
    }
} // namespace app::manager

M products/BellHybrid/services/appmgr/CMakeLists.txt => products/BellHybrid/services/appmgr/CMakeLists.txt +2 -0
@@ 14,6 14,8 @@ target_include_directories(appmgr

target_link_libraries(appmgr
   PRIVATE
        alarms
        evtmgr
        module-apps
        service-appmgr
)

M products/BellHybrid/services/appmgr/include/appmgr/ApplicationManager.hpp => products/BellHybrid/services/appmgr/include/appmgr/ApplicationManager.hpp +2 -5
@@ 12,14 12,11 @@ namespace app::manager
      public:
        ApplicationManager(const ApplicationName &serviceName,
                           std::vector<std::unique_ptr<app::ApplicationLauncher>> &&launchers,
                           const ApplicationName &_rootApplicationName)
            : ApplicationManagerCommon(serviceName, std::move(launchers), _rootApplicationName)
        {
            registerMessageHandlers();
        }
                           const ApplicationName &_rootApplicationName);

      private:
        auto startApplication(ApplicationHandle &app) -> bool override;
        auto resolveHomeApplication() -> std::string override;
        void registerMessageHandlers() override;
    };
} // namespace app::manager

M products/BellHybrid/services/evtmgr/CMakeLists.txt => products/BellHybrid/services/evtmgr/CMakeLists.txt +3 -0
@@ 11,6 11,7 @@ target_sources(evtmgr
    PUBLIC
        include/evtmgr/EventManager.hpp
        include/evtmgr/api/TemperatureApi.hpp
        include/evtmgr/messages/AlarmMessage.hpp
)

target_include_directories(evtmgr


@@ 22,6 23,8 @@ target_include_directories(evtmgr

target_link_libraries(evtmgr
   PRIVATE
        alarms
        keymap
        module-bsp
        module-utils
        service-evtmgr

M products/BellHybrid/services/evtmgr/EventManager.cpp => products/BellHybrid/services/evtmgr/EventManager.cpp +19 -0
@@ 4,7 4,10 @@
#include "internal/StaticData.hpp"

#include <evtmgr/EventManager.hpp>
#include <evtmgr/messages/AlarmMessage.hpp>
#include <keymap/KeyMap.hpp>
#include <module-bsp/hal/temperature_source/TemperatureSource.hpp>
#include <service-evtmgr/KbdMessage.hpp>

namespace
{


@@ 26,3 29,19 @@ EventManager::EventManager(const std::string &name)

    onMinuteTick = [this](const time_t) { updateTemperature(*temperatureSource); };
}

void EventManager::handleKeyEvent(sys::Message *msg)
{
    EventManagerCommon::handleKeyEvent(msg);

    auto kbdMessage = dynamic_cast<sevm::KbdMessage *>(msg);
    if (kbdMessage == nullptr) {
        return;
    }

    auto key = mapKey(static_cast<gui::KeyCode>(kbdMessage->key.keyCode));

    if (key == KeyMap::DeepPressUp && kbdMessage->key.state == RawKey::State::Released) {
        bus.sendMulticast(std::make_unique<AlarmActivated>(), sys::BusChannel::AlarmChanges);
    }
}

M products/BellHybrid/services/evtmgr/include/evtmgr/EventManager.hpp => products/BellHybrid/services/evtmgr/include/evtmgr/EventManager.hpp +3 -0
@@ 16,6 16,9 @@ class EventManager : public EventManagerCommon
    explicit EventManager(const std::string &name = service::name::evt_manager);

  private:
    void handleKeyEvent(sys::Message *msg) override;

  private:
    std::shared_ptr<hal::temperature::AbstractTemperatureSource> temperatureSource;
};


A products/BellHybrid/services/evtmgr/include/evtmgr/messages/AlarmMessage.hpp => products/BellHybrid/services/evtmgr/include/evtmgr/messages/AlarmMessage.hpp +22 -0
@@ 0,0 1,22 @@
// 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-sys/Service/Message.hpp>
#include <popups/AlarmPopupRequestParams.hpp>
#include <service-appmgr/Actions.hpp>
#include <service-appmgr/messages/ActionRequest.hpp>

class AlarmActivated : public sys::DataMessage, public app::manager::actions::ConvertibleToAction
{
  public:
    AlarmActivated() : sys::DataMessage{MessageType::MessageTypeUninitialized}
    {}

    [[nodiscard]] auto toAction() const -> std::unique_ptr<app::manager::ActionRequest> override
    {
        return std::make_unique<app::manager::ActionRequest>(
            sender, app::manager::actions::ShowPopup, std::make_unique<gui::AlarmPopupRequestParams>());
    }
};