80,350
社区成员
发帖
与我相关
我的任务
分享
/**
* 返回布局类型
* @param position item的位置
* @return 0:发送的布局 1:接收的布局
*/
@Override
public int getItemViewType(int position) {
TaskProcess t = mDatas.get(position);
if (t.currentUser) {
return 0;
}
return 1;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
TaskProcess t = mDatas.get(position);
ViewHolder vh;
if (convertView == null) {
if (getItemViewType(position) == 0) {
convertView = inflater.inflate(R.layout.listitem_task_right, parent, false);
vh = new ViewHolder();
vh.tv_record_time = (TextView) convertView.findViewById(R.id.tv_record_right_time);
vh.iv_msg_head = (ImageView) convertView.findViewById(R.id.iv_msg_right_head);
vh.tv_msg_name = (TextView) convertView.findViewById(R.id.tv_msg_right_name);
vh.rl_msg_content_root = (RelativeLayout) convertView.findViewById(R.id.rl_msg_right_content_root);
vh.tv_msg_content = (TextView) convertView.findViewById(R.id.tv_msg_right_content);
vh.rl_msg_voice_root = (RelativeLayout) convertView.findViewById(R.id.rl_msg_right_voice_root);
vh.rl_voice_bg = (RelativeLayout) convertView.findViewById(R.id.rl_right_voice_bg);
vh.iv_msg_voice_anim = (ImageView) convertView.findViewById(R.id.iv_msg_voice_send_anim);
vh.tv_msg_voice_duration = (TextView) convertView.findViewById(R.id.tv_msg_right_voice_duration);
vh.rl_msg_img_root = (RelativeLayout) convertView.findViewById(R.id.rl_msg_right_img_root);
vh.iv_msg_image = (ImageView) convertView.findViewById(R.id.iv_msg_right_image);
vh.rl_msg_file_root = (RelativeLayout) convertView.findViewById(R.id.rl_msg_right_file_root);
vh.ll_msg_file = (LinearLayout) convertView.findViewById(R.id.ll_msg_right_file);
vh.iv_msg_file = (ImageView) convertView.findViewById(R.id.iv_msg_right_file);
vh.tv_msg_file_name = (TextView) convertView.findViewById(R.id.tv_msg_right_file_name);
vh.tv_msg_file_size = (TextView) convertView.findViewById(R.id.tv_msg_right_file_size);
convertView.setTag(vh);
} else {
convertView = inflater.inflate(R.layout.listitem_task_left, parent, false);
vh = new ViewHolder();
vh.tv_record_time = (TextView) convertView.findViewById(R.id.tv_record_left_time);
vh.iv_msg_head = (ImageView) convertView.findViewById(R.id.iv_msg_left_head);
vh.tv_msg_name = (TextView) convertView.findViewById(R.id.tv_msg_left_name);
vh.rl_msg_content_root = (RelativeLayout) convertView.findViewById(R.id.rl_msg_left_content_root);
vh.tv_msg_content = (TextView) convertView.findViewById(R.id.tv_msg_left_content);
vh.rl_msg_voice_root = (RelativeLayout) convertView.findViewById(R.id.rl_msg_left_voice_root);
vh.rl_voice_bg = (RelativeLayout) convertView.findViewById(R.id.rl_left_voice_bg);
vh.iv_msg_voice_anim = (ImageView) convertView.findViewById(R.id.iv_msg_voice_get_anim);
vh.tv_msg_voice_duration = (TextView) convertView.findViewById(R.id.tv_msg_left_voice_duration);
vh.rl_msg_img_root = (RelativeLayout) convertView.findViewById(R.id.rl_msg_left_img_root);
vh.iv_msg_image = (ImageView) convertView.findViewById(R.id.iv_msg_left_image);
vh.rl_msg_file_root = (RelativeLayout) convertView.findViewById(R.id.rl_msg_left_file_root);
vh.ll_msg_file = (LinearLayout) convertView.findViewById(R.id.ll_msg_left_file);
vh.iv_msg_file = (ImageView) convertView.findViewById(R.id.iv_msg_left_file);
vh.tv_msg_file_name = (TextView) convertView.findViewById(R.id.tv_msg_left_file_name);
vh.tv_msg_file_size = (TextView) convertView.findViewById(R.id.tv_msg_left_file_size);
convertView.setTag(vh);
}
} else {
vh = (ViewHolder) convertView.getTag();
}
if (t.nextTime) {
vh.tv_record_time.setText(t.created);
vh.tv_record_time.setVisibility(View.VISIBLE);
} else {
vh.tv_record_time.setVisibility(View.GONE);
}
// vh.iv_msg_right_head = mDatas.get(position).elephant;
vh.tv_msg_name.setText(t.username);
//判断是否为文字布局
if (null != t.content && !t.content.equals("")) {
vh.tv_msg_content.setText(t.content);
vh.rl_msg_content_root.setVisibility(View.VISIBLE);
vh.rl_msg_voice_root.setVisibility(View.GONE);
vh.rl_msg_img_root.setVisibility(View.GONE);
vh.rl_msg_file_root.setVisibility(View.GONE);
} else {
if (t.is_sound_file) {
//设置宽高度
ViewGroup.LayoutParams params = vh.rl_voice_bg.getLayoutParams();
if (Integer.valueOf(t.playtime) == 60 || Integer.valueOf(t.playtime) > 60) {
params.width = (int) getResources().getDimension(R.dimen.voice_bg_with) + (65 * ((CommonUtil.getScreenWith(TaskProcessActivity.this) / 2) / 65));
} else {
params.width = (int) getResources().getDimension(R.dimen.voice_bg_with) + ((Integer.valueOf(t.playtime) + 5) * ((CommonUtil.getScreenWith(TaskProcessActivity.this) / 2) / 65));
}
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
vh.rl_voice_bg.setLayoutParams(params);
vh.tv_msg_voice_duration.setText(t.playtime + "’");
vh.rl_msg_voice_root.setVisibility(View.VISIBLE);
vh.rl_msg_content_root.setVisibility(View.GONE);
vh.rl_msg_img_root.setVisibility(View.GONE);
vh.rl_msg_file_root.setVisibility(View.GONE);
} else {
if (CommonUtil.isImage(t.filename)) {
Glide.with(TaskProcessActivity.this).load(t.url).override(120, 120).into(vh.iv_msg_image);
vh.rl_msg_img_root.setVisibility(View.VISIBLE);
vh.rl_msg_content_root.setVisibility(View.GONE);
vh.rl_msg_voice_root.setVisibility(View.GONE);
vh.rl_msg_file_root.setVisibility(View.GONE);
} else {
vh.tv_msg_file_name.setText(t.filename);
vh.tv_msg_file_size.setText(t.size);
vh.rl_msg_file_root.setVisibility(View.VISIBLE);
vh.rl_msg_content_root.setVisibility(View.GONE);
vh.rl_msg_voice_root.setVisibility(View.GONE);
vh.rl_msg_img_root.setVisibility(View.GONE);
}
}
}
return convertView;
}