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 cd808a86ff30d4d897e50f82b4fe16008c94242f..61fc8cdb50c3aae9f7c738b8451e4fdfb7e04c24 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 f70c9f1ee9d0d8ad8085a6a24cc9b39fa9aebf5f..872cabc0e17e32a57601a54ae5292f74b1b1619c 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 674a06a0b5e5b4971622fc0fa6f60ecbcdca6d75..4e6b9d2815175be8a09492181791c0b09d48bf6d 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 1263cb3630b4b0668246c21e1d268879ee2433f1..54c4a7741870f5a4eec203658be2bd3f26cb78c9 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 431fb25fb51465b696f48b97a8041c3fe7715070..6ab18317e79670c5910601e9a69c3cf9989c2ffd 100644 (file)
@@ -74,14 +74,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
index 616ae95fa25592075d41845617b5f46be09e1cde..11ac30b569c74d3515dab640b93e0b9ed5d9bb4d 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 303bb17e27f641a15ecefc497bb6ab31e450a620..bcfee13554a2fa71bfbd1b7fd704b1290c64a3b1 100644 (file)
@@ -95,6 +95,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
index b668e013d70b3894afe622d5d53f3ab6d81d8c22..bdda24d8796437aa8bbbac815707cbb8d38d024a 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 2cdf211c1c29c2d14100433a52942445974f5655..31e360ef643f7835501d9e57c8e310e2cba3d07d 100644 (file)
@@ -64,14 +64,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
index 56b1aab90f4e51506c0ccc2af45eca1ce2903d8e..062bc5664b3e27dc83dcec981581c4ab5ae1768e 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 35f5c99099a5a29c111825bf7b2bd2b671799118..f6a8ce16a00e6cde576c73a5bcf33960557c5d3e 100644 (file)
@@ -72,14 +72,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
index 51ce8c871fc00bafb46c3747bd6b12574a309dc8..a1bda0ee9dcd0bbb910f46752019888a9b7a9eed 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 f79bade018362d0b6bacf4b9b14c475838ba1460..39b6ab611187544ab1425190dd1c84be0455c967 100644 (file)
@@ -78,6 +78,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
index 94e6297c07be07ad5c48d491f429ac5a352ca368..d6a521b745a1e27361c68b9c10da8ebfb6be835b 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 36ef4cbc84fb407201f11782aa8e9c7fe0297adc..224aa63721f13c6647be97c355495080aee4dd85 100644 (file)
@@ -75,6 +75,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
index 42d8a0576cf1a7da097ef0d3c153ba196e8e0b30..788354ed225a4f257b13c1fb6b4a7c4d8810afa7 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 5008650d6c71d3e0539672ed8f49742d9b641ed7..8cf60663b6a50948d3ca6b23079582f649bb62ea 100644 (file)
@@ -79,14 +79,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
index 8bb7a10d71a2cf8c0090ed56d07540f1a604041e..d19f2daf50bc42343f944d4ea96d7d82b39f4446 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 6de51f5e9755f11fc72a0ae57ccf8a39e1ffb936..2325860fdbdd01b18bad74847bd1f9248455f3d8 100644 (file)
@@ -70,14 +70,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
index c27ccf747c64074c15ac7aff7eeda5e6b7330d4e..30981b3cc3a5bc1f20c694b3b1a0f6259667e62e 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 b339d72f53d230c841eef840dbc46f07b42bec10..0db75501b68b285aaf08934b226674e42d57ae3f 100644 (file)
@@ -84,14 +84,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
index b63708c2fc9ae4bacee75d7d520ceeb56d07fa77..b25cdbe2a86706344846969282fedef3ca8ecc18 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 32601c86d590b892552e562aca67bed0101ec11b..9e793fe20a6f71c41673768ec740de6a19b002ca 100644 (file)
@@ -76,14 +76,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
index cb1d612d3dbcb2f3e3bdffb343413cc5eb28d660..8bac87c9fccd2db43548bf9666d8cd34fd4cb7ff 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 c363bd3d82a7390afd6fb3ee78451e8ef9fe49ba..bc76b75fb1a93d8d1f96ff36ac9939d400e83214 100644 (file)
@@ -89,14 +89,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
index 6957d3e4350f4cc3564ae87abdf9c90d1075782e..89a5ed3a931b0a27cf45cd62fb541294908db8d3 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