199 lines
5.4 KiB
Java
199 lines
5.4 KiB
Java
package cn.shangyu.gdxzExpert.adapter;
|
|
|
|
import static com.netease.nim.uikit.common.util.sys.TimeUtil.isSameYear;
|
|
|
|
import android.content.Context;
|
|
import android.text.TextUtils;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
import android.widget.BaseAdapter;
|
|
import android.widget.ImageView;
|
|
import android.widget.TextView;
|
|
|
|
import com.nostra13.universalimageloader.core.ImageLoader;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
|
|
import cn.shangyu.gdxzExpert.R;
|
|
import cn.shangyu.gdxzExpert.bean.NewListBean.NewsList;
|
|
import cn.shangyu.gdxzExpert.utils.CommonUtil;
|
|
import cn.shangyu.gdxzExpert.utils.ImageOptions;
|
|
import cn.shangyu.gdxzExpert.utils.StringUtil;
|
|
import cn.shangyu.gdxzExpert.utils.Url;
|
|
|
|
/**
|
|
* 新闻适配器
|
|
*
|
|
* 类名称:NewsAdapter 类描述:TODO 创建人:苏三元 时间:2015-9-24 下午3:12:40 版权:河南商宇科技有限公司--版权所有
|
|
* (c) 2015
|
|
*
|
|
*/
|
|
public class NewsAdapter extends BaseAdapter {
|
|
|
|
private Context context;
|
|
private List<NewsList> newsList;
|
|
|
|
public NewsAdapter(Context context) {
|
|
this.context = context;
|
|
// this.newsList = newsList;
|
|
}
|
|
|
|
@Override
|
|
public int getCount() {
|
|
return newsList.size();
|
|
}
|
|
|
|
public void getDatas(ArrayList<NewsList> newsList) {
|
|
this.newsList = newsList;
|
|
}
|
|
|
|
@Override
|
|
public View getView(int position, View convertView, ViewGroup parent) {
|
|
NewsViewHolder mHolder = null;
|
|
if (convertView == null) {
|
|
if(CommonUtil.BigModule())
|
|
{
|
|
convertView = View.inflate(context, R.layout.item_news_big, null);
|
|
}
|
|
else
|
|
{
|
|
convertView = View.inflate(context, R.layout.item_news, null);
|
|
}
|
|
|
|
mHolder = new NewsViewHolder();
|
|
mHolder.ivImage = (ImageView) convertView
|
|
.findViewById(R.id.iv_news_image);
|
|
mHolder.tvTitle = (TextView) convertView
|
|
.findViewById(R.id.tv_news_title);
|
|
mHolder.tvDate = (TextView) convertView
|
|
.findViewById(R.id.tv_news_date);
|
|
mHolder.tv_Now = (TextView) convertView
|
|
.findViewById(R.id.tv_news_now);
|
|
mHolder.tvSummary = (TextView) convertView
|
|
.findViewById(R.id.tv_news_summary);
|
|
// 点赞阅读
|
|
mHolder.tvdianzannum = (TextView) convertView
|
|
.findViewById(R.id.tv_dianzan_count);
|
|
mHolder.tvreadnum = (TextView) convertView
|
|
.findViewById(R.id.tv_read_count);
|
|
convertView.setTag(mHolder);
|
|
} else {
|
|
mHolder = (NewsViewHolder) convertView.getTag();
|
|
}
|
|
|
|
// 给控件赋值.
|
|
NewsList news = newsList.get(position);
|
|
mHolder.tvTitle.setText(news.title);
|
|
|
|
if (!TextUtils.isEmpty(news.createDate)
|
|
&& news.createDate.length() > 10) {
|
|
if(inNow(news.createDate.substring(0, 10))){
|
|
mHolder.tvDate.setVisibility(View.GONE);
|
|
mHolder.tv_Now.setVisibility(View.VISIBLE);
|
|
}else{
|
|
mHolder.tv_Now.setVisibility(View.GONE);
|
|
mHolder.tvDate.setVisibility(View.VISIBLE);
|
|
if(isSameYear(news.createDate.substring(0, 4)))
|
|
{
|
|
mHolder.tvDate.setText(news.createDate.substring(5, 10));
|
|
}
|
|
else
|
|
{
|
|
mHolder.tvDate.setText(news.createDate.substring(0, 10));
|
|
}
|
|
|
|
}
|
|
|
|
} else if (!TextUtils.isEmpty(news.createDate)) {
|
|
mHolder.tvDate.setText(news.createDate);
|
|
}
|
|
if (!TextUtils.isEmpty(news.headImg)) {
|
|
ImageLoader.getInstance().displayImage(Url.urlHtml + news.headImg,
|
|
mHolder.ivImage,
|
|
ImageOptions.getImageOptions(R.drawable.default_news_iv));
|
|
} else {
|
|
mHolder.ivImage.setImageResource(R.drawable.default_news_iv);
|
|
}
|
|
if (!StringUtil.isEmpty(news.summary)) {
|
|
mHolder.tvSummary.setText(news.summary);
|
|
} else {
|
|
mHolder.tvSummary.setText("");
|
|
}
|
|
|
|
// 点赞和阅读量
|
|
if (!TextUtils.isEmpty(news.agreenum)) {
|
|
Double agree = Double.parseDouble(news.agreenum);
|
|
if (agree > 10000) {
|
|
double agreeNum = (double) (Math.round((double) agree / 1000) / 10.0);
|
|
mHolder.tvdianzannum.setText(agreeNum + "万");
|
|
} else {
|
|
mHolder.tvdianzannum.setText(news.agreenum);
|
|
}
|
|
} else {
|
|
mHolder.tvdianzannum.setText("");
|
|
}
|
|
if (!TextUtils.isEmpty(news.readnum)) {
|
|
Double read = Double.parseDouble(news.readnum);
|
|
if (read > 10000) {
|
|
double readNum = (double) (Math.round((double) read / 1000) / 10.0);
|
|
mHolder.tvreadnum.setText(readNum + "万");
|
|
if(CommonUtil.BigModule())
|
|
{
|
|
mHolder.tvreadnum.setText(readNum + "万人观看");
|
|
}
|
|
} else {
|
|
mHolder.tvreadnum.setText(news.readnum);
|
|
if(CommonUtil.BigModule())
|
|
{
|
|
mHolder.tvreadnum.setText(news.readnum + "人观看");
|
|
}
|
|
}
|
|
} else {
|
|
mHolder.tvreadnum.setText("");
|
|
}
|
|
if(CommonUtil.BigModule())
|
|
{
|
|
mHolder.tvSummary.setVisibility(View.GONE);
|
|
// mHolder.tv_Now.setVisibility(View.GONE);
|
|
}
|
|
return convertView;
|
|
}
|
|
|
|
@Override
|
|
public Object getItem(int position) {
|
|
// TODO Auto-generated method stub
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
public long getItemId(int position) {
|
|
// TODO Auto-generated method stub
|
|
return 0;
|
|
}
|
|
|
|
private class NewsViewHolder {
|
|
|
|
public TextView tvreadnum;
|
|
public TextView tvdianzannum;
|
|
public TextView tvSummary;
|
|
public ImageView ivImage;
|
|
public TextView tvTitle;
|
|
public TextView tvDate;
|
|
public TextView tv_Now;
|
|
}
|
|
|
|
public boolean inNow(String date) {
|
|
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
String ds1 = formatter.format(new Date());
|
|
if (date.equals(ds1)) {
|
|
return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
}
|