Skip to content

Commit a522b6f

Browse files
committed
Client:优化动态相关类的代码及注释
1 parent d769e10 commit a522b6f

6 files changed

Lines changed: 187 additions & 207 deletions

File tree

APIJSON(Android)/APIJSON(ADT)/APIJSONApp/APIJSONApp/src/apijson/demo/client/model/MomentItem.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,6 @@ public MomentItem setCommentItemList(List<CommentItem> commentItemList) {
152152
public List<Long> getPraiseUserIdList() {
153153
return getMoment().getPraiseUserIdList();
154154
}
155-
public List<Long> getCommentIdList() {
156-
return getMoment().getCommentIdList();
157-
}
158155

159156

160157
private Boolean isPraised;
@@ -237,34 +234,12 @@ public boolean getIsCommented(final long userId) {
237234
}
238235
return value(isCommented);
239236
}
240-
public MomentItem setIsCommented(boolean isCommented, long userId) {
241-
this.isCommented = isCommented;
242-
243-
List<Long> list = getCommentIdList();
244-
if (list == null) {
245-
list = new ArrayList<>();
246-
}
247-
if (isCommented == false) {
248-
list.remove(userId);
249-
} else {
250-
if (list.contains(userId) == false) {
251-
list.add(userId);
252-
}
253-
}
254-
getMoment().setCommentIdList(list);
255-
256-
return this;
257-
}
258237

259238
private int commentCount;
260239
public int getCommentCount() {
261240
return commentCount;
262241
}
263242
public MomentItem setCommentCount(int commentCount) {
264-
int idCount = count(getCommentIdList());
265-
if (commentCount < idCount) {
266-
commentCount = idCount;
267-
}
268243
this.commentCount = commentCount;
269244
return this;
270245
}

APIJSON(Android)/APIJSON(ADT)/APIJSONApp/APIJSONApp/src/apijson/demo/client/server/model/Moment.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public class Moment extends BaseModel {
3434
private String content;
3535
private List<String> pictureList;
3636
private List<Long> praiseUserIdList;
37-
private List<Long> commentIdList;
3837

3938
public Moment() {
4039
super();
@@ -75,11 +74,5 @@ public Moment setPraiseUserIdList(List<Long> praiseUserIdList) {
7574
this.praiseUserIdList = praiseUserIdList;
7675
return this;
7776
}
78-
public List<Long> getCommentIdList() {
79-
return commentIdList;
80-
}
81-
public Moment setCommentIdList(List<Long> commentIdList) {
82-
this.commentIdList = commentIdList;
83-
return this;
84-
}
77+
8578
}

APIJSON(Android)/APIJSON(ADT)/APIJSONApp/APIJSONApp/src/apijson/demo/client/view/CommentContainerView.java

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414

1515
package apijson.demo.client.view;
1616

17+
import java.util.List;
18+
19+
import zuo.biao.library.base.BaseView;
20+
import zuo.biao.library.util.Log;
21+
import zuo.biao.library.util.StringUtil;
1722
import android.annotation.SuppressLint;
1823
import android.app.Activity;
1924
import android.content.res.Resources;
@@ -22,28 +27,25 @@
2227
import android.view.View.OnClickListener;
2328
import android.view.View.OnLongClickListener;
2429
import android.view.ViewGroup;
25-
26-
import java.util.ArrayList;
27-
import java.util.List;
28-
2930
import apijson.demo.client.R;
3031
import apijson.demo.client.model.CommentItem;
3132
import apijson.demo.client.view.CommentView.OnCommentClickListener;
32-
import zuo.biao.library.base.BaseView;
33-
import zuo.biao.library.util.Log;
34-
import zuo.biao.library.util.StringUtil;
3533

3634
/**评论容器
3735
* @author Lemon
3836
* @use
39-
CommentContainerView commentContainerView = new CommentContainerView(context, inflater);
40-
adapter中使用convertView = commentContainerView.getView();//[具体见.DemoAdapter] 或 其它类中使用
41-
containerView.addView(commentContainerView.getConvertView());
42-
commentContainerView.bindView(data);
43-
commentContainerView.setOnClickPictureListener(onClickPictureListener);//非必需
44-
commentContainerView.setOnDataChangedListener(onDataChangedListener);data = commentContainerView.getData();//非必需
45-
commentContainerView.setOnClickListener(onClickListener);//非必需
46-
...
37+
* <br> CommentContainerView commentContainerView = new CommentContainerView(context, resources);
38+
* <br> adapter中使用:[具体参考.DemoAdapter2(getView使用自定义View的写法)]
39+
* <br> convertView = commentContainerView.createView(inflater, position, viewType);
40+
* <br> commentContainerView.bindView(data, position, viewType);
41+
* <br> 或 其它类中使用:
42+
* <br> containerView.addView(commentContainerView.createView(inflater));
43+
* <br> commentContainerView.bindView(data);
44+
* <br> 然后
45+
* <br> commentContainerView.setOnCommentClickListener(onCommentClickListener);//非必需
46+
* <br> commentContainerView.setOnDataChangedListener(onDataChangedListener);data = commentContainerView.getData();//非必需
47+
* <br> commentContainerView.setOnClickListener(onClickListener);//非必需
48+
* <br> ...
4749
*/
4850
public class CommentContainerView extends BaseView<List<CommentItem>> {
4951
private static final String TAG = "CommentContainerView";
@@ -84,38 +86,14 @@ public View createView(LayoutInflater inflater) {
8486

8587
@Override
8688
public void bindView(List<CommentItem> list){
87-
llCommentContainerViewContainer.setVisibility(list == null || list.isEmpty() ? View.GONE : View.VISIBLE);
88-
if (list == null) {
89-
Log.w(TAG, "bindView data_ == null >> data_ = new List<CommentItem>();");
90-
list = new ArrayList<CommentItem>();
91-
}
9289
this.data = list;
9390

94-
// 评论
95-
setComment(list);
96-
}
97-
98-
99-
private int maxShowCount = 3;
100-
/**设置最多显示数量,超过则折叠
101-
* @param maxShowCount <= 0 ? 显示全部 : 超过则折叠
102-
*/
103-
public void setMaxShowCount(int maxShowCount) {
104-
this.maxShowCount = maxShowCount;
105-
}
106-
107-
108-
/**设置评论
109-
* @param list
110-
*/
111-
public void setComment(List<CommentItem> list) {
11291
int count = list == null ? 0 : list.size();
11392
boolean showMore = maxShowCount > 0 && count > maxShowCount;
11493

11594
tvCommentContainerViewMore.setVisibility(showMore ? View.VISIBLE : View.GONE);
116-
117-
llCommentContainerViewContainer.removeAllViews();
11895
llCommentContainerViewContainer.setVisibility(count <= 0 ? View.GONE : View.VISIBLE);
96+
llCommentContainerViewContainer.removeAllViews();//TODO 貌似比 只在count > 0时执行 性能更好,有待具体测试
11997

12098
if (count > 0) {
12199
if (showMore) {
@@ -125,10 +103,21 @@ public void setComment(List<CommentItem> list) {
125103
addCommentView(i, list.get(i));
126104
}
127105
}
106+
107+
}
128108

109+
110+
private int maxShowCount = 3;
111+
/**设置最多显示数量,超过则折叠
112+
* @param maxShowCount <= 0 ? 显示全部 : 超过则折叠
113+
* @must 在bindView前调用
114+
*/
115+
public void setMaxShowCount(int maxShowCount) {
116+
this.maxShowCount = maxShowCount;
129117
}
130118

131119

120+
132121
/**添加评论
133122
* @param index
134123
* @param comment

0 commit comments

Comments
 (0)