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.
19 #include "notification-ex/icon_text_item.h"
20 #include "notification-ex/icon_text_item_implementation.h"
21 #include "notification-ex/factory_manager.h"
22 #include "notification-ex/exception.h"
28 #define LOG_TAG "NOTIFICATION_EX"
29 #define ICONTEXT_PATH_KEY "__ICONTEXT_PATH_KEY__"
30 #define ICONTEXT_TITLE_KEY "__ICONTEXT_TITLE_KEY__"
32 namespace notification {
35 IconTextItem::IconTextItem(std::string id, std::shared_ptr<IconItem> icon,
36 std::shared_ptr<TextItem> text, std::shared_ptr<AbstractAction> action)
37 : AbstractItem(id, action),
38 impl_(new Impl(this, icon, text)) {
41 IconTextItem::Impl::Impl(IconTextItem* parent, std::shared_ptr<IconItem> icon,
42 std::shared_ptr<TextItem> text)
43 : parent_(parent), icon_(icon), text_(text) {
44 LOGI("IconTextItem impl created");
47 int IconTextItem::GetType() const {
48 return AbstractItem::IconText;
51 Bundle IconTextItem::Serialize() {
53 b = AbstractItem::Serialize();
55 b.Add(ICONTEXT_PATH_KEY,
56 reinterpret_cast<char*>(impl_->icon_->Serialize().ToRaw().first.get()));
57 b.Add(ICONTEXT_TITLE_KEY,
58 reinterpret_cast<char*>(impl_->text_->Serialize().ToRaw().first.get()));
62 void IconTextItem::Deserialize(Bundle b) {
63 AbstractItem::Deserialize(b);
65 std::shared_ptr<AbstractItem> icon =
66 FactoryManager::GetInst().CreateItem(AbstractItem::Icon);
67 icon.get()->Deserialize(Bundle(b.GetString(ICONTEXT_PATH_KEY)));
68 impl_->icon_ = std::static_pointer_cast<IconItem>(icon);
70 std::shared_ptr<AbstractItem> text =
71 FactoryManager::GetInst().CreateItem(AbstractItem::Text);
72 text.get()->Deserialize(Bundle(b.GetString(ICONTEXT_TITLE_KEY)));
73 impl_->text_ = std::static_pointer_cast<TextItem>(text);
76 AbstractItem& IconTextItem::FindByID(std::string id) {
80 return FactoryManager::GetInst().GetNullItem();
83 IconItem& IconTextItem::GetIconItem() const {
84 return *(impl_->icon_);
87 TextItem& IconTextItem::GetTextItem() const {
88 return *(impl_->text_);
91 IconTextItem::~IconTextItem() = default;
92 IconTextItem::Impl::~Impl() = default;
95 } // namespace notification_ex