Add possibility to update switch for camera & screen providers 98/208598/4
authorOskar Chodowicz <o.chodowicz@samsung.com>
Wed, 26 Jun 2019 08:44:21 +0000 (10:44 +0200)
committerLukasz Wlazly <l.wlazly@partner.samsung.com>
Thu, 27 Jun 2019 06:57:41 +0000 (08:57 +0200)
Change-Id: I206051f003c9480d711ffaaad14f6585e33fd1a7

src/presenter/SelectActionPagePresenter.cpp
src/presenter/SwitchesPagePresenter.cpp
src/presenter/SwitchesPagePresenter.hpp
src/utils/utils.hpp

index 9fe29eb..46747c4 100644 (file)
@@ -27,7 +27,7 @@ void SelectActionPagePresenter::addOrUpdateSwitchConfigurationItem(const std::st
                model_.addSwitch({switchId_, userName_, activityType});
                break;
        case ChangeType::UPDATE:
-               model_.addSwitch({switchId_, userName_, activityType});
+               model_.updateSwitch({switchId_, userName_, activityType});
                break;
        default:
                ASSERT(0, "Unhandled change type");
index 22a082c..528d3d8 100644 (file)
@@ -3,6 +3,7 @@
 #include "AddSwitchPagePresenter.hpp"
 #include "AppContext.hpp"
 #include "RemoveSwitchesPagePresenter.hpp"
+#include "SelectActionPagePresenter.hpp"
 #include "UniversalSwitchConstants.hpp"
 
 SwitchesPagePresenter::SwitchesPagePresenter()
@@ -27,12 +28,12 @@ void SwitchesPagePresenter::addItemsToList()
 {
        auto &items = groups_.back().items_;
        auto switches = model_.getAllSwitchConfigurationItems();
-       for (auto oneSwitch : switches) {
+       for (auto &oneSwitch : switches) {
                items.push_back(std::make_unique<ListItem>(
                        oneSwitch.userName,
                        model_.getActivityName(oneSwitch.activityType),
-                       [this](auto item) {
-                               //UpdateSwitchPage should be added here
+                       [this, oneSwitch](auto item) {
+                               this->createUpdatePage(oneSwitch.switchId);
                        }));
        }
        items.push_back(std::make_unique<ListItem>(
@@ -47,3 +48,19 @@ void SwitchesPagePresenter::addItemsToList()
                true,
                ACCESSIBILITY_UNIVERSAL_SWITCH_PLUS_ICON));
 }
+
+void SwitchesPagePresenter::createUpdatePage(const std::string &switchId)
+{
+       auto providerName = utils::stringSplitByDelimiter(switchId, '_')[0];
+       if (providerName == ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_PROVIDER) {
+               Singleton<AppContext>::instance().push(std::make_unique<SelectActionPagePresenter>(switchId, ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN, ChangeType::UPDATE, 0));
+               return;
+       }
+       if (providerName == ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER) {
+               return;
+       }
+       if (providerName == ACCESSIBILITY_UNIVERSAL_SWITCH_CAMERA_SWITCH_PROVIDER) {
+               Singleton<AppContext>::instance().push(std::make_unique<SelectActionPagePresenter>(switchId, ACCESSIBILITY_UNIVERSAL_SWITCH_CAMERA_SWITCH_PROVIDER, ChangeType::UPDATE, 0));
+               return;
+       }
+}
\ No newline at end of file
index dabc2f2..74b27c9 100644 (file)
@@ -12,6 +12,7 @@ class SwitchesPagePresenter : public ListPresenter
        private:
        SwitchesPageModel model_;
        void addItemsToList();
+       void createUpdatePage(const std::string &switchId);
 };
 
 #endif
index 0c9ca9f..835f899 100644 (file)
@@ -20,6 +20,7 @@
 #include "Elementary.h"
 
 #include <sstream>
+#include <vector>
 
 using SettingCallback = void (*)(void *, Evas_Object *, void *);
 
@@ -76,6 +77,17 @@ namespace utils
 
                return out.str();
        }
+
+       inline std::vector<std::string> stringSplitByDelimiter(const std::string &s, char delimiter)
+       {
+               std::vector<std::string> tokens;
+               std::string token;
+               std::istringstream tokenStream(s);
+               while (std::getline(tokenStream, token, delimiter)) {
+                       tokens.push_back(token);
+               }
+               return tokens;
+       }
 } // namespace utils
 
 #endif