#include "notification-ex/item_info_internal.h"
#include "notification-ex/ex_util.h"
#include "notification-ex/action_inflator.h"
+#include "notification-ex/factory_manager.h"
#ifdef LOG_TAG
#undef LOG_TAG
#define ABSTRACT_ITEM_HIDE_VIEWER_KEY "__ABSTRACT_ITEM_HIDE_VIEWER_KEY__"
#define ABSTRACT_ITEM_TRUE "TRUE"
#define ABSTRACT_ITEM_ONGOING_KEY "__ABSTRACT_ITEM_ONGOING_KEY__"
+#define ABSTRACT_ITEM_MAIN_TYPE_KEY "__ABSTRACT_ITEM_MAIN_TYPE_KEY__"
using namespace std;
using namespace tizen_base;
b.Add(ABSTRACT_ITEM_ENABLE_KEY, to_string((int)impl_->enable_));
b.Add(ABSTRACT_ITEM_POLICY_KEY, to_string((int)impl_->policy_));
b.Add(ABSTRACT_ITEM_ONGOING_KEY, to_string((int)impl_->ongoing_));
+ b.Add(ABSTRACT_ITEM_MAIN_TYPE_KEY, to_string((int)impl_->main_type_));
if (impl_->receiver_group_list_.size() != 0) {
vector<string> arr;
impl_->visible_ = static_cast<bool>(stoi(b.GetString(ABSTRACT_ITEM_VISIBLE_KEY)));
impl_->enable_ = static_cast<bool>(stoi(b.GetString(ABSTRACT_ITEM_ENABLE_KEY)));
impl_->ongoing_ = static_cast<bool>(stoi(b.GetString(ABSTRACT_ITEM_ONGOING_KEY)));
+ impl_->main_type_ = static_cast<MainType>(stoi(b.GetString(ABSTRACT_ITEM_MAIN_TYPE_KEY)));
vector<string> receiver_group = b.GetStringArray(ABSTRACT_ITEM_RECEIVER_GROUP_KEY);
if (receiver_group.size() != 0) {
return impl_->ongoing_;
}
+bool AbstractItem::SetMainType(std::string target_id, MainType type) {
+ AbstractItem& target = FindByID(target_id);
+ if (target.GetType() == NullObject)
+ return false;
+ AbstractItem& old = FindByMainType(type);
+ if (target.GetType() != NullObject)
+ old.impl_->main_type_ = MainNone;
+ target.impl_->main_type_ = type;
+
+ return true;
+}
+
+AbstractItem::MainType AbstractItem::GetMainType() const {
+ return impl_->main_type_;
+}
+
+AbstractItem& AbstractItem::FindByID(std::string id) {
+ if (GetId() == id)
+ return *this;
+
+ return FactoryManager::GetInst().GetNullItem();
+}
+
+AbstractItem& AbstractItem::FindByMainType(AbstractItem::MainType type) {
+ if (impl_->main_type_ == type)
+ return *this;
+
+ return FactoryManager::GetInst().GetNullItem();
+}
+
} // namespace item
} // namespace notification
SimMode = 1 << 1,
};
+ enum MainType {
+ MainNone = 0,
+ MainTitle,
+ MainContents,
+ MainIcon,
+ MainButton
+ };
+
public:
/**
* @brief Constructor
* @param[in] id notification item id
* @return AbstractItem object
*/
- virtual AbstractItem& FindByID(std::string id) = 0;
+ virtual AbstractItem& FindByID(std::string id);
+
+ /**
+ * @brief Finds the AbstractItem using by main type.
+ * @since_tizen 5.5
+ * @param[in] type The main type
+ * @return AbstractItem object
+ */
+ virtual AbstractItem& FindByMainType(MainType type);
/**
* @brief Checks the item type exist in this notification.
*/
bool GetOnGoingState() const;
+ /**
+ * @brief Sets the main type of notification item.
+ * @since_tizen 5.5
+ * @param[in] target_id The ID of notification item to set
+ * @param[in] type The main type
+ * @return true if target_id is valid to set
+ */
+ bool SetMainType(std::string target_id, MainType type);
+
+ /**
+ * @brief Gets the main type of notification item.
+ * @since_tizen 5.5
+ * @return The main type
+ */
+ MainType GetMainType() const;
+
private:
class Impl;
std::unique_ptr<Impl> impl_;
int request_id_ = 0;
std::string background_;
bool ongoing_ = false;
+ MainType main_type_ = MainNone;
};
} // namespace item
impl_->title_ = b.GetString(BUTTON_TITLE_KEY);
}
-AbstractItem& ButtonItem::FindByID(std::string id) {
- if (GetId() == id)
- return *this;
- return FactoryManager::GetInst().GetNullItem();
-}
-
bool ButtonItem::IsItemTypeExist(int type) {
if (GetType() == type)
return true;
void Deserialize(tizen_base::Bundle b) override;
/**
- * @brief Finds the AbstractItem using by notification item id.
- * @since_tizen 5.5
- * @param[in] id notification item id
- * @return AbstractItem object
- */
- AbstractItem& FindByID(std::string id) override;
-
- /**
* @brief Checks the item type exist in this notification.
* @since_tizen 5.5
* @param[in] type notification item type
impl_->type_ = static_cast<Type>(std::stoi(b.GetString(CHATMESSAGE_TYPE_KEY)));
}
-AbstractItem& ChatMessageItem::FindByID(std::string id) {
+AbstractItem& ChatMessageItem::FindByID(std::string id) {
if (GetId() == id)
return *this;
+ if (impl_->name_->GetId() == id)
+ return *(impl_->name_);
+
+ if (impl_->text_->GetId() == id)
+ return *(impl_->text_);
+
+ if (impl_->image_->GetId() == id)
+ return *(impl_->image_);
+
+ if (impl_->time_->GetId() == id)
+ return *(impl_->time_);
+
+ return FactoryManager::GetInst().GetNullItem();
+}
+
+AbstractItem& ChatMessageItem::FindByMainType(MainType type) {
+ if (GetMainType() == type)
+ return *this;
+
+ if (impl_->name_->GetMainType() == type)
+ return *(impl_->name_);
+
+ if (impl_->text_->GetMainType() == type)
+ return *(impl_->text_);
+
+ if (impl_->image_->GetMainType() == type)
+ return *(impl_->image_);
+
+ if (impl_->time_->GetMainType() == type)
+ return *(impl_->time_);
+
return FactoryManager::GetInst().GetNullItem();
}
AbstractItem& FindByID(std::string id) override;
/**
+ * @brief Finds the AbstractItem using by main type.
+ * @since_tizen 5.5
+ * @param[in] type The main type
+ * @return AbstractItem object
+ */
+ AbstractItem& FindByMainType(MainType type) override;
+
+ /**
* @brief Checks the item type exist in this notification.
* @since_tizen 5.5
* @param[in] type notification item type
impl_->checked_ = std::stoi(b.GetString(CHECKBOX_CHECKED_KEY));
}
-AbstractItem& CheckBoxItem::FindByID(std::string id) {
- if (GetId() == id)
- return *this;
-
- return FactoryManager::GetInst().GetNullItem();
-}
-
bool CheckBoxItem::IsItemTypeExist(int type) {
if (GetType() == type)
return true;
void Deserialize(tizen_base::Bundle b) override;
/**
- * @brief Finds the AbstractItem using by notification item id.
- * @since_tizen 5.5
- * @param[in] id notification item id
- * @return AbstractItem object
- */
- AbstractItem& FindByID(std::string id) override;
-
- /**
* @brief Checks the item type exist in this notification.
* @since_tizen 5.5
* @param[in] type notification item type
impl_->limit_ = std::stoi(b.GetString(ENTRY_LIMIT_KEY));
}
-AbstractItem& EntryItem::FindByID(std::string id) {
- if (GetId() == id)
- return *this;
- return FactoryManager::GetInst().GetNullItem();
-}
-
bool EntryItem::IsItemTypeExist(int type) {
if (GetType() == type)
return true;
void Deserialize(tizen_base::Bundle b) override;
/**
- * @brief Finds the AbstractItem using by notification item id.
- * @since_tizen 5.5
- * @param[in] id notification item id
- * @return AbstractItem object
- */
- AbstractItem& FindByID(std::string id) override;
-
- /**
* @brief Checks the item type exist in this notification.
* @since_tizen 5.5
* @param[in] type notification item type
return FactoryManager::GetInst().GetNullItem();
}
+AbstractItem& GroupItem::FindByMainType(MainType type) {
+ if (GetMainType() == type)
+ return *this;
+
+ for (auto& i : impl_->children_list_) {
+ auto& re = i.get()->FindByMainType(type);
+ if (re.GetType() != NullObject)
+ return re;
+ }
+ return FactoryManager::GetInst().GetNullItem();
+}
+
bool GroupItem::IsItemTypeExist(int type) {
if (GetType() == type)
return true;
AbstractItem& FindByID(std::string id) override;
/**
+ * @brief Finds the AbstractItem using by main type.
+ * @since_tizen 5.5
+ * @param[in] type The main type
+ * @return AbstractItem object
+ */
+ AbstractItem& FindByMainType(MainType type) override;
+
+ /**
* @brief Checks the item type exist in this notification.
* @since_tizen 5.5
* @param[in] type notification item type
if (GetId() == id)
return *this;
+ if (impl_->icon_->GetId() == id)
+ return *(impl_->icon_);
+
+ if (impl_->text_->GetId() == id)
+ return *(impl_->text_);
+
+ return FactoryManager::GetInst().GetNullItem();
+}
+
+AbstractItem& IconTextItem::FindByMainType(MainType type) {
+ if (GetMainType() == type)
+ return *this;
+
+ if (impl_->icon_->GetMainType() == type)
+ return *(impl_->icon_);
+
+ if (impl_->text_->GetMainType() == type)
+ return *(impl_->text_);
+
return FactoryManager::GetInst().GetNullItem();
}
AbstractItem& FindByID(std::string id) override;
/**
+ * @brief Finds the AbstractItem using by main type.
+ * @since_tizen 5.5
+ * @param[in] type The main type
+ * @return AbstractItem object
+ */
+ AbstractItem& FindByMainType(MainType type) override;
+
+ /**
* @brief Checks the item type exist in this notification.
* @since_tizen 5.5
* @param[in] type notification item type
impl_->image_path_ = b.GetString(IMAGE_PATH_KEY);
}
-AbstractItem& ImageItem::FindByID(std::string id) {
- if (GetId() == id)
- return *this;
-
- return FactoryManager::GetInst().GetNullItem();
-}
-
bool ImageItem::IsItemTypeExist(int type) {
if (GetType() == type)
return true;
void Deserialize(tizen_base::Bundle b) override;
/**
- * @brief Finds the AbstractItem using by notification item id.
- * @since_tizen 5.5
- * @param[in] id notification item id
- * @return AbstractItem object
- */
- AbstractItem& FindByID(std::string id) override;
-
- /**
* @brief Checks the item type exist in this notification.
* @since_tizen 5.5
* @param[in] type notification item type
impl_->contents_ = list<string>(contents.begin(), contents.end());
}
-AbstractItem& InputSelectorItem::FindByID(std::string id) {
- if (GetId() == id)
- return *this;
- return FactoryManager::GetInst().GetNullItem();
-}
-
bool InputSelectorItem::IsItemTypeExist(int type) {
if (GetType() == type)
return true;
virtual void Deserialize(tizen_base::Bundle b) override;
/**
- * @brief Finds the AbstractItem using by notification item id.
- * @since_tizen 5.5
- * @param[in] id notification item id
- * @return AbstractItem object
- */
- virtual AbstractItem& FindByID(std::string id) override;
-
- /**
* @brief Checks the item type exist in this notification.
* @since_tizen 5.5
* @param[in] type notification item type
impl_->unit_ = b.GetString(PROGRESS_UNIT_KEY);
}
-AbstractItem& ProgressItem::FindByID(std::string id) {
- if (GetId() == id)
- return *this;
- return FactoryManager::GetInst().GetNullItem();
-}
-
bool ProgressItem::IsItemTypeExist(int type) {
if (GetType() == type)
return true;
virtual void Deserialize(tizen_base::Bundle b) override;
/**
- * @brief Finds the AbstractItem using by notification item id.
- * @since_tizen 5.5
- * @param[in] id notification item id
- * @return AbstractItem object
- */
- virtual AbstractItem& FindByID(std::string id) override;
-
- /**
* @brief Checks the item type exist in this notification.
* @since_tizen 5.5
* @param[in] type notification item type
impl_->hyperlink_ = b.GetString(TEXT_HYPERLINK_KEY);
}
-AbstractItem& TextItem::FindByID(std::string id) {
- if (GetId() == id)
- return *this;
- return FactoryManager::GetInst().GetNullItem();
-}
-
bool TextItem::IsItemTypeExist(int type) {
if (GetType() == type)
return true;
void Deserialize(tizen_base::Bundle b) override;
/**
- * @brief Finds the AbstractItem using by notification item id.
- * @since_tizen 5.5
- * @param[in] id notification item id
- * @return AbstractItem object
- */
- AbstractItem& FindByID(std::string id) override;
-
- /**
* @brief Checks the item type exist in this notification.
* @since_tizen 5.5
* @param[in] type notification item type
impl_->time_ = mktime(&timeinfo);
}
-AbstractItem& TimeItem::FindByID(std::string id) {
- if (GetId() == id)
- return *this;
-
- return FactoryManager::GetInst().GetNullItem();
-}
-
bool TimeItem::IsItemTypeExist(int type) {
if (GetType() == type)
return true;
void Deserialize(tizen_base::Bundle b) override;
/**
- * @brief Finds the AbstractItem using by notification item id.
- * @since_tizen 5.5
- * @param[in] id notification item id
- * @return AbstractItem object
- */
- AbstractItem& FindByID(std::string id) override;
-
- /**
* @brief Checks the item type exist in this notification.
* @since_tizen 5.5
* @param[in] type notification item type
#include "notification-ex/iitem_factory.h"
#include "notification-ex/factory_manager.h"
#include "notification-ex/default_item_factory.h"
+#include "notification-ex/group_item.h"
+#include "notification-ex/button_item.h"
#define MY_ITEM_TYPE AbstractItem::Type::Custom + 1
ASSERT_EQ(item.GetOnGoingState(), true);
}
+TEST_F(AbstractItemTest, SetGetFindMainType) {
+ auto root = std::make_shared<GroupItem>("test_group");
+ auto item = std::make_shared<ButtonItem>("test_id", "title");
+ root->AddChild(item);
+
+ bool ret = root->SetMainType("test_id", AbstractItem::MainButton);
+ EXPECT_TRUE(ret);
+ EXPECT_EQ(item->GetMainType(), AbstractItem::MainButton);
+ auto& i = root->FindByMainType(AbstractItem::MainButton);
+ EXPECT_EQ(i.GetId(), "test_id");
+}
+
} // namespace
\ No newline at end of file