ScreenReaderPage in MVP 14/204414/5
authorOskar Chodowicz <o.chodowicz@samsung.com>
Tue, 23 Apr 2019 18:14:12 +0000 (20:14 +0200)
committerOskar Chodowicz <o.chodowicz@samsung.com>
Thu, 25 Apr 2019 15:42:53 +0000 (17:42 +0200)
Change-Id: I6c1c49db66cf2ea85e34992b13f1e47307752cd3

src/ScreenReaderPage.cpp [deleted file]
src/ScreenReaderPage.hpp [deleted file]
src/model/ScreenReaderModel.cpp [new file with mode: 0644]
src/model/ScreenReaderModel.hpp [new file with mode: 0644]
src/presenter/MainPagePresenter.cpp
src/presenter/MainPagePresenter.hpp
src/presenter/ScreenReaderPresenter.cpp [new file with mode: 0644]
src/presenter/ScreenReaderPresenter.hpp [new file with mode: 0644]
src/view/ListView.cpp

diff --git a/src/ScreenReaderPage.cpp b/src/ScreenReaderPage.cpp
deleted file mode 100644 (file)
index 0e85f2c..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright 2018 Samsung Electronics Co., Ltd
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "ScreenReaderPage.hpp"
-
-#include "AccessibilitySettingLog.hpp"
-#include "Genlist.hpp"
-#include "Singleton.hpp"
-#include "TextToSpeech.hpp"
-#include "setting-accessibility.h"
-
-#include <app.h>
-
-ScreenReaderPage::ScreenReaderPage()
-       : context_(Singleton<AppContext>::instance())
-{
-       auto genlist = Widget::make<Genlist>(context_.navContext_.getNaviframe());
-       genlist->setMode(ELM_LIST_COMPRESS);
-       genlist->setStyle("dialogue");
-       genlist->clear(); // TODO check if necessary
-
-       screenReaderItem_ = genlist->appendItem({"type1",
-               "IDS_ST_MBODY_SCREEN_READER_HTTS",
-               {},
-               [this](auto item) {
-                       auto state = item->getState();
-                       Singleton<VConfInterface>::instance().set(VCONFKEY_SETAPPL_ACCESSIBILITY_TTS, state);
-                       if (!state) {
-                               auto buf = TranslatedString{"IDS_ST_MBODY_SCREEN_READER_HTTS"} + " " + TranslatedString{"IDS_ST_BODY_OFF"};
-                               Singleton<TextToSpeech>::instance().play(buf.str());
-                       }
-               },
-               GenlistItem::WidgetType::toggle});
-
-       auto onVConfValueChangeCb = [this](bool screenReaderState) {
-               screenReaderItem_->setState(screenReaderState);
-               screenReaderItem_->setDescription(screenReaderState ? "IDS_ST_BODY_ON" : "IDS_ST_BODY_OFF");
-       };
-       screenReaderStateHandle_ = Singleton<VConfInterface>::instance().registerAndGet<bool>({VCONFKEY_SETAPPL_ACCESSIBILITY_TTS}, false, onVConfValueChangeCb);
-
-       genlist->appendItem({"multiline", {}, "IDS_ACCS_BODY_WHILE_SCREEN_READER_IS_ENABLED_YOUR_PHONE_WILL_PROVIDE_VOICE_FEEDBACK_FOR_EXAMPLE_SCREEN_READER_WILL_MSG"});
-
-       genlist->appendItem({"type1",
-               "IDS_ST_OPT_SETTINGS",
-               {},
-               [this](auto item) {
-                       this->screenReaderSettingsPage_ = std::make_unique<ScreenReaderSettingsPage>();
-               }});
-
-       context_.navContext_.getNaviframe()->pushBack("IDS_ST_MBODY_SCREEN_READER_HTTS", genlist, [this]() {
-               screenReaderStateHandle_ = {};
-       });
-}
\ No newline at end of file
diff --git a/src/ScreenReaderPage.hpp b/src/ScreenReaderPage.hpp
deleted file mode 100644 (file)
index fb907a8..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright 2018 Samsung Electronics Co., Ltd
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
-
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef SCREEN_READER_PAGE_HPP
-#define SCREEN_READER_PAGE_HPP
-
-#include "AppContext.hpp"
-#include "GenlistItem.hpp"
-#include "ScreenReaderSettingsPage.hpp"
-#include "VConf.hpp"
-
-#include <Elementary.h>
-#include <vconf.h>
-
-/**
- * View allowing to turn on/off Screen Reader feature and to start configuration of its options
- *
- * @param ad global context of application
- *
- * TODO:
- *  replace classical callbacks with lambda expressions
- */
-class ScreenReaderPage
-{
-       public:
-       ScreenReaderPage();
-
-       private:
-       AppContext &context_;
-       std::unique_ptr<ScreenReaderSettingsPage> screenReaderSettingsPage_;
-       GenlistItem *screenReaderItem_ = nullptr;
-       VConfInterface::CallbackHandle screenReaderStateHandle_;
-};
-
-#endif
diff --git a/src/model/ScreenReaderModel.cpp b/src/model/ScreenReaderModel.cpp
new file mode 100644 (file)
index 0000000..c3b4bf4
--- /dev/null
@@ -0,0 +1,14 @@
+#include "ScreenReaderModel.hpp"
+
+#define VCONFKEY_ACCESSIBILITY_TTS "db/setting/accessibility/tts"
+
+ScreenReaderModel::ScreenReaderModel()
+{
+       screenReaderStateHandle_ = Singleton<VConfInterface>::instance().registerAndGet<bool>(std::string{VCONFKEY_ACCESSIBILITY_TTS}, false, [this](auto state) {
+               this->state_ = state;
+       });
+
+       state_.attach([](auto val) {
+               Singleton<VConfInterface>::instance().set(VCONFKEY_ACCESSIBILITY_TTS, val);
+       });
+}
\ No newline at end of file
diff --git a/src/model/ScreenReaderModel.hpp b/src/model/ScreenReaderModel.hpp
new file mode 100644 (file)
index 0000000..0ddaeb5
--- /dev/null
@@ -0,0 +1,17 @@
+#ifndef SCREEN_READER_MODEL_HPP
+#define SCREEN_READER_MODEL_HPP
+
+#include "ObservableProperty.hpp"
+#include "VConf.hpp"
+
+class ScreenReaderModel
+{
+       public:
+       ScreenReaderModel();
+       ObservableProperty<bool> state_;
+
+       private:
+       VConfInterface::CallbackHandle screenReaderStateHandle_;
+};
+
+#endif
\ No newline at end of file
index c2c68ec12779dc077f5d6525540e22ce337bd1be..4778a34a487aef0794a6fa5f621c4e6e074c07c2 100644 (file)
@@ -1,5 +1,7 @@
 #include "MainPagePresenter.hpp"
 
+#include "ScreenReaderPresenter.hpp"
+
 #include <app.h>
 
 MainPagePresenter::MainPagePresenter()
@@ -8,8 +10,11 @@ MainPagePresenter::MainPagePresenter()
        groups_.emplace_back("IDS_ST_HEADER_VISION");
        groups_.back().items_.push_back(std::make_unique<ListItem>(
                "IDS_ST_MBODY_SCREEN_READER_HTTS",
-               "IDS_ST_BODY_OFF",
-               [this](auto item) { screenReaderPage_ = std::make_unique<ScreenReaderPage>(); }));
+               model_.state_.value() ? "IDS_ST_BODY_ON" : "IDS_ST_BODY_OFF",
+               [this](auto item) { Singleton<AppContext>::instance().push(std::make_unique<ScreenReaderPresenter>()); },
+               ListItem::WidgetType::none,
+               std::function<void(ListItem * item)>{},
+               model_.state_.value()));
        groups_.back().items_.push_back(std::make_unique<ListItem>(
                "IDS_ACCS_UNIVERSAL_SWITCH",
                "IDS_ACCS_UNIVERSAL_SWITCH_HINT",
@@ -23,4 +28,7 @@ MainPagePresenter::MainPagePresenter()
                screenReaderStateHandle_ = {};
                ui_app_exit();
        };
+       model_.state_.attach([this](auto state) {
+               auto item = groups_[0].items_[0]->description_ = state ? "IDS_ST_BODY_ON" : "IDS_ST_BODY_OFF";
+       });
 }
\ No newline at end of file
index fd1bcdaf25f1ae1e0a604477ae0309a6c666314f..7a85dceb8e10444ca7ad86f090403f615077116e 100644 (file)
@@ -3,7 +3,7 @@
 
 #include "AccessibilityLauncherPagePresenter.hpp"
 #include "ListPresenter.hpp"
-#include "ScreenReaderPage.hpp"
+#include "ScreenReaderModel.hpp"
 #include "UniversalSwitchPage.hpp"
 #include "VConf.hpp"
 
@@ -13,10 +13,10 @@ class MainPagePresenter : public ListPresenter
        MainPagePresenter();
 
        private:
-       std::unique_ptr<ScreenReaderPage> screenReaderPage_;
        std::unique_ptr<UniversalSwitchPage> universalSwitchPage_;
        std::unique_ptr<AccessibilityLauncherPagePresenter> accessibilityLauncherPage_;
        VConfInterface::CallbackHandle screenReaderStateHandle_;
+       ScreenReaderModel model_;
 };
 
 #endif
\ No newline at end of file
diff --git a/src/presenter/ScreenReaderPresenter.cpp b/src/presenter/ScreenReaderPresenter.cpp
new file mode 100644 (file)
index 0000000..e78ec83
--- /dev/null
@@ -0,0 +1,37 @@
+#include "ScreenReaderPresenter.hpp"
+
+#include "TextToSpeech.hpp"
+
+ScreenReaderPresenter::ScreenReaderPresenter()
+{
+       groups_.emplace_back("");
+
+       auto &items = groups_.back().items_;
+       items.push_back(std::make_unique<ListItem>(
+               "IDS_ST_MBODY_SCREEN_READER_HTTS",
+               model_.state_.value() ? "IDS_ST_BODY_ON" : "IDS_ST_BODY_OFF",
+               [this](auto item) {
+                       this->model_.state_ = item->widgetState_.value();
+               },
+               ListItem::WidgetType::toggle,
+               std::function<void(ListItem * item)>{},
+               model_.state_.value()));
+       items.push_back(std::make_unique<ListItem>(
+               std::string{},
+               "IDS_ACCS_BODY_WHILE_SCREEN_READER_IS_ENABLED_YOUR_PHONE_WILL_PROVIDE_VOICE_FEEDBACK_FOR_EXAMPLE_SCREEN_READER_WILL_MSG"));
+       items.push_back(std::make_unique<ListItem>(
+               "IDS_ST_OPT_SETTINGS",
+               std::string{},
+               [this](auto item) {
+                       this->screenReaderSettingsPage_ = std::make_unique<ScreenReaderSettingsPage>();
+               }));
+       model_.state_.attach([this](auto state) {
+               auto item = groups_[0].items_[0].get();
+               item->widgetState_ = state;
+               item->description_ = state ? "IDS_ST_BODY_ON" : "IDS_ST_BODY_OFF";
+               if (!state) {
+                       auto buf = TranslatedString{"IDS_ST_MBODY_SCREEN_READER_HTTS"} + " " + TranslatedString{"IDS_ST_BODY_OFF"};
+                       Singleton<TextToSpeech>::instance().play(buf.str());
+               }
+       });
+}
\ No newline at end of file
diff --git a/src/presenter/ScreenReaderPresenter.hpp b/src/presenter/ScreenReaderPresenter.hpp
new file mode 100644 (file)
index 0000000..59ce837
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef SCREEN_READER_PRESENTER_HPP
+#define SCREEN_READER_PRESENTER_HPP
+
+#include "ListPresenter.hpp"
+#include "ScreenReaderModel.hpp"
+#include "ScreenReaderSettingsPage.hpp"
+
+#include <vector>
+
+class ScreenReaderPresenter : public ListPresenter
+{
+       public:
+       ScreenReaderPresenter();
+
+       private:
+       ScreenReaderModel model_;
+       std::unique_ptr<ScreenReaderSettingsPage> screenReaderSettingsPage_;
+};
+
+#endif
\ No newline at end of file
index 57138fa1840c4143c6fe77d9ac1ccf0da8afe513..d78fa2c476c1c0c7c9e123a31644ce7e8a6c6779 100644 (file)
@@ -59,6 +59,7 @@ void ListView::addItemsToGenlist()
                        itemsMapping_.emplace(genlistItem, it.get());
                        it->title_.attach([this, gi = genlistItem](auto val) { gi->setText(val); });
                        it->description_.attach([this, gi = genlistItem](auto val) { gi->setDescription(val); });
+                       genlistItem->setState(it->widgetState_.value());
                        it->widgetState_.attach([this, gi = genlistItem](auto val) { gi->setState(val); });
                        it->enabled_.attach([this, gi = genlistItem](auto val) {
                                if (val)