-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathBlogFragment.java
More file actions
202 lines (174 loc) · 4.91 KB
/
Copy pathBlogFragment.java
File metadata and controls
202 lines (174 loc) · 4.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
package cn.eoe.app.view;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import cn.eoe.app.R;
import cn.eoe.app.biz.BlogsDao;
import cn.eoe.app.entity.BlogContentItem;
import cn.eoe.app.entity.BlogsCategoryListEntity;
import cn.eoe.app.entity.BlogsMoreResponse;
import cn.eoe.app.utils.ImageUtil;
/**
* 博客部分的Fragment
*
* @author wangxin
*
*/
public class BlogFragment extends BaseListFragment {
List<BlogContentItem> items_list = new ArrayList<BlogContentItem>();
private Activity mActivity;
private String more_url;
private BlogsCategoryListEntity loadMoreEntity;
private MyAdapter mAdapter;
public BlogFragment() {
}
private Handler mHandler = new Handler() {
public void handleMessage(android.os.Message msg) {
switch (msg.what) {
case 0:
more_url = loadMoreEntity.getMore_url();
mAdapter.appendToList(loadMoreEntity.getItems());
break;
}
onLoad();
};
};
public BlogFragment(Activity c, BlogsCategoryListEntity categorys) {
this.mActivity = c;
if (categorys != null) {
more_url = categorys.getMore_url();
this.items_list = categorys.getItems();
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
listview.setXListViewListener(this);
// construct the RelativeLayout
listview.setXListViewListener(this);
// construct the RelativeLayout
mAdapter = new MyAdapter();
mAdapter.appendToList(items_list);
listview.setAdapter(mAdapter);
listview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
BlogContentItem item = (BlogContentItem) mAdapter
.getItem(position - 1);
startDetailActivity(mActivity, item.getDetail_url(), "博客",
item.getTitle());
}
});
return view;
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
}
class MyAdapter extends BaseAdapter {
List<BlogContentItem> mList = new ArrayList<BlogContentItem>();
public MyAdapter() {
}
public void appendToList(List<BlogContentItem> lists) {
if (lists == null) {
return;
}
mList.addAll(lists);
notifyDataSetChanged();
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return mList.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return mList.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder;
BlogContentItem item = mList.get(position);
if (convertView == null) {
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.blogs_item_layout,
null);
holder.header_ = (TextView) convertView
.findViewById(R.id.tx_header_title);
holder.title_ = (TextView) convertView
.findViewById(R.id.txt_title);
holder.short_ = (TextView) convertView
.findViewById(R.id.txt_short_content);
holder.img_thu = (ImageView) convertView
.findViewById(R.id.img_thu);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.header_.setText(item.getName());
holder.title_.setText(item.getTitle());
holder.short_.setText(item.getShort_content());
String url = item.getHead_image_url().replaceAll("=small",
"=middle");
if (url == null || url.equals("")) {
holder.img_thu.setVisibility(View.GONE);
} else {
holder.img_thu.setVisibility(View.VISIBLE);
ImageUtil.setThumbnailView(url, holder.img_thu, mActivity,
callback1, false);
}
return convertView;
}
}
static class ViewHolder {
public TextView header_;
public TextView title_;
public TextView short_;
public ImageView img_thu;
}
@Override
public void onRefresh() {
// TODO Auto-generated method stub
onLoad();
}
@Override
public void onLoadMore() {
// TODO Auto-generated method stub
if (more_url==null || more_url.equals("")) {
mHandler.sendEmptyMessage(1);
return;
} else {
new Thread() {
@Override
public void run() {
BlogsMoreResponse response = new BlogsDao(mActivity)
.getMore(more_url);
if (response != null) {
loadMoreEntity = response.getResponse();
mHandler.sendEmptyMessage(0);
}
}
}.start();
}
}
}