2 * Copyright (c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include "notification-ex/text_item.h"
22 #include "notification-ex/text_item_implementation.h"
23 #include "notification-ex/item_factory.h"
29 #define LOG_TAG "NOTIFICATION_EX"
30 #define TEXT_CONTENTS_KEY "__TEXT_CONTENTS_KEY__"
31 #define TEXT_HYPERLINK_KEY "__TEXT_HYPERLINK_KEY__"
33 namespace notification {
35 TextItem::TextItem(std::string text, std::shared_ptr<AbstractAction> action)
36 : AbstractItem(AbstractItem::Type::Text), impl_(new Impl(text)) {
39 TextItem::TextItem(std::string id, std::string text,
40 std::shared_ptr<AbstractAction> action)
41 : AbstractItem(id, AbstractItem::Type::Text), impl_(new Impl(text)) {
44 TextItem::Impl::Impl(std::string text)
46 LOGI("TextItem created");
49 TextItem::~TextItem() = default;
50 TextItem::Impl::~Impl() = default;
52 Bundle TextItem::Serialize() {
54 b = AbstractItem::Serialize();
56 if (!impl_->text_.empty())
57 b.Add(TEXT_CONTENTS_KEY, impl_->text_);
59 if (!impl_->hyperlink_.empty())
60 b.Add(TEXT_HYPERLINK_KEY, impl_->hyperlink_);
65 void TextItem::Deserialize(Bundle b) {
66 AbstractItem::Deserialize(b);
67 impl_->text_ = b.GetString(TEXT_CONTENTS_KEY);
68 impl_->hyperlink_ = b.GetString(TEXT_HYPERLINK_KEY);
71 AbstractItem& TextItem::FindByID(std::string id) {
74 return ItemFactory::GetNullItem();
77 void TextItem::SetContents(std::string contents) {
78 impl_->text_ = contents;
81 std::string TextItem::GetContents() const {
85 std::string TextItem::GetHyperLink() const {
86 return impl_->hyperlink_;
90 } // namespace notification