Select Action Page in mvp 52/208052/3
authorOskar Chodowicz <o.chodowicz@samsung.com>
Mon, 17 Jun 2019 15:30:00 +0000 (17:30 +0200)
committerOskar Chodowicz <o.chodowicz@samsung.com>
Tue, 25 Jun 2019 13:45:54 +0000 (15:45 +0200)
Change-Id: If681134f26d585b9947a5e24f6b7afb3e1d7888d

src/model/SelectActionPageModel.cpp [new file with mode: 0644]
src/model/SelectActionPageModel.hpp [new file with mode: 0644]
src/presenter/AddSwitchPagePresenter.cpp
src/presenter/AddSwitchPagePresenter.hpp
src/presenter/SelectActionPagePresenter.cpp [new file with mode: 0644]
src/presenter/SelectActionPagePresenter.hpp [new file with mode: 0644]
src/utils/UniversalSwitchConstants.hpp

diff --git a/src/model/SelectActionPageModel.cpp b/src/model/SelectActionPageModel.cpp
new file mode 100644 (file)
index 0000000..2e58800
--- /dev/null
@@ -0,0 +1,43 @@
+#include "SelectActionPageModel.hpp"
+
+#include "DBus.hpp"
+#include "UniversalSwitchConstants.hpp"
+
+std::vector<InfoType> SelectActionPageModel::getBindableActivityTypes()
+{
+       std::vector<InfoType> bindableActivities{};
+       auto dBusClient = DBus::DBusClient{BUS, PATH, IFACE, DBus::ConnectionType::SESSION};
+       auto reply = dBusClient.method<DBus::ValueOrError<std::vector<std::tuple<std::string, std::string, std::string>>>()>("getBindableActivityTypes").call();
+       if (reply) {
+               for (auto activity : std::get<0>(reply))
+                       bindableActivities.push_back(InfoType{std::get<0>(activity), std::get<1>(activity), std::get<2>(activity)});
+       } else {
+               ERROR("Error on function getBindableActivityTypes call");
+               ERROR("%s", reply.getError().message.c_str());
+       }
+       return bindableActivities;
+}
+
+void SelectActionPageModel::updateSwitch(const SwitchConfigurationItem &item)
+{
+       auto dBusClient = DBus::DBusClient{BUS, PATH, IFACE, DBus::ConnectionType::SESSION};
+       auto reply = dBusClient.method<DBus::ValueOrError<>(std::string, std::string, std::string)>("updateSwitchConfigurationItem").call(item.switchId, item.userName, item.activityType);
+       if (reply)
+               DEBUG("Switch: %s updated successfully", item.switchId.c_str());
+       else {
+               ERROR("Error on function updateSwitchConfigurationItem call");
+               ERROR("%s", reply.getError().message.c_str());
+       }
+}
+
+void SelectActionPageModel::addSwitch(const SwitchConfigurationItem &item)
+{
+       auto dBusClient = DBus::DBusClient{BUS, PATH, IFACE, DBus::ConnectionType::SESSION};
+       auto reply = dBusClient.method<DBus::ValueOrError<>(std::string, std::string, std::string)>("addSwitchConfigurationItem").call(item.switchId, item.userName, item.activityType);
+       if (reply)
+               DEBUG("Switch: %s added successfully", item.switchId.c_str());
+       else {
+               ERROR("Error on function addSwitchConfigurationItem call");
+               ERROR("%s", reply.getError().message.c_str());
+       }
+}
\ No newline at end of file
diff --git a/src/model/SelectActionPageModel.hpp b/src/model/SelectActionPageModel.hpp
new file mode 100644 (file)
index 0000000..fa419be
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef SELECT_ACTION_PAGE_MODEL_HPP
+#define SELECT_ACTION_PAGE_MODEL_HPP
+
+#include "ObservableProperty.hpp"
+#include "UniversalSwitchTypes.hpp"
+#include "VConf.hpp"
+
+class SelectActionPageModel
+{
+       public:
+       std::vector<InfoType> getBindableActivityTypes();
+       void updateSwitch(const SwitchConfigurationItem &item);
+       void addSwitch(const SwitchConfigurationItem &item);
+};
+
+#endif
\ No newline at end of file
index 683055a3577aca5d12c51f582f4f172ee4b3c69a..f29b61c80838ec5bc65ddb0548ab3343ab1570ca 100644 (file)
@@ -1,16 +1,20 @@
 #include "AddSwitchPagePresenter.hpp"
 
+#include "AppContext.hpp"
+#include "SelectActionPagePresenter.hpp"
+#include "UniversalSwitchConstants.hpp"
+
 AddSwitchPagePresenter::AddSwitchPagePresenter()
 {
        setTitle("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_SWITCHES");
        groups_.emplace_back("");
        auto &items = groups_.back().items_;
-       for (auto provider : model_.getProviders()) {
+       for (auto &provider : model_.getProviders()) {
                items.push_back(std::make_unique<ListItem>(
                        provider.name,
                        provider.description,
-                       [this](auto item) {
-                               //Page for adding special switch should be added here
+                       [=](auto item) {
+                               this->createPageForProvider(provider);
                        }));
        }
        auto onConfigurationChange = [this](auto changeTime) {
@@ -21,4 +25,39 @@ AddSwitchPagePresenter::AddSwitchPagePresenter()
        };
        model_.switchesConfigurationChanged_.attach(onConfigurationChange);
        onConfigurationChange(std::chrono::system_clock::now());
+}
+
+void AddSwitchPagePresenter::createPageForProvider(const InfoType &provider)
+{
+       if (provider.id == ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_PROVIDER) {
+               createPageForScreenProvider();
+               return;
+       }
+       if (provider.id == ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER) {
+               createPageForAccessoriesProvider();
+               return;
+       }
+       if (provider.id == ACCESSIBILITY_UNIVERSAL_SWITCH_CAMERA_SWITCH_PROVIDER) {
+               createPageForCameraProvider();
+               return;
+       }
+}
+
+void AddSwitchPagePresenter::createPageForScreenProvider()
+{
+       auto switches = model_.getAllSwitchesByProvider(ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_PROVIDER);
+       if (switches.size() != 1)
+               return;
+       auto screenSwitch = switches[0];
+       Singleton<AppContext>::instance().push(std::make_unique<SelectActionPagePresenter>(screenSwitch.id, ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN, ChangeType::ADD, 1));
+}
+
+void AddSwitchPagePresenter::createPageForAccessoriesProvider()
+{
+       //Singleton<AppContext>::instance().push(std::make_unique<AccessoriesProviderPagePresenter>());
+}
+
+void AddSwitchPagePresenter::createPageForCameraProvider()
+{
+       //Singleton<AppContext>::instance().push(std::make_unique<CameraProviderPagePresenter>());
 }
\ No newline at end of file
index b205c3be12e9fb55fdd0f8069922a50c00e244a7..f59cb607c9df3610e01f140a40dee1fe642a4c54 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "AddSwitchPageModel.hpp"
 #include "ListPresenter.hpp"
+#include "UniversalSwitchTypes.hpp"
 
 class AddSwitchPagePresenter : public ListPresenter
 {
@@ -11,6 +12,10 @@ class AddSwitchPagePresenter : public ListPresenter
 
        private:
        AddSwitchPageModel model_;
+       void createPageForProvider(const InfoType &provider);
+       void createPageForScreenProvider();
+       void createPageForAccessoriesProvider();
+       void createPageForCameraProvider();
 };
 
 #endif
diff --git a/src/presenter/SelectActionPagePresenter.cpp b/src/presenter/SelectActionPagePresenter.cpp
new file mode 100644 (file)
index 0000000..ed8c88b
--- /dev/null
@@ -0,0 +1,35 @@
+#include "SelectActionPagePresenter.hpp"
+
+SelectActionPagePresenter::SelectActionPagePresenter(std::string switchId, std::string userName, ChangeType changeType, int countOfPagesToPop)
+       : switchId_(std::move(switchId)), userName_(std::move(userName)), changeType_(changeType), countOfPagesToPop_(countOfPagesToPop)
+{
+       setTitle("IDS_ACCS_UNIVERSAL_SWITCH_SELECT_ACTION");
+       groups_.emplace_back("");
+       auto &items = groups_.back().items_;
+
+       for (auto &activity : model_.getBindableActivityTypes()) {
+               items.push_back(std::make_unique<ListItem>(
+                       activity.name,
+                       std::string{},
+                       [=](auto item) {
+                               this->addOrUpdateSwitchConfigurationItem(activity.id);
+                       },
+                       ListItem::WidgetType::radio));
+       }
+}
+
+void SelectActionPagePresenter::addOrUpdateSwitchConfigurationItem(const std::string &activityType)
+{
+       switch (changeType_) {
+       case ChangeType::ADD:
+               model_.addSwitch({switchId_, userName_, activityType});
+               break;
+       case ChangeType::UPDATE:
+               model_.addSwitch({switchId_, userName_, activityType});
+               break;
+       default:
+               ASSERT(0, "Unhandled change type");
+               break;
+       }
+       //Singleton<AppContext>::instance().pop(countOfPagesToPop+1);
+}
\ No newline at end of file
diff --git a/src/presenter/SelectActionPagePresenter.hpp b/src/presenter/SelectActionPagePresenter.hpp
new file mode 100644 (file)
index 0000000..cf01cd2
--- /dev/null
@@ -0,0 +1,22 @@
+#ifndef SELECT_ACTION_PAGE_PRESENTER_HPP
+#define SELECT_ACTION_PAGE_PRESENTER_HPP
+
+#include "ListPresenter.hpp"
+#include "SelectActionPageModel.hpp"
+#include "UniversalSwitchTypes.hpp"
+
+class SelectActionPagePresenter : public ListPresenter
+{
+       public:
+       SelectActionPagePresenter(std::string switchId, std::string userName, ChangeType changeType, int countOfPagesToPop);
+
+       private:
+       void addOrUpdateSwitchConfigurationItem(const std::string &activityType);
+       const std::string switchId_;
+       const std::string userName_;
+       ChangeType changeType_;
+       const int countOfPagesToPop_;
+       SelectActionPageModel model_;
+};
+
+#endif
index 043834b95e7f6e3c92286bcb3492a1451a43fb48..fca07bee27afbd7e8892f85d9c301f07ddf6cf49 100644 (file)
@@ -80,4 +80,9 @@
 
 #define ACCESSIBILITY_UNIVERSAL_SWITCH_PLUS_ICON RESDIR "/icons/plus.png"
 
+#define ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN_SWITCH_PROVIDER "ScreenSwitchProvider"
+#define ACCESSIBILITY_UNIVERSAL_SWITCH_ACCESSORIES_SWITCH_PROVIDER "AccessoriesSwitchProvider"
+#define ACCESSIBILITY_UNIVERSAL_SWITCH_CAMERA_SWITCH_PROVIDER "CameraSwitchProvider"
+#define ACCESSIBILITY_UNIVERSAL_SWITCH_SCREEN "Screen"
+
 #endif