Create "Auto move interval" item with new genlist API 88/201788/1
authorLukasz Wlazly <l.wlazly@partner.samsung.com>
Tue, 19 Mar 2019 11:37:25 +0000 (12:37 +0100)
committerLukasz Wlazly <l.wlazly@partner.samsung.com>
Tue, 19 Mar 2019 11:37:25 +0000 (12:37 +0100)
Change-Id: I4a0a94e01c2c8634872b9e64e57065e0d59ad31d

src/UniversalSwitchSettingsPage.cpp
src/UniversalSwitchSettingsPage.hpp

index ed21abb..cb612ad 100644 (file)
@@ -375,10 +375,41 @@ void UniversalSwitchSettingsPage::createAdditionalSettingsGroup()
 
        str = getValueUnitText(NULL, &context_->us_configuration.auto_move_int_value, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_SECONDS"),
                                                   !context_->us_configuration.auto_move_int_state, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_OFF"));
-       universal_switch_auto_move_int = addMenuItem(_("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_ADD_SETTINGS_AUTO_MOVE_INT"),
-                                                                        str, autoMoveIntervalCb, true, context_->us_configuration.auto_move_int_state, autoMoveIntervalCheckboxCb);
-       universal_switch_auto_move_int->userdata = this;
-       elm_object_item_disabled_set(universal_switch_auto_move_int->item, (Eina_Bool)context_->us_configuration.auto_scan);
+
+       autoMoveInterval_ = genlist_->appendItem({"type1", "IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_ADD_SETTINGS_AUTO_MOVE_INT", str,
+                                               [this](auto item)
+       {
+               setValuePage_ = std::make_unique<SetValuePage>(context_, ValueEditorType::NUMERIC_SWITCH, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_ADD_SETTINGS_AUTO_MOVE_INT"));
+               setValuePage_->setSwitch(context_->us_configuration.auto_move_int_state);
+               setValuePage_->addValueChangedCb([this](auto val) {
+                       this->autoMoveIntervalValueChangedCb(val);
+               });
+               setValuePage_->addSwitchChangedCb([this](auto state) {
+                       this->autoMoveIntervalSwitchChangedCb(state);
+               });
+               setValuePage_->setDescription(_("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_SET_VALUE_DESC_AUTO_MOVE_INT"));
+               setValuePage_->setRange(RANGE_MIN_AUTO_MOVE_INT, RANGE_MAX_AUTO_MOVE_INT, STEP_AUTO_MOVE_INT);
+               setValuePage_->setValue(context_->us_configuration.auto_move_int_value, "seconds");
+       },
+       [this](auto item)
+       {
+               context_->us_configuration.auto_move_int_state = item->getState();
+               auto str = getValueUnitText(NULL, &context_->us_configuration.auto_move_int_value, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_SECONDS"),
+                                                                       !context_->us_configuration.auto_move_int_state, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_OFF"));
+               item->setDescription(str);
+               item->update();
+               vconf_set_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_AUTO_MOVE_INT_STATE, item->getState());
+       }, GenlistItem::WidgetType::toggle
+                                                                                        });
+       if (context_->us_configuration.auto_move_int_state) {
+               autoMoveInterval_->setState(true);
+               auto str = getValueUnitText(NULL, &context_->us_configuration.auto_tap_value, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_SECONDS"),
+                                                                       !context_->us_configuration.auto_move_int_state, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_OFF"));
+               autoMoveInterval_->setDescription(str);
+               autoMoveInterval_->update();
+       }
+       if (context_->us_configuration.auto_scan)
+               autoMoveInterval_->disable();
 
        addMenuItem(_("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_ADD_SETTINGS_AUTO_TAP_KBD"),
                                _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_ADD_SETTINGS_AUTO_TAP_KBD_SUB"), autoTapKBDMenuItemSelected, true, context_->us_configuration.auto_tap_kbd_state, autoTapKbdCheckboxCb);
@@ -896,34 +927,15 @@ void UniversalSwitchSettingsPage::autoTapKbdCheckboxCb(void *data, Evas_Object *
        updateVconfValue(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_AUTO_TAP_KBD_STATE, (bool *)&list_item->chk_status, NULL, NULL);
 }
 
-void UniversalSwitchSettingsPage::autoMoveIntervalCb(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_AUTO_MOVE_INT"));
-       self->setValuePage_->setSwitch(self->context_->us_configuration.auto_move_int_state);
-       self->setValuePage_->addValueChangedCb([self](auto val) {
-               self->autoMoveIntervalValueChangedCb(val);
-       });
-       self->setValuePage_->addSwitchChangedCb([self](auto state) {
-               self->autoMoveIntervalSwitchChangedCb(state);
-       });
-       self->setValuePage_->setDescription(_("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_SET_VALUE_DESC_AUTO_MOVE_INT"));
-       self->setValuePage_->setRange(RANGE_MIN_AUTO_MOVE_INT, RANGE_MAX_AUTO_MOVE_INT, STEP_AUTO_MOVE_INT);
-       self->setValuePage_->setValue(self->context_->us_configuration.auto_move_int_value, "seconds");
-}
-
 void UniversalSwitchSettingsPage::autoMoveIntervalSwitchChangedCb(bool state)
 {
        context_->us_configuration.auto_move_int_state = state;
-       updateVconfValue(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_AUTO_MOVE_INT_STATE, &state, NULL, NULL);
-
-       universal_switch_auto_move_int->chk_status = state;
-       elm_check_state_set(universal_switch_auto_move_int->eo_check, state);
-       universal_switch_auto_move_int->sub_desc = getValueUnitText(NULL, &context_->us_configuration.auto_move_int_value, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_SECONDS"),
-                       !context_->us_configuration.auto_move_int_state, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_OFF"));
-       elm_genlist_item_update(universal_switch_auto_move_int->item);
+       vconf_set_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_AUTO_MOVE_INT_STATE, state);
+       autoMoveInterval_->setState(state);
+       auto str = getValueUnitText(NULL, &context_->us_configuration.auto_move_int_value, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_SECONDS"),
+                                                               !context_->us_configuration.auto_move_int_state, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_OFF"));
+       autoMoveInterval_->setDescription(str);
+       autoMoveInterval_->update();
 }
 
 void UniversalSwitchSettingsPage::autoTapSwitchChangedCb(bool state)
@@ -1190,12 +1202,13 @@ void UniversalSwitchSettingsPage::autoScanCheckboxCb(void *data, Evas_Object *ob
 
        elm_object_item_disabled_set(self->universal_switch_auto_scan_int->item, (Eina_Bool)!self->context_->us_configuration.auto_scan);
        elm_object_item_disabled_set(self->universal_switch_scans_num->item, (Eina_Bool)!self->context_->us_configuration.auto_scan);
-       if (self->context_->us_configuration.auto_scan)
+       if (self->context_->us_configuration.auto_scan) {
                self->pauseOnFirst_->enable();
-       else
+               self->autoMoveInterval_->disable();
+       } else {
                self->pauseOnFirst_->disable();
-
-       elm_object_item_disabled_set(self->universal_switch_auto_move_int->item, (Eina_Bool)self->context_->us_configuration.auto_scan);
+               self->autoMoveInterval_->enable();
+       }
 
        updateVconfValue(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_AUTO_SCAN_ENABLED, (bool *)&list_item->chk_status, NULL, NULL);
 }
@@ -1246,30 +1259,15 @@ void UniversalSwitchSettingsPage::syncCheckboxWithVconf(keynode_t *node, void *u
        }
 }
 
-void UniversalSwitchSettingsPage::autoMoveIntervalCheckboxCb(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.auto_move_int_state = list_item->chk_status;
-
-       self->universal_switch_auto_move_int->sub_desc = getValueUnitText(NULL, &self->context_->us_configuration.auto_move_int_value, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_SECONDS"),
-                       !self->context_->us_configuration.auto_move_int_state, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_OFF"));
-       elm_genlist_item_update(self->universal_switch_auto_move_int->item);
-
-       updateVconfValue(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_AUTO_MOVE_INT_STATE, (bool *)&list_item->chk_status, NULL, NULL);
-}
-
 void UniversalSwitchSettingsPage::autoMoveIntervalValueChangedCb(double value)
 {
        context_->us_configuration.auto_move_int_value = value;
-       updateVconfValue(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_AUTO_MOVE_INT_VALUE, NULL, NULL, &value);
+       vconf_set_dbl(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_AUTO_MOVE_INT_VALUE, value);
 
-       universal_switch_auto_move_int->sub_desc = getValueUnitText(NULL, &context_->us_configuration.auto_move_int_value, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_SECONDS"),
-                       !context_->us_configuration.auto_move_int_state, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_OFF"));
-       elm_genlist_item_update(universal_switch_auto_move_int->item);
+       auto str = getValueUnitText(NULL, &context_->us_configuration.auto_move_int_value, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_SECONDS"),
+                                                               !context_->us_configuration.auto_move_int_state, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_OFF"));
+       autoMoveInterval_->setDescription(str);
+       autoMoveInterval_->update();
 }
 
 void UniversalSwitchSettingsPage::onAutoScanItemSelection(void *data, Evas_Object *obj, void *event_info)
@@ -1287,11 +1285,13 @@ void UniversalSwitchSettingsPage::onAutoScanItemSelection(void *data, Evas_Objec
        self->context_->us_configuration.auto_scan = list_item->chk_status;
        elm_object_item_disabled_set(self->universal_switch_auto_scan_int->item, (Eina_Bool)!self->context_->us_configuration.auto_scan);
        elm_object_item_disabled_set(self->universal_switch_scans_num->item, (Eina_Bool)!self->context_->us_configuration.auto_scan);
-       if (self->context_->us_configuration.auto_scan)
+       if (self->context_->us_configuration.auto_scan) {
                self->pauseOnFirst_->enable();
-       else
+               self->autoMoveInterval_->disable();
+       } else {
                self->pauseOnFirst_->disable();
-       elm_object_item_disabled_set(self->universal_switch_auto_move_int->item, (Eina_Bool)self->context_->us_configuration.auto_scan);
+               self->autoMoveInterval_->enable();
+       }
 
        updateVconfValue(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_AUTO_SCAN_ENABLED, (bool *)&list_item->chk_status, NULL, NULL);
 }
index cff091d..2756b15 100644 (file)
@@ -80,7 +80,6 @@ private:
        static void cursorColorCb(void *data, Evas_Object *obj, void *event_info);
        void cursorColorListItemChangedCb(int item_id);
        static void autoTapKbdCheckboxCb(void *data, Evas_Object *obj, void *event_info);
-       static void autoMoveIntervalCb(void *data, Evas_Object *obj, void *event_info);
        void autoMoveIntervalSwitchChangedCb(bool state);
        void autoTapSwitchChangedCb(bool state);
        void autoTapValueChangedCb(double value);
@@ -105,7 +104,6 @@ private:
        static void syncSoundFeedbackWithVconf(keynode_t *node, void *user_data);
        static void syncAutoScanWithVconf(keynode_t *node, void *user_data);
        static void syncCheckboxWithVconf(keynode_t *node, void *user_data, SettingCallback cb_func);
-       static void autoMoveIntervalCheckboxCb(void *data, Evas_Object *obj, void *event_info);
        void autoMoveIntervalValueChangedCb(double value);
 
        SettingAccessibility *context_ = nullptr;
@@ -121,7 +119,7 @@ private:
        GenlistItem *universal_switch_feedback_voice = nullptr;
        GenGroupItemData *universal_switch_feedback_voice_speech_rate = nullptr;
        GenGroupItemData *universal_switch_feedback_voice_speech_volume = nullptr;
-       GenGroupItemData *universal_switch_auto_move_int = nullptr;
+       GenlistItem *autoMoveInterval_ = nullptr;
        GenlistItem *autoTap_ = nullptr;
        GenlistItem *singleInteractionInterval_ = nullptr;
        GenlistItem *tapDuration_ = nullptr;