~aleteoryx/muditaos

72f01e450b21ed5346c94f7736c4ac21787022a7 — Lukasz Mastalerz 2 years ago 2ec5be1
[BH-1815] Optimalize loading music files in relaxation

Add relaxation list refresh after files added or deleted
M module-vfs/src/purefs/fs/notifier.cpp => module-vfs/src/purefs/fs/notifier.cpp +2 -2
@@ 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 <purefs/fs/notifier.hpp>
#include <purefs/fs/inotify_message.hpp>


@@ 109,7 109,7 @@ namespace purefs::fs::internal
            svc->bus.sendUnicast(std::move(msg), svc->GetName());
        }
        else {
            LOG_WARN("Sent notification to the same thread is forbidded");
            LOG_WARN("Sending a notification to the same thread is forbidden");
        }
    }
} // namespace purefs::fs::internal

M products/BellHybrid/apps/application-bell-relaxation/ApplicationBellRelaxation.cpp => products/BellHybrid/apps/application-bell-relaxation/ApplicationBellRelaxation.cpp +31 -2
@@ 28,9 28,16 @@
#include <common/models/BatteryModel.hpp>
#include <common/models/AudioModel.hpp>
#include <audio/AudioMessage.hpp>
#include <service-db/DBNotificationMessage.hpp>

#include <log/log.hpp>

namespace
{
    constexpr auto relaxationRebuildTimer         = "RelaxationRebuildTimer";
    constexpr auto relaxationRebuildTimerInterval = std::chrono::milliseconds{5000};
} // namespace

namespace app
{
    ApplicationBellRelaxation::ApplicationBellRelaxation(std::string name,


@@ 42,6 49,7 @@ namespace app
          audioModel{std::make_unique<AudioModel>(this)}
    {
        bus.channels.push_back(sys::BusChannel::ServiceAudioNotifications);
        bus.channels.push_back(sys::BusChannel::ServiceDBNotifications);
    }
    ApplicationBellRelaxation::~ApplicationBellRelaxation() = default;



@@ 52,8 60,15 @@ namespace app
            return ret;
        }

        batteryModel = std::make_unique<app::BatteryModel>(this);
        player       = std::make_unique<relaxation::RelaxationPlayer>(*audioModel);
        batteryModel                 = std::make_unique<app::BatteryModel>(this);
        player                       = std::make_unique<relaxation::RelaxationPlayer>(*audioModel);
        relaxationRebuildTimerHandle = sys::TimerFactory::createSingleShotTimer(
            this, relaxationRebuildTimer, relaxationRebuildTimerInterval, [this](sys::Timer &) {
                const auto mainWindow = getWindow(gui::name::window::main_window);
                if (mainWindow != nullptr) {
                    mainWindow->rebuild();
                }
            });

        createUserInterface();



@@ 141,6 156,20 @@ namespace app
            return retMsg;
        }

        if (auto msg = dynamic_cast<db::NotificationMessage *>(msgl); msg != nullptr) {
            if (msg->interface == db::Interface::Name::MultimediaFiles && msg->type != db::Query::Type::Read) {
                if (!relaxationRebuildTimerHandle.isActive()) {
                    relaxationRebuildTimerHandle.start();
                }
                else {
                    relaxationRebuildTimerHandle.restart(relaxationRebuildTimerInterval);
                }
                return sys::msgHandled();
            }
            userInterfaceDBNotification(
                msgl, [&]([[maybe_unused]] sys::Message *, [[maybe_unused]] const std::string &) { return true; });
            return sys::msgHandled();
        }
        return handleAsyncResponse(resp);
    }


M products/BellHybrid/apps/application-bell-relaxation/include/application-bell-relaxation/ApplicationBellRelaxation.hpp => products/BellHybrid/apps/application-bell-relaxation/include/application-bell-relaxation/ApplicationBellRelaxation.hpp +1 -0
@@ 33,6 33,7 @@ namespace app
        std::unique_ptr<AbstractAudioModel> audioModel;
        std::unique_ptr<AbstractBatteryModel> batteryModel;
        std::unique_ptr<relaxation::RelaxationPlayer> player;
        sys::TimerHandle relaxationRebuildTimerHandle{};

        void onStop() override;
        sys::MessagePointer handleSwitchWindow(sys::Message *msgl) override;

M products/BellHybrid/apps/application-bell-relaxation/model/RelaxationSongsModel.cpp => products/BellHybrid/apps/application-bell-relaxation/model/RelaxationSongsModel.cpp +7 -2
@@ 22,6 22,11 @@ namespace app::relaxation
        songsRepository->init();
    }

    void RelaxationSongsModel::updateRecordsCount()
    {
        songsRepository->updateFilesCount();
    }

    unsigned int RelaxationSongsModel::requestRecordsCount()
    {
        return songsRepository->getRecordsCount();


@@ 39,11 44,11 @@ namespace app::relaxation

        auto item = new gui::option::OptionBellMenu(
            sound->tags.title,
            [=](gui::Item &item) {
            [=]([[maybe_unused]] gui::Item &item) {
                activateCallback(*sound);
                return true;
            },
            [=](gui::Item &item) { return true; },
            [=]([[maybe_unused]] gui::Item &item) { return true; },
            nullptr);

        return item->build();

M products/BellHybrid/apps/application-bell-relaxation/model/RelaxationSongsModel.hpp => products/BellHybrid/apps/application-bell-relaxation/model/RelaxationSongsModel.hpp +1 -0
@@ 44,5 44,6 @@ namespace app::relaxation
        void requestRecords(std::uint32_t offset, std::uint32_t limit) override;

        void createData(OnActivateCallback activateCallback) override;
        void updateRecordsCount();
    };
} // namespace app::relaxation

M products/BellHybrid/apps/application-bell-relaxation/model/RelaxationSongsRepository.cpp => products/BellHybrid/apps/application-bell-relaxation/model/RelaxationSongsRepository.cpp +5 -1
@@ 34,6 34,11 @@ namespace app::relaxation

    void RelaxationSongsRepository::init()
    {
        updateFilesCount();
    }

    void RelaxationSongsRepository::updateFilesCount()
    {
        for (const auto &[musicType, musicPath] : pathPrefixes) {
            updateFilesCount(musicType, musicPath);
        }


@@ 79,7 84,6 @@ namespace app::relaxation
            if (viewUpdateCallback) {
                viewUpdateCallback(musicFilesViewCache.records, musicFilesViewCache.recordsCount);
            }
            updateCountCallback(musicType, result->getCount());
            return true;
        };


M products/BellHybrid/apps/application-bell-relaxation/model/RelaxationSongsRepository.hpp => products/BellHybrid/apps/application-bell-relaxation/model/RelaxationSongsRepository.hpp +1 -0
@@ 27,6 27,7 @@ namespace app::relaxation
                           const OnGetMusicFilesListCallback &viewUpdateCallback);

        std::uint32_t getRecordsCount();
        void updateFilesCount();

      private:
        ApplicationCommon *application;

M products/BellHybrid/apps/application-bell-relaxation/presenter/RelaxationMainWindowPresenter.cpp => products/BellHybrid/apps/application-bell-relaxation/presenter/RelaxationMainWindowPresenter.cpp +5 -0
@@ 23,6 23,11 @@ namespace app::relaxation
        }
    }

    void RelaxationMainWindowPresenter::updateRecordsCount()
    {
        songsModel->updateRecordsCount();
    }

    std::shared_ptr<RelaxationSongsModel> RelaxationMainWindowPresenter::getSongsModel()
    {
        return songsModel;

M products/BellHybrid/apps/application-bell-relaxation/presenter/RelaxationMainWindowPresenter.hpp => products/BellHybrid/apps/application-bell-relaxation/presenter/RelaxationMainWindowPresenter.hpp +2 -0
@@ 33,6 33,7 @@ namespace app::relaxation
          public:
            virtual void createData(RelaxationSongsModel::OnActivateCallback activateCallback) = 0;
            virtual void updateViewState()                                                     = 0;
            virtual void updateRecordsCount()                                                  = 0;
            virtual std::shared_ptr<RelaxationSongsModel> getSongsModel()                      = 0;
        };
    };


@@ 43,6 44,7 @@ namespace app::relaxation
        std::shared_ptr<RelaxationSongsModel> songsModel;
        void createData(RelaxationSongsModel::OnActivateCallback activateCallback) override;
        void updateViewState() override;
        void updateRecordsCount() override;
        std::shared_ptr<RelaxationSongsModel> getSongsModel() override;

      public:

M products/BellHybrid/apps/application-bell-relaxation/windows/RelaxationMainWindow.cpp => products/BellHybrid/apps/application-bell-relaxation/windows/RelaxationMainWindow.cpp +1 -0
@@ 70,6 70,7 @@ namespace gui
    }
    void RelaxationMainWindow::rebuild()
    {
        presenter->updateRecordsCount();
        songList->rebuildList(gui::listview::RebuildType::Full);
    }