Create "Tap duration" item with new genlist API 71/201771/1
authorLukasz Wlazly <l.wlazly@partner.samsung.com>
Tue, 19 Mar 2019 09:28:07 +0000 (10:28 +0100)
committerLukasz Wlazly <l.wlazly@partner.samsung.com>
Tue, 19 Mar 2019 09:28:07 +0000 (10:28 +0100)
Change-Id: I081219bf5ca7a28354e788ffa4873062cf0f2797

src/UniversalSwitchSettingsPage.cpp
src/UniversalSwitchSettingsPage.hpp

index c2bf260..8820870 100644 (file)
@@ -264,9 +264,40 @@ void UniversalSwitchSettingsPage::createAdditionalSettingsGroup()
 
        str = getValueUnitText(NULL, &context_->us_configuration.tap_duration_value, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_SECONDS"),
                                                   !context_->us_configuration.tap_duration_state, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_OFF"));
-       universal_switch_tap_duration = addMenuItem(_("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_ADD_SETTINGS_TAP_DURATION"),
-                                                                       str, tapDurationCb, true, context_->us_configuration.tap_duration_state, tapDurationCheckboxCb);
-       universal_switch_tap_duration->userdata = this;
+
+       tapDuration_ = genlist_->appendItem({"type1", "IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_ADD_SETTINGS_TAP_DURATION", str,
+                                                                                [this](auto item)
+       {
+               setValuePage_ = std::make_unique<SetValuePage>(context_, ValueEditorType::NUMERIC_SWITCH, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_ADD_SETTINGS_TAP_DURATION"));
+               setValuePage_->setSwitch(context_->us_configuration.tap_duration_state);
+               setValuePage_->addValueChangedCb([this](auto val) {
+                       this->tapDurationValueChangedCb(val);
+               });
+               setValuePage_->addSwitchChangedCb([this](auto state) {
+                       this->tapDurationSwitchChangedCb(state);
+               });
+               setValuePage_->setDescription(_("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_SET_VALUE_DESC_TAP_DURATION"));
+               setValuePage_->setRange(RANGE_MIN_TAP_DURATION, RANGE_MAX_TAP_DURATION, STEP_TAP_DURATION);
+               setValuePage_->setValue(context_->us_configuration.tap_duration_value, "seconds");
+       },
+       [this](auto item)
+       {
+               context_->us_configuration.tap_duration_state = item->getState();
+               auto str = getValueUnitText(NULL, &context_->us_configuration.tap_duration_value, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_SECONDS"),
+                                                                       !context_->us_configuration.tap_duration_state, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_OFF"));
+               item->setDescription(str);
+               item->update();
+               vconf_set_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_TAP_DURATION_STATE, item->getState());
+       }, GenlistItem::WidgetType::toggle
+                                                                               });
+
+       if (context_->us_configuration.tap_duration_state) {
+               tapDuration_->setState(true);
+               auto str = getValueUnitText(NULL, &context_->us_configuration.tap_duration_value, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_SECONDS"),
+                                                                       !context_->us_configuration.tap_duration_state, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_OFF"));
+               tapDuration_->setDescription(str);
+               tapDuration_->update();
+       }
 
        str = getValueUnitText(NULL, &context_->us_configuration.sgl_iaction_int_value, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_SECONDS"),
                                                   !context_->us_configuration.sgl_iaction_int_state, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_OFF"));
@@ -942,60 +973,27 @@ void UniversalSwitchSettingsPage::sglInactionIntervalCheckboxCb(void *data, Evas
        updateVconfValue(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_SGL_IACTION_INT_STATE, (bool *)&list_item->chk_status, NULL, NULL);
 }
 
-void UniversalSwitchSettingsPage::tapDurationCb(void *data, Evas_Object *obj, void *event_info)
-{
-       auto self = static_cast<UniversalSwitchSettingsPage *>(data);
-       elm_genlist_item_selected_set((Elm_Object_Item *)event_info, EINA_FALSE);
-
-       self->setValuePage_ = std::make_unique<SetValuePage>(self->context_, ValueEditorType::NUMERIC_SWITCH, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_ADD_SETTINGS_TAP_DURATION"));
-       self->setValuePage_->setSwitch(self->context_->us_configuration.tap_duration_state);
-       self->setValuePage_->addValueChangedCb([self](auto val) {
-               self->tapDurationValueChangedCb(val);
-       });
-       self->setValuePage_->addSwitchChangedCb([self](auto state) {
-               self->tapDurationSwitchChangedCb(state);
-       });
-       self->setValuePage_->setDescription(_("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_SET_VALUE_DESC_TAP_DURATION"));
-       self->setValuePage_->setRange(RANGE_MIN_TAP_DURATION, RANGE_MAX_TAP_DURATION, STEP_TAP_DURATION);
-       self->setValuePage_->setValue(self->context_->us_configuration.tap_duration_value, "seconds");
-}
-
 void UniversalSwitchSettingsPage::tapDurationSwitchChangedCb(bool state)
 {
        context_->us_configuration.tap_duration_state = state;
-       updateVconfValue(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_TAP_DURATION_STATE, &state, NULL, NULL);
+       vconf_set_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_TAP_DURATION_STATE, state);
 
-       universal_switch_tap_duration->chk_status = state;
-       elm_check_state_set(universal_switch_tap_duration->eo_check, state);
-       universal_switch_tap_duration->sub_desc = getValueUnitText(NULL, &context_->us_configuration.tap_duration_value, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_SECONDS"),
-                       !context_->us_configuration.tap_duration_state, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_OFF"));
-       elm_genlist_item_update(universal_switch_tap_duration->item);
+       tapDuration_->setState(state);
+       auto str = getValueUnitText(NULL, &context_->us_configuration.tap_duration_value, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_SECONDS"),
+                                                               !context_->us_configuration.tap_duration_state, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_OFF"));
+       tapDuration_->setDescription(str);
+       tapDuration_->update();
 }
 
 void UniversalSwitchSettingsPage::tapDurationValueChangedCb(double value)
 {
        context_->us_configuration.tap_duration_value = value;
-       updateVconfValue(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_TAP_DURATION_VALUE, NULL, NULL, &value);
-
-       universal_switch_tap_duration->sub_desc = getValueUnitText(NULL, &context_->us_configuration.tap_duration_value, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_SECONDS"),
-                       !context_->us_configuration.tap_duration_state, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_OFF"));
-       elm_genlist_item_update(universal_switch_tap_duration->item);
-}
-
-void UniversalSwitchSettingsPage::tapDurationCheckboxCb(void *data, Evas_Object *obj, void *event_info)
-{
-       retm_if(data == NULL, "Data parameter is NULL");
-       auto list_item = static_cast<GenGroupItemData *>(data);
-       auto self = static_cast<UniversalSwitchSettingsPage *>(list_item->userdata);
-
-       list_item->chk_status = elm_check_state_get(obj);
-       self->context_->us_configuration.tap_duration_state = list_item->chk_status;
-
-       self->universal_switch_tap_duration->sub_desc = getValueUnitText(NULL, &self->context_->us_configuration.tap_duration_value, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_SECONDS"),
-                       !self->context_->us_configuration.tap_duration_state, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_OFF"));
-       elm_genlist_item_update(self->universal_switch_tap_duration->item);
+       vconf_set_dbl(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_TAP_DURATION_VALUE, value);
 
-       updateVconfValue(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_TAP_DURATION_STATE, (bool *)&list_item->chk_status, NULL, NULL);
+       auto str = getValueUnitText(NULL, &context_->us_configuration.tap_duration_value, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_SECONDS"),
+                                                               !context_->us_configuration.tap_duration_state, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_OFF"));
+       tapDuration_->setDescription(str);
+       tapDuration_->update();
 }
 
 void UniversalSwitchSettingsPage::pauseOnFirstSwitchChangedCb(bool state)
index 7c658c5..7b1301b 100644 (file)
@@ -90,10 +90,8 @@ private:
        void sglInactionIntervalSwitchChangedCb(bool state);
        void sglInactionIntervalValueChangedCb(double value);
        static void sglInactionIntervalCheckboxCb(void *data, Evas_Object *obj, void *event_info);
-       static void tapDurationCb(void *data, Evas_Object *obj, void *event_info);
        void tapDurationSwitchChangedCb(bool state);
        void tapDurationValueChangedCb(double value);
-       static void tapDurationCheckboxCb(void *data, Evas_Object *obj, void *event_info);
        void pauseOnFirstSwitchChangedCb(bool state);
        void pauseOnFirstValueChangedCb(double value);
        static void scanSpeedCb(void *data, Evas_Object *obj, void *event_info);
@@ -130,7 +128,7 @@ private:
        GenGroupItemData *universal_switch_auto_move_int = nullptr;
        GenGroupItemData *universal_switch_auto_tap = nullptr;
        GenGroupItemData *universal_switch_sgl_iaction_int = nullptr;
-       GenGroupItemData *universal_switch_tap_duration = nullptr;
+       GenlistItem *tapDuration_ = nullptr;
        GenlistItem *pauseOnFirst_ = nullptr;
        GenGroupItemData *universal_switch_scan_speed = nullptr;
        GenGroupItemData *universal_switch_scans_num = nullptr;