Add VoicePresenter 14/207714/9
authorLukasz Wlazly <l.wlazly@partner.samsung.com>
Tue, 11 Jun 2019 09:01:40 +0000 (11:01 +0200)
committerLukasz Wlazly <l.wlazly@partner.samsung.com>
Tue, 18 Jun 2019 11:13:30 +0000 (13:13 +0200)
Change-Id: Ia490cdafedbc16b23d1449082cd3b8dd0202ddbd

src/model/VoiceModel.cpp [new file with mode: 0644]
src/model/VoiceModel.hpp [new file with mode: 0644]
src/presenter/UniversalSwitchSettingsPagePresenter.cpp
src/presenter/VoicePresenter.cpp [new file with mode: 0644]
src/presenter/VoicePresenter.hpp [new file with mode: 0644]

diff --git a/src/model/VoiceModel.cpp b/src/model/VoiceModel.cpp
new file mode 100644 (file)
index 0000000..a1b4fc5
--- /dev/null
@@ -0,0 +1,28 @@
+#include "VoiceModel.hpp"
+
+VoiceModel::VoiceModel()
+{
+       stateHandle_ = Singleton<VConfInterface>::instance().registerAndGet<bool>("db/setting/accessibility/universal-switch/FEEDBACK_VOICE_ENABLED", false, [this](auto val) {
+               this->state_ = val;
+       });
+
+       state_.attach([](auto val) {
+               Singleton<VConfInterface>::instance().set("db/setting/accessibility/universal-switch/FEEDBACK_VOICE_ENABLED", val);
+       });
+
+       rateHandle_ = Singleton<VConfInterface>::instance().registerAndGet<double>("db/setting/accessibility/universal-switch/FEEDBACK_VOICE_SPEECH_RATE", 1.0, [this](auto val) {
+               this->rate_ = val;
+       });
+
+       rate_.attach([](auto val) {
+               Singleton<VConfInterface>::instance().set("db/setting/accessibility/universal-switch/FEEDBACK_VOICE_SPEECH_RATE", val);
+       });
+
+       volumeHandle_ = Singleton<VConfInterface>::instance().registerAndGet<double>("db/setting/accessibility/universal-switch/FEEDBACK_VOICE_SPEECH_VOLUME", 1.0, [this](auto val) {
+               this->volume_ = val;
+       });
+
+       volume_.attach([](auto val) {
+               Singleton<VConfInterface>::instance().set("db/setting/accessibility/universal-switch/FEEDBACK_VOICE_SPEECH_VOLUME", val);
+       });
+}
\ No newline at end of file
diff --git a/src/model/VoiceModel.hpp b/src/model/VoiceModel.hpp
new file mode 100644 (file)
index 0000000..a218f4f
--- /dev/null
@@ -0,0 +1,26 @@
+#ifndef VOICE_MODEL_HPP
+#define VOICE_MODEL_HPP
+
+#include "ObservableProperty.hpp"
+#include "VConf.hpp"
+#include "utils.hpp"
+
+class VoiceModel
+{
+       public:
+       VoiceModel();
+
+       const utils::Range<double> range_ = {0.1, 1.0};
+       const double step_ = 0.1;
+
+       ObservableProperty<bool> state_;
+       ObservableProperty<double> rate_;
+       ObservableProperty<double> volume_;
+
+       private:
+       VConfInterface::CallbackHandle stateHandle_;
+       VConfInterface::CallbackHandle rateHandle_;
+       VConfInterface::CallbackHandle volumeHandle_;
+};
+
+#endif
\ No newline at end of file
index 042e2b6..3ff5d92 100644 (file)
@@ -7,6 +7,9 @@
 #include "PauseOnFirstPresenter.hpp"
 #include "SoundPresenter.hpp"
 #include "TapDurationPresenter.hpp"
+#include "AutoTapPresenter.hpp"
+#include "AutoMoveIntervalPresenter.hpp"
+#include "VoicePresenter.hpp"
 
 UniversalSwitchSettingsPagePresenter::UniversalSwitchSettingsPagePresenter()
 {
@@ -293,6 +296,7 @@ void UniversalSwitchSettingsPagePresenter::createFeedbackGroup()
                model_.feedbackVoiceState_.value() ? std::string{"IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_ON"} : std::string{"IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_OFF"},
                [this](auto item) {
                        DEBUG("feedback sound widget");
+                       Singleton<AppContext>::instance().push(std::make_unique<VoicePresenter>());
                },
                ListItem::WidgetType::toggle,
                [this](auto item) {
diff --git a/src/presenter/VoicePresenter.cpp b/src/presenter/VoicePresenter.cpp
new file mode 100644 (file)
index 0000000..62b18e7
--- /dev/null
@@ -0,0 +1,102 @@
+#include "VoicePresenter.hpp"
+
+VoicePresenter::VoicePresenter()
+{
+       setTitle("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_FEEDBACK_VOICE");
+
+       groups_.emplace_back("");
+       auto &items = groups_.back().items_;
+
+       items.push_back(std::make_unique<ListItem>(
+               model_.state_.value() ? "IDS_ST_BODY_ON" : "IDS_ST_BODY_OFF",
+               std::string{},
+               [this](auto item) {
+                       this->model_.state_ = item->widgetState_.value();
+               },
+               ListItem::WidgetType::toggle,
+               std::function<void(ListItem * item)>{},
+               std::function<void(ListItem * item)>{},
+               model_.state_.value()));
+       model_.state_.attach([this](auto val) {
+               groups_[0].items_[0]->title_ = val ? "IDS_ST_BODY_ON" : "IDS_ST_BODY_OFF";
+       });
+
+       items.push_back(std::make_unique<ListItem>(
+               std::string{},
+               "IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_SET_VALUE_DESC_FEEDBACK_VOICE"));
+
+       groups_.emplace_back("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_FEEDBACK_VOICE_SPEECH_RATE");
+       auto speechRateItem = std::make_unique<ListItem>(
+               std::string{},
+               std::string{},
+               std::function<void(ListItem * item)>{},
+               ListItem::WidgetType::slider,
+               std::function<void(ListItem * item)>{},
+               [this](auto item) {
+                       this->model_.rate_ = item->value_;
+               });
+       speechRateItem->value_ = model_.rate_.value();
+       speechRateItem->range_ = {model_.range_.begin, model_.range_.end};
+       speechRateItem->step_ = model_.step_;
+
+       groups_.back().items_.push_back(std::move(speechRateItem));
+
+       groups_.emplace_back("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_FEEDBACK_VOICE_SPEECH_VOLUME");
+       auto &radioItems = groups_.back().items_;
+
+       radioItems.push_back(std::make_unique<ListItem>(
+               "Match media volume",
+               std::string{},
+               [this](auto item) {
+                       this->model_.volume_ = 1.0;
+                       this->updateRadioItems();
+               },
+               ListItem::WidgetType::radio,
+               std::function<void(ListItem * item)>{},
+               std::function<void(ListItem * item)>{},
+               model_.volume_.value() == 1.0));
+
+       radioItems.push_back(std::make_unique<ListItem>(
+               "75% of media volume",
+               std::string{},
+               [this](auto item) {
+                       this->model_.volume_ = 0.75;
+                       this->updateRadioItems();
+               },
+               ListItem::WidgetType::radio,
+               std::function<void(ListItem * item)>{},
+               std::function<void(ListItem * item)>{},
+               model_.volume_.value() == 0.75));
+
+       radioItems.push_back(std::make_unique<ListItem>(
+               "50% of media volume",
+               std::string{},
+               [this](auto item) {
+                       this->model_.volume_ = 0.50;
+                       this->updateRadioItems();
+               },
+               ListItem::WidgetType::radio,
+               std::function<void(ListItem * item)>{},
+               std::function<void(ListItem * item)>{},
+               model_.volume_.value() == 0.50));
+
+       radioItems.push_back(std::make_unique<ListItem>(
+               "25% of media volume",
+               std::string{},
+               [this](auto item) {
+                       this->model_.volume_ = 0.25;
+                       this->updateRadioItems();
+               },
+               ListItem::WidgetType::radio,
+               std::function<void(ListItem * item)>{},
+               std::function<void(ListItem * item)>{},
+               model_.volume_.value() == 0.25));
+}
+
+void VoicePresenter::updateRadioItems()
+{
+       for (auto i = 1; i <= 4; ++i) {
+               auto idx = 4 - i;
+               groups_[2].items_[idx]->widgetState_ = model_.volume_.value() == 0.25 * i;
+       }
+}
\ No newline at end of file
diff --git a/src/presenter/VoicePresenter.hpp b/src/presenter/VoicePresenter.hpp
new file mode 100644 (file)
index 0000000..ad20eaa
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef VOICE_PRESENTER_HPP
+#define VOICE_PRESENTER_HPP
+
+#include "ListPresenter.hpp"
+#include "VoiceModel.hpp"
+
+class VoicePresenter : public ListPresenter
+{
+       public:
+       VoicePresenter();
+
+       private:
+       void updateRadioItems();
+
+       VoiceModel model_;
+};
+
+#endif
\ No newline at end of file