1414
1515package apijson .demo .client .adapter ;
1616
17+ import android .app .Activity ;
18+ import android .view .ViewGroup ;
19+
1720import java .util .HashMap ;
1821import java .util .List ;
1922import java .util .Map ;
2023
21- import zuo .biao .library .base .BaseView ;
22- import zuo .biao .library .base .BaseViewAdapter ;
23- import zuo .biao .library .util .ImageLoaderUtil ;
24- import zuo .biao .library .util .StringUtil ;
25- import zuo .biao .library .util .TimeUtil ;
26- import android .annotation .SuppressLint ;
27- import android .app .Activity ;
28- import android .content .res .Resources ;
29- import android .text .Html ;
30- import android .view .LayoutInflater ;
31- import android .view .View ;
32- import android .view .View .OnClickListener ;
33- import android .view .View .OnLongClickListener ;
34- import android .view .ViewGroup ;
35- import android .widget .ImageView ;
36- import android .widget .LinearLayout ;
37- import android .widget .TextView ;
38- import apijson .demo .client .R ;
39- import apijson .demo .client .activity_fragment .UserActivity ;
40- import apijson .demo .client .adapter .CommentAdapter .ItemView ;
41- import apijson .demo .client .adapter .CommentAdapter .ItemView .OnCommentClickListener ;
42- import apijson .demo .client .adapter .CommentAdapter .ItemView .OnShowAllListener ;
4324import apijson .demo .client .model .CommentItem ;
44- import apijson .demo .client .view .CommentContainerView ;
25+ import apijson .demo .client .view .CommentItemView ;
26+ import apijson .demo .client .view .CommentItemView .OnCommentClickListener ;
27+ import apijson .demo .client .view .CommentItemView .OnShowAllListener ;
28+ import zuo .biao .library .base .BaseViewAdapter ;
4529
4630/**评论列表
4731 * @author Lemon
4832 */
49- public class CommentAdapter extends BaseViewAdapter <CommentItem , ItemView > {
33+ public class CommentAdapter extends BaseViewAdapter <CommentItem , CommentItemView > {
5034
5135
5236 private OnCommentClickListener onCommentClickListener ;
53- public CommentAdapter (Activity context , OnCommentClickListener onCommentClickListener ) {
37+
38+ public CommentAdapter (Activity context , OnCommentClickListener onCommentClickListener ) {
5439 super (context );
5540 this .onCommentClickListener = onCommentClickListener ;
5641 }
@@ -61,6 +46,7 @@ public long getItemId(int position) {
6146 }
6247
6348 private boolean showAll = false ;
49+
6450 public void setShowAll (boolean showAll ) {
6551 this .showAll = showAll ;
6652 }
@@ -72,176 +58,25 @@ public synchronized void refresh(List<CommentItem> list) {
7258 }
7359
7460 @ Override
75- public ItemView createView (int position , ViewGroup parent ) {
76- return new ItemView (context , resources )
77- .setOnCommentClickListener (onCommentClickListener )
78- .setOnShowAllListener (new OnShowAllListener () {
79- @ Override
80- public void onShowAll (int position , ItemView bv , boolean show ) {
81- showAllMap .put (position , show );
82- bindView (position , bv );
83- }
84- });
61+ public CommentItemView createView (int position , ViewGroup parent ) {
62+ return new CommentItemView (context , resources )
63+ .setOnCommentClickListener (onCommentClickListener )
64+ .setOnShowAllListener (new OnShowAllListener () {
65+ @ Override
66+ public void onShowAll (int position , CommentItemView bv , boolean show ) {
67+ showAllMap .put (position , show );
68+ bindView (position , bv );
69+ }
70+ });
8571 }
8672
8773 private Map <Integer , Boolean > showAllMap = new HashMap <>();
74+
8875 @ Override
89- public void bindView (int position , ItemView bv ) {
76+ public void bindView (int position , CommentItemView bv ) {
9077 //true : showAllMap.get(position)怎么搞都崩溃
9178 bv .setShowAll (showAll ? Boolean .valueOf (true ) : showAllMap .get (position ));
9279 super .bindView (position , bv );
9380 }
9481
95-
96- public static class ItemView extends BaseView <CommentItem > implements OnClickListener {
97-
98- /**点击评论监听回调
99- */
100- public interface OnCommentClickListener {
101- void onCommentClick (CommentItem item , int position , int index , boolean isLong );
102- }
103-
104- /**显示更多监听回调
105- * @author Lemon
106- */
107- public interface OnShowAllListener {
108- public void onShowAll (int position , ItemView bv , boolean show );
109- }
110-
111- private OnCommentClickListener onCommentClickListener ;
112- public ItemView setOnCommentClickListener (OnCommentClickListener onCommentClickListener ) {
113- this .onCommentClickListener = onCommentClickListener ;
114- return this ;
115- }
116-
117- private OnShowAllListener onShowAllListener ;
118- public ItemView setOnShowAllListener (OnShowAllListener onShowAllListener ) {
119- this .onShowAllListener = onShowAllListener ;
120- return this ;
121- }
122-
123-
124-
125- public ItemView (Activity context , Resources resources ) {
126- super (context , resources );
127- }
128-
129- private LayoutInflater inflater ;
130-
131- public ImageView ivCommentHead ;
132- public TextView tvCommentName ;
133- public TextView tvCommentContent ;
134- public TextView tvCommentTime ;
135-
136-
137- public LinearLayout llCommentContainer ;
138-
139- @ SuppressLint ("InflateParams" )
140- @ Override
141- public View createView (LayoutInflater inflater ) {
142- this .inflater = inflater ;
143- convertView = inflater .inflate (R .layout .comment_main_item , null );
144-
145- ivCommentHead = findViewById (R .id .ivCommentHead , this );
146-
147- tvCommentName = (TextView ) findViewById (R .id .tvCommentName , this );
148- tvCommentContent = (TextView ) findViewById (R .id .tvCommentContent );
149- tvCommentTime = (TextView ) findViewById (R .id .tvCommentTime );
150-
151- llCommentContainer = findViewById (R .id .llCommentContainer );
152-
153- return convertView ;
154- }
155-
156-
157- private boolean showAll = false ;
158- public void setShowAll (Boolean showAll ) {
159- this .showAll = showAll == null ? false : showAll ;
160- }
161-
162- @ Override
163- public void bindView (CommentItem data ){
164- this .data = data ;
165-
166- String name = StringUtil .getTrimedString (data .getUser ().getName ());
167- String content = StringUtil .getTrimedString (data .getComment ().getContent ());
168-
169- tvCommentName .setText ("" + name );
170- tvCommentContent .setText ("" + content );
171- tvCommentTime .setText ("" + TimeUtil .getSmartDate (data .getDate ()));
172- ImageLoaderUtil .loadImage (ivCommentHead , data .getUser ().getHead (), ImageLoaderUtil .TYPE_OVAL );
173-
174- setChildComment ();
175- }
176-
177-
178- @ Override
179- public void onClick (View v ) {
180- switch (v .getId ()) {
181- case R .id .ivCommentHead :
182- case R .id .tvCommentName :
183- toActivity (UserActivity .createIntent (context , data .getUser ().getId ()));
184- break ;
185- case R .id .tvCommentContainerViewMore :
186- if (onShowAllListener != null ) {
187- onShowAllListener .onShowAll (position , this , true );
188- }
189- break ;
190- default :
191- break ;
192- }
193- }
194-
195- public CommentContainerView commentContainerView ;
196- /**显示子评论
197- * @param data
198- */
199- @ SuppressLint ("InflateParams" )
200- public void setChildComment () {
201- if (commentContainerView == null ) {
202- commentContainerView = new CommentContainerView (context , resources );
203- llCommentContainer .removeAllViews ();
204- llCommentContainer .addView (commentContainerView .createView (inflater ));
205-
206- commentContainerView .setOnCommentClickListener (onCommentClickListener );
207- commentContainerView .tvCommentContainerViewMore .setOnClickListener (this );
208- }
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- // }
242-
243- }
244-
245- }
246-
247- }
82+ }
0 commit comments