Add methods for setting and finding main type 62/211462/6
authorJunghoon Park <jh9216.park@samsung.com>
Mon, 5 Aug 2019 09:00:33 +0000 (18:00 +0900)
committermk5004.lee <mk5004.lee@samsung.com>
Mon, 12 Aug 2019 06:34:43 +0000 (15:34 +0900)
Change-Id: I12e9e9e6ed66e8619b198fe7669b569122322d70
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
26 files changed:
notification-ex/abstract_item.cc
notification-ex/abstract_item.h
notification-ex/abstract_item_implementation.h
notification-ex/button_item.cc
notification-ex/button_item.h
notification-ex/chat_message_item.cc
notification-ex/chat_message_item.h
notification-ex/checkbox_item.cc
notification-ex/checkbox_item.h
notification-ex/entry_item.cc
notification-ex/entry_item.h
notification-ex/group_item.cc
notification-ex/group_item.h
notification-ex/icon_text_item.cc
notification-ex/icon_text_item.h
notification-ex/image_item.cc
notification-ex/image_item.h
notification-ex/input_selector_item.cc
notification-ex/input_selector_item.h
notification-ex/progress_item.cc
notification-ex/progress_item.h
notification-ex/text_item.cc
notification-ex/text_item.h
notification-ex/time_item.cc
notification-ex/time_item.h
unittest/src/test_abstract_item.cc

index cd808a8..61fc8cd 100644 (file)
@@ -28,6 +28,7 @@
 #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
@@ -80,6 +81,7 @@
 #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;
@@ -171,6 +173,7 @@ Bundle AbstractItem::Serialize() const {
   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;
@@ -295,6 +298,7 @@ void AbstractItem::Deserialize(Bundle b) {
   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) {
@@ -511,5 +515,35 @@ bool AbstractItem::GetOnGoingState() const {
   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
index f70c9f1..872cabc 100644 (file)
@@ -729,6 +729,14 @@ class EXPORT_API AbstractItem {
     SimMode = 1 << 1,
   };
 
+  enum MainType {
+    MainNone = 0,
+    MainTitle,
+    MainContents,
+    MainIcon,
+    MainButton
+  };
+
  public:
   /**
    * @brief Constructor
@@ -773,7 +781,15 @@ class EXPORT_API AbstractItem {
    * @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.
@@ -1014,6 +1030,22 @@ class EXPORT_API AbstractItem {
    */
   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_;
index 674a06a..4e6b9d2 100644 (file)
@@ -66,6 +66,7 @@ class AbstractItem::Impl {
   int request_id_ = 0;
   std::string background_;
   bool ongoing_ = false;
+  MainType main_type_ = MainNone;
 };
 
 }  // namespace item
index 1263cb3..54c4a77 100644 (file)
@@ -68,12 +68,6 @@ void ButtonItem::Deserialize(Bundle b) {
   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;
index 431fb25..6ab1831 100644 (file)
@@ -75,14 +75,6 @@ class EXPORT_API ButtonItem : public AbstractItem {
   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
index 616ae95..11ac30b 100644 (file)
@@ -126,10 +126,41 @@ void ChatMessageItem::Deserialize(Bundle b) {
   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();
 }
 
index 303bb17..bcfee13 100644 (file)
@@ -96,6 +96,14 @@ class EXPORT_API ChatMessageItem : public AbstractItem {
   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
index b668e01..bdda24d 100644 (file)
@@ -65,13 +65,6 @@ void CheckBoxItem::Deserialize(Bundle b) {
   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;
index 2cdf211..31e360e 100644 (file)
@@ -65,14 +65,6 @@ class EXPORT_API CheckBoxItem : public AbstractItem {
   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
index 56b1aab..062bc56 100644 (file)
@@ -73,12 +73,6 @@ void EntryItem::Deserialize(Bundle b) {
   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;
index 35f5c99..f6a8ce1 100644 (file)
@@ -73,14 +73,6 @@ class EXPORT_API EntryItem : public AbstractItem {
   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
index 51ce8c8..a1bda0e 100644 (file)
@@ -119,6 +119,18 @@ AbstractItem& GroupItem::FindByID(std::string id) {
   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;
index f79bade..39b6ab6 100644 (file)
@@ -79,6 +79,14 @@ class EXPORT_API GroupItem : public AbstractItem {
   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
index 94e6297..d6a521b 100644 (file)
@@ -78,6 +78,25 @@ AbstractItem& IconTextItem::FindByID(std::string id) {
   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();
 }
 
index 36ef4cb..224aa63 100644 (file)
@@ -76,6 +76,14 @@ class EXPORT_API IconTextItem : public AbstractItem {
   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
index 42d8a05..788354e 100644 (file)
@@ -65,13 +65,6 @@ void ImageItem::Deserialize(Bundle b) {
   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;
index 5008650..8cf6066 100644 (file)
@@ -80,14 +80,6 @@ class EXPORT_API ImageItem : public AbstractItem {
   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
index 8bb7a10..d19f2da 100644 (file)
@@ -74,12 +74,6 @@ void InputSelectorItem::Deserialize(Bundle b) {
   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;
index 6de51f5..2325860 100644 (file)
@@ -71,14 +71,6 @@ class EXPORT_API InputSelectorItem : public AbstractItem {
   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
index c27ccf7..30981b3 100644 (file)
@@ -89,12 +89,6 @@ void ProgressItem::Deserialize(Bundle b) {
   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;
index b339d72..0db7550 100644 (file)
@@ -85,14 +85,6 @@ class EXPORT_API ProgressItem : public AbstractItem {
   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
index b63708c..b25cdbe 100644 (file)
@@ -70,12 +70,6 @@ void TextItem::Deserialize(Bundle b) {
   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;
index 32601c8..9e793fe 100644 (file)
@@ -77,14 +77,6 @@ class EXPORT_API TextItem : public AbstractItem {
   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
index cb1d612..8bac87c 100644 (file)
@@ -88,13 +88,6 @@ void TimeItem::Deserialize(Bundle b) {
   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;
index c363bd3..bc76b75 100644 (file)
@@ -90,14 +90,6 @@ class EXPORT_API TimeItem : public AbstractItem {
   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
index 6957d3e..89a5ed3 100644 (file)
@@ -24,6 +24,8 @@
 #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
 
@@ -290,4 +292,16 @@ TEST_F(AbstractItemTest, SetGetOnGoingState) {
   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