@@ -226,49 +226,54 @@ public String getText() {
226
226
}
227
227
228
228
public static class ChatHolder extends RecyclerView .ViewHolder {
229
- View mView ;
229
+ private final TextView mNameField ;
230
+ private final TextView mTextField ;
231
+ private final FrameLayout mLeftArrow ;
232
+ private final FrameLayout mRightArrow ;
233
+ private final RelativeLayout mMessageContainer ;
234
+ private final LinearLayout mMessage ;
235
+ private final int mGreen300 ;
236
+ private final int mGray300 ;
230
237
231
238
public ChatHolder (View itemView ) {
232
239
super (itemView );
233
- mView = itemView ;
240
+ mNameField = (TextView ) itemView .findViewById (R .id .name_text );
241
+ mTextField = (TextView ) itemView .findViewById (R .id .message_text );
242
+ mLeftArrow = (FrameLayout ) itemView .findViewById (R .id .left_arrow );
243
+ mRightArrow = (FrameLayout ) itemView .findViewById (R .id .right_arrow );
244
+ mMessageContainer = (RelativeLayout ) itemView .findViewById (R .id .message_container );
245
+ mMessage = (LinearLayout ) itemView .findViewById (R .id .message );
246
+ mGreen300 = ContextCompat .getColor (itemView .getContext (), R .color .material_green_300 );
247
+ mGray300 = ContextCompat .getColor (itemView .getContext (), R .color .material_gray_300 );
234
248
}
235
249
236
- public void setIsSender (Boolean isSender ) {
237
- FrameLayout left_arrow = (FrameLayout ) mView .findViewById (R .id .left_arrow );
238
- FrameLayout right_arrow = (FrameLayout ) mView .findViewById (R .id .right_arrow );
239
- RelativeLayout messageContainer = (RelativeLayout ) mView .findViewById (R .id .message_container );
240
- LinearLayout message = (LinearLayout ) mView .findViewById (R .id .message );
241
-
242
- int color ;
250
+ public void setIsSender (boolean isSender ) {
251
+ final int color ;
243
252
if (isSender ) {
244
- color = ContextCompat .getColor (mView .getContext (), R .color .material_green_300 );
245
-
246
- left_arrow .setVisibility (View .GONE );
247
- right_arrow .setVisibility (View .VISIBLE );
248
- messageContainer .setGravity (Gravity .END );
253
+ color = mGreen300 ;
254
+ mLeftArrow .setVisibility (View .GONE );
255
+ mRightArrow .setVisibility (View .VISIBLE );
256
+ mMessageContainer .setGravity (Gravity .END );
249
257
} else {
250
- color = ContextCompat .getColor (mView .getContext (), R .color .material_gray_300 );
251
-
252
- left_arrow .setVisibility (View .VISIBLE );
253
- right_arrow .setVisibility (View .GONE );
254
- messageContainer .setGravity (Gravity .START );
258
+ color = mGray300 ;
259
+ mLeftArrow .setVisibility (View .VISIBLE );
260
+ mRightArrow .setVisibility (View .GONE );
261
+ mMessageContainer .setGravity (Gravity .START );
255
262
}
256
263
257
- ((GradientDrawable ) message .getBackground ()).setColor (color );
258
- ((RotateDrawable ) left_arrow .getBackground ()).getDrawable ()
264
+ ((GradientDrawable ) mMessage .getBackground ()).setColor (color );
265
+ ((RotateDrawable ) mLeftArrow .getBackground ()).getDrawable ()
259
266
.setColorFilter (color , PorterDuff .Mode .SRC );
260
- ((RotateDrawable ) right_arrow .getBackground ()).getDrawable ()
267
+ ((RotateDrawable ) mRightArrow .getBackground ()).getDrawable ()
261
268
.setColorFilter (color , PorterDuff .Mode .SRC );
262
269
}
263
270
264
271
public void setName (String name ) {
265
- TextView field = (TextView ) mView .findViewById (R .id .name_text );
266
- field .setText (name );
272
+ mNameField .setText (name );
267
273
}
268
274
269
275
public void setText (String text ) {
270
- TextView field = (TextView ) mView .findViewById (R .id .message_text );
271
- field .setText (text );
276
+ mTextField .setText (text );
272
277
}
273
278
}
274
279
}
0 commit comments