~aleteoryx/muditaos

035eb4239a5ff640743c78b19c9c1f8eed730901 — Lefucjusz 3 years ago d7c8a8a
[MOS-174] Fix broken events counter for 99+ events

Fix of the issue that events counter
was displayed incorrectly for more
than 99 events.
M module-apps/apps-common/notifications/NotificationListItem.cpp => module-apps/apps-common/notifications/NotificationListItem.cpp +19 -13
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "NotificationListItem.hpp"


@@ 10,6 10,7 @@

#include <widgets/Style.hpp>
#include <map>
#include <Utils.hpp>

using namespace gui;



@@ 57,30 58,35 @@ namespace
        hbox->setMaximumSize(style::window::default_body_width, style::notifications::itemHeight);
    }

    constexpr auto maxNotificationValue = "99+";
    constexpr auto singleNotification   = "1";
    constexpr auto singleNotification             = 1;
    constexpr auto maxNotificationValue           = 99;
    constexpr auto maxNotificationReplacementText = "99+";

    auto buildNotificationCountText(const UTF8 &indicator) -> gui::Text *
    auto buildNotificationCountText(unsigned count) -> gui::Text *
    {
        auto number = new gui::TextFixedSize();
        if (indicator.length() > 2) {
            number->setText(maxNotificationValue);
        const auto number = new gui::TextFixedSize();
        UTF8 countText;

        if (count == singleNotification) {
            countText = "";
        }
        else if (indicator == singleNotification) {
            number->clear();
        else if (count > maxNotificationValue) {
            countText = maxNotificationReplacementText;
        }
        else {
            number->setText(indicator);
            countText = utils::to_string(count);
        }

        number->drawUnderline(false);
        number->setFont(style::window::font::mediumbold);
        number->setMinimumWidthToFitText(indicator);
        number->setMinimumWidthToFitText(countText);
        number->setMinimumHeightToFitText();
        number->setPenWidth(style::window::default_border_no_focus_w);
        number->setMargins(gui::Margins(0, 0, style::window::default_right_margin, 0));
        number->setAlignment(Alignment(gui::Alignment::Horizontal::Right, gui::Alignment::Vertical::Center));
        number->setText(countText);
        number->activeItem = false;

        return number;
    }



@@ 133,11 139,11 @@ notifications::NotificationType NotificationListItem::getType() const noexcept
    return type;
}

NotificationWithEventCounter::NotificationWithEventCounter(notifications::NotificationType type, const UTF8 &indicator)
NotificationWithEventCounter::NotificationWithEventCounter(notifications::NotificationType type, unsigned count)
    : NotificationListItem(type)
{
    box->addWidget(buildImageInactive("dot_12px_hard_alpha_W_G"));
    box->addWidget(buildNotificationCountText(indicator));
    box->addWidget(buildNotificationCountText(count));
    text->setMaximumSize(text->getSize(Axis::X), Axis::X);
}


M module-apps/apps-common/notifications/NotificationListItem.hpp => module-apps/apps-common/notifications/NotificationListItem.hpp +2 -3
@@ 1,4 1,4 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once


@@ 39,12 39,11 @@ namespace gui
    class NotificationWithEventCounter : public NotificationListItem
    {
      public:
        NotificationWithEventCounter(notifications::NotificationType type, const UTF8 &indicator);
        NotificationWithEventCounter(notifications::NotificationType type, unsigned count);
    };

    class NotificationWithOnOffButton : public NotificationListItem
    {

      public:
        NotificationWithOnOffButton(notifications::NotificationType type, gui::ButtonTriState::State state);
    };

M module-apps/apps-common/notifications/NotificationsListPresenter.cpp => module-apps/apps-common/notifications/NotificationsListPresenter.cpp +6 -7
@@ 1,4 1,4 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "NotificationsListPresenter.hpp"


@@ 76,8 76,7 @@ bool NotificationsListPresenter::isEmpty() const noexcept
auto NotificationsListPresenter::create(const notifications::NotSeenSMSNotification *notification)
    -> NotificationListItem *
{
    auto item = new NotificationWithEventCounter(notifications::NotificationType::NotSeenSms,
                                                 utils::to_string(notification->getValue()));
    auto item = new NotificationWithEventCounter(notifications::NotificationType::NotSeenSms, notification->getValue());
    setNotificationText(item, notification, "app_desktop_unread_messages");
    item->deleteByList = false;
    return item;


@@ 85,8 84,8 @@ auto NotificationsListPresenter::create(const notifications::NotSeenSMSNotificat
auto NotificationsListPresenter::create(const notifications::NotSeenCallNotification *notification)
    -> NotificationListItem *
{
    auto item = new NotificationWithEventCounter(notifications::NotificationType::NotSeenCall,
                                                 utils::to_string(notification->getValue()));
    auto item =
        new NotificationWithEventCounter(notifications::NotificationType::NotSeenCall, notification->getValue());
    setNotificationText(item, notification, "app_desktop_missed_calls");
    item->deleteByList = false;
    return item;


@@ 105,8 104,8 @@ auto NotificationsListPresenter::create(const notifications::TetheringNotificati
auto NotificationsListPresenter::create(const notifications::AlarmSnoozeNotification *notification)
    -> NotificationListItem *
{
    auto item = new NotificationWithEventCounter(notifications::NotificationType::AlarmSnooze,
                                                 utils::to_string(notification->getValue()));
    auto item =
        new NotificationWithEventCounter(notifications::NotificationType::AlarmSnooze, notification->getValue());
    item->setName(utils::translate("app_desktop_alarm_snooze"), true);
    item->deleteByList = false;
    return item;

M pure_changelog.md => pure_changelog.md +1 -0
@@ 46,6 46,7 @@
* Fixed time disappearing in SMS thread
* Fixed scrollbar behavior in call log view
* Fixed contacts imported from SIM do not show up in Mudita Center 
* Fixed broken events counter on main screen for more than 99 events

### Added