From: Soohye Shin Date: Sun, 16 Aug 2015 05:47:19 +0000 (+0900) Subject: reset user edit view when pressed reset button from action menu X-Git-Tag: accepted/tizen/tv/20150821.130446~10 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1b2ed347473e2167ec16f0b19feecffe980cfdde;p=profile%2Ftv%2Fapps%2Fnative%2Fair_home.git reset user edit view when pressed reset button from action menu - add reset popup - add discard popup Change-Id: I442ba4f842b0ca50a8b2e62944bf94cd205d5a56 Signed-off-by: Soohye Shin --- diff --git a/include/defs.h b/include/defs.h index 5132e63..59c62e3 100644 --- a/include/defs.h +++ b/include/defs.h @@ -215,8 +215,10 @@ #define MESSAGE_OK "OK" #define MESSAGE_DONE "Done" #define MESSAGE_DISCARD "Discard" +#define MESSAGE_RESET "Reset" #define MESSAGE_DELETE_CONTENTS "If you delete this user, their data will also be deleted." #define MESSAGE_DISCARD_CONTENTS "Discard all entered data?
If you are out of this screen, data won't be saved" +#define MESSAGE_RESET_CONTENTS "Reset all entered data?
If you choose the Reset, all data will be deleted" #define KEY_MEDIA "media_id" #define KEY_CHANNEL "service_id" diff --git a/include/view.h b/include/view.h index de827f5..2b34f75 100644 --- a/include/view.h +++ b/include/view.h @@ -21,7 +21,8 @@ enum update_type { UPDATE_TYPE_EDIT, UPDATE_TYPE_PHOTO, UPDATE_TYPE_NOTI, - UPDATE_TYPE_USER + UPDATE_TYPE_USER, + UPDATE_TYPE_RESET }; view_class *view_home_get_vclass(void); diff --git a/src/view/view_action_menu.c b/src/view/view_action_menu.c index b392b13..37f34c9 100644 --- a/src/view/view_action_menu.c +++ b/src/view/view_action_menu.c @@ -26,8 +26,11 @@ #define ACTION_MENU_TITLE_RESET "Reset" enum input_handler_type { - INPUT_HANDLER_BTN, - INPUT_HANDLER_ITEM + INPUT_HANDLER_TYPE_BTN, + INPUT_HANDLER_TYPE_ITEM, + INPUT_HANDLER_TYPE_RESET, + INPUT_HANDLER_TYPE_DISCARD, + INPUT_HANDLER_TYPE_CANCEL }; struct _priv { @@ -35,6 +38,9 @@ struct _priv { Evas_Object *base; Evas_Object *btn; Evas_Object *item; + Evas_Object *popup; + + bool edited; }; static void _focused(int id, void *data, Evas_Object *obj, @@ -49,14 +55,101 @@ static void _unfocused(int id, void *data, Evas_Object *obj, elm_object_signal_emit(obj, SIG_UNFOCUS, SRC_PROG); } +static void _key_down(int id, void *data, Evas *e, Evas_Object *obj, + Evas_Event_Key_Down *ev); + +static void _mouse_down(int id, void *data, Evas *e, Evas_Object *obj, + Evas_Event_Mouse_Down *ev); + +static void _mouse_move(int id, void *data, Evas *e, Evas_Object *obj, + Evas_Event_Mouse_Move *ev) +{ + if (!elm_object_focus_get(obj)) + elm_object_focus_set(obj, EINA_TRUE); +} + +static input_handler handler = { + .focused = _focused, + .unfocused = _unfocused, + .key_down = _key_down, + .mouse_down = _mouse_down, + .mouse_move = _mouse_move +}; + +static void _add_popup(struct _priv *priv, char *title, char *message, + char *first_btn_message, int first_btn_id, + char *second_btn_message, int second_btn_id) +{ + Evas_Object *popup, *first_btn, *second_btn; + + popup = utils_add_popup(priv->base, title, message); + if (!popup) { + _ERR("failed to add popup"); + return; + } + + first_btn = utils_add_button(popup, first_btn_message, + PART_POPUP_BUTTON_1); + if (!first_btn) { + _ERR("failed to add delete btn"); + evas_object_del(popup); + return; + } + inputmgr_add_callback(first_btn, first_btn_id, &handler, priv); + + second_btn = utils_add_button(popup, second_btn_message, + PART_POPUP_BUTTON_2); + if (!second_btn) { + _ERR("failed to add cancel btn"); + evas_object_del(popup); + return; + } + inputmgr_add_callback(second_btn, second_btn_id, &handler, priv); + elm_object_focus_set(second_btn, EINA_TRUE); + + priv->popup = popup; +} + +static void _delete_popup(struct _priv *priv, Evas_Object *obj) +{ + inputmgr_remove_callback(obj, &handler); + evas_object_del(priv->popup); + priv->popup = NULL; +} + static void _select(int id, void *data, Evas_Object *obj) { - /* It should be implemented later */ + struct _priv *priv; + + priv = data; switch (id) { - case INPUT_HANDLER_BTN: + case INPUT_HANDLER_TYPE_BTN: + if (priv->edited) { + _add_popup(priv, MESSAGE_DISCARD, + MESSAGE_DISCARD_CONTENTS, + MESSAGE_DISCARD, + INPUT_HANDLER_TYPE_DISCARD, + MESSAGE_CANCEL, + INPUT_HANDLER_TYPE_CANCEL); + return; + } + viewmgr_update_view(VIEW_USER_EDIT, UPDATE_TYPE_RESET, NULL); + viewmgr_hide_view(VIEW_ACTION_MENU); + break; + case INPUT_HANDLER_TYPE_ITEM: + _add_popup(priv, MESSAGE_RESET, MESSAGE_RESET_CONTENTS, + MESSAGE_RESET, INPUT_HANDLER_TYPE_RESET, + MESSAGE_CANCEL, INPUT_HANDLER_TYPE_CANCEL); + break; + case INPUT_HANDLER_TYPE_RESET: + case INPUT_HANDLER_TYPE_DISCARD: + viewmgr_update_view(VIEW_USER_EDIT, UPDATE_TYPE_RESET, NULL); + viewmgr_hide_view(VIEW_ACTION_MENU); + _delete_popup(priv, obj); break; - case INPUT_HANDLER_ITEM: + case INPUT_HANDLER_TYPE_CANCEL: + _delete_popup(priv, obj); break; default: return; @@ -66,9 +159,30 @@ static void _select(int id, void *data, Evas_Object *obj) static void _key_down(int id, void *data, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev) { + struct _priv *priv; + + if (!data) { + _ERR("Invalid argument"); + return; + } + + priv = data; if (!strcmp(ev->keyname, KEY_BACK) || !strcmp(ev->keyname, KEY_BACK_REMOTE)) { - viewmgr_hide_view(VIEW_ACTION_MENU); + switch (id) { + case INPUT_HANDLER_TYPE_BTN: + case INPUT_HANDLER_TYPE_ITEM: + viewmgr_hide_view(VIEW_ACTION_MENU); + break; + case INPUT_HANDLER_TYPE_RESET: + case INPUT_HANDLER_TYPE_DISCARD: + case INPUT_HANDLER_TYPE_CANCEL: + if (priv->popup) + _delete_popup(priv, obj); + break; + default: + return; + } } else if (!strcmp(ev->keyname, KEY_ENTER) || !strcmp(ev->keyname, KEY_ENTER_REMOTE)) { _select(id, data, obj); @@ -78,24 +192,14 @@ static void _key_down(int id, void *data, Evas *e, Evas_Object *obj, static void _mouse_down(int id, void *data, Evas *e, Evas_Object *obj, Evas_Event_Mouse_Down *ev) { - _select(id, data, obj); -} + if (!data || !obj) { + _ERR("Invalid argument"); + return; + } -static void _mouse_move(int id, void *data, Evas *e, Evas_Object *obj, - Evas_Event_Mouse_Move *ev) -{ - if (!elm_object_focus_get(obj)) - elm_object_focus_set(obj, EINA_TRUE); + _select(id, data, obj); } -static input_handler handler = { - .focused = _focused, - .unfocused = _unfocused, - .key_down = _key_down, - .mouse_down = _mouse_down, - .mouse_move = _mouse_move -}; - static Evas_Object *_add_item(Evas_Object *box, struct _priv *priv) { Evas_Object *item, *ic, *focus_ic, *lbl, *focus_lbl, *bg; @@ -136,7 +240,7 @@ static Evas_Object *_add_item(Evas_Object *box, struct _priv *priv) goto err; evas_object_show(item); - inputmgr_add_callback(item, INPUT_HANDLER_ITEM, &handler, priv); + inputmgr_add_callback(item, INPUT_HANDLER_TYPE_ITEM, &handler, priv); return item; err: @@ -154,7 +258,7 @@ static bool _add_menu(struct _priv *priv) _ERR("failed to add btn"); return false; } - inputmgr_add_callback(btn, INPUT_HANDLER_BTN, &handler, priv); + inputmgr_add_callback(btn, INPUT_HANDLER_TYPE_BTN, &handler, priv); priv->btn = btn; box = utils_add_box(priv->base, true); @@ -243,6 +347,7 @@ static void _hide(void *data) priv = data; evas_object_hide(priv->base); + priv->edited = false; } static void _destroy(void *data) @@ -256,16 +361,41 @@ static void _destroy(void *data) priv = data; + inputmgr_remove_callback(priv->btn, &handler); + inputmgr_remove_callback(priv->item, &handler); + evas_object_del(priv->base); free(priv); } +static void _update(void *view_data, int update_type, void *data) +{ + struct _priv *priv; + + if (!view_data) { + _ERR("Invalid argument"); + return; + } + + priv = view_data; + + switch (update_type) { + case UPDATE_TYPE_EDIT: + priv->edited = *(bool *)data; + break; + default: + _ERR("Invalid type"); + return; + } +} + static view_class vclass = { .view_id = VIEW_ACTION_MENU, .create = _create, .show = _show, .hide = _hide, .destroy = _destroy, + .update = _update }; view_class *view_action_menu_get_vclass(void) diff --git a/src/view/view_user_edit.c b/src/view/view_user_edit.c index a0f2d22..cb348c8 100644 --- a/src/view/view_user_edit.c +++ b/src/view/view_user_edit.c @@ -1,5 +1,4 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); @@ -593,6 +592,7 @@ static void _key_down(int id, void *data, Evas *e, Evas_Object *obj, Evas_Event_Key_Down *ev) { struct _priv *priv; + bool edited; if (!data) { _ERR("Invalid argument"); @@ -642,7 +642,20 @@ static void _key_down(int id, void *data, Evas *e, Evas_Object *obj, elm_object_focus_set(priv->del, EINA_TRUE); } else if (!strcmp(ev->keyname, KEY_MENU) || !strcmp(ev->keyname, KEY_MENU_REMOTE)) { - viewmgr_show_view(VIEW_ACTION_MENU); + switch (id) { + case INPUT_HANDLER_TYPE_PHOTO: + case INPUT_HANDLER_TYPE_BTN_DONE: + case INPUT_HANDLER_TYPE_BTN_CANCEL: + case INPUT_HANDLER_TYPE_DELETE: + case INPUT_HANDLER_TYPE_ENTRY: + edited = _check_changed_input(priv); + viewmgr_update_view(VIEW_ACTION_MENU, UPDATE_TYPE_EDIT, + &edited); + viewmgr_show_view(VIEW_ACTION_MENU); + break; + default: + return; + } } } @@ -684,10 +697,30 @@ static void _change_entry(Evas_Object *name, Evas_Object *ly, Eina_Bool disable, elm_object_signal_emit(ly, signal, SRC_PROG); } +static void _reset(struct _priv *priv) +{ + const char *photo, *focus_photo; + + if (priv->selected_photo) { + _load_user_icon(priv, priv->selected_photo, + priv->selected_photo); + return; + } + + if (priv->di) { + photo = utils_get_photo_from_icon(priv->di->icon); + focus_photo = utils_get_focus_photo_from_photo(photo); + _load_user_icon(priv, photo, focus_photo); + } else { + _change_entry(priv->name, priv->ly, EINA_TRUE, "", SIG_ENABLE); + _load_user_icon(priv, IMAGE_USER_CURRENT_DEFAULT, + IMAGE_USER_CURRENT_DEFAULT_FOCUS); + } +} + static void _show(void *data) { struct _priv *priv; - const char *photo, *focus_photo; if (!data) { _ERR("Invalid argument"); @@ -701,31 +734,19 @@ static void _show(void *data) MESSAGE_EDIT_USER); _change_entry(priv->name, priv->ly, EINA_FALSE, priv->di->title, SIG_DISABLE); - if (priv->selected_photo) { - _load_user_icon(priv, priv->selected_photo, - priv->selected_photo); - } else { - photo = utils_get_photo_from_icon(priv->di->icon); - focus_photo = utils_get_focus_photo_from_photo(photo); - _load_user_icon(priv, photo, focus_photo); - } if (priv->user_type == USER_ITEM_ADMIN && priv->di->type != USER_ITEM_ADMIN) _load_del_btn(priv); } else { elm_object_part_text_set(priv->base, PART_USER_EDIT_TITLE, MESSAGE_ADD_USER); - _change_entry(priv->name, priv->ly, EINA_TRUE, "", SIG_ENABLE); - if (priv->selected_photo) - _load_user_icon(priv, priv->selected_photo, - priv->selected_photo); - else - _load_user_icon(priv, IMAGE_USER_CURRENT_DEFAULT, - IMAGE_USER_CURRENT_DEFAULT_FOCUS); } + _reset(priv); + evas_object_show(priv->base); elm_object_focus_set(priv->cancel, EINA_TRUE); + priv->selected_photo = NULL; } static void _hide(void *data) @@ -789,6 +810,9 @@ static void _update(void *view_data, int update_type, void *data) case UPDATE_TYPE_USER: priv->user_type = (enum user_item_type) data; break; + case UPDATE_TYPE_RESET: + _reset(priv); + break; default: _ERR("Invalid type"); return;