Skip to content

Commit 50cba8a

Browse files
committed
Client:新增CommentContainerView优化MomentView,CommentAdapter
1 parent e8728fa commit 50cba8a

9 files changed

Lines changed: 298 additions & 118 deletions

File tree

2 Bytes
Loading
-2 Bytes
Loading
28 Bytes
Loading
-28 Bytes
Loading
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
style="@style/ll_vertical_match_wrap" >
4+
5+
<LinearLayout
6+
android:id="@+id/llCommentContainerViewContainer"
7+
style="@style/ll_vertical_match_wrap" >
8+
</LinearLayout>
9+
10+
<TextView
11+
android:id="@+id/tvCommentContainerViewMore"
12+
style="@style/text_small_blue"
13+
android:layout_width="match_parent"
14+
android:background="@drawable/bg_item_to_alpha"
15+
android:gravity="left|center_vertical"
16+
android:paddingBottom="4dp"
17+
android:paddingLeft="8dp"
18+
android:paddingRight="8dp"
19+
android:paddingTop="4dp"
20+
android:text="查看所有" />
21+
22+
</LinearLayout>

‎APIJSON(Android)/APIJSON(ADT)/APIJSONApp/APIJSONApp/res/layout/moment_view.xml‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@
8989
style="@style/img_btn"
9090
android:layout_marginRight="18dp"
9191
android:background="@drawable/bg_item_to_alpha"
92-
android:src="@drawable/praised" />
92+
android:src="@drawable/praise" />
9393

9494
<ImageView
9595
android:id="@+id/ivMomentViewComment"
9696
style="@style/img_btn"
9797
android:background="@drawable/bg_item_to_alpha"
98-
android:src="@drawable/commented" />
98+
android:src="@drawable/comment" />
9999
</LinearLayout>
100100

101101
<LinearLayout
@@ -106,18 +106,6 @@
106106
android:visibility="gone" >
107107
</LinearLayout>
108108

109-
<TextView
110-
android:id="@+id/tvMomentViewCommentMore"
111-
style="@style/text_small_blue"
112-
android:layout_width="match_parent"
113-
android:background="@drawable/bg_item_to_alpha"
114-
android:gravity="left|center_vertical"
115-
android:paddingBottom="4dp"
116-
android:paddingLeft="8dp"
117-
android:paddingRight="8dp"
118-
android:paddingTop="4dp"
119-
android:text="查看所有"
120-
android:visibility="gone" />
121109
</LinearLayout>
122110
</LinearLayout>
123111

‎APIJSON(Android)/APIJSON(ADT)/APIJSONApp/APIJSONApp/src/apijson/demo/client/adapter/CommentAdapter.java‎

Lines changed: 42 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import apijson.demo.client.adapter.CommentAdapter.ItemView.OnCommentClickListener;
4242
import apijson.demo.client.adapter.CommentAdapter.ItemView.OnShowAllListener;
4343
import 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

Comments
 (0)