Skip to content

Commit

Permalink
修改点赞列表中图标的显示方式
Browse files Browse the repository at this point in the history
  • Loading branch information
Naoki2015 committed Jan 3, 2016
1 parent 3f502d8 commit 062ff08
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@
import com.yiw.circledemo.bean.User;
import com.yiw.circledemo.contral.CirclePublicCommentContral;
import com.yiw.circledemo.mvp.presenter.CirclePresenter;
import com.yiw.circledemo.mvp.view.ICircleViewUpdateListener;
import com.yiw.circledemo.mvp.view.ICircleViewUpdate;
import com.yiw.circledemo.spannable.ISpanClick;
import com.yiw.circledemo.utils.DatasUtil;
import com.yiw.circledemo.widgets.AppNoScrollerListView;
import com.yiw.circledemo.widgets.CircularImage;
import com.yiw.circledemo.widgets.FavortListAdapter;
import com.yiw.circledemo.widgets.FavortListView;
import com.yiw.circledemo.widgets.MultiImageView;
import com.yiw.circledemo.widgets.SnsPopupWindow;
Expand All @@ -46,7 +45,7 @@
* @date 2015-12-28 上午09:37:23
*
*/
public class CircleAdapter extends BaseAdapter implements ICircleViewUpdateListener{
public class CircleAdapter extends BaseAdapter implements ICircleViewUpdate {
private static final int ITEM_VIEW_TYPE_DEFAULT = 0;
private static final int ITEM_VIEW_TYPE_URL = 1;
private static final int ITEM_VIEW_TYPE_IMAGE = 2;
Expand All @@ -60,7 +59,7 @@ public class CircleAdapter extends BaseAdapter implements ICircleViewUpdateListe
private CirclePresenter mPresenter;
private CirclePublicCommentContral mCirclePublicCommentContral;
private List<CircleItem> datas = new ArrayList<CircleItem>();

public void setmCirclePublicCommentContral(
CirclePublicCommentContral mCirclePublicCommentContral) {
this.mCirclePublicCommentContral = mCirclePublicCommentContral;
Expand Down Expand Up @@ -186,6 +185,8 @@ public View getView(final int position, View convertView, ViewGroup parent) {
holder.nameTv.setText(name);
holder.timeTv.setText(createTime);
holder.contentTv.setText(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{
Expand Down Expand Up @@ -219,11 +220,14 @@ public void onClick(int position) {
holder.bbsAdapter.setCommentClickListener(new ICommentItemClickListener() {
@Override
public void onItemClick(int commentPosition) {

CommentItem commentItem = commentsDatas.get(commentPosition);
if(DatasUtil.curUser.getId().equals(commentItem.getUser().getId())){//复制或者删除自己的评论

CommentDialog dialog = new CommentDialog(mContext, mPresenter, commentItem, position);
dialog.show();
}else{//回复别人的评论

if(mCirclePublicCommentContral!=null){
mCirclePublicCommentContral.editTextBodyVisible(View.VISIBLE, mPresenter, position, TYPE_REPLY_COMMENT, commentItem.getUser(), commentPosition);
}
Expand All @@ -236,6 +240,7 @@ public void onItemClick(int commentPosition) {
holder.commentList.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View view, final int commentPosition, long id) {

//长按进行复制或者删除
CommentItem commentItem = commentsDatas.get(commentPosition);
CommentDialog dialog = new CommentDialog(mContext, mPresenter, commentItem, position);
Expand All @@ -244,18 +249,16 @@ public boolean onItemLongClick(AdapterView<?> arg0, View view, final int comment
}
});
}else {

holder.commentList.setVisibility(View.GONE);
}
holder.digCommentBody.setVisibility(View.VISIBLE);
}else{
holder.digCommentBody.setVisibility(View.GONE);
}
if(hasFavort && hasComment){
holder.digLine.setVisibility(View.VISIBLE);
}else{
holder.digLine.setVisibility(View.GONE);
}


holder.digLine.setVisibility(hasFavort && hasComment ? View.VISIBLE : View.GONE);

final SnsPopupWindow snsPopupWindow = holder.snsPopupWindow;
//判断是否已点赞
String curUserFavortId = circleItem.getCurUserFavortId(DatasUtil.curUser.getId());
Expand Down Expand Up @@ -335,11 +338,13 @@ private class PopupItemClickListener implements SnsPopupWindow.OnItemClickListen
private int mCirclePosition;
private long mLasttime = 0;
private CircleItem mCircleItem;

public PopupItemClickListener(int circlePosition, CircleItem circleItem, String favorId){
this.mFavorId = favorId;
this.mCirclePosition = circlePosition;
this.mCircleItem = circleItem;
}

@Override
public void onItemClick(ActionItem actionitem, int position) {
switch (position) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,12 @@ public View getView(final int position, View convertView, ViewGroup parent) {
}

SpannableStringBuilder builder = new SpannableStringBuilder();
builder.append(getSpannableString(name, 0));
builder.append(setClickableSpan(name, 0));

if (!TextUtils.isEmpty(toReplyName)) {

builder.append(" 回复 ");

builder.append(getSpannableString(toReplyName, 1));
builder.append(setClickableSpan(toReplyName, 1));
}
builder.append(": ");
//转换表情字符
Expand All @@ -122,7 +121,7 @@ public void onClick(View v) {
}

@NonNull
private SpannableString getSpannableString(String textStr, int position) {
private SpannableString setClickableSpan(String textStr, int position) {
SpannableString subjectSpanText = new SpannableString(textStr);
subjectSpanText.setSpan(new NameClickable(new NameClickListener(
subjectSpanText, ""), position), 0, subjectSpanText.length(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package com.yiw.circledemo.widgets;
package com.yiw.circledemo.adapter;

import android.support.annotation.NonNull;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.style.DynamicDrawableSpan;
import android.text.style.ImageSpan;

import com.yiw.circledemo.MyApplication;
import com.yiw.circledemo.R;
import com.yiw.circledemo.bean.FavortItem;
import com.yiw.circledemo.spannable.CircleMovementMethod;
import com.yiw.circledemo.spannable.NameClickable;
import com.yiw.circledemo.widgets.FavortListView;

import java.util.List;

Expand Down Expand Up @@ -60,12 +62,13 @@ public void notifyDataSetChanged(){
SpannableStringBuilder builder = new SpannableStringBuilder();
if(datas != null && datas.size() > 0){
//添加点赞图标
//builder.append(setImgSpannable());
builder.append(setImageSpan());
//builder.append(" ");
FavortItem item = null;
for (int i=0; i<datas.size(); i++){
item = datas.get(i);
if(item != null){
builder.append(getSpannableString(item.getUser().getName(), i));
builder.append(setClickableSpan(item.getUser().getName(), i));
if(i != datas.size()-1){
builder.append(", ");
}
Expand All @@ -78,18 +81,18 @@ public void notifyDataSetChanged(){
}

@NonNull
private SpannableString getSpannableString(String textStr, int position) {
private SpannableString setClickableSpan(String textStr, int position) {
SpannableString subjectSpanText = new SpannableString(textStr);
subjectSpanText.setSpan(new NameClickable(mListView.getSpanClickListener(), position), 0, subjectSpanText.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return subjectSpanText;
}

private SpannableString setImgSpannable(){
String text = " ";
private SpannableString setImageSpan(){
String text = " ";
SpannableString imgSpanText = new SpannableString(text);
imgSpanText.setSpan(new ImageSpan(MyApplication.getContext(), R.drawable.im_ic_dig_tips),
0 ,text.length(),Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
imgSpanText.setSpan(new ImageSpan(MyApplication.getContext(), R.drawable.im_ic_dig_tips, DynamicDrawableSpan.ALIGN_BASELINE),
0 , 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return imgSpanText;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.yiw.circledemo.R;
import com.yiw.circledemo.bean.User;
import com.yiw.circledemo.mvp.presenter.CirclePresenter;
import com.yiw.circledemo.mvp.view.ICircleViewUpdateListener;
import com.yiw.circledemo.mvp.view.ICircleViewUpdate;
import com.yiw.circledemo.utils.CommonUtils;
import com.yiw.circledemo.widgets.AppNoScrollerListView;
/**
Expand Down Expand Up @@ -93,7 +93,7 @@ public void editTextBodyVisible(int visibility, CirclePresenter mCirclePresenter
View selectCircleItem = mListView.getChildAt(mCirclePosition-firstPosition);
mSelectCircleItemH = selectCircleItem.getHeight();

if(commentType == ICircleViewUpdateListener.TYPE_REPLY_COMMENT){//回复评论的情况
if(commentType == ICircleViewUpdate.TYPE_REPLY_COMMENT){//回复评论的情况
AppNoScrollerListView commentLv = (AppNoScrollerListView) selectCircleItem.findViewById(R.id.commentList);
if(commentLv!=null){
int firstCommentPosition = commentLv.getFirstVisiblePosition();
Expand Down Expand Up @@ -121,7 +121,7 @@ public void handleListViewScroll() {
int screenlH = ((MainActivity)mContext).getScreenHeight();//整个应用屏幕的高度
int listviewOffset = screenlH - mSelectCircleItemH - keyH - editTextBodyH;
Log.d(TAG, "offset="+listviewOffset + " &mSelectCircleItemH="+mSelectCircleItemH + " &keyH="+keyH + " &editTextBodyH="+editTextBodyH);
if(mCommentType == ICircleViewUpdateListener.TYPE_REPLY_COMMENT){
if(mCommentType == ICircleViewUpdate.TYPE_REPLY_COMMENT){
listviewOffset = listviewOffset + mSelectCommentItemBottom;
}
if(mListView!=null){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.yiw.circledemo.bean.User;
import com.yiw.circledemo.mvp.modle.CircleModel;
import com.yiw.circledemo.mvp.modle.IDataRequestListener;
import com.yiw.circledemo.mvp.view.ICircleViewUpdateListener;
import com.yiw.circledemo.mvp.view.ICircleViewUpdate;
/**
*
* @ClassName: CirclePresenter
Expand All @@ -14,9 +14,9 @@
*/
public class CirclePresenter {
private CircleModel mCircleModel;
private ICircleViewUpdateListener mCircleView;
private ICircleViewUpdate mCircleView;

public CirclePresenter(ICircleViewUpdateListener view){
public CirclePresenter(ICircleViewUpdate view){
this.mCircleView = view;
mCircleModel = new CircleModel();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @date 2015-12-28 下午4:13:04
*
*/
public interface ICircleViewUpdateListener {
public interface ICircleViewUpdate {
/**
* 发布评论
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.util.AttributeSet;
import android.widget.TextView;

import com.yiw.circledemo.adapter.FavortListAdapter;
import com.yiw.circledemo.spannable.ISpanClick;

/**
Expand Down
2 changes: 0 additions & 2 deletions CircleDemo/app/src/main/res/layout/adapter_circle_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@
android:id="@+id/favortListTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/im_ic_dig_tips"
android:drawablePadding="5dp"
android:gravity="center_vertical"
android:lineSpacingMultiplier="1.1"
android:textSize="14sp"
Expand Down

0 comments on commit 062ff08

Please sign in to comment.