#include "ui_himalaya_data.h"
#include "ui_himalaya_api.h"

#if TCFG_HIMALAYA_ENABLE

#define STYLE_NAME JL
REGISTER_UI_STYLE(STYLE_NAME)

#define LOG_TAG_CONST       UI
#define LOG_TAG     		"[HIMALAYA_UI]"
#define LOG_ERROR_ENABLE
#define LOG_DEBUG_ENABLE
#define LOG_INFO_ENABLE
/* #define LOG_DUMP_ENABLE */
#define LOG_CLI_ENABLE
#include "debug.h"
himalaya_info * ui_info=NULL;
himalaya_qr * qr=NULL;

#define ui_grid_for_id(id) \
	({ \
		struct element *elm = ui_core_get_element_by_id(id); \
	 	elm ? container_of(elm, struct ui_grid, elm): NULL; \
	 })


void h_set_album_list_grid(u8 num)
{
	struct ui_grid *grid = ui_grid_for_id(H_ALBUM_LIST);
	static int col,row;
	int del,add;
	col=0;
	row=grid->dynamic->drow_num;
	if(row>num)
	{
		del=row-num;
		ui_grid_del_dynamic(grid,&del,&col,1);
	}
	else if(row<num)
	{
		add=num-row;
		ui_grid_add_dynamic(grid,&add,&col,1);
	}
}

void h_set_track_list_grid(u8 num)
{
	struct ui_grid *grid = ui_grid_for_id(H_TRACK_LIST);
	static int col,row;
	int del,add;
	col=0;
	row=0;
	row=grid->dynamic->drow_num;
	log_info(">>>>>row %d \n",row);
	if(row>num)
	{
		del=row-num;
		log_info(">>>>>del %d \n",del);
		ui_grid_del_dynamic(grid,&del,&col,1);
	}
	else if(row<num)
	{
		add=num-row;
		log_info(">>>>>add %d \n",add);
		ui_grid_add_dynamic(grid,&add,&col,1);
	}
}

void h_set_history_list_grid(u8 num)
{
	struct ui_grid *grid = ui_grid_for_id(H_HISTORY_LIST);
	static int col,row;
	int del,add;
	col=0;
	row=0;
	row=grid->dynamic->drow_num;
	if(row>num)
	{
		del=row-num;
		ui_grid_del_dynamic(grid,&del,&col,1);
	}
	else if(row<num)
	{
		add=num-row;
		ui_grid_add_dynamic(grid,&add,&col,1);
	}
}
static void h_change_layout_css(u8 tmp,struct element * elm)
{
	if (__this->ui.core == tmp) {
		elm->css.invisible = 0;
	} else {
		elm->css.invisible = 1;
	}
}

void h_ui_layout_switch(u8 ui_temp)
{
	struct element *ctr = ui_core_get_element_by_id(BASEFORM_HIMALAYA); 		
	if (ctr == NULL) {
		return;
	}
	__this->ui.core = ui_temp;
	struct element *elm;
	list_for_each_child_element(elm, (struct element *)ctr) {
		switch (elm->id) {
			case H_INIT:
				h_change_layout_css(INIT_H,elm);
				break;
			case H_PRIVARY:
				h_change_layout_css(PRIVARY_H,elm);
				break;
			case H_PERSONAL:
				h_change_layout_css(PERSONAL_H,elm);
				break;
			case H_QR_CODE:
				h_change_layout_css(QRCODE_H,elm);
				break;
			case H_ACCOUNT_INFO:
				h_change_layout_css(ACCOUNT_INFO_H,elm);
				break;
			case H_HISTORY:
				h_change_layout_css(HISTORY_H,elm);
				break;
			case H_ALBUM:
				h_change_layout_css(ALBUM_H,elm);
				break;
			case H_TRACK_ALL:
				h_change_layout_css(TRACK_LIST_H,elm);
				break;
			case H_ACCOUNT_QUIT:
				h_change_layout_css(ACCOUNT_QUIT_H,elm);
				break;
			case H_QUIT_LAYOUT:
				h_change_layout_css(LAYOUT_QUIT_H,elm);
				break;
			case H_PLAYER:
				h_change_layout_css(PLAYER_H,elm);
				break;
			case H_VOLUME:
				h_change_layout_css(VOLUME_H,elm);
				break;
		}
		ui_core_redraw(ctr);
	}
}
static int h_ui_baseform_onchange(void *ctr, enum element_change_event e, void *arg)
{
	switch (e) {
		case ON_CHANGE_INIT:
			himalaya_ui_cmd_server(CMD_INIT);
			ui_auto_shut_down_disable();
			break;
		case ON_CHANGE_FIRST_SHOW:
			__this->ui.core = 0;
			struct element *elm;
			list_for_each_child_element(elm, (struct element *)ctr) {
				switch (elm->id) {
					case H_INIT:
						h_change_layout_css(INIT_H,elm);
						break;
					case H_PRIVARY:
						h_change_layout_css(PRIVARY_H,elm);
						break;
					case H_PERSONAL:
						h_change_layout_css(PERSONAL_H,elm);
						break;
					case H_QR_CODE:
						h_change_layout_css(QRCODE_H,elm);
						break;
					case H_ACCOUNT_INFO:
						h_change_layout_css(ACCOUNT_INFO_H,elm);
						break;
					case H_HISTORY:
						h_change_layout_css(HISTORY_H,elm);
						break;
					case H_ALBUM:
						h_change_layout_css(ALBUM_H,elm);
						break;
					case H_TRACK_ALL:
						h_change_layout_css(TRACK_LIST_H,elm);
						break;
					case H_ACCOUNT_QUIT:
						h_change_layout_css(ACCOUNT_QUIT_H,elm);
						break;
					case H_QUIT_LAYOUT:
						h_change_layout_css(LAYOUT_QUIT_H,elm);
						break;
					case H_PLAYER:
						h_change_layout_css(PLAYER_H,elm);
						break;
					case H_VOLUME:
						h_change_layout_css(VOLUME_H,elm);
						break;
				}
			}
			break;
		case ON_CHANGE_RELEASE:
			himalaya_ui_cmd_server(CMD_RELEASE);
			ui_auto_shut_down_enable();
			break;
	}
	return false;
}
REGISTER_UI_EVENT_HANDLER(BASEFORM_HIMALAYA)
.onchange = h_ui_baseform_onchange,
 .onkey = NULL,
  .ontouch = NULL,
};



// [msg_handler]
static const struct uimsg_handl ui_msg_handler[] = 
{
    {"H_msg_status", h_msg_handler},
    {NULL, NULL},
};

static int h_init_layout_onchange(void *ctr, enum element_change_event e, void *arg)
{
	switch (e) {
		case ON_CHANGE_FIRST_SHOW:
			ui_register_msg_handler(ID_WINDOW_HIMALAYA, ui_msg_handler);
			himalaya_ui_cmd_server(CMD_NET_CHECK);
			break;
	}
	return false;
}
REGISTER_UI_EVENT_HANDLER(H_INIT)
.onchange = h_init_layout_onchange,
 .onkey = NULL,
  .ontouch = NULL,
};


static int h_button_ontouch(void *ctr, struct element_touch_event *e)
{
	struct element *elm  = (struct element *) ctr;
	static u8 touch_action;
    switch (e->event) {
    case ELM_EVENT_TOUCH_UP:
		switch(elm->id)
		{
			case H_PRI_CONFIRM:
				himalaya_ui_cmd_server(CMD_GET_HOMEPAGE);
				break;
			case H_PRI_QUIT:
				h_ui_layout_switch(LAYOUT_QUIT_H);//不同意跳转到退出页面
				break;
			case H_PRIVACY_ENTRY:
				himalaya_ui_cmd_server(CMD_GET_PRIVACY);
				break;
			case H_ACCOUNT_QUIT_BUTTON:
				h_ui_layout_switch(ACCOUNT_QUIT_H);//退出登录页面
				break;
			case H_REJECT_QUIT:
				h_ui_layout_switch(PERSONAL_H);//返回个人中心
				break;
			case H_CONFIRM_QUIT:
				himalaya_ui_cmd_server(CMD_CLEAR);
				break;
			case  H_QUIT_CONFIRM:
				h_ui_quit_himalaya();
				break;
		}
        break;
    default:
        break;
    }
    return false;
}

//[privacy]
REGISTER_UI_EVENT_HANDLER(H_PRI_CONFIRM)// 同意隐私
.onchange = NULL,
 .onkey = NULL,
  .ontouch = h_button_ontouch,
};
REGISTER_UI_EVENT_HANDLER(H_PRI_QUIT)   // 不同意隐私
.onchange = NULL,
 .onkey = NULL,
  .ontouch = h_button_ontouch,
};
REGISTER_UI_EVENT_HANDLER(H_PRIVACY_ENTRY)// 隐私二维码
.onchange = NULL,
 .onkey = NULL,
  .ontouch = h_button_ontouch,
};
REGISTER_UI_EVENT_HANDLER(H_ACCOUNT_QUIT_BUTTON)// 登录二维码--退出登录
.onchange = NULL,
 .onkey = NULL,
  .ontouch = h_button_ontouch,
};
REGISTER_UI_EVENT_HANDLER(H_REJECT_QUIT)	// 取消退出登录
.onchange = NULL,
 .onkey = NULL,
  .ontouch = h_button_ontouch,
};
REGISTER_UI_EVENT_HANDLER(H_CONFIRM_QUIT)	// 确认退出登录
.onchange = NULL,
 .onkey = NULL,
  .ontouch = h_button_ontouch,
};
REGISTER_UI_EVENT_HANDLER(H_QUIT_CONFIRM)	// 同意退出
.onchange = NULL,
 .onkey = NULL,
  .ontouch = h_button_ontouch,
};


/********************************************************************************************/
static int h_personal_entry_ontouch(void *ctrl, struct element_touch_event *e)
{
	struct element *elm  = (struct element *) ctrl;
	static u8 touch_action = 0;
	switch (e->event) {
		case ELM_EVENT_TOUCH_UP:
			if(touch_action==1)
			{
				switch(elm->id)
				{
					case H_ACCOUNT_ENTRY:
						himalaya_ui_cmd_server(CMD_USR_ACCOUNT);
						break;
					case H_HISTORY_ENTRY:
						himalaya_ui_cmd_server(CMD_USR_HISTORY);
						break;
					case H_AUDIO_LIST_ENTRY:
						himalaya_ui_cmd_server(CMD_USR_SUBSCRIBE);
						break;
				}
			}
			break;
		case ELM_EVENT_TOUCH_DOWN:
			touch_action = 1;
			break;
		case ELM_EVENT_TOUCH_MOVE:
			touch_action = 2;
			break;
		case ELM_EVENT_TOUCH_R_MOVE:
			touch_action = 3;
			break;
		case  ELM_EVENT_TOUCH_L_MOVE:
			touch_action = 4;
			himalaya_ui_cmd_server(CMD_GET_HOMEPAGE);
			return true;
			break;
	}
	return false;
}
REGISTER_UI_EVENT_HANDLER(H_ACCOUNT_ENTRY) // 主页--登录
.onchange = NULL,
 .onkey = NULL,
  .ontouch = h_personal_entry_ontouch,
};
REGISTER_UI_EVENT_HANDLER(H_HISTORY_ENTRY) // 主页--历史
.onchange = NULL,
 .onkey = NULL,
  .ontouch = h_personal_entry_ontouch,
};
REGISTER_UI_EVENT_HANDLER(H_AUDIO_LIST_ENTRY)    // 主页--听单
.onchange = NULL,
 .onkey = NULL,
  .ontouch = h_personal_entry_ontouch,
};


/********************************************************************************************/
//homepage
static int h_album_list_ontouch(void *ctrl, struct element_touch_event *e)
{
	struct ui_grid *grid = (struct ui_grid *)ctrl;
	static u8 touch_action = 0;
	switch (e->event) {
		case ELM_EVENT_TOUCH_UP:
			if (touch_action == 1) {
				__this->homepage.sel_item = ui_grid_cur_item_dynamic(grid);
				himalaya_ui_cmd_server(CMD_HOMEPAGE_ALBUM_BY_LISTENID);
			}
			break;
		case ELM_EVENT_TOUCH_DOWN:
			touch_action = 1;
			break;
		case ELM_EVENT_TOUCH_MOVE:
			touch_action = 2;
			break;
		case ELM_EVENT_TOUCH_R_MOVE:
			h_ui_layout_switch(PERSONAL_H);//返回个人中心
			return true;
			break;
		case  ELM_EVENT_TOUCH_L_MOVE:
			h_ui_layout_switch(PLAYER_H);
			return true;
			break;
	}
	return false;
}



static int h_album_list_onchange(void *ctr, enum element_change_event e, void *arg)
{

	struct ui_grid *grid = (struct ui_grid *) ctr;
	int col,row;
	switch (e) {
		case ON_CHANGE_FIRST_SHOW:
			col=1;
			row=__this->homepage.listen_total;
			ui_grid_init_dynamic(grid, &row, &col);
			ui_grid_set_slide_direction(grid, SCROLL_DIRECTION_UD);
			break;
		case ON_CHANGE_RELEASE:
			break;
	}
	return false;
}
REGISTER_UI_EVENT_HANDLER(H_ALBUM_LIST)
.onchange =	h_album_list_onchange,
 .onkey = NULL,
  .ontouch =h_album_list_ontouch,
};




static int h_album_title_onchange(void *_ctrl, enum element_change_event event, void *arg)
{
	struct ui_text *text = (struct ui_text *)_ctrl;
	int index;
	switch (event) {
		case ON_CHANGE_UPDATE_ITEM:
			index = (u32)arg;
			ui_text_set_utf8_str(text,"text",__this->homepage.listen_array[index].listen_name,strlen(__this->homepage.listen_array[index].listen_name),FONT_DEFAULT|FONT_SHOW_MULTI_LINE);
			break;
	}
	return FALSE;
}
REGISTER_UI_EVENT_HANDLER(H_ALBUM_TITLE0)
.onchange = h_album_title_onchange,
 .onkey = NULL,
  .ontouch = NULL,
};
REGISTER_UI_EVENT_HANDLER(H_ALBUM_TITLE1)
.onchange = h_album_title_onchange,
 .onkey = NULL,
  .ontouch = NULL,
};
REGISTER_UI_EVENT_HANDLER(H_ALBUM_TITLE2)
.onchange = h_album_title_onchange,
 .onkey = NULL,
  .ontouch = NULL,
};








static int h_track_list_ontouch(void *ctrl, struct element_touch_event *e)
{
	struct ui_grid *grid = (struct ui_grid *)ctrl;
	static u8 touch_action = 0;
	static int sel_item = 0;
	switch (e->event) {
		case ELM_EVENT_TOUCH_UP:
			if (touch_action == 1) {
				sel_item = ui_grid_cur_item_dynamic(grid);
				himalaya_ui_refresh_by_listen_id(sel_item);
			}
			break;
		case ELM_EVENT_TOUCH_DOWN:
			touch_action = 1;
			break;
		case ELM_EVENT_TOUCH_MOVE:
			touch_action = 2;
			break;
		case ELM_EVENT_TOUCH_R_MOVE:
			himalaya_ui_track_page_return();
			touch_action = 3;
			return true;
			break;
	}
	return false;
}


static int h_track_list_onchange(void *ctr, enum element_change_event e, void *arg)
{
	struct element *elm  = (struct element *) ctr;
	struct ui_grid *grid = (struct ui_grid *) ctr;
	int num;
	switch (e) {
		case ON_CHANGE_FIRST_SHOW:
			int col = 1;
			int row = 10;
			ui_grid_init_dynamic(grid, &row, &col);
			ui_grid_set_slide_direction(grid, SCROLL_DIRECTION_UD);
			break;
		case ON_CHANGE_RELEASE:
			break;
	}
	return false;
}

REGISTER_UI_EVENT_HANDLER(H_TRACK_LIST)
.onchange =	h_track_list_onchange,
 .onkey = NULL,
  .ontouch =h_track_list_ontouch,
};

static int h_track_title_onchange(void *_ctrl, enum element_change_event event, void *arg)
{
	struct ui_text *text = (struct ui_text *)_ctrl;
	int index,level,mode;
	switch (event) {
		case ON_CHANGE_UPDATE_ITEM:
			index = (u32)arg;
			level=himalaya_ui_return_track_level();
			mode=himalaya_ui_return_track_mode();
			if(level==TRACK_LEVEL_I)
			{
				if(mode==TRACK_HOMEPAGE)
				{
					ui_text_set_utf8_str(text,"text",__this->source_list.source_array[index].title,strlen(__this->source_list.source_array[index].title),FONT_DEFAULT|FONT_SHOW_MULTI_LINE);
				}
				else if(mode==TRACK_PERSONAL)
				{
					ui_text_set_utf8_str(text,"text",__this->favorite_list.source_array[index].title,strlen(__this->favorite_list.source_array[index].title),FONT_DEFAULT|FONT_SHOW_MULTI_LINE);
				}
			}
			else if(level==TRACK_LEVEL_II)
			{
				ui_text_set_utf8_str(text,"text",__this->track_list.source_array[index].title,strlen(__this->track_list.source_array[index].title),FONT_DEFAULT|FONT_SHOW_MULTI_LINE);
			}
			break;
	}
	return FALSE;
}

REGISTER_UI_EVENT_HANDLER(H_TRACK_TITLE0)
.onchange = h_track_title_onchange,
 .onkey = NULL,
  .ontouch = NULL,
};
REGISTER_UI_EVENT_HANDLER(H_TRACK_TITLE1)
.onchange = h_track_title_onchange,
 .onkey = NULL,
  .ontouch = NULL,
};
REGISTER_UI_EVENT_HANDLER(H_TRACK_TITLE2)
.onchange = h_track_title_onchange,
 .onkey = NULL,
  .ontouch = NULL,
};


static int h_track_pay_onchange(void *_ctrl, enum element_change_event event, void *arg)
{
	struct ui_pic *pic = (struct ui_pic *)_ctrl;
	int num,index,level;
	switch (event) {
		case ON_CHANGE_UPDATE_ITEM:
			num=(u32)arg;
			level=himalaya_ui_return_track_level();
			if(level==TRACK_LEVEL_I)
			{
				index=__this->source_list.source_array[num].pay_type;
			}
			else if(level==TRACK_LEVEL_II)
			{
				index=__this->track_list.source_array[num].pay_type;
			}
			index-=1;
			if(index<0)
			{
				ui_pic_set_hide_by_id(pic->elm.id,true);
			}
			else
			{
				ui_pic_set_hide_by_id(pic->elm.id,false);
				ui_pic_set_image_index(pic, index);
			}
			break;
	}
	return FALSE;
}

REGISTER_UI_EVENT_HANDLER(H_TRACK_PAY0)
.onchange = h_track_pay_onchange,
 .onkey = NULL,
  .ontouch = NULL,
};
REGISTER_UI_EVENT_HANDLER(H_TRACK_PAY1)
.onchange = h_track_pay_onchange,
 .onkey = NULL,
  .ontouch = NULL,
};
REGISTER_UI_EVENT_HANDLER(H_TRACK_PAY2)
.onchange = h_track_pay_onchange,
 .onkey = NULL,
  .ontouch = NULL,
};












static int h_player_ontouch(void *ctrl, struct element_touch_event *e)
{
	switch (e->event) {
		case  ELM_EVENT_TOUCH_R_MOVE:
			himalaya_ui_cmd_server(CMD_GET_HOMEPAGE);
			return true;
			break;
	}
	return true;
}


REGISTER_UI_EVENT_HANDLER(H_PLAYER)
.onchange = NULL,
 .onkey = NULL,
  .ontouch =h_player_ontouch,
};

static int h_player_button_ontouch(void *ctr, struct element_touch_event *e)
{
	struct element *elm  = (struct element *) ctr;
	struct ui_pic * p_pic;
	int vslider_percent;
	static u8 touch_action,mode;
	switch (e->event) {
		case ELM_EVENT_TOUCH_R_MOVE:
			touch_action=2;
			return false;
			break;
		case ELM_EVENT_TOUCH_DOWN:	
			touch_action=1;
			break;
		case ELM_EVENT_TOUCH_UP:
			if(touch_action==1)
			{
				switch(elm->id)
				{
					case H_P_STATUS:
						p_pic=ui_grid_for_id(elm->id);
						__this->ui.play_status=p_pic->index;
						__this->ui.play_status=!__this->ui.play_status;
						if(__this->ui.play_status)
						{
							os_taskq_post_msg("HIMALAYA_NET_MUSIC",1,HIMALAYA_RESTART);//[restart]
						}
						else
						{
							os_taskq_post_msg("HIMALAYA_NET_MUSIC",1,HIMALAYA_PAUSE);//[pause]
						}
						ui_pic_show_image_by_id(elm->id,__this->ui.play_status);
						break;
					case H_P_VOLUME:
						h_ui_layout_switch(VOLUME_H);
						vslider_percent = h_ui_voice_to_percent(app_audio_get_volume(APP_AUDIO_STATE_MUSIC));
						ui_vslider_set_persent_by_id(H_VOLUME_VSLIDE, vslider_percent);
						break;
					case H_P_ORDER:
						p_pic=ui_grid_for_id(elm->id);
						mode=p_pic->index;
						mode+=1;
						if(mode>=3)
						{
							mode=0;	
						}
						ui_pic_show_image_by_id(elm->id,mode);
						himalaya_set_music_mode(mode);
						break;
				}
			}
			break;
		default:
			break;
	}
	return true;
}

static int h_player_status_onchange(void *_ctrl, enum element_change_event event, void *arg)
{
	struct ui_pic *pic = (struct ui_pic *)_ctrl;
	int num,index,level;
	switch (event) {
		case ON_CHANGE_FIRST_SHOW:
			log_info(">>>>>func %s line %d status %d \n",__func__,__LINE__,__this->ui.play_status);
			break;
	}
	return FALSE;
}

REGISTER_UI_EVENT_HANDLER(H_P_STATUS)
.onchange = h_player_status_onchange,
 .onkey = NULL,
  .ontouch = h_player_button_ontouch,
};
REGISTER_UI_EVENT_HANDLER(H_P_VOLUME)
.onchange = NULL,
 .onkey = NULL,
  .ontouch = h_player_button_ontouch,
};
REGISTER_UI_EVENT_HANDLER(H_P_ORDER)
.onchange = NULL,
 .onkey = NULL,
  .ontouch = h_player_button_ontouch,
};

static int h_volume_button_ontouch(void *ctr, struct element_touch_event *e)
{
	struct element *elm  = (struct element *) ctr;
	static u8 touch_action=0;
	int vslider_percent;
	switch (e->event) {
		case ELM_EVENT_TOUCH_DOWN:	
			touch_action=1;
			break;
		case ELM_EVENT_TOUCH_UP:
			if(touch_action!=1)
			{
				break;	
			}
			switch(elm->id)
			{
				case VOLUMEADD:
					volume_up();
					break;
				case VOLUMEMINUS:
					volume_down();
					break;
				default:
					return false;
			}
			vslider_percent = h_ui_voice_to_percent(app_audio_get_volume(APP_AUDIO_STATE_MUSIC));
			ui_vslider_set_persent_by_id(H_VOLUME_VSLIDE, vslider_percent);
			break;
		case ELM_EVENT_TOUCH_R_MOVE:
			touch_action=2;
			if(touch_action=2)
			{
				h_ui_layout_switch(PLAYER_H);
			}
			break;
		default:
			break;
	}
	return true;
}
REGISTER_UI_EVENT_HANDLER(VOLUMEADD)
.onchange = NULL,
 .onkey = NULL,
  .ontouch = h_volume_button_ontouch,
};
REGISTER_UI_EVENT_HANDLER(VOLUMEMINUS)
.onchange = NULL,
 .onkey = NULL,
  .ontouch = h_volume_button_ontouch,
};
static int h_player_status_ontouch(void *ctrl, struct element_touch_event *e)
{
	struct element *elm  = (struct element *) ctrl;
	switch (e->event) {
		case ELM_EVENT_TOUCH_R_MOVE:
			return false;
		case ELM_EVENT_TOUCH_UP:
			switch(elm->id)
			{
				case H_P_FORWORD:
					os_taskq_post_msg("HIMALAYA_NET_MUSIC",1,HIMALAYA_PREV);//[prev]
					break;
				case H_P_BACKWORD:
					os_taskq_post_msg("HIMALAYA_NET_MUSIC",1,HIMALAYA_BACK);//[back]
					break;
				case H_P_LIST:
					h_ui_layout_switch(TRACK_LIST_H);
					break;
			}
			return true;
			break;
	}
	return true;
}

REGISTER_UI_EVENT_HANDLER(H_P_BACKWORD)
.onchange = NULL,
 .onkey = NULL,
  .ontouch = h_player_status_ontouch,
};
REGISTER_UI_EVENT_HANDLER(H_P_FORWORD)
.onchange = NULL,
 .onkey = NULL,
  .ontouch = h_player_status_ontouch,
};
REGISTER_UI_EVENT_HANDLER(H_P_LIST)
.onchange = NULL,
 .onkey = NULL,
  .ontouch = h_player_status_ontouch,
};







/********************************************************************************************/
//[qr_code]
static int h_qrcode_onchange(void *ctr, enum element_change_event e, void *arg)
{
	struct rect rect = {0};
	struct draw_context *dc = (struct draw_context *)arg;
	struct element *elm  = (struct element *) ctr;
	switch (e) {
		case ON_CHANGE_FIRST_SHOW:
			break;
		case ON_CHANGE_SHOW_POST:
			ui_core_get_element_abs_rect(elm, &rect); //跟随控件移动,注释掉这句则不跟随控件移动
			int draw_width = (rect.width > rect.height) ? rect.height : rect.width;
			if (draw_width <= __qr->data.img_w) {
				ASSERT(0);
			}
			ui_draw(dc,
					NULL,
					rect.left + (draw_width - __qr->data.img_w) / 2,
					rect.top + (draw_width - __qr->data.img_w) / 2,
					__qr->data.img_w,
					__qr->data.img_w,
					h_draw_qrcode,
					(void *)&__qr->data,
					sizeof(struct _H_QRCODE),
					0);
			break;
		case ON_CHANGE_RELEASE:
			break;
	}
	return false;
}
static int h_qrcode_ontouch(void *ctrl, struct element_touch_event *e)
{
	switch (e->event) {
		case ELM_EVENT_TOUCH_R_MOVE:
			ask_himalaya_qrcode_status();
			h_ui_layout_switch(PERSONAL_H);//返回个人中心
			return true;
			break;
	}
	return false;
}
REGISTER_UI_EVENT_HANDLER(DRAW_H_QR_CODE)
.onchange =	h_qrcode_onchange,
 .onkey = NULL,
  .ontouch =h_qrcode_ontouch,
};



static int h_history_list_ontouch(void *ctrl, struct element_touch_event *e)
{
	struct ui_grid *grid = (struct ui_grid *)ctrl;
	static u8 touch_action = 0;
	u8 sel_item=0;
	switch (e->event) {
		case ELM_EVENT_TOUCH_UP:
			if (touch_action == 1) {
				__this->history_list.sel_item = ui_grid_cur_item_dynamic(grid);
				himalaya_ui_cmd_server(CMD_HISTORY_TRACK_BY_LISTENID);
			}
			break;
		case ELM_EVENT_TOUCH_DOWN:
			touch_action = 1;
			break;
		case ELM_EVENT_TOUCH_MOVE:
			touch_action = 2;
			break;
		case ELM_EVENT_TOUCH_R_MOVE:
			h_ui_layout_switch(PERSONAL_H);//返回个人中心
			return true;
			break;
	}
	return false;
}

static int h_history_list_onchange(void *ctr, enum element_change_event e, void *arg)
{
	struct ui_grid *grid = (struct ui_grid *) ctr;
	switch (e) {
		case ON_CHANGE_FIRST_SHOW:
			int col = 1;
			int row = __this->history_list.source_total;
			ui_grid_init_dynamic(grid, &row, &col);
			ui_grid_set_slide_direction(grid, SCROLL_DIRECTION_UD);
			break;
		case ON_CHANGE_RELEASE:
			break;
	}
	return false;
}

REGISTER_UI_EVENT_HANDLER(H_HISTORY_LIST)
.onchange =	h_history_list_onchange,
 .onkey = NULL,
  .ontouch =h_history_list_ontouch,
};

static int h_history_title_onchange(void *_ctrl, enum element_change_event event, void *arg)
{
	struct ui_text *text = (struct ui_text *)_ctrl;
	int index;
	switch (event) {
		case ON_CHANGE_UPDATE_ITEM:
			index = (u32)arg;
			ui_text_set_utf8_str(text,"text",__this->history_list.source_array[index].title,strlen(__this->history_list.source_array[index].title),FONT_DEFAULT|FONT_SHOW_MULTI_LINE);
			break;
	}
	return FALSE;
}

REGISTER_UI_EVENT_HANDLER(H_HISTORY_TITLE0)
.onchange = h_history_title_onchange,
 .onkey = NULL,
  .ontouch = NULL,
};
REGISTER_UI_EVENT_HANDLER(H_HISTORY_TITLE1)
.onchange = h_history_title_onchange,
 .onkey = NULL,
  .ontouch = NULL,
};
REGISTER_UI_EVENT_HANDLER(H_HISTORY_TITLE2)
.onchange = h_history_title_onchange,
 .onkey = NULL,
  .ontouch = NULL,
};
#endif
