Repeatable actions in context menu 45/152645/8
authorPawel Kurowski <p.kurowski2@samsung.com>
Fri, 29 Sep 2017 10:06:32 +0000 (12:06 +0200)
committerPawel Kurowski <p.kurowski2@samsung.com>
Tue, 3 Oct 2017 11:18:34 +0000 (13:18 +0200)
Repeatable activity can be selected multiple times,
without closing context menu.

Change-Id: Icfaac8f7bde849987c502a4d885f29b394cc0b8f

src/MenuBuilder.cpp
src/MenuBuilder.hpp
src/SelectActivity.cpp

index c6633ee..ed23ae8 100644 (file)
@@ -13,7 +13,7 @@ class VconfTypeMenuItem : public MenuItem
 {
 public:
        VconfTypeMenuItem(std::vector<std::string> names, std::string iconPath, std::string activityType,
-                                         std::string subMenuLabel, std::string showingStateVconfKey);
+                                         std::string subMenuLabel, std::string showingStateVconfKey, RepetitionPolicy repetitionPolicy);
 
        std::string getName() const override;
 
@@ -29,7 +29,7 @@ class VconfIntTypeMenuItem : public VconfTypeMenuItem
 public:
        VconfIntTypeMenuItem(std::vector<std::string> names, std::string iconPath, std::string activityType,
                                                 std::string vconfStateKey,
-                                                std::string subMenuLabel = {}, std::string showingStateVconfKey = {});
+                                                std::string subMenuLabel = {}, std::string showingStateVconfKey = {}, RepetitionPolicy repetitionPolicy = RepetitionPolicy::single);
 
        size_t getIndex() const override;
 
@@ -41,17 +41,25 @@ class VconfBoolTypeMenuItem : public VconfTypeMenuItem
 public:
        VconfBoolTypeMenuItem(std::vector<std::string> names, std::string iconPath, std::string activityType,
                                                  std::vector<std::string> vconfStateKeys,
-                                                 std::string subMenuLabel = {}, std::string showingStateVconfKey = {});
+                                                 std::string subMenuLabel = {}, std::string showingStateVconfKey = {}, RepetitionPolicy repetitionPolicy = RepetitionPolicy::single);
 
        size_t getIndex() const override;
 
        std::vector<std::string> vconfStateKeys;
 };
 
+class QuickpanelTypeMenuItem : public MenuItem
+{
+public:
+       QuickpanelTypeMenuItem(std::vector<std::string> names, std::string iconPath, std::string activityType);
+
+       std::string getName() const override;
+};
 
-MenuItem::MenuItem(std::vector<std::string> names, std::string iconPath, std::string activityType, std::string subMenuLabel, std::string showingStateVconfKey)
+MenuItem::MenuItem(std::vector<std::string> names, std::string iconPath, std::string activityType, std::string subMenuLabel,
+                                  std::string showingStateVconfKey, RepetitionPolicy repetitionPolicy)
        : names(std::move(names)), iconPath(std::move(iconPath)), activityType(std::move(activityType)),
-         subMenuLabel(std::move(subMenuLabel)), showingStateVconfKey(std::move(showingStateVconfKey)) {}
+         subMenuLabel(std::move(subMenuLabel)), showingStateVconfKey(std::move(showingStateVconfKey)), repetitionPolicy(repetitionPolicy) {}
 
 std::string MenuItem::getName() const
 {
@@ -78,9 +86,15 @@ std::string MenuItem::getShowingStateVconfKey() const
        return showingStateVconfKey;
 }
 
+bool MenuItem::isRepeatable() const
+{
+       return static_cast<bool>(repetitionPolicy);
+}
+
 VconfTypeMenuItem::VconfTypeMenuItem(std::vector<std::string> names, std::string iconPath, std::string activityType,
-                                                                        std::string subMenuLabel, std::string showingStateVconfKey)
-       : MenuItem(std::move(names), std::move(iconPath), std::move(activityType), std::move(subMenuLabel), std::move(showingStateVconfKey)), index(0)
+                                                                        std::string subMenuLabel, std::string showingStateVconfKey, RepetitionPolicy repetitionPolicy)
+       : MenuItem(std::move(names), std::move(iconPath), std::move(activityType), std::move(subMenuLabel), std::move(showingStateVconfKey), repetitionPolicy),
+         index(0)
 {
        ASSERT(!this->names.empty(), "Forbidden VconfTypeMenuItem");
 }
@@ -97,9 +111,8 @@ void VconfTypeMenuItem::vconfChangeCb()
 }
 
 VconfIntTypeMenuItem::VconfIntTypeMenuItem(std::vector<std::string> names, std::string iconPath, std::string activityType,
-               std::string vconfStateKey,
-               std::string subMenuLabel, std::string showingStateVconfKey)
-       : VconfTypeMenuItem(std::move(names), std::move(iconPath), std::move(activityType), std::move(subMenuLabel), std::move(showingStateVconfKey)),
+               std::string vconfStateKey, std::string subMenuLabel, std::string showingStateVconfKey, RepetitionPolicy repetitionPolicy)
+       : VconfTypeMenuItem(std::move(names), std::move(iconPath), std::move(activityType), std::move(subMenuLabel), std::move(showingStateVconfKey), repetitionPolicy),
          vconfStateKey(std::move(vconfStateKey))
 {
        index = getIndex();
@@ -120,8 +133,8 @@ size_t VconfIntTypeMenuItem::getIndex() const
 
 VconfBoolTypeMenuItem::VconfBoolTypeMenuItem(std::vector<std::string> names, std::string iconPath, std::string activityType,
                std::vector<std::string> vconfStateKeys,
-               std::string subMenuLabel, std::string showingStateVconfKey)
-       : VconfTypeMenuItem(std::move(names), std::move(iconPath), std::move(activityType), std::move(subMenuLabel), std::move(showingStateVconfKey)),
+               std::string subMenuLabel, std::string showingStateVconfKey, RepetitionPolicy repetitionPolicy)
+       : VconfTypeMenuItem(std::move(names), std::move(iconPath), std::move(activityType), std::move(subMenuLabel), std::move(showingStateVconfKey), repetitionPolicy),
          vconfStateKeys(std::move(vconfStateKeys))
 {
        index = getIndex();
@@ -145,14 +158,6 @@ size_t VconfBoolTypeMenuItem::getIndex() const
        return static_cast<size_t>(idx);
 }
 
-class QuickpanelTypeMenuItem : public MenuItem
-{
-public:
-       QuickpanelTypeMenuItem(std::vector<std::string> names, std::string iconPath, std::string activityType);
-
-       std::string getName() const override;
-};
-
 QuickpanelTypeMenuItem::QuickpanelTypeMenuItem(std::vector<std::string> names, std::string iconPath, std::string activityType)
        : MenuItem(std::move(names), std::move(iconPath), std::move(activityType))
 {}
@@ -215,11 +220,17 @@ MenuMap::MenuMap()
        auto increase                           =       std::make_shared<MenuItem>(
                                                                                std::vector<std::string> {"IDS_INCREASE"},
                                                                                defaultImg,
-                                                                               std::string {"INCREASE_UI_ELEMENT_VALUE"});
+                                                                               std::string {"INCREASE_UI_ELEMENT_VALUE"},
+                                                                               std::string {},
+                                                                               std::string {},
+                                                                               RepetitionPolicy::multiple);
        auto decrease                           =       std::make_shared<MenuItem>(
                                                                                std::vector<std::string> {"IDS_DECREASE"},
                                                                                defaultImg,
-                                                                               std::string {"DECREASE_UI_ELEMENT_VALUE"});
+                                                                               std::string {"DECREASE_UI_ELEMENT_VALUE"},
+                                                                               std::string {},
+                                                                               std::string {},
+                                                                               RepetitionPolicy::multiple);
        auto selectionMode                      =       std::make_shared<MenuItem>(
                                                                                std::vector<std::string> {"IDS_SELECTION_MODE"},
                                                                                defaultImg);
@@ -308,7 +319,10 @@ MenuMap::MenuMap()
                                                                                std::vector<std::string> {"IDS_SOUND", "IDS_VIBRATION", "IDS_MUTE"},
                                                                                defaultImg,
                                                                                "CHANGE_SOUND_PROFILE_ACTIVITY",
-                                                                               std::vector<std::string> {VCONF_KEY_SOUND_ENABLED, VCONF_KEY_VIBRATION_ENABLED});
+                                                                               std::vector<std::string> {VCONF_KEY_SOUND_ENABLED, VCONF_KEY_VIBRATION_ENABLED},
+                                                                               std::string {},
+                                                                               std::string {},
+                                                                               RepetitionPolicy::multiple);
        auto lock                                       =       std::make_shared<MenuItem>(
                                                                                std::vector<std::string> {"IDS_LOCK"},
                                                                                defaultImg,
@@ -328,11 +342,17 @@ MenuMap::MenuMap()
        auto speedUpScaning                     =       std::make_shared<MenuItem>(
                                                                                std::vector<std::string> {"IDS_SPEED_UP_SCANING"},
                                                                                defaultImg,
-                                                                               std::string{"SPEED_UP_AUTO_SCAN_ACTIVITY"});
+                                                                               std::string{"SPEED_UP_AUTO_SCAN_ACTIVITY"},
+                                                                               std::string {},
+                                                                               std::string {},
+                                                                               RepetitionPolicy::multiple);
        auto slowDownScaning            =       std::make_shared<MenuItem>(
                                                                                std::vector<std::string> {"IDS_SLOW_DOWN_SCANING"},
                                                                                defaultImg,
-                                                                               std::string{"SLOW_DOWN_AUTO_SCAN_ACTIVITY"});
+                                                                               std::string{"SLOW_DOWN_AUTO_SCAN_ACTIVITY"},
+                                                                               std::string {},
+                                                                               std::string {},
+                                                                               RepetitionPolicy::multiple);
        auto scanMethod                         =       std::make_shared<VconfIntTypeMenuItem>(
                                                                                std::vector<std::string> {"IDS_ROW_SCAN", "IDS_POINT_SCAN"},
                                                                                defaultImg,
@@ -371,19 +391,31 @@ MenuMap::MenuMap()
        auto ringtoneVolIncrease        =       std::make_shared<MenuItem>(
                                                                                std::vector<std::string> {"IDS_RINGTONE_VOLUME_INC"},
                                                                                defaultImg,
-                                                                               "INCREASE_RINGTONE_VOLUME");
+                                                                               "INCREASE_RINGTONE_VOLUME",
+                                                                               std::string {},
+                                                                               std::string {},
+                                                                               RepetitionPolicy::multiple);
        auto ringtoneVolDecrease        =       std::make_shared<MenuItem>(
                                                                                std::vector<std::string> {"IDS_RINGTONE_VOLUME_DEC"},
                                                                                defaultImg,
-                                                                               "DECREASE_RINGTONE_VOLUME");
+                                                                               "DECREASE_RINGTONE_VOLUME",
+                                                                               std::string {},
+                                                                               std::string {},
+                                                                               RepetitionPolicy::multiple);
        auto mediaVolumeIncrease        =       std::make_shared<MenuItem>(
                                                                                std::vector<std::string> {"IDS_MEDIA_VOLUME_INC"},
                                                                                defaultImg,
-                                                                               "INCREASE_MEDIA_VOLUME");
+                                                                               "INCREASE_MEDIA_VOLUME",
+                                                                               std::string {},
+                                                                               std::string {},
+                                                                               RepetitionPolicy::multiple);
        auto mediaVolumeDecrease        =       std::make_shared<MenuItem>(
                                                                                std::vector<std::string> {"IDS_MEDIA_VOLUME_DEC"},
                                                                                defaultImg,
-                                                                               "DECREASE_MEDIA_VOLUME");
+                                                                               "DECREASE_MEDIA_VOLUME",
+                                                                               std::string {},
+                                                                               std::string {},
+                                                                               RepetitionPolicy::multiple);
        auto tapHomeButtonx2            =       std::make_shared<MenuItem>(
                                                                                std::vector<std::string> {"IDS_TAP_HOME_BUTTON_X2"},
                                                                                defaultImg,
@@ -398,11 +430,17 @@ MenuMap::MenuMap()
        auto notiVolumeIncrease         =       std::make_shared<MenuItem>(
                                                                                std::vector<std::string> {"IDS_NOTI_VOLUME_INC"},
                                                                                defaultImg,
-                                                                               "INCREASE_NOTIFICATIONS_VOLUME");
+                                                                               "INCREASE_NOTIFICATIONS_VOLUME",
+                                                                               std::string {},
+                                                                               std::string {},
+                                                                               RepetitionPolicy::multiple);
        auto notiVolumeDecrease         =       std::make_shared<MenuItem>(
                                                                                std::vector<std::string> {"IDS_NOTI_VOLUME_DEC"},
                                                                                defaultImg,
-                                                                               "DECREASE_NOTIFICATIONS_VOLUME");
+                                                                               "DECREASE_NOTIFICATIONS_VOLUME",
+                                                                               std::string {},
+                                                                               std::string {},
+                                                                               RepetitionPolicy::multiple);
        auto autoScroll                         =       std::make_shared<MenuItem>(
                                                                                std::vector<std::string> {"IDS_AUTO_SCROLL"},
                                                                                defaultImg,
index b84652b..e121061 100644 (file)
@@ -8,17 +8,23 @@
 #include <string>
 #include <vector>
 
+enum class RepetitionPolicy : bool {
+       single = false,
+       multiple = true
+};
+
 class MenuItem : public std::enable_shared_from_this<MenuItem>, public Subject<MenuItem>
 {
 public:
        MenuItem(std::vector<std::string> names = {}, std::string iconPath = {}, std::string activityType = {},
-                        std::string subMenuLabel = {}, std::string showingStateVconfKey = {});
+                        std::string subMenuLabel = {}, std::string showingStateVconfKey = {}, RepetitionPolicy repetitionPolicy = RepetitionPolicy::single);
 
        virtual std::string getName() const;
        std::string getIconPath() const;
        std::string getActivityType() const;
        std::string getSubMenuLabel() const;
        std::string getShowingStateVconfKey() const;
+       bool isRepeatable() const;
 
 protected:
        std::vector<std::string> names;
@@ -26,6 +32,7 @@ protected:
        std::string activityType;
        std::string subMenuLabel;
        std::string showingStateVconfKey;
+       RepetitionPolicy repetitionPolicy;
 };
 
 class MenuMap
index 3867658..5214a96 100644 (file)
@@ -253,8 +253,11 @@ void SelectActivity::navigateThroughSubMenuOrCreateActivityChangeRequest(MenuIte
                return;
        }
 
-       removeMenu();
-       completed = true;
+       if (!menuItem->isRepeatable()) {
+               removeMenu();
+               completed = true;
+       }
+
        notify(std::make_shared<ActivityChangeRequest>(menuItem->getActivityType(), realUiElement));
 }