1 package com
.weibo
.view
;
6 import android
.content
.Context
;
7 import android
.graphics
.drawable
.Drawable
;
8 import android
.text
.method
.LinkMovementMethod
;
9 import android
.view
.LayoutInflater
;
10 import android
.view
.View
;
11 import android
.view
.ViewGroup
;
12 import android
.widget
.ArrayAdapter
;
13 import android
.widget
.ImageView
;
14 import android
.widget
.ListView
;
15 import android
.widget
.TextView
;
17 import com
.weibo
.json
.Statuses
;
18 import com
.weibo
.sina
.R
;
19 import com
.weibo
.util
.MD5
;
20 import com
.weibo
.util
.Util
;
22 public class StatusAdapter
extends ArrayAdapter
<Statuses
> {
23 private List
<Statuses
> mFriendsTimeline
;
25 private Context mContext
;
26 static final String TAG
= "StatusAdapter";
27 private ListView mListView
;
29 public StatusAdapter(Context context
, int resource
, List
<Statuses
> objects
,
31 super(context
, resource
, objects
);
32 mFriendsTimeline
= objects
;
39 public View
getView(int position
, View convertView
, ViewGroup parent
) {
40 View row
= convertView
;
44 LayoutInflater inflater
= (LayoutInflater
) mContext
45 .getSystemService(Context
.LAYOUT_INFLATER_SERVICE
);
47 row
= inflater
.inflate(mLayout
, parent
, false);
48 // data =mFriendsTimeline.get(position);
51 // data = (Status) row.getTag();
53 data
= mFriendsTimeline
.get(position
);
54 //Log.e(TAG,"Mid = "+data.getMid()+"id = "+data.getId()+" ");
55 TextView tmp
= (TextView
) row
.findViewById(R
.id
.user_name
);
56 tmp
.setText("@" + data
.getUser().getName());
57 Util
.addLink(tmp
, true);
59 tmp
= (TextView
) row
.findViewById(R
.id
.post_time
);
61 tmp
.setText(Util
.getPastTime(new Date(data
.getCreated_at())));
63 tmp
= (TextView
) row
.findViewById(R
.id
.content
);
65 tmp
.setText(data
.getText());
66 ImageView imageView
=null;
68 Drawable imageDrawable
=null;
69 Util
.addLink(tmp
, false);
70 if (data
.getRetweeted_status() != null) {
71 View t
= row
.findViewById(R
.id
.rt_layout
);
72 t
.setVisibility(View
.VISIBLE
);
73 tmp
= (TextView
) row
.findViewById(R
.id
.rt_reason
);
74 tmp
.setText(data
.getRetweeted_status().getUser().getName() + "\n"
75 + data
.getRetweeted_status().getText());
76 Util
.addLink(tmp
, false);
77 tmp
.setMovementMethod(LinkMovementMethod
.getInstance());
78 // imageView = (ImageView) row.findViewById(R.id.rt_image);
79 // if (data.getRetweeted_status().getThumbnail_pic().length()>0) {
80 // imageView.setImageResource(R.drawable.preview_pic_loading);
81 // imageView.setVisibility(View.VISIBLE);
82 // key = MD5.getMD5(data.getRetweeted_status().getThumbnail_pic().getBytes());
83 // imageDrawable = Util.loadImage(key, data.getRetweeted_status().getThumbnail_pic(),getContext(),this);
84 // if (imageDrawable != null)
85 // imageView.setImageDrawable(imageDrawable);
87 // imageView.setVisibility(View.GONE);
90 View t
= row
.findViewById(R
.id
.rt_layout
);
91 t
.setVisibility(View
.GONE
);
94 imageView
= (ImageView
) row
.findViewById(R
.id
.face
);
96 // face.setTag(data.getUser().getProfileImageURL().toString());
98 // if(data.getThumbnail_pic()!=null){
99 // //Log.e(TAG, data.getThumbnail_pic());
100 // //Log.e(TAG, "MD5="+MD5.getMD5(data.getThumbnail_pic().getBytes()));
102 key
= MD5
.getMD5(data
.getUser().getProfile_image_url().getBytes());
103 imageDrawable
= Util
.loadImage(key
, data
.getUser().getProfile_image_url(),getContext(),this);
104 if (imageDrawable
!= null)
105 imageView
.setBackgroundDrawable(imageDrawable
);
107 imageView
.setBackgroundResource(R
.drawable
.face
);
110 imageView
= (ImageView
) row
.findViewById(R
.id
.image
);
111 if (data
.getThumbnail_pic()!=null&&data
.getThumbnail_pic().length()>0) {
112 imageView
.setImageResource(R
.drawable
.preview_pic_loading
);
113 imageView
.setVisibility(View
.VISIBLE
);
114 key
= MD5
.getMD5(data
.getThumbnail_pic().getBytes());
115 imageDrawable
= Util
.loadImage(key
, data
.getThumbnail_pic(),getContext(),this);
116 if (imageDrawable
!= null)
117 imageView
.setImageDrawable(imageDrawable
);
119 imageView
.setVisibility(View
.GONE
);
122 // if (cachedImage == null) {
123 // face.setImageResource(R.drawable.face);
125 // face.setImageDrawable(cachedImage);
127 // row.setPressed(true);