use of com.yiw.circledemo.bean.CircleItem in project CircleDemo by Naoki2015.
the class CircleAdapter method getItemViewType.
@Override
public int getItemViewType(int position) {
if (position == 0) {
return TYPE_HEAD;
}
int itemType = 0;
CircleItem item = (CircleItem) datas.get(position - 1);
if (CircleItem.TYPE_URL.equals(item.getType())) {
itemType = CircleViewHolder.TYPE_URL;
} else if (CircleItem.TYPE_IMG.equals(item.getType())) {
itemType = CircleViewHolder.TYPE_IMAGE;
} else if (CircleItem.TYPE_VIDEO.equals(item.getType())) {
itemType = CircleViewHolder.TYPE_VIDEO;
}
return itemType;
}
use of com.yiw.circledemo.bean.CircleItem in project CircleDemo by Naoki2015.
the class CircleAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
if (getItemViewType(position) == TYPE_HEAD) {
//HeaderViewHolder holder = (HeaderViewHolder) viewHolder;
} else {
final int circlePosition = position - HEADVIEW_SIZE;
final CircleViewHolder holder = (CircleViewHolder) viewHolder;
final CircleItem circleItem = (CircleItem) datas.get(circlePosition);
final String circleId = circleItem.getId();
String name = circleItem.getUser().getName();
String headImg = circleItem.getUser().getHeadUrl();
final String content = circleItem.getContent();
String createTime = circleItem.getCreateTime();
final List<FavortItem> favortDatas = circleItem.getFavorters();
final List<CommentItem> commentsDatas = circleItem.getComments();
boolean hasFavort = circleItem.hasFavort();
boolean hasComment = circleItem.hasComment();
Glide.with(context).load(headImg).diskCacheStrategy(DiskCacheStrategy.ALL).placeholder(R.color.bg_no_photo).transform(new GlideCircleTransform(context)).into(holder.headIv);
holder.nameTv.setText(name);
holder.timeTv.setText(createTime);
if (!TextUtils.isEmpty(content)) {
holder.contentTv.setExpand(circleItem.isExpand());
holder.contentTv.setExpandStatusListener(new ExpandTextView.ExpandStatusListener() {
@Override
public void statusChange(boolean isExpand) {
circleItem.setExpand(isExpand);
}
});
holder.contentTv.setText(UrlUtils.formatUrlString(content));
}
holder.contentTv.setVisibility(TextUtils.isEmpty(content) ? View.GONE : View.VISIBLE);
if (DatasUtil.curUser.getId().equals(circleItem.getUser().getId())) {
holder.deleteBtn.setVisibility(View.VISIBLE);
} else {
holder.deleteBtn.setVisibility(View.GONE);
}
holder.deleteBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//删除
if (presenter != null) {
presenter.deleteCircle(circleId);
}
}
});
if (hasFavort || hasComment) {
if (hasFavort) {
//处理点赞列表
holder.praiseListView.setOnItemClickListener(new PraiseListView.OnItemClickListener() {
@Override
public void onClick(int position) {
String userName = favortDatas.get(position).getUser().getName();
String userId = favortDatas.get(position).getUser().getId();
Toast.makeText(MyApplication.getContext(), userName + " &id = " + userId, Toast.LENGTH_SHORT).show();
}
});
holder.praiseListView.setDatas(favortDatas);
holder.praiseListView.setVisibility(View.VISIBLE);
} else {
holder.praiseListView.setVisibility(View.GONE);
}
if (hasComment) {
//处理评论列表
holder.commentList.setOnItemClickListener(new CommentListView.OnItemClickListener() {
@Override
public void onItemClick(int commentPosition) {
CommentItem commentItem = commentsDatas.get(commentPosition);
if (DatasUtil.curUser.getId().equals(commentItem.getUser().getId())) {
//复制或者删除自己的评论
CommentDialog dialog = new CommentDialog(context, presenter, commentItem, circlePosition);
dialog.show();
} else {
//回复别人的评论
if (presenter != null) {
CommentConfig config = new CommentConfig();
config.circlePosition = circlePosition;
config.commentPosition = commentPosition;
config.commentType = CommentConfig.Type.REPLY;
config.replyUser = commentItem.getUser();
presenter.showEditTextBody(config);
}
}
}
});
holder.commentList.setOnItemLongClickListener(new CommentListView.OnItemLongClickListener() {
@Override
public void onItemLongClick(int commentPosition) {
//长按进行复制或者删除
CommentItem commentItem = commentsDatas.get(commentPosition);
CommentDialog dialog = new CommentDialog(context, presenter, commentItem, circlePosition);
dialog.show();
}
});
holder.commentList.setDatas(commentsDatas);
holder.commentList.setVisibility(View.VISIBLE);
} else {
holder.commentList.setVisibility(View.GONE);
}
holder.digCommentBody.setVisibility(View.VISIBLE);
} else {
holder.digCommentBody.setVisibility(View.GONE);
}
holder.digLine.setVisibility(hasFavort && hasComment ? View.VISIBLE : View.GONE);
final SnsPopupWindow snsPopupWindow = holder.snsPopupWindow;
//判断是否已点赞
String curUserFavortId = circleItem.getCurUserFavortId(DatasUtil.curUser.getId());
if (!TextUtils.isEmpty(curUserFavortId)) {
snsPopupWindow.getmActionItems().get(0).mTitle = "取消";
} else {
snsPopupWindow.getmActionItems().get(0).mTitle = "赞";
}
snsPopupWindow.update();
snsPopupWindow.setmItemClickListener(new PopupItemClickListener(circlePosition, circleItem, curUserFavortId));
holder.snsBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//弹出popupwindow
snsPopupWindow.showPopupWindow(view);
}
});
holder.urlTipTv.setVisibility(View.GONE);
switch(holder.viewType) {
case // 处理链接动态的链接内容和和图片
CircleViewHolder.TYPE_URL:
if (holder instanceof URLViewHolder) {
String linkImg = circleItem.getLinkImg();
String linkTitle = circleItem.getLinkTitle();
Glide.with(context).load(linkImg).into(((URLViewHolder) holder).urlImageIv);
((URLViewHolder) holder).urlContentTv.setText(linkTitle);
((URLViewHolder) holder).urlBody.setVisibility(View.VISIBLE);
((URLViewHolder) holder).urlTipTv.setVisibility(View.VISIBLE);
}
break;
case // 处理图片
CircleViewHolder.TYPE_IMAGE:
if (holder instanceof ImageViewHolder) {
final List<PhotoInfo> photos = circleItem.getPhotos();
if (photos != null && photos.size() > 0) {
((ImageViewHolder) holder).multiImageView.setVisibility(View.VISIBLE);
((ImageViewHolder) holder).multiImageView.setList(photos);
((ImageViewHolder) holder).multiImageView.setOnItemClickListener(new MultiImageView.OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
//imagesize是作为loading时的图片size
ImagePagerActivity.ImageSize imageSize = new ImagePagerActivity.ImageSize(view.getMeasuredWidth(), view.getMeasuredHeight());
List<String> photoUrls = new ArrayList<String>();
for (PhotoInfo photoInfo : photos) {
photoUrls.add(photoInfo.url);
}
ImagePagerActivity.startImagePagerActivity(((MainActivity) context), photoUrls, position, imageSize);
}
});
} else {
((ImageViewHolder) holder).multiImageView.setVisibility(View.GONE);
}
}
break;
case CircleViewHolder.TYPE_VIDEO:
if (holder instanceof VideoViewHolder) {
((VideoViewHolder) holder).videoView.setVideoUrl(circleItem.getVideoUrl());
//视频封面图片
((VideoViewHolder) holder).videoView.setVideoImgUrl(circleItem.getVideoImgUrl());
((VideoViewHolder) holder).videoView.setPostion(position);
((VideoViewHolder) holder).videoView.setOnPlayClickListener(new CircleVideoView.OnPlayClickListener() {
@Override
public void onPlayClick(int pos) {
curPlayIndex = pos;
}
});
}
break;
default:
break;
}
}
}
use of com.yiw.circledemo.bean.CircleItem in project CircleDemo by Naoki2015.
the class MainActivity method update2DeleteCircle.
@Override
public void update2DeleteCircle(String circleId) {
List<CircleItem> circleItems = circleAdapter.getDatas();
for (int i = 0; i < circleItems.size(); i++) {
if (circleId.equals(circleItems.get(i).getId())) {
circleItems.remove(i);
circleAdapter.notifyDataSetChanged();
//circleAdapter.notifyItemRemoved(i+1);
return;
}
}
}
use of com.yiw.circledemo.bean.CircleItem in project CircleDemo by Naoki2015.
the class MainActivity method update2AddComment.
@Override
public void update2AddComment(int circlePosition, CommentItem addItem) {
if (addItem != null) {
CircleItem item = (CircleItem) circleAdapter.getDatas().get(circlePosition);
item.getComments().add(addItem);
circleAdapter.notifyDataSetChanged();
//circleAdapter.notifyItemChanged(circlePosition+1);
}
//清空评论文本
editText.setText("");
}
use of com.yiw.circledemo.bean.CircleItem in project CircleDemo by Naoki2015.
the class DatasUtil method createVideoItem.
public static CircleItem createVideoItem(String videoUrl, String imgUrl) {
CircleItem item = new CircleItem();
item.setId(String.valueOf(circleId++));
item.setUser(curUser);
//item.setContent(getContent());
item.setCreateTime("12月24日");
//item.setFavorters(createFavortItemList());
//item.setComments(createCommentItemList());
// 图片
item.setType("3");
item.setVideoUrl(videoUrl);
item.setVideoImgUrl(imgUrl);
return item;
}
Aggregations