~aleteoryx/muditaos

ref: ef3f840a4dfa76f16dd009c536782a8b28fec6e9 muditaos/module-apps/application-music-player/models/SongsModel.cpp -rw-r--r-- 1.5 KiB
ef3f840a — Marcin Smoczyński [EGD-6049] Add voice call over HSP 4 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "SongsModel.hpp"
#include "application-music-player/widgets/SongItem.hpp"

#include <ListView.hpp>
#include <service-audio/AudioServiceAPI.hpp>
#include <time/time_conversion.hpp>

SongsModel::SongsModel(app::Application *app) : application(app)
{}

auto SongsModel::requestRecordsCount() -> unsigned int
{
    return internalData.size();
}

auto SongsModel::getMinimalItemHeight() const -> unsigned int
{
    return musicPlayerStyle::songItem::h;
}

void SongsModel::requestRecords(const uint32_t offset, const uint32_t limit)
{
    setupModel(offset, limit);
    list->onProviderDataUpdate();
}

auto SongsModel::getItem(gui::Order order) -> gui::ListItem *
{
    return getRecord(order);
}

void SongsModel::createData(const std::vector<audio::Tags> &songsList,
                            std::function<bool(const std::string &fileName)> func)
{
    for (const auto &song : songsList) {
        auto item = new gui::SongItem(song.artist, song.title, utils::time::Duration(song.total_duration_s).str());

        item->activatedCallback = [=](gui::Item &) {
            func(song.filePath);
            return true;
        };

        internalData.push_back(item);
    }

    for (auto item : internalData) {
        item->deleteByList = false;
    }

    list->rebuildList();
}

void SongsModel::clearData()
{
    list->reset();

    list->rebuildList();
}