~aleteoryx/muditaos

ref: f4bcc5ce6f0d66f6ee55949f9978ad0c0399fddb muditaos/module-apps/application-music-player/windows/MusicPlayerMainWindow.hpp -rw-r--r-- 3.6 KiB
f4bcc5ce — Dawid Wojtas [BH-1758] Fix information about next alarm ring 2 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include <application-music-player/presenters/SongsPresenter.hpp>
#include <AppWindow.hpp>
#include <TextFixedSize.hpp>
#include <OptionWindow.hpp>
#include <module-apps/apps-common/InternalModel.hpp>

namespace gui
{
    class ListView;
    class ImageBox;
    class OptionSettings;

    /// Start MP app window with possible three internal states:
    /// - init screen
    /// - music library screen
    /// - track preview screen
    class MusicPlayerMainWindow : public OptionWindow, public app::music_player::SongsContract::View
    {
      public:
        /// number of vertical items in track's progress bar
        static constexpr uint8_t progressBarSize = 27;

        /// current view mode (switching with up / down arrow)
        enum class ViewMode
        {
            START = 1, // start screen "press down arrow to choose..."
            TRACK,     // track info
            LIBRARY    // Music library
        };

        explicit MusicPlayerMainWindow(app::ApplicationCommon *app,
                                       std::shared_ptr<app::music_player::SongsContract::Presenter> presenter);

        void onBeforeShow([[maybe_unused]] ShowMode mode, [[maybe_unused]] SwitchData *data) override;

        void rebuild() override;
        void buildInterface() override;
        void destroyInterface() override;
        bool onInput(const InputEvent &inputEvent) override;

        void updateSongsState(std::optional<db::multimedia_files::MultimediaFilesRecord> record,
                              RecordState state) override;
        void updateSongProgress(float progress) override;
        void refreshWindow() override;
        void setNavBarTemporaryMode(const std::string &text) override;
        void restoreFromNavBarTemporaryMode() override;

        void changeCurrentMode(ViewMode m);

      protected:
        void buildInterfaceStartMode();
        void buildInterfaceTrackMode();
        void buildInterfaceLibraryMode();

        void buildPlayButtonsInterface(VBox *parent);
        void buildSwipeDownInterface(VBox *parent);
        void buildTrackProgressInterface(VBox *parent);
        void buildTrackInfoInterface(VBox *parent);
        void updateVisibleTrackData(RecordState state) noexcept;
        void updateVisibleProgressData(void) noexcept;

        bool onInputTrackMode(const InputEvent &inputEvent);

      private:
        ViewMode myViewMode = ViewMode::START;

        std::shared_ptr<app::music_player::SongsContract::Presenter> presenter;
        Label *titleText                         = nullptr;
        Label *artistText                        = nullptr;
        Text *currentTimeText                    = nullptr;
        Text *totalTimeText                      = nullptr;
        ImageBox *rewImageBox                    = nullptr;
        ImageBox *pauseImageBox                  = nullptr;
        ImageBox *ffImageBox                     = nullptr;
        ImageBox *stateImageBox                  = nullptr;
        Label *descriptionText                   = nullptr;
        Image *progressBarItems[progressBarSize] = {nullptr};

        float currentProgress            = 0.f;
        uint32_t currentTotalTime        = 0;
        uint8_t currentProgressBarsBlack = 0;
        std::string currentTitle;
        std::string currentArtist;
        std::string currentTimeString;
        std::string currentTotalTimeString;
        bool isPermissionToChangeViewMode = false;
        bool needToDeepRedrawScreen       = false;
    };

} /* namespace gui */