From: Lukasz Wlazly Date: Tue, 5 Mar 2019 11:11:24 +0000 (+0100) Subject: Add new type of GenlistItem - Toggle with different actions X-Git-Tag: submit/tizen/20190314.062257~3^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b0fc6034d45d3ac068a7aac43c34abd1e32edfd2;p=profile%2Fmobile%2Fapps%2Fnative%2Faccessibility-setting.git Add new type of GenlistItem - Toggle with different actions This change introduce new type of GenlistItem, which has different actions on clicking item and widget. Change-Id: Ia29d6e53d3bff16968c243b149a3eff97f74bd59 --- diff --git a/src/Genlist.cpp b/src/Genlist.cpp index e84a32c..2dfdb3c 100644 --- a/src/Genlist.cpp +++ b/src/Genlist.cpp @@ -33,7 +33,7 @@ GenlistItem *Genlist::appendItem(GenlistItem item, GenlistItem *parent) itemPtr->genlist_ = this; itemPtr->objItem_ = elm_genlist_item_append(uniqueObj_.get(), itc.get(), itemPtr.get(), parentPtr, type, GenlistItem::onItemSelection, itemPtr.get()); - if (!itemPtr->onSelection_) + if (!itemPtr->onItemSelection_) elm_genlist_item_select_mode_set(itemPtr->objItem_, ELM_OBJECT_SELECT_MODE_NONE); items_.push_back(std::move(itemPtr)); diff --git a/src/GenlistItem.cpp b/src/GenlistItem.cpp index 6db26a3..18db006 100644 --- a/src/GenlistItem.cpp +++ b/src/GenlistItem.cpp @@ -9,16 +9,20 @@ GenlistItem::GenlistItem(std::string style, TranslatedString text, TranslatedStr : style_(std::move(style)), text_(std::move(text)), description_(std::move(desc)), type_(type) {} -GenlistItem::GenlistItem(std::string style, TranslatedString text, TranslatedString desc, std::function onSelection, Type type) - : style_(std::move(style)), text_(std::move(text)), description_(std::move(desc)), onSelection_(std::move(onSelection)), type_(type) +GenlistItem::GenlistItem(std::string style, TranslatedString text, TranslatedString desc, std::function onItemSelection, Type type) + : style_(std::move(style)), text_(std::move(text)), description_(std::move(desc)), onItemSelection_(std::move(onItemSelection)), type_(type) {} -GenlistItem::GenlistItem(std::string style, TranslatedString text, TranslatedString desc, std::function onSelection, WidgetType type) - : style_(std::move(style)), text_(std::move(text)), description_(std::move(desc)), onSelection_(std::move(onSelection)), widgetType_(type) +GenlistItem::GenlistItem(std::string style, TranslatedString text, TranslatedString desc, std::function onItemSelection, WidgetType type) + : style_(std::move(style)), text_(std::move(text)), description_(std::move(desc)), onItemSelection_(std::move(onItemSelection)), widgetType_(type) {} -GenlistItem::GenlistItem(std::string style, TranslatedString text, TranslatedString desc, std::function onSelection, std::string iconPath, WidgetType type) - : style_(std::move(style)), text_(std::move(text)), description_(std::move(desc)), onSelection_(std::move(onSelection)), iconPath_(std::move(iconPath)), widgetType_(type) +GenlistItem::GenlistItem(std::string style, TranslatedString text, TranslatedString desc, std::function onItemSelection, std::string iconPath, WidgetType type) + : style_(std::move(style)), text_(std::move(text)), description_(std::move(desc)), onItemSelection_(std::move(onItemSelection)), iconPath_(std::move(iconPath)), widgetType_(type) +{} + +GenlistItem::GenlistItem(std::string style, TranslatedString text, TranslatedString desc, std::function onItemSelection, std::function onContentSelection, WidgetType type) + : style_(std::move(style)), text_(std::move(text)), description_(std::move(desc)), onItemSelection_(std::move(onItemSelection)), onContentSelection_(std::move(onContentSelection)), widgetType_(type) {} void GenlistItem::setText(const TranslatedString &text) @@ -159,7 +163,10 @@ Evas_Object *GenlistItem::realizeToggle(const std::string &part) elm_atspi_accessible_relationship_append(objItem_, ELM_ATSPI_RELATION_CONTROLLER_FOR, check->getObject()); check->setEvasSmartCallback("changed", [this]() { - onSelection_(this); + if (onContentSelection_) + onContentSelection_(this); + else + onItemSelection_(this); }); return check->getObject(); @@ -177,8 +184,10 @@ Evas_Object *GenlistItem::realizeCheck(const std::string &part) check->setPassEvents(true); check->setEvasSmartCallback("changed", [this]() { - SETTING_TRACE_ERROR("smart callback \"changed\""); - onSelection_(this); + if (onContentSelection_) + onContentSelection_(this); + else + onItemSelection_(this); }); return check->getObject(); @@ -201,12 +210,12 @@ void GenlistItem::onItemSelection(void *data, Evas_Object *obj, void *event_info SETTING_TRACE_ERROR("."); auto self = static_cast(data); - if (self->widgetType_ == WidgetType::toggle || self->widgetType_ == WidgetType::check) { + if ((self->widgetType_ == WidgetType::toggle || self->widgetType_ == WidgetType::check) && !self->onContentSelection_) { self->state_ = !self->state_; elm_genlist_item_fields_update(self->objItem_, "*", ELM_GENLIST_ITEM_FIELD_CONTENT); } - if (self->onSelection_) - self->onSelection_(self); + if (self->onItemSelection_) + self->onItemSelection_(self); elm_genlist_item_selected_set(self->objItem_, EINA_FALSE); } \ No newline at end of file diff --git a/src/GenlistItem.hpp b/src/GenlistItem.hpp index 2738c7d..cf54b1e 100644 --- a/src/GenlistItem.hpp +++ b/src/GenlistItem.hpp @@ -22,6 +22,7 @@ public: GenlistItem(std::string style, TranslatedString text, TranslatedString desc, std::function onSelection, Type type = Type::regular); GenlistItem(std::string style, TranslatedString text, TranslatedString desc, std::function onSelection, WidgetType type); GenlistItem(std::string style, TranslatedString text, TranslatedString desc, std::function onSelection, std::string iconPath, WidgetType type = WidgetType::icon); + GenlistItem(std::string style, TranslatedString text, TranslatedString desc, std::function onItemSelection, std::function onWidgetSelection, WidgetType type); void setText(const TranslatedString &text); void setDescription(const TranslatedString &desc); @@ -50,7 +51,8 @@ private: std::string style_; TranslatedString text_; TranslatedString description_; - std::function onSelection_; + std::function onItemSelection_; + std::function onContentSelection_; Genlist *genlist_ = nullptr; Eina_Bool state_ = EINA_FALSE; std::string iconPath_; diff --git a/src/UniversalSwitchSettingsPage.cpp b/src/UniversalSwitchSettingsPage.cpp index a3ad414..e20e6d4 100644 --- a/src/UniversalSwitchSettingsPage.cpp +++ b/src/UniversalSwitchSettingsPage.cpp @@ -193,12 +193,25 @@ void UniversalSwitchSettingsPage::createFeedbackGroup() str = getBoleanText(context_->us_configuration.feedback_voice_state, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_ON"), _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_OFF")); - universal_switch_feedback_voice = addMenuItem(_("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_FEEDBACK_VOICE"), - str, feedbackVoiceCb, true, context_->us_configuration.feedback_voice_state, feedbackVoiceCheckboxCb); - universal_switch_feedback_voice->userdata = this; - vconf_ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_FEEDBACK_VOICE_STATE, syncVoiceFeedbackWithVconf, universal_switch_feedback_voice); - if (vconf_ret) - SETTING_TRACE_ERROR("FAIL: vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_FEEDBACK_VOICE_STATE)"); + + universal_switch_feedback_voice = genlist_->appendItem({"type1", "IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_GROUP_FEEDBACK_VOICE", str, + [this](auto item) + { + feedbackVoiceCb(this, nullptr, nullptr); + }, + [this](auto item) + { + if (context_) { + context_->us_configuration.feedback_voice_state = item->getState(); + + item->setDescription(context_->us_configuration.feedback_voice_state ? "IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_ON" : "IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_OFF"); + item->update(); + } + + vconf_set_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_FEEDBACK_VOICE_STATE, item->getState()); + }, GenlistItem::WidgetType::toggle + }); + universal_switch_feedback_voice->setState(context_->us_configuration.feedback_voice_state); } void UniversalSwitchSettingsPage::createAdditionalSettingsGroup() @@ -559,7 +572,11 @@ void UniversalSwitchSettingsPage::feedbackVoiceCb(void *data, Evas_Object *obj, self->nestedSetValuePage_->setSwitch(self->context_->us_configuration.feedback_voice_state); self->nestedSetValuePage_->setDescription(_("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_SET_VALUE_DESC_FEEDBACK_VOICE")); self->nestedSetValuePage_->addSwitchChangedCb([self](auto state) { - self->feedbackVoiceSwitchChangedCb(state); + self->universal_switch_feedback_voice->setDescription(state ? "IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_ON" : "IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_OFF"); + self->universal_switch_feedback_voice->setState(state); + self->universal_switch_feedback_voice->update(); + self->context_->us_configuration.feedback_voice_state = state; + vconf_set_bool(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_FEEDBACK_VOICE_STATE, state); });; int vconf_ret = vconf_notify_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_FEEDBACK_VOICE_STATE, SetValuePage::syncPageWithVconf, self->nestedSetValuePage_.get()); if (vconf_ret) @@ -633,44 +650,6 @@ void UniversalSwitchSettingsPage::feedbackVoiceSpeechRateChangedCb(int item_id) elm_genlist_item_update(universal_switch_feedback_voice_speech_rate->item); } -void UniversalSwitchSettingsPage::feedbackVoiceSwitchChangedCb(bool state) -{ - const char *str = NULL; - - context_->us_configuration.feedback_voice_state = state; - updateVconfValue(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_FEEDBACK_VOICE_STATE, &state, NULL, NULL); - - if (context_->us_configuration.feedback_voice_state) - str = _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_ON"); - else - str = _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_OFF"); - - universal_switch_feedback_voice->chk_status = state; - elm_check_state_set(universal_switch_feedback_voice->eo_check, state); - universal_switch_feedback_voice->sub_desc = str ? str : std::string{}; - elm_genlist_item_update(universal_switch_feedback_voice->item); -} - -void UniversalSwitchSettingsPage::feedbackVoiceCheckboxCb(void *data, Evas_Object *obj, void *event_info) -{ - retm_if(data == NULL, "Data parameter is NULL"); - auto list_item = static_cast(data); - auto self = static_cast(list_item->userdata); - - list_item->chk_status = elm_check_state_get(obj); - - if (self->context_) { - self->context_->us_configuration.feedback_voice_state = list_item->chk_status; - - const char *str = getBoleanText(self->context_->us_configuration.feedback_voice_state, _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_ON"), - _("IDS_ACCS_UNIVERSAL_SWITCH_SETTINGS_OFF")); - self->universal_switch_feedback_voice->sub_desc = str ? str : std::string{}; - elm_genlist_item_update(self->universal_switch_feedback_voice->item); - } - - updateVconfValue(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_FEEDBACK_VOICE_STATE, (bool *)&list_item->chk_status, NULL, NULL); -} - void UniversalSwitchSettingsPage::feedbackSoundCb(void *data, Evas_Object *obj, void *event_info) { auto self = static_cast(data); @@ -1256,8 +1235,6 @@ Eina_Bool UniversalSwitchSettingsPage::naviframPopCb(void *data, Elm_Object_Item retv_if(ad == NULL, EINA_TRUE); vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_AUTO_SCAN_ENABLED, syncAutoScanWithVconf); vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_FEEDBACK_SOUND_STATE, syncSoundFeedbackWithVconf); - vconf_ignore_key_changed(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_SETTINGS_FEEDBACK_VOICE_STATE, syncVoiceFeedbackWithVconf); - return EINA_TRUE; } @@ -1270,11 +1247,6 @@ void UniversalSwitchSettingsPage::backCb(void *data, Evas_Object *obj, void *eve elm_naviframe_item_pop(ad->md.getNaviframe()->getObject()); } -void UniversalSwitchSettingsPage::syncVoiceFeedbackWithVconf(keynode_t *node, void *user_data) -{ - syncCheckboxWithVconf(node, user_data, feedbackVoiceCheckboxCb); -} - void UniversalSwitchSettingsPage::syncSoundFeedbackWithVconf(keynode_t *node, void *user_data) { syncCheckboxWithVconf(node, user_data, feedbackSoundCheckboxCb); diff --git a/src/UniversalSwitchSettingsPage.hpp b/src/UniversalSwitchSettingsPage.hpp index 4bc326f..7c064fb 100644 --- a/src/UniversalSwitchSettingsPage.hpp +++ b/src/UniversalSwitchSettingsPage.hpp @@ -72,8 +72,6 @@ private: void feedbackVoiceItemOptionsRequestCb(int option_id); void feedbackVoiceSpeechVolumeChangedCb(int item_id); void feedbackVoiceSpeechRateChangedCb(int item_id); - void feedbackVoiceSwitchChangedCb(bool state); - static void feedbackVoiceCheckboxCb(void *data, Evas_Object *obj, void *event_info); static void feedbackSoundCb(void *data, Evas_Object *obj, void *event_info); void feedbackSoundItemOptionsRequestCb(int option_id); void feedbackSoundVolumeChangedCb(int item_id); @@ -113,7 +111,6 @@ private: static void ctxPopupDelCb(void *data, Evas_Object *obj, void *event_info); static Eina_Bool naviframPopCb(void *data, Elm_Object_Item *it); static void backCb(void *data, Evas_Object *obj, void *event_info); - static void syncVoiceFeedbackWithVconf(keynode_t *node, void *user_data); 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); @@ -130,7 +127,7 @@ private: GenGroupItemData *universal_switch_feedback_cursor_cl; GenGroupItemData *universal_switch_feedback_sound_volume; GenGroupItemData *universal_switch_feedback_sound; - GenGroupItemData *universal_switch_feedback_voice; + GenlistItem *universal_switch_feedback_voice; GenGroupItemData *universal_switch_feedback_voice_speech_rate; GenGroupItemData *universal_switch_feedback_voice_speech_volume; GenGroupItemData *universal_switch_auto_move_int;