6
6
import android .support .v7 .widget .RecyclerView ;
7
7
import android .text .Html ;
8
8
import android .text .TextUtils ;
9
+ import android .view .LayoutInflater ;
9
10
import android .view .View ;
10
11
import android .view .ViewGroup ;
11
12
import android .widget .LinearLayout ;
26
27
public class TopicReplyAdapter extends BaseAdapter <TopicReplyEntity > {
27
28
28
29
public static String TAG = "TopicReplyAdapter" ;
30
+ private final int VIEW_ITEM = 1 ;
31
+ private final int VIEW_DELETE_ITEM = 0 ;
29
32
30
33
public TopicReplyAdapter (Context context ) {
31
34
super (context );
32
35
}
33
36
37
+
38
+ @ Override
39
+ public int getItemViewType (int position ) {
40
+ return mItems .get (position ).isDeleted () ? VIEW_DELETE_ITEM : VIEW_ITEM ;
41
+ }
42
+
34
43
@ Override
35
44
public RecyclerView .ViewHolder onCreateViewHolder (ViewGroup parent , int viewType ) {
36
- View view = View .inflate (parent .getContext (), R .layout .list_item_reply , null );
37
- return new ReplyViewHolder (view );
45
+ if (viewType == VIEW_ITEM ) {
46
+ View view = View .inflate (parent .getContext (), R .layout .list_item_reply , null );
47
+ return new ReplyViewHolder (view );
48
+ } else {
49
+ View view = LayoutInflater .from (parent .getContext ()).inflate (
50
+ R .layout .list_item_delete_reply , parent , false );
51
+ return new DeleteFloorHolder (view );
52
+ }
53
+
38
54
}
39
55
40
56
@ Override
41
57
public void onBindViewHolder (RecyclerView .ViewHolder viewHolder , int position ) {
42
- ReplyViewHolder holder = (ReplyViewHolder ) viewHolder ;
43
58
44
- TopicReplyEntity topicReplyEntity = mItems .get (position );
45
59
46
- if (topicReplyEntity .isDeleted ()) {
47
- holder .userAvatar .setVisibility (View .INVISIBLE );
48
- holder .topicItemAuthor .setVisibility (View .INVISIBLE );
49
- holder .topicTime .setVisibility (View .INVISIBLE );
50
- holder .praiseReplyLayout .setVisibility (View .INVISIBLE );
51
- holder .topicItemBody .setText ("该楼层已被删除" );
52
- holder .topicItemBody .getPaint ().setFlags (Paint .STRIKE_THRU_TEXT_FLAG ); //中划线
53
- } else {
60
+ if (viewHolder instanceof ReplyViewHolder ) {
61
+ TopicReplyEntity topicReplyEntity = mItems .get (position );
62
+ ReplyViewHolder holder = (ReplyViewHolder ) viewHolder ;
54
63
holder .praiseReplyLayout .setVisibility (View .VISIBLE );
55
64
holder .userAvatar .setVisibility (View .VISIBLE );
56
65
holder .topicItemAuthor .setVisibility (View .VISIBLE );
@@ -63,9 +72,16 @@ public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
63
72
holder .topicItemBody .getPaint ().setFlags (0 );
64
73
holder .userAvatar .setImageURI (Uri .parse (Config .getImageUrl (topicReplyEntity .getUser ().getAvatar_url ())));
65
74
66
- if (position == mItems .size () - 1 && mListener != null ) {
67
- mListener .onListEnded ();
68
- }
75
+ } else {
76
+ DeleteFloorHolder holder = (DeleteFloorHolder ) viewHolder ;
77
+ holder .topicItemBody .setText ("该楼层已被删除" );
78
+ holder .topicItemBody .getPaint ().setFlags (Paint .STRIKE_THRU_TEXT_FLAG ); //中划线
79
+
80
+
81
+ }
82
+
83
+ if (position == mItems .size () - 1 && mListener != null ) {
84
+ mListener .onListEnded ();
69
85
}
70
86
}
71
87
@@ -102,4 +118,17 @@ public ReplyViewHolder(View itemView) {
102
118
103
119
}
104
120
121
+ public static class DeleteFloorHolder extends RecyclerView .ViewHolder {
122
+
123
+
124
+ @ Bind (R .id .id_topic_item_content )
125
+ TextView topicItemBody ;
126
+
127
+ public DeleteFloorHolder (View itemView ) {
128
+ super (itemView );
129
+ ButterKnife .bind (this , itemView );
130
+ }
131
+ }
132
+
133
+
105
134
}
0 commit comments