~aleteoryx/muditaos

ref: cd0cc6dc1a24355eb8637e8b3af1c07dde272c3e muditaos/module-apps/application-alarm-clock/presenter/AlarmPresenter.hpp -rw-r--r-- 2.6 KiB
cd0cc6dc — Mateusz Piesta [BH-890] Home screen alarm popups 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
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
// 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 "log.hpp"

#include <AlarmEventRecord.hpp>
#include <time/time_locale.hpp>
#include <rrule/rrule/rrule.hpp>
#include <utf8/UTF8.hpp>

#include <functional>
#include <list>
#include <memory>

namespace app::alarmClock
{
    typedef utils::time::Locale utl;

    class AlarmPresenter;

    class AlarmEventItem;

    class AlarmPresenter
    {
      private:
        /// our model
        std::shared_ptr<AlarmEventRecord> alarm;
        /// view managed

      protected:
        /// changes day from lib to our days from monday
        utl::Day dayToDay(uint32_t day_no);
        /// changes day from our days to lib format
        uint8_t dayToDay(utl::Day);
        uint8_t set_bit_days();
        static constexpr uint8_t weekdaysMask = 0b0111110;
        static constexpr uint8_t weekMask     = 0b1111111;

      public:
        enum class Spinner
        {
            Never,    /// we do not have any events set
            OnDay,    /// we have event on some - single day
            Custom,   /// there is some custom setup i.e. weekly + sunday - monday
            Weekly,   /// everyday occurrence
            Weekdays, /// every monday to friday occurrence
        };

        virtual ~AlarmPresenter() = default;
        explicit AlarmPresenter(std::shared_ptr<AlarmEventRecord> alarm) : alarm(std::move(alarm)){};

        /// get description for days in week as a coma separated string days, or weekday etc
        UTF8 getDescription();
        /// get information what time of occurrences we have in rrule
        /// please see `enum::Spinner` for more details
        Spinner getSpinner();
        /// set proper rrule from spinner
        void setSpinner(Spinner, const std::function<void(Spinner)> &cb);

        /// set values in model based on list of Enums (Mon, Tue etc)
        void setDays(const std::list<utl::Day> &days);
        /// get values in model as a list
        std::list<utl::Day> getDays();

        /// if rrule is empty we can safely assume that there is no recurrence in the event
        bool hasRecurrence() const
        {
            return alarm && !alarm->rruleText.empty();
        }

        const auto &getAlarm()
        {
            return alarm;
        }
    };

    class AlarmEventItem
    {
        AlarmPresenter p;

      protected:
        auto &presenter()
        {
            return p;
        }

      public:
        explicit AlarmEventItem(AlarmPresenter p) : p(p)
        {}
    };

} // namespace app::alarmClock