~aleteoryx/muditaos

5b88233d379ba7b6f38af79feb26b054a0276693 — Marcin Zieliński 3 years ago 3cbfe43
[MOS-791] Introduce tri-state switch widget

Introduced the new logic.

From now on, every button can be tri-state, that is,
OFF/ON/Transiting whereas the Transiting state is
marked with the 'cheking...' caption written on the
button.
M image/assets/lang/Deutsch.json => image/assets/lang/Deutsch.json +2 -1
@@ 483,8 483,9 @@
  "app_settings_network_sim1": "SIM 1",
  "app_settings_network_sim2": "SIM 2",
  "app_settings_network_sim_none": "Keine SIM",
  "app_settings_network_voice_over_lte": "VoLTE (experimentell)",
  "app_settings_network_voice_over_lte": "VoLTE",
  "app_settings_network_apn_settings": "APN-Einstellungen",
  "app_settings_toggle_transiting": "wird geprüft...",
  "app_settings_toggle_on": "EIN",
  "app_settings_toggle_off": "AUS",
  "app_settings_security_phone_lock": "Sicherheitscode für Bildschirmsperre",

M image/assets/lang/English.json => image/assets/lang/English.json +2 -1
@@ 440,8 440,9 @@
  "app_settings_network_sim1": "SIM1",
  "app_settings_network_sim2": "SIM2",
  "app_settings_network_sim_none": "No SIM",
  "app_settings_network_voice_over_lte": "VoLTE (experimental)",
  "app_settings_network_voice_over_lte": "VoLTE",
  "app_settings_network_apn_settings": "APN settings",
  "app_settings_toggle_transiting": "checking...",
  "app_settings_toggle_on": "ON",
  "app_settings_toggle_off": "OFF",
  "app_settings_security_phone_lock": "Lock screen passcode",

M image/assets/lang/Espanol.json => image/assets/lang/Espanol.json +2 -1
@@ 484,9 484,10 @@
  "app_settings_network_sim1": "SIM1",
  "app_settings_network_sim2": "SIM2",
  "app_settings_network_sim_none": "No hay SIM",
  "app_settings_network_voice_over_lte": "VoLTE (experimental)",
  "app_settings_network_voice_over_lte": "VoLTE",
  "app_settings_network_apn_settings": "Configuración de APN",
  "app_settings_security_phone_lock": "Código de acceso",
  "app_settings_toggle_transiting": "comprobando...",
  "app_settings_toggle_on": "ACT",
  "app_settings_toggle_off": "DES",
  "app_settings_display_security_autolock": "Bloq. auto.",

M image/assets/lang/Francais.json => image/assets/lang/Francais.json +2 -1
@@ 451,8 451,9 @@
  "app_settings_network_sim1": "SIM1",
  "app_settings_network_sim2": "SIM2",
  "app_settings_network_sim_none": "Pas de SIM",
  "app_settings_network_voice_over_lte": "VoLTE (expérimental)",
  "app_settings_network_voice_over_lte": "VoLTE",
  "app_settings_network_apn_settings": "APN settings",
  "app_settings_toggle_transiting": "vérification...",
  "app_settings_toggle_on": "ACT",
  "app_settings_toggle_off": "DES",
  "app_settings_security_phone_lock": "Code d'accès de l'écran de verrouillage",

M image/assets/lang/Polski.json => image/assets/lang/Polski.json +2 -1
@@ 494,8 494,9 @@
  "app_settings_network_sim1": "SIM1",
  "app_settings_network_sim2": "SIM2",
  "app_settings_network_sim_none": "Brak karty SIM",
  "app_settings_network_voice_over_lte": "VoLTE (funkcja eksperymentalna)",
  "app_settings_network_voice_over_lte": "VoLTE",
  "app_settings_network_apn_settings": "Ustawienia APN",
  "app_settings_toggle_transiting": "sprawdzanie...",
  "app_settings_toggle_on": "WŁ",
  "app_settings_toggle_off": "WYŁ",
  "app_settings_security_phone_lock": "Kod ekranu blokady",

M image/assets/lang/Svenska.json => image/assets/lang/Svenska.json +2 -1
@@ 390,7 390,7 @@
  "app_settings_network_sim1": "SIM1",
  "app_settings_network_sim2": "SIM2",
  "app_settings_network_sim_none": "Inget SIM",
  "app_settings_network_voice_over_lte": "VoLTE (under utveckling)",
  "app_settings_network_voice_over_lte": "VoLTE",
  "app_settings_network_apn_settings": "APN-inställningar",
  "app_settings_option_connected": "ANSLUTAD",
  "app_settings_option_connected_audio": "ANSLUTAD LJUD",


@@ 410,6 410,7 @@
  "app_settings_info_dnd": "Ta emot alla aviseringar tyst. Du kan tillåta fullständiga aviseringar från favoritkontakter.",
  "app_settings_info_offline_flight_mode": "Helt frånkopplad. Samtal, meddelanden och internetdelning är inte tillgängliga.",
  "app_settings_info_offline_messages_only": "Skicka och ladda ner meddelanden baserat på anslutningsintervall. Inga samtal eller internetdelning.",
  "app_settings_toggle_transiting": "kontrollerar...",
  "app_settings_toggle_on": "PÅ",
  "app_settings_toggle_off": "AV",
  "app_settings_security_phone_lock": "Lösenord för att låsa telefonen",

M module-apps/application-alarm-clock/widgets/AlarmItem.cpp => module-apps/application-alarm-clock/widgets/AlarmItem.cpp +2 -1
@@ 54,7 54,8 @@ namespace gui
                                          getPresenter()->getAlarm()->alarmTime.minuteOfHour,
                                          utils::time::TimestampType::Time);
        timeLabel->setText(time);
        onOffImage->switchState(getPresenter()->getAlarm()->enabled ? ButtonTriState::State::On : ButtonTriState::State::Off);
        onOffImage->switchState(getPresenter()->getAlarm()->enabled ? ButtonTriState::State::On
                                                                    : ButtonTriState::State::Off);

        if (getPresenter()->hasRecurrence()) {
            periodLabel->setText(getPresenter()->getDescription());

M module-apps/application-settings/windows/network/NetworkWindow.cpp => module-apps/application-settings/windows/network/NetworkWindow.cpp +30 -1
@@ 5,8 5,8 @@

#include <application-settings/ApplicationSettings.hpp>
#include <application-settings/windows/WindowNames.hpp>

#include <OptionSetting.hpp>
#include <widgets/ButtonTriState.hpp>

namespace gui
{


@@ 37,6 37,35 @@ namespace gui
            gui::option::SettingRightItem::ArrowWhite,
            false));

#if ENABLE_VOLTE == 1
#pragma message "state switching not connected to the actual state yet - see MOS-793"
        auto getNextVolteState = []() {
            using namespace gui::option;

            static size_t volteStateIndex;
            static constexpr SettingRightItem volteStates[]{
                SettingRightItem::Transiting, SettingRightItem::On, SettingRightItem::Off};

            auto currentIndex = ++volteStateIndex % (sizeof(volteStates) / sizeof(volteStates[0]));
            return volteStates[currentIndex];
        };

        optList.emplace_back(std::make_unique<gui::option::OptionSettings>(
            utils::translate("app_settings_network_voice_over_lte"),
            [=](gui::Item &item) {
                refreshOptionsList();
                return true;
            },
            [&](Item &item) {
                auto navBarCaption =
                    (item.focus) ? utils::translate("common_switch") : utils::translate("common_select");
                navBar->setText(nav_bar::Side::Center, navBarCaption);
                return true;
            },
            nullptr,
            getNextVolteState()));
#endif

#if DISABLED_SETTINGS_OPTIONS == 1
        auto operatorsOn = operatorsSettings->getOperatorsOn();
        optList.emplace_back(std::make_unique<gui::option::OptionSettings>(

M module-apps/apps-common/notifications/NotificationListItem.cpp => module-apps/apps-common/notifications/NotificationListItem.cpp +2 -1
@@ 141,7 141,8 @@ NotificationWithEventCounter::NotificationWithEventCounter(notifications::Notifi
    text->setMaximumSize(text->getSize(Axis::X), Axis::X);
}

NotificationWithOnOffButton::NotificationWithOnOffButton(notifications::NotificationType type, gui::ButtonTriState::State state)
NotificationWithOnOffButton::NotificationWithOnOffButton(notifications::NotificationType type,
                                                         gui::ButtonTriState::State state)
    : NotificationListItem(type)
{
    auto button = new ButtonTriState(nullptr, state);

M module-apps/apps-common/notifications/NotificationsListPresenter.cpp => module-apps/apps-common/notifications/NotificationsListPresenter.cpp +2 -1
@@ 95,7 95,8 @@ auto NotificationsListPresenter::create(const notifications::NotSeenCallNotifica
auto NotificationsListPresenter::create(const notifications::TetheringNotification *notification)
    -> NotificationListItem *
{
    auto item = new NotificationWithOnOffButton(notifications::NotificationType::Tethering, gui::ButtonTriState::State::On);
    auto item =
        new NotificationWithOnOffButton(notifications::NotificationType::Tethering, gui::ButtonTriState::State::On);
    item->setName(utils::translate("Tethering"), false);
    item->deleteByList = false;
    return item;

M module-apps/apps-common/options/OptionStyle.hpp => module-apps/apps-common/options/OptionStyle.hpp +1 -0
@@ 26,6 26,7 @@ namespace gui::option
        Disabled,
        ArrowBlack,
        ArrowWhite,
        Transiting,
        On,
        Off,
        Bt,

M module-apps/apps-common/options/type/OptionSetting.cpp => module-apps/apps-common/options/type/OptionSetting.cpp +3 -0
@@ 44,6 44,9 @@ namespace gui::option
        case SettingRightItem::ArrowWhite:
            imageName = "arrow_right_empty_32px_W_G";
            break;
        case SettingRightItem::Transiting:
            button = new ButtonTriState(optionBodyHBox, ButtonTriState::State::Transiting);
            break;
        case SettingRightItem::On:
            button = new ButtonTriState(optionBodyHBox, ButtonTriState::State::On);
            break;

M module-apps/apps-common/widgets/ButtonTriState.cpp => module-apps/apps-common/widgets/ButtonTriState.cpp +40 -22
@@ 8,40 8,58 @@

namespace gui
{
    ButtonTriState::ButtonTriState(Item *parent, State state) : Label{parent}
    ButtonTriState::ButtonTriState(Item *parent, State state)
        : Label{parent}, transitingText{utils::translate("app_settings_toggle_transiting")}
    {
        setMinimumSize(style::buttonTriState::w, style::buttonTriState::h);
        setEdges(RectangleEdge::None);
        switchState(state);
    }

        setAlignment(Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));
    void ButtonTriState::switchState(State requestedState)
    {
        setFont(style::window::font::small);
        setRadius(4);
        setPenWidth(2);

        fill = new Rect(this, 0, 0, 0, 0);
        fill->setEdges(RectangleEdge::All);
        fill->setCorners(RectangleRoundedCorner::All);
        fill->setRadius(4);
        fill->setPenWidth(2);

        dimensionChangedCallback = [&](gui::Item &, const BoundingBox &newDim) -> bool {
            fill->setArea({0, 0, newDim.w, newDim.h});
            return true;
        auto setRectangleStyle = [this]() {
            setAlignment(Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center));
            setMinimumSize(style::buttonTriState::w, style::buttonTriState::h);
            setEdges(RectangleEdge::All);
            setCorners(RectangleRoundedCorner::All);
        };

        switchState(state);
    }
        auto setTextOnlyStyle = [this]() {
            setAlignment(Alignment(gui::Alignment::Horizontal::Right, gui::Alignment::Vertical::Center));
            setMinimumSize(120,
                           style::buttonTriState::h); // unfortunately, setMinimumWidthToFitText() doesn't work here
            setEdges(RectangleEdge::None);
            setCorners(RectangleRoundedCorner::None);
            setColor(ColorFullBlack);
        };

    void ButtonTriState::switchState(State requestedState)
    {
        currentState = requestedState;
        if (currentState == State::On) {
            fill->setFillColor(ColorFullBlack);
        // placed here instead of a narrower scope because magic_enum can't retrieve the enum element's name inside a
        // switch()
        std::string_view stateName = magic_enum::enum_name(currentState);
        switch (currentState) {
        case State::On:
            setRectangleStyle();
            setFillColor(ColorFullBlack);
            setColor(ColorFullWhite);
            setText(utils::translate("app_settings_toggle_on"));
        }
        else {
            fill->setFillColor(ColorFullWhite);
            break;
        case State::Transiting:
            setTextOnlyStyle();
            setText(transitingText);
            break;
        default:
            LOG_ERROR("button state '%s' not implemented - defaulting to OFF", stateName.data());
            [[fallthrough]];
        case State::Off:
            setRectangleStyle();
            setFillColor(ColorFullWhite);
            setColor(ColorFullBlack);
            setText(utils::translate("app_settings_toggle_off"));
            break;
        }
    }
} /* namespace gui */

M module-apps/apps-common/widgets/ButtonTriState.hpp => module-apps/apps-common/widgets/ButtonTriState.hpp +4 -4
@@ 11,8 11,8 @@ namespace style
    {
        constexpr uint32_t w = 56;
        constexpr uint32_t h = 32;
    }
}
    } // namespace buttonTriState
} // namespace style

namespace gui
{


@@ 30,7 30,7 @@ namespace gui
        void switchState(State requestedState);

      private:
        Rect *fill = nullptr;
        std::string const transitingText;
        State currentState;
    };
}
} // namespace gui