~aleteoryx/muditaos

e9934359ecb93af31a00f6ff25aecebb32ea8c2d — Lefucjusz 1 year, 11 months ago 49f4e46
[BH-1897] Integration fixes and cleanups

* Fix of the issue that quick returning
from window next to the list window to
the one before list window result in
playback not being stopped.
* Fix of the issue that list context
wouldn't be restored after returning
from popup.
* Minor cleanup of the logic after adding
opening on selected sound on list
entering - removed redundant call to
setValue, rename of some methods
and variables.
M module-utils/unicode/utf8/utf8/UTF8.hpp => module-utils/unicode/utf8/utf8/UTF8.hpp +5 -1
@@ 1,4 1,4 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once


@@ 86,6 86,10 @@ class UTF8
    UTF8 operator+(const UTF8 &utf) const;
    UTF8 &operator+=(const UTF8 &utf);
    bool operator==(const UTF8 &utf) const;
    friend bool operator==(const std::string &lhs, const UTF8 &rhs)
    {
        return rhs == lhs;
    }
    bool operator!=(const UTF8 &utf) const
    {
        return !operator==(utf);

M products/BellHybrid/apps/application-bell-bedtime/models/BedtimeListItemProvider.cpp => products/BellHybrid/apps/application-bell-bedtime/models/BedtimeListItemProvider.cpp +2 -2
@@ 24,7 24,7 @@ namespace app::bell_bedtime
        constexpr auto itemCount = 2U;
        internalData.reserve(itemCount);

        auto onOff       = new OnOffListItem(model.get()->getBedtimeOnOff(), utils::translate("app_bellmain_bedtime"));
        auto onOff       = new OnOffListItem(model->getBedtimeOnOff(), utils::translate("app_bellmain_bedtime"));
        onOff->onProceed = [onOff, this]() {
            if (not onOff->isActive()) {
                this->onExit();


@@ 33,7 33,7 @@ namespace app::bell_bedtime
            return false;
        };
        internalData.emplace_back(onOff);
        internalData.emplace_back(new TimeListItem(model.get()->getBedtimeTime(),
        internalData.emplace_back(new TimeListItem(model->getBedtimeTime(),
                                                   stm::api::timeFormat(),
                                                   bell_bedtime_style::time_set_fmt_spinner::focusFont,
                                                   bell_bedtime_style::time_set_fmt_spinner::noFocusFont,

M products/BellHybrid/apps/application-bell-settings/models/alarm_settings/AlarmSettingsListItemProvider.cpp => products/BellHybrid/apps/application-bell-settings/models/alarm_settings/AlarmSettingsListItemProvider.cpp +8 -5
@@ 33,19 33,22 @@ namespace app::bell_settings

        auto alarmTone = new SongsListViewItem(
            utils::translate("app_bell_settings_alarm_settings_chime"), settingsModel.getAlarmTone(), songsModel);

        currentSoundPath = settingsModel.getAlarmTone().getValue();
        alarmTone->set_on_value_change_cb([this](const auto &val) {
            currentSoundPath = val;
            if (onToneChange) {
                onToneChange(val);
                onToneChange(currentSoundPath);
            }
        });
        alarmTone->onEnter = [this, alarmTone]() {
        alarmTone->onEnter = [this]() {
            if (onToneEnter) {
                onToneEnter(alarmTone->value());
                onToneEnter(currentSoundPath);
            }
        };
        alarmTone->onExit = [this, alarmTone]() {
        alarmTone->onExit = [this]() {
            if (onToneExit) {
                onToneExit(alarmTone->value());
                onToneExit(currentSoundPath);
            }
        };
        internalData.emplace_back(alarmTone);

M products/BellHybrid/apps/application-bell-settings/models/alarm_settings/AlarmSettingsListItemProvider.hpp => products/BellHybrid/apps/application-bell-settings/models/alarm_settings/AlarmSettingsListItemProvider.hpp +1 -0
@@ 30,5 30,6 @@ namespace app::bell_settings
        AbstractAlarmSettingsModel &settingsModel;
        app::list_items::NumericWithBar *alarmVolume{nullptr};
        std::shared_ptr<SongsModel> songsModel;
        UTF8 currentSoundPath;
    };
} // namespace app::bell_settings

M products/BellHybrid/apps/application-bell-settings/models/alarm_settings/BedtimeSettingsListItemProvider.cpp => products/BellHybrid/apps/application-bell-settings/models/alarm_settings/BedtimeSettingsListItemProvider.cpp +7 -5
@@ 25,19 25,21 @@ namespace app::bell_settings
        auto chimeTone = new SongsListViewItem(
            utils::translate("app_bell_settings_bedtime_settings_tone"), settingsModel->getBedtimeTone(), songsModel);

        currentSoundPath = settingsModel->getBedtimeTone().getValue();
        chimeTone->set_on_value_change_cb([this](const auto &val) {
            currentSoundPath = val;
            if (onToneChange) {
                onToneChange(val);
                onToneChange(currentSoundPath);
            }
        });
        chimeTone->onEnter = [this, chimeTone]() {
        chimeTone->onEnter = [this]() {
            if (onToneEnter) {
                onToneEnter(chimeTone->value());
                onToneEnter(currentSoundPath);
            }
        };
        chimeTone->onExit = [this, chimeTone]() {
        chimeTone->onExit = [this]() {
            if (onToneExit) {
                onToneExit(chimeTone->value());
                onToneExit(currentSoundPath);
            }
        };
        internalData.emplace_back(chimeTone);

M products/BellHybrid/apps/application-bell-settings/models/alarm_settings/BedtimeSettingsListItemProvider.hpp => products/BellHybrid/apps/application-bell-settings/models/alarm_settings/BedtimeSettingsListItemProvider.hpp +1 -0
@@ 32,5 32,6 @@ namespace app::bell_settings
        std::shared_ptr<AbstractBedtimeModel> settingsModel;
        std::shared_ptr<SongsModel> songsModel;
        app::list_items::NumericWithBar *bedtimeVolume{nullptr};
        UTF8 currentSoundPath;
    };
} // namespace app::bell_settings

M products/BellHybrid/apps/application-bell-settings/models/alarm_settings/PrewakeUpListItemProvider.cpp => products/BellHybrid/apps/application-bell-settings/models/alarm_settings/PrewakeUpListItemProvider.cpp +4 -3
@@ 52,10 52,11 @@ namespace app::bell_settings
                                  settingsModel.getChimeTone(),
                                  songsModel);

        currentSoundPath = settingsModel.getChimeTone().getValue();
        chimeTone->set_on_value_change_cb([this](const auto &val) {
            currentSoundPath = val;
            if (onToneChange) {
                onToneChange(val);
                onToneChange(currentSoundPath);
            }
        });



@@ 104,7 105,7 @@ namespace app::bell_settings
            utils::translate("app_bell_settings_alarm_settings_prewake_up_light_top_description"),
            utils::translate("app_bell_settings_alarm_settings_prewake_up_light_bottom_description"));

        lightDuration->onReturn = [chimeDuration, this]() {
        lightDuration->onReturn = [this, chimeDuration]() {
            if (chimeDuration->value() == 0) {
                list->rebuildList(gui::listview::RebuildType::OnOffset, 0);
                return true;


@@ 112,7 113,7 @@ namespace app::bell_settings
            return false;
        };

        lightDuration->onProceed = [lightDuration, this]() {
        lightDuration->onProceed = [this, lightDuration]() {
            if (lightDuration->value() == 0) {
                this->onExit();
                return true;

M products/BellHybrid/apps/application-bell-settings/models/alarm_settings/SnoozeListItemProvider.cpp => products/BellHybrid/apps/application-bell-settings/models/alarm_settings/SnoozeListItemProvider.cpp +4 -2
@@ 127,10 127,12 @@ namespace app::bell_settings
            new SongsListViewItem(utils::translate("app_bell_settings_alarm_settings_snooze_chime_tone"),
                                  settingsModel.getSnoozeChimeTone(),
                                  songsModel);
        snoozeChimeTone->set_on_value_change_cb([chimeInterval, this](const auto &val) {

        currentSoundPath = settingsModel.getSnoozeChimeTone().getValue();
        snoozeChimeTone->set_on_value_change_cb([this](const auto &val) {
            currentSoundPath = val;
            if (onToneChange) {
                onToneChange(val);
                onToneChange(currentSoundPath);
            }
        });
        snoozeChimeTone->onEnter = [this, chimeInterval]() {

M products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/PrewakeUpPresenter.cpp => products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/PrewakeUpPresenter.cpp +1 -1
@@ 26,7 26,7 @@ namespace app::bell_settings
        this->provider->onToneChange = playSound;

        this->provider->onVolumeEnter  = playSound;
        this->provider->onVolumeExit   = [this](const auto &) { this->stopSound(); };
        this->provider->onVolumeExit   = [this](const auto &) { stopSound(); };
        this->provider->onVolumeChange = [this, playSound](const auto &val) {
            this->audioModel.setVolume(
                val, AbstractAudioModel::PlaybackType::PreWakeup, audio::VolumeUpdateType::SkipUpdateDB);

M products/BellHybrid/apps/application-bell-settings/widgets/SongsListViewItem.cpp => products/BellHybrid/apps/application-bell-settings/widgets/SongsListViewItem.cpp +34 -5
@@ 26,6 26,25 @@ namespace gui
        list->setListTitle(title);
        list->setListTitleFont(style::bell_sidelist_item::title_font);

        focusChangedCallback = [this]([[maybe_unused]] Item &item) {
            if (focus) {
                /* Prevent re-focusing if list already focused, as it
                 * will cause loss of currently active list position. */
                if (!list->focus) {
                    setFocusItem(body);
                }
                if (onEnter) {
                    onEnter();
                }
            }
            else {
                if (onExit) {
                    onExit();
                }
            }
            return true;
        };

        auto storedCallback = list->inputCallback;
        list->inputCallback = [storedCallback](Item &item, const InputEvent &event) {
            return storedCallback(item, invertNavigationDirection(event));


@@ 40,7 59,18 @@ namespace gui
            return false;
        };
        auto onListItemFocusAcquire = [this](const db::multimedia_files::MultimediaFilesRecord &record) {
            onValueChange(record.fileInfo.path);
            const auto &recordPath = record.fileInfo.path;

            /* Suppress initial calls of this function while the list is being
             * loaded, only handle those caused by knob rotation. */
            if (!listLoadingDone) {
                if (recordPath == value()) {
                    listLoadingDone = true;
                }
            }
            else {
                onValueChange(recordPath);
            }
            return true;
        };
        auto onOffsetUpdateCallback = [this](std::uint32_t offset) {


@@ 48,11 78,10 @@ namespace gui
            return true;
        };

        setValue();
        this->songsModel->createData(std::move(onListItemActivate),
                                     std::move(onListItemFocusAcquire),
                                     this->settingsModel.getValue(),
                                     std::move(onOffsetUpdateCallback));
                                     std::move(onOffsetUpdateCallback),
                                     this->settingsModel.getValue());
    }

    auto SongsListViewItem::value() const -> UTF8


@@ 62,7 91,7 @@ namespace gui

    auto SongsListViewItem::set_value(const UTF8 &value) -> void
    {
        songsModel->setCurrentlyChosenRecordPath(value);
        songsModel->updateCurrentlyChosenRecordPath(value);
    }

    auto SongsListViewItem::set_on_value_change_cb(std::function<void(const UTF8 &)> &&cb) -> void

M products/BellHybrid/apps/application-bell-settings/widgets/SongsListViewItem.hpp => products/BellHybrid/apps/application-bell-settings/widgets/SongsListViewItem.hpp +1 -0
@@ 33,5 33,6 @@ namespace gui
        std::shared_ptr<app::SongsModel> songsModel;
        ListViewWithLabels *list{nullptr};
        std::function<void(const UTF8 &)> onValueChange;
        bool listLoadingDone{false};
    };
} // namespace gui

M products/BellHybrid/apps/common/include/common/SoundsRepository.hpp => products/BellHybrid/apps/common/include/common/SoundsRepository.hpp +5 -5
@@ 15,8 15,8 @@ class AbstractSimpleSoundsRepository
{
  public:
    virtual ~AbstractSimpleSoundsRepository()                                         = default;
    virtual std::optional<std::filesystem::path> titleToPath(const UTF8 &title) const = 0;
    virtual std::optional<UTF8> pathToTitle(std::filesystem::path) const              = 0;
    [[nodiscard]] virtual std::optional<std::filesystem::path> titleToPath(const UTF8 &title) const = 0;
    [[nodiscard]] virtual std::optional<UTF8> pathToTitle(std::filesystem::path) const              = 0;
    virtual std::vector<UTF8> getSongTitles()                                         = 0;
};



@@ 25,8 25,8 @@ class SimpleSoundsRepository : public AbstractSimpleSoundsRepository
  public:
    explicit SimpleSoundsRepository(std::filesystem::path dirToScan);

    std::optional<std::filesystem::path> titleToPath(const UTF8 &title) const override;
    std::optional<UTF8> pathToTitle(std::filesystem::path path) const override;
    [[nodiscard]] std::optional<std::filesystem::path> titleToPath(const UTF8 &title) const override;
    [[nodiscard]] std::optional<UTF8> pathToTitle(std::filesystem::path path) const override;
    std::vector<UTF8> getSongTitles() override;

  private:


@@ 99,5 99,5 @@ class SoundsRepository : public AbstractSoundsRepository, public app::AsyncCallb
                       const OnGetMusicFilesListCallback &viewUpdateCallback);
    std::optional<PathDetails> getPathDetails(const std::string &songPath);
    void updateOffsetFromSavedPath(const std::string &savedPath, OnOffsetUpdateCallback offsetUpdateCallback);
    std::optional<std::uint32_t> calculateOffsetFromDB(std::uint32_t offset, const std::string songPath);
    std::optional<std::uint32_t> calculateOffsetFromDB(std::uint32_t offset, const std::string &songPath);
};

M products/BellHybrid/apps/common/include/common/models/SongsModel.hpp => products/BellHybrid/apps/common/include/common/models/SongsModel.hpp +5 -5
@@ 27,8 27,8 @@ namespace app

        virtual auto createData(OnActivateCallback activateCallback,
                                OnFocusAcquireCallback focusChangeCallback,
                                const std::string &savedPath,
                                OnOffsetUpdateCallback offsetUpdateCallback) -> void = 0;
                                OnOffsetUpdateCallback offsetUpdateCallback,
                                const std::string &savedPath) -> void = 0;
    };

    class SongsModel : public SongsProvider


@@ 49,12 49,12 @@ namespace app

        auto createData(OnActivateCallback activateCallback         = nullptr,
                        OnFocusAcquireCallback focusChangeCallback  = nullptr,
                        const std::string &savedPath                = "",
                        OnOffsetUpdateCallback offsetUpdateCallback = nullptr) -> void override;
                        OnOffsetUpdateCallback offsetUpdateCallback = nullptr,
                        const std::string &chosenRecordPath         = "") -> void override;
        auto updateRecordsCount() -> void;
        auto nextRecordExists(gui::Order order) -> bool;

        auto setCurrentlyChosenRecordPath(const std::string &path) -> void;
        auto updateCurrentlyChosenRecordPath(const std::string &path) -> void;
        [[nodiscard]] auto getCurrentlyChosenRecordPath() const -> std::string;

      private:

M products/BellHybrid/apps/common/src/SoundsRepository.cpp => products/BellHybrid/apps/common/src/SoundsRepository.cpp +1 -1
@@ 254,7 254,7 @@ std::optional<SoundsRepository::PathDetails> SoundsRepository::getPathDetails(co
    return std::nullopt;
}

std::optional<std::uint32_t> SoundsRepository::calculateOffsetFromDB(std::uint32_t offset, const std::string songPath)
std::optional<std::uint32_t> SoundsRepository::calculateOffsetFromDB(std::uint32_t offset, const std::string &songPath)
{
    // the offset returned by the database is incremented from 1,
    // while the offset used in listView is from 0

M products/BellHybrid/apps/common/src/models/SongsModel.cpp => products/BellHybrid/apps/common/src/models/SongsModel.cpp +5 -4
@@ 65,12 65,13 @@ namespace app

    auto SongsModel::createData(OnActivateCallback onActivate,
                                OnFocusAcquireCallback onFocusAcquire,
                                const std::string &savedPath,
                                OnOffsetUpdateCallback offsetUpdateCallback) -> void
                                OnOffsetUpdateCallback offsetUpdateCallback,
                                const std::string &chosenRecordPath) -> void
    {
        currentlyChosenRecordPath = chosenRecordPath;
        activateCallback    = std::move(onActivate);
        focusAcquireCallback = std::move(onFocusAcquire);
        songsRepository->init(savedPath, std::move(offsetUpdateCallback));
        songsRepository->init(currentlyChosenRecordPath, std::move(offsetUpdateCallback));
    }

    auto SongsModel::updateRecordsCount() -> void


@@ 113,7 114,7 @@ namespace app
        return std::nullopt;
    }

    auto SongsModel::setCurrentlyChosenRecordPath(const std::string &path) -> void
    auto SongsModel::updateCurrentlyChosenRecordPath(const std::string &path) -> void
    {
        currentlyChosenRecordPath = path;
    }