impl_->channel_ = channel;
}
+void AbstractItem::SetSoundPath(std::string path) {
+ impl_->sound_path_ = path;
+}
+void AbstractItem::SetVibrationPath(std::string path) {
+ impl_->vibration_path_ = path;
+}
+std::string AbstractItem::GetSoundPath() const {
+ return impl_->sound_path_;
+}
+std::string AbstractItem::GetVibrationPath() const {
+ return impl_->vibration_path_;
+}
+
} // namespace item
} // namespace notification
IconText,
InputSelector,
Group,
- Effect,
+ Entry,
Progress,
Custom,
};
void SetChannel(std::string channel);
void SetLEDInfo(std::shared_ptr<LEDInfo> led);
std::shared_ptr<LEDInfo> GetLEDInfo() const;
+ void SetSoundPath(std::string path);
+ void SetVibrationPath(std::string path);
+ std::string GetSoundPath() const;
+ std::string GetVibrationPath() const;
private:
class Impl;
std::string can_receive_;
std::shared_ptr<AbstractAction> action_;
AbstractItem* parent_;
+ std::string sound_path_;
+ std::string vibration_path_;
};
} // namespace item
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dlog.h>
+
+#include <memory>
+
+#include "notification-ex/entry_item.h"
+#include "notification-ex/entry_item_implementation.h"
+#include "notification-ex/item_factory.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "NOTIFICATION_EX"
+#define ENTRY_TEXT_KEY "__ENTRY_TEXT_KEY__"
+#define ENTRY_LIMIT_KEY "__ENTRY_LIMIT_KEY__"
+
+namespace notification {
+namespace item {
+
+EntryItem::EntryItem(std::string id, std::shared_ptr<AbstractAction> action)
+ : AbstractItem(id, AbstractItem::Type::Entry), impl_(new Impl()) {
+}
+
+EntryItem::EntryItem(std::shared_ptr<AbstractAction> action)
+ : AbstractItem(AbstractItem::Type::Entry), impl_(new Impl()) {
+}
+
+EntryItem::Impl::Impl() {
+ LOGI("EntryItem created");
+}
+
+EntryItem::~EntryItem() = default;
+EntryItem::Impl::~Impl() = default;
+
+Bundle EntryItem::Serialize() {
+ Bundle b;
+ b = AbstractItem::Serialize();
+
+ if (!impl_->text_.empty())
+ b.Add(ENTRY_TEXT_KEY, impl_->text_);
+
+ b.Add(ENTRY_LIMIT_KEY, std::to_string(impl_->limit_));
+
+ return b;
+}
+
+void EntryItem::Deserialize(Bundle b) {
+ AbstractItem::Deserialize(b);
+ impl_->text_ = b.GetString(ENTRY_TEXT_KEY);
+ impl_->limit_ = std::stoi(b.GetString(ENTRY_LIMIT_KEY));
+}
+
+AbstractItem& EntryItem::FindByID(std::string id) {
+ if (GetId() == id)
+ return *this;
+ return ItemFactory::GetNullItem();
+}
+
+std::string EntryItem::GetText() const {
+ return impl_->text_;
+}
+
+void EntryItem::SetText(std::string text) {
+ impl_->text_ = text;
+}
+
+int EntryItem::GetTextLimit() const {
+ return impl_->limit_;
+}
+
+} // namespace item
+} // namespace notification
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef NOTIFICATION_EX_ENTRY_ITEM_H_
+#define NOTIFICATION_EX_ENTRY_ITEM_H_
+
+#include <memory>
+#include <string>
+
+#include "notification-ex/abstract_item.h"
+
+#ifndef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+namespace notification {
+namespace item {
+
+class EXPORT_API EntryItem : public AbstractItem {
+ public:
+ EntryItem(std::shared_ptr<AbstractAction> action = std::shared_ptr<AbstractAction>({}));
+ EntryItem(std::string id,
+ std::shared_ptr<AbstractAction> action = std::shared_ptr<AbstractAction>({}));
+ virtual ~EntryItem();
+
+ Bundle Serialize() override;
+ void Deserialize(Bundle b) override;
+ AbstractItem& FindByID(std::string id) override;
+ std::string GetText() const;
+ void SetText(std::string text);
+ int GetTextLimit() const;
+
+ private:
+ class Impl;
+ std::unique_ptr<Impl> impl_;
+}; // class EntryItem
+
+} // namespace item
+} // nampace notification
+#endif // NOTIFICATION_EX_ENTRY_ITEM_H_
\ No newline at end of file
* limitations under the License.
*/
-#include <gtest/gtest.h>
-#include <gmock/gmock.h>
+#ifndef NOTIFICATION_EX_ENTRY_ITEM_IMPLEMENTATION_H_
+#define NOTIFICATION_EX_ENTRY_ITEM_IMPLEMENTATION_H_
-#include "notification-ex/item.h"
+#include <string>
+#include <memory>
-class ENTRY_ITEM : public ::testing::Test {
+#include "notification-ex/entry_item.h"
+
+namespace notification {
+namespace item {
+
+class EntryItem::Impl {
public:
- virtual void SetUp() {
- }
- virtual void TearDown() {
- }
-};
\ No newline at end of file
+ virtual ~Impl();
+
+ private:
+ Impl();
+
+ private:
+ friend class EntryItem;
+
+ std::string text_;
+ int limit_ = 160;
+};
+
+} // namespace item
+} // namespace notification
+
+#endif // NOTIFICATION_EX_ENTRY_ITEM_IMPLEMENTATION_H_
namespace notification {
namespace item {
-class EXPORT_API TextItem : public AbstractItem {
- public:
- TextItem(std::string text);
- virtual ~TextItem();
-
- Bundle Serialize() override;
- void Deserialize(Bundle b) override;
- AbstractItem& FindByID(std::string id) override;
- void SetContents(std::string contents);
- std::string GetContents() const;
- std::string GetHyperLink() const;
-
- private:
- std::string text_ = nullptr;
-}; // class TextItem
-
class EXPORT_API IconItem : public AbstractItem {
public:
IconItem(std::string iconpath);
Type GetType() const;
}; // class ChatMessageItem
-class EXPORT_API EntryItem : public AbstractItem {
- public:
- EntryItem();
- virtual ~EntryItem();
-
- Bundle Serialize() override;
- void Deserialize(Bundle b) override;
- AbstractItem& FindByID(std::string id) override;
- std::string GetText() const;
- void SetText(std::string text);
- void SetTextLimit(int size);
- int GetTextLimit() const;
-
- private:
- std::string text_ = nullptr;
- int limit_ = 160;
-}; // class EntryItem
-
-class EXPORT_API EffectItem : public AbstractItem {
- public:
- EffectItem();
- virtual ~EffectItem();
-
- Bundle Serialize() override;
- void Deserialize(Bundle b) override;
- AbstractItem& FindByID(std::string id) override;
- std::string GetSoundPath() const;
- std::string GetVibrationPath() const;
-
- private:
- std::string soundPath_ = nullptr;
- std::string vibrationPath_ = nullptr;
-}; // class EffectItem
-
class EXPORT_API CustomItem : public AbstractItem {
public:
CustomItem();
#include "notification-ex/button_item.h"
#include "notification-ex/group_item.h"
#include "notification-ex/null_item.h"
+#include "notification-ex/entry_item.h"
+#include "notification-ex/text_item.h"
#include "notification-ex/exception.h"
#include "notification-ex/input_selector_item.h"
#include "notification-ex/progress_item.h"
case AbstractItem::NullObject :
THROW(NOTIFICATION_ERROR_INVALID_PARAMETER);
case AbstractItem::Text :
- return make_shared<ButtonItem>("");
+ return make_shared<TextItem>("");
case AbstractItem::Icon :
return make_shared<ButtonItem>("");
case AbstractItem::Image :
return make_shared<InputSelectorItem>();
case AbstractItem::Group :
return make_shared<GroupItem>();
- case AbstractItem::Effect :
- return make_shared<ButtonItem>("");
+ case AbstractItem::Entry :
+ return make_shared<EntryItem>("");
case AbstractItem::Progress :
return make_shared<ProgressItem>(0.0, 0.0, 0.0);
case AbstractItem::Custom :
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dlog.h>
+
+#include <memory>
+
+#include "notification-ex/text_item.h"
+#include "notification-ex/text_item_implementation.h"
+#include "notification-ex/item_factory.h"
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+
+#define LOG_TAG "NOTIFICATION_EX"
+#define TEXT_CONTENTS_KEY "__TEXT_CONTENTS_KEY__"
+#define TEXT_HYPERLINK_KEY "__TEXT_HYPERLINK_KEY__"
+
+namespace notification {
+namespace item {
+TextItem::TextItem(std::string text, std::shared_ptr<AbstractAction> action)
+ : AbstractItem(AbstractItem::Type::Text), impl_(new Impl(text)) {
+}
+
+TextItem::TextItem(std::string id, std::string text,
+ std::shared_ptr<AbstractAction> action)
+ : AbstractItem(id, AbstractItem::Type::Text), impl_(new Impl(text)) {
+}
+
+TextItem::Impl::Impl(std::string text)
+ : text_(text) {
+ LOGI("TextItem created");
+}
+
+TextItem::~TextItem() = default;
+TextItem::Impl::~Impl() = default;
+
+Bundle TextItem::Serialize() {
+ Bundle b;
+ b = AbstractItem::Serialize();
+
+ if (!impl_->text_.empty())
+ b.Add(TEXT_CONTENTS_KEY, impl_->text_);
+
+ if (!impl_->hyperlink_.empty())
+ b.Add(TEXT_HYPERLINK_KEY, impl_->hyperlink_);
+
+ return b;
+}
+
+void TextItem::Deserialize(Bundle b) {
+ AbstractItem::Deserialize(b);
+ impl_->text_ = b.GetString(TEXT_CONTENTS_KEY);
+ impl_->hyperlink_ = b.GetString(TEXT_HYPERLINK_KEY);
+}
+
+AbstractItem& TextItem::FindByID(std::string id) {
+ if (GetId() == id)
+ return *this;
+ return ItemFactory::GetNullItem();
+}
+
+void TextItem::SetContents(std::string contents) {
+ impl_->text_ = contents;
+}
+
+std::string TextItem::GetContents() const {
+ return impl_->text_;
+}
+
+std::string TextItem::GetHyperLink() const {
+ return impl_->hyperlink_;
+}
+
+} // namespace item
+} // namespace notification
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef NOTIFICATION_EX_TEXT_ITEM_H_
+#define NOTIFICATION_EX_TEXT_ITEM_H_
+
+#include <memory>
+#include <string>
+
+#include "notification-ex/abstract_item.h"
+
+#ifndef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+namespace notification {
+namespace item {
+
+class EXPORT_API TextItem : public AbstractItem {
+ public:
+ TextItem(std::string text,
+ std::shared_ptr<AbstractAction> action = std::shared_ptr<AbstractAction>({}));
+ TextItem(std::string id, std::string text,
+ std::shared_ptr<AbstractAction> action = std::shared_ptr<AbstractAction>({}));
+ virtual ~TextItem();
+
+ Bundle Serialize() override;
+ void Deserialize(Bundle b) override;
+ AbstractItem& FindByID(std::string id) override;
+ void SetContents(std::string contents);
+ std::string GetContents() const;
+ std::string GetHyperLink() const;
+
+ private:
+ class Impl;
+ std::unique_ptr<Impl> impl_;
+}; // class TextItem
+
+} // namespace item
+} // nampace notification
+#endif // NOTIFICATION_EX_TEXT_ITEM_H_
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef NOTIFICATION_EX_TEXT_ITEM_IMPLEMENTATION_H_
+#define NOTIFICATION_EX_TEXT_ITEM_IMPLEMENTATION_H_
+
+#include <string>
+#include <memory>
+
+#include "notification-ex/text_item.h"
+
+namespace notification {
+namespace item {
+
+class TextItem::Impl {
+ public:
+ virtual ~Impl();
+
+ private:
+ Impl(std::string text);
+
+ private:
+ friend class TextItem;
+
+ std::string text_;
+ std::string hyperlink_;
+};
+
+} // namespace item
+} // namespace notification
+
+#endif // NOTIFICATION_EX_TEXT_ITEM_IMPLEMENTATION_H_
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+#include "notification-ex/entry_item.h"
+#include "notification-ex/item_inflator.h"
+
+using namespace notification::item;
+
+namespace {
+
+class EntryItemTest : public ::testing::Test {
+ public:
+ virtual void SetUp() {}
+ virtual void TearDown() {}
+};
+
+TEST_F(EntryItemTest, FindByID) {
+ EntryItem item("entry_id");
+
+ AbstractItem& child = item.FindByID("entry_id");
+ EntryItem& btn = static_cast<EntryItem&>(child);
+ ASSERT_EQ(btn.GetId(), "entry_id");
+}
+
+TEST_F(EntryItemTest, FindByIDNullItemReturn) {
+ EntryItem item("entry_id");
+
+ AbstractItem& child = item.FindByID("not_existed_item");
+ ASSERT_EQ(child.GetType(), EntryItem::NullObject);
+}
+
+TEST_F(EntryItemTest, SerializeDeserialize) {
+ EntryItem item("entry_id");
+ Bundle b = item.Serialize();
+ ItemFactory factory;
+ std::shared_ptr<AbstractItem> gen_item = ItemInflator::Create(factory, b);
+ ASSERT_EQ(gen_item.get()->GetType(), item.GetType());
+
+ EntryItem* gen_effect = static_cast<EntryItem*>(gen_item.get());
+ ASSERT_EQ(item.GetId(), gen_effect->GetId());
+}
+
+TEST_F(EntryItemTest, SetTextGetText) {
+ EntryItem item("entry_id");
+ item.SetText("test");
+
+ ASSERT_EQ(item.GetText(), "test");
+}
+
+TEST_F(EntryItemTest, GetTextLimit) {
+ EntryItem item("entry_id");
+
+ ASSERT_EQ(item.GetTextLimit(), 160);
+}
+
+} // namespace
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+#include "notification-ex/text_item.h"
+#include "notification-ex/item_inflator.h"
+
+using namespace notification::item;
+
+namespace {
+
+class TexttItemTest : public ::testing::Test {
+ public:
+ virtual void SetUp() {
+ }
+ virtual void TearDown() {
+ }
+};
+
+TEST_F(TexttItemTest, FindByID) {
+ TextItem item("text_id", "default");
+
+ AbstractItem& child = item.FindByID("text_id");
+ TextItem& btn = static_cast<TextItem&>(child);
+ ASSERT_EQ(btn.GetContents(), "default");
+}
+
+TEST_F(TexttItemTest, FindByIDNullItemReturn) {
+ TextItem item("text_id", "default");
+
+ AbstractItem& child = item.FindByID("not_existed_item");
+ ASSERT_EQ(child.GetType(), TextItem::NullObject);
+}
+
+TEST_F(TexttItemTest, SerializeDeserializeGetContents) {
+ TextItem item("text_id", "default");
+ Bundle b = item.Serialize();
+ ItemFactory factory;
+ std::shared_ptr<AbstractItem> gen_item = ItemInflator::Create(factory, b);
+ ASSERT_EQ(gen_item.get()->GetType(), item.GetType());
+
+ TextItem* gen_text = static_cast<TextItem*>(gen_item.get());
+ ASSERT_EQ(item.GetContents(), gen_text->GetContents());
+}
+
+TEST_F(TexttItemTest, SetContentsGetContents) {
+ TextItem item("text_id", "default");
+ item.SetContents("test");
+
+ ASSERT_EQ(item.GetContents(), "test");
+}
+
+TEST_F(TexttItemTest, GetHyperLink) {
+ TextItem item("text_id", "default");
+
+ ASSERT_EQ(item.GetHyperLink(), "");
+}
+
+} // namespace
\ No newline at end of file