11package cn .jiguang .imui .messages .viewholder ;
22
33import android .support .v7 .widget .RecyclerView ;
4+ import android .text .TextUtils ;
45import android .view .View ;
56import android .widget .TextView ;
67
8+ import java .text .DecimalFormat ;
9+
710import cn .jiguang .imui .R ;
811import cn .jiguang .imui .commons .models .IBankTransfer ;
912import cn .jiguang .imui .commons .models .IMessage ;
@@ -17,27 +20,53 @@ public class BankTransferViewHolder<MESSAGE extends IMessage> extends AvatarView
1720
1821 private TextView value ;
1922 private TextView comments ;
20-
23+ private View layoutTop ;
2124
2225 public BankTransferViewHolder (RecyclerView .Adapter adapter , View itemView , boolean isSender ) {
2326 super (adapter , itemView , isSender );
2427 value = (TextView ) itemView .findViewById (R .id .bank_transfer_value );
2528 comments = (TextView ) itemView .findViewById (R .id .bank_transfer_comments );
26-
29+ layoutTop = itemView . findViewById ( R . id . layout_top );
2730 }
2831
2932 @ Override
3033 public void onBind (final MESSAGE message ) {
3134 super .onBind (message );
3235 IBankTransfer extend = getExtend (message );
3336 if (extend != null ) {
34- value .setText (extend .getAmount ());
35- comments .setText (extend .getComments ());
37+ value .setText (formatAmount (extend .getAmount ()));
38+ if (TextUtils .isEmpty (extend .getComments ())) {
39+ comments .setText ("飞马转账" );
40+ } else {
41+ comments .setText (extend .getComments ());
42+ }
43+ }
44+ layoutTop .setOnClickListener (new View .OnClickListener () {
45+ @ Override
46+ public void onClick (View v ) {
47+ if (mMsgClickListener != null ) {
48+ mMsgClickListener .onMessageClick (message );
49+ }
50+ }
51+ });
52+ }
53+
54+ final DecimalFormat format = new DecimalFormat ("#.00" );
55+
56+ String formatAmount (String amount ) {
57+
58+ try {
59+ return format .format (Integer .valueOf (amount )) + "元" ;
60+ } catch (NumberFormatException e ) {
61+ e .printStackTrace ();
62+ return amount + "元" ;
3663 }
3764 }
3865
3966 @ Override
4067 public void applyStyle (MessageListStyle style ) {
4168 super .applyStyle (style );
69+ // layout.getLayoutParams().width = (int) (style.getWindowWidth() * 0.65);
70+ layoutTop .setBackground (style .getRedPacketTopDrawable ());
4271 }
4372}
0 commit comments