• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_LOCAL_LIVE_VIEW_CONTENT_H
17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_LOCAL_LIVE_VIEW_CONTENT_H
18 
19 #include "notification_capsule.h"
20 #include "notification_progress.h"
21 #include "notification_local_live_view_button.h"
22 #include "message_user.h"
23 #include "notification_basic_content.h"
24 #include "notification_conversational_message.h"
25 #include "notification_json_convert.h"
26 #include "notification_time.h"
27 #include "parcel.h"
28 #include <vector>
29 #include "ans_const_define.h"
30 
31 namespace OHOS {
32 namespace Notification {
33 class NotificationLocalLiveViewContent : public NotificationBasicContent {
34 public:
35     enum LiveViewContentInner {
36         CAPSULE = 1,
37         BUTTON,
38         PROGRESS,
39         TIME,
40         INITIAL_TIME,
41         CARD_BUTTON,
42     };
43 
44     enum class LiveViewTypes {
45         LIVE_VIEW_ACTIVITY,
46         LIVE_VIEW_INSTANT,
47         LIVE_VIEW_LONG_TERM,
48         LIVE_VIEW_INSTANT_BANNER,
49     };
50 
51     NotificationLocalLiveViewContent() = default;
52     ~NotificationLocalLiveViewContent() = default;
53 
54     /*
55      * @brief Sets the type to be included in a local live view notification.
56      *
57      * @param type Indicates the type to be included.
58      */
59     void SetType(int32_t type);
60 
61     /*
62      * @brief Get the type of a local live view notification.
63      *
64      */
65     int32_t GetType();
66 
67     /*
68      * @brief Sets the capsule to be included in a local live view notification.
69      *
70      * @param capsule Indicates the type to be included.
71      */
72     void SetCapsule(NotificationCapsule capsule);
73 
74     /*
75      * @brief Get the capsule of a local live view notification.
76      *
77      */
78     NotificationCapsule GetCapsule();
79 
80     /*
81      * @brief Sets the button to be included in a local live view notification.
82      *
83      * @param button Indicates the type to be included.
84      */
85     void SetButton(NotificationLocalLiveViewButton button);
86 
87     /*
88      * @brief Get the button of a local live view notification.
89      *
90      */
91     NotificationLocalLiveViewButton GetButton();
92 
93     /*
94      * @brief Sets the card button to be included in a local live view notification.
95      *
96      * @param button Indicates the type to be included.
97      */
98     void SetCardButton(std::vector<NotificationIconButton> buttons);
99 
100     /*
101      * @brief Get the card button of a local live view notification.
102      *
103      */
104     std::vector<NotificationIconButton> GetCardButton();
105 
106     /*
107      * @brief Sets the progress to be included in a local live view notification.
108      *
109      * @param progress Indicates the type to be included.
110      */
111     void SetProgress(NotificationProgress progress);
112 
113     /*
114      * @brief Get the progress of a local live view notification.
115      *
116      */
117     NotificationProgress GetProgress();
118 
119     /*
120      * @brief Sets the time to be included in a local live view notification.
121      *
122      * @param time Indicates the type to be included.
123      */
124     void SetTime(NotificationTime time);
125 
126     /*
127      * @brief Get the time of a local live view notification.
128      *
129      */
130     NotificationTime GetTime();
131 
132     /*
133      * @add flag function.
134      *
135      * @param flag Indicates the flag to be added.
136      */
137     void addFlag(int32_t flag);
138 
139     /*
140      * @return is the given flag exist.
141      *
142      * @param flag Indicates the flag to be added.
143      */
144     bool isFlagExist(int32_t flag);
145 
146     /*
147      * @brief Sets the type to be included in a local live view notification.
148      *
149      * @param type Indicates the type to be included.
150      */
151     void SetLiveViewType(const LiveViewTypes type);
152 
153     /*
154      * @brief Get the type of a local live view notification.
155      *
156      */
157     LiveViewTypes GetLiveViewType() const;
158 
159     /**
160      * @brief Returns a string representation of the object.
161      *
162      * @return Returns a string representation of the object.
163      */
164     std::string Dump() override;
165 
166     /**
167      * @brief Converts a NotificationConversationalContent object into a Json.
168      *
169      * @param jsonObject Indicates the Json object.
170      * @return Returns true if succeed; returns false otherwise.
171      */
172     virtual bool ToJson(nlohmann::json &jsonObject) const override;
173 
174     /**
175      * @brief Creates a NotificationConversationalContent object from a Json.
176      *
177      * @param jsonObject Indicates the Json object.
178      * @return Returns the NotificationConversationalContent.
179      */
180     static NotificationLocalLiveViewContent *FromJson(const nlohmann::json &jsonObject);
181 
182     /**
183      * @brief Marshal a object into a Parcel.
184      *
185      * @param parcel Indicates the object into the parcel.
186      * @return Returns true if succeed; returns false otherwise.
187      */
188     virtual bool Marshalling(Parcel &parcel) const override;
189 
190     /**
191      * @brief Unmarshal object from a Parcel.
192      *
193      * @param parcel Indicates the parcel object.
194      * @return Returns the NotificationConversationalContent.
195      */
196     static NotificationLocalLiveViewContent *Unmarshalling(Parcel &parcel);
197 
198     void ClearButton();
199 
200     void ClearCapsuleIcon();
201 
202 protected:
203     /**
204      * @brief Read a NotificationConversationalContent object from a Parcel.
205      *
206      * @param parcel Indicates the parcel object.
207      * @return Returns true if succeed; returns false otherwise.
208      */
209     bool ReadFromParcel(Parcel &parcel) override;
210 
211 private:
212     int32_t type_ {0};
213     NotificationCapsule capsule_ {};
214     NotificationLocalLiveViewButton button_ {};
215     std::vector<NotificationIconButton> card_button_ {};
216     NotificationProgress progress_ {};
217     NotificationTime time_ {};
218     std::vector<int32_t> flags_ {};
219     LiveViewTypes liveviewType_;
220 };
221 }  // namespace Notification
222 }  // namespace OHOS
223 
224 #endif  // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_CONVERSATIONAL_CONTENT_H
225