use of com.yiw.circledemo.bean.PhotoInfo 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.PhotoInfo in project CircleDemo by Naoki2015.
the class DatasUtil method createPhotos.
public static List<PhotoInfo> createPhotos() {
List<PhotoInfo> photos = new ArrayList<PhotoInfo>();
int size = getRandomNum(PHOTOS.size());
if (size > 0) {
if (size > 9) {
size = 9;
}
for (int i = 0; i < size; i++) {
PhotoInfo photo = PHOTOS.get(getRandomNum(PHOTOS.size()));
if (!photos.contains(photo)) {
photos.add(photo);
} else {
i--;
}
}
}
return photos;
}
use of com.yiw.circledemo.bean.PhotoInfo in project CircleDemo by Naoki2015.
the class MultiImageView method createImageView.
private ImageView createImageView(int position, final boolean isMultiImage) {
PhotoInfo photoInfo = imagesList.get(position);
ImageView imageView = new ColorFilterImageView(getContext());
if (isMultiImage) {
imageView.setScaleType(ScaleType.CENTER_CROP);
imageView.setLayoutParams(position % MAX_PER_ROW_COUNT == 0 ? moreParaColumnFirst : morePara);
} else {
imageView.setAdjustViewBounds(true);
imageView.setScaleType(ScaleType.CENTER_INSIDE);
//imageView.setMaxHeight(pxOneMaxWandH);
int expectW = photoInfo.w;
int expectH = photoInfo.h;
if (expectW == 0 || expectH == 0) {
imageView.setLayoutParams(onePicPara);
} else {
int actualW = 0;
int actualH = 0;
float scale = ((float) expectH) / ((float) expectW);
if (expectW > pxOneMaxWandH) {
actualW = pxOneMaxWandH;
actualH = (int) (actualW * scale);
} else if (expectW < pxMoreWandH) {
actualW = pxMoreWandH;
actualH = (int) (actualW * scale);
} else {
actualW = expectW;
actualH = expectH;
}
imageView.setLayoutParams(new LayoutParams(actualW, actualH));
}
}
imageView.setId(photoInfo.url.hashCode());
imageView.setOnClickListener(new ImageOnClickListener(position));
imageView.setBackgroundColor(getResources().getColor(R.color.im_font_color_text_hint));
Glide.with(getContext()).load(photoInfo.url).diskCacheStrategy(DiskCacheStrategy.ALL).into(imageView);
return imageView;
}
Aggregations