4141import apijson .demo .client .adapter .CommentAdapter .ItemView .OnCommentClickListener ;
4242import apijson .demo .client .adapter .CommentAdapter .ItemView .OnShowAllListener ;
4343import apijson .demo .client .model .CommentItem ;
44+ import apijson .demo .client .view .CommentContainerView ;
4445
4546/**评论列表
4647 * @author Lemon
@@ -134,7 +135,6 @@ public ItemView(Activity context, Resources resources) {
134135
135136
136137 public LinearLayout llCommentContainer ;
137- public TextView tvCommentMore ;
138138
139139 @ SuppressLint ("InflateParams" )
140140 @ Override
@@ -149,7 +149,6 @@ public View createView(LayoutInflater inflater) {
149149 tvCommentTime = (TextView ) findViewById (R .id .tvCommentTime );
150150
151151 llCommentContainer = findViewById (R .id .llCommentContainer );
152- tvCommentMore = findViewById (R .id .tvCommentMore , this );
153152
154153 return convertView ;
155154 }
@@ -183,7 +182,7 @@ public void onClick(View v) {
183182 case R .id .tvCommentName :
184183 toActivity (UserActivity .createIntent (context , data .getUser ().getId ()));
185184 break ;
186- case R .id .tvCommentMore :
185+ case R .id .tvCommentContainerViewMore :
187186 if (onShowAllListener != null ) {
188187 onShowAllListener .onShowAll (position , this , true );
189188 }
@@ -193,63 +192,56 @@ public void onClick(View v) {
193192 }
194193 }
195194
195+ public CommentContainerView commentContainerView ;
196196 /**显示子评论
197197 * @param data
198198 */
199199 @ SuppressLint ("InflateParams" )
200200 public void setChildComment () {
201- List <CommentItem > downList = data .getChildList ();
202- boolean isEmpty = downList == null || downList .isEmpty ();
201+ if (commentContainerView == null ) {
202+ commentContainerView = new CommentContainerView (context , resources );
203+ llCommentContainer .removeAllViews ();
204+ llCommentContainer .addView (commentContainerView .createView (inflater ));
203205
204- llCommentContainer .removeAllViews ();
205- tvCommentMore .setVisibility (View .GONE );
206-
207- if (isEmpty ) {
208- return ;
209- }
210-
211- if (showAll == false && downList .size () > 3 ) {
212- tvCommentMore .setVisibility (View .VISIBLE );
213- downList = downList .subList (0 , 3 );
214- }
215-
216- for (int i = 0 ; i < downList .size (); i ++) {
217- final int index = i ;
218-
219- TextView childComment = (TextView ) inflater .inflate (R .layout .comment_down_item , null );
220-
221- final CommentItem data = downList .get (i );
222- String name = StringUtil .getTrimedString (data .getUser ().getName ());
223- String content = StringUtil .getTrimedString (data .getComment ().getContent ());
224- childComment .setText (Html .fromHtml ("<font color=\" #009ed3\" >" + StringUtil .getString (name ) + "</font>"
225- + " 回复 " + "<font color=\" #009ed3\" >" + StringUtil .getString (data .getToUser ().getName ())
226- + "</font>" + " : " + content ));
227-
228- childComment .setOnClickListener (new OnClickListener () {
229- @ Override
230- public void onClick (View v ) {
231- onCommentClick (data , position , index , false );
232- }
233- });
234- childComment .setOnLongClickListener (new OnLongClickListener () {
235-
236- @ Override
237- public boolean onLongClick (View v ) {
238- onCommentClick (data , position , index , true );
239- return true ;
240- }
241- });
242-
243- llCommentContainer .addView (childComment );
206+ commentContainerView .setOnCommentClickListener (onCommentClickListener );
207+ commentContainerView .tvCommentContainerViewMore .setOnClickListener (this );
244208 }
209+
210+ commentContainerView .setMaxShowCount (showAll ? 0 : 3 );
211+ commentContainerView .bindView (data .getChildList ());
212+
213+ // for (int i = 0; i < downList.size(); i++) {
214+ // final int index = i;
215+ //
216+ // TextView childComment = (TextView) inflater.inflate(R.layout.comment_down_item, null);
217+ //
218+ // final CommentItem data = downList.get(i);
219+ // String name = StringUtil.getTrimedString(data.getUser().getName());
220+ // String content = StringUtil.getTrimedString(data.getComment().getContent());
221+ // childComment.setText(Html.fromHtml("<font color=\"#009ed3\">" + StringUtil.getString(name) + "</font>"
222+ // + " 回复 " + "<font color=\"#009ed3\">" + StringUtil.getString(data.getToUser().getName())
223+ // + "</font>" + " : " + content));
224+ //
225+ // childComment.setOnClickListener(new OnClickListener() {
226+ // @Override
227+ // public void onClick(View v) {
228+ // onCommentClick(data, position, index, false);
229+ // }
230+ // });
231+ // childComment.setOnLongClickListener(new OnLongClickListener() {
232+ //
233+ // @Override
234+ // public boolean onLongClick(View v) {
235+ // onCommentClick(data, position, index, true);
236+ // return true;
237+ // }
238+ // });
239+ //
240+ // llCommentContainer.addView(childComment);
241+ // }
245242
246243 }
247244
248- protected void onCommentClick (CommentItem item , int position , int index , boolean isLong ) {
249- if (onCommentClickListener != null ) {
250- onCommentClickListener .onCommentClick (item , position , index , isLong );
251- }
252- }
253245 }
254246
255247}
0 commit comments