/** * 时间显示格式 * * @param date * @return */ private String tranTime(Date date) { long span = (new Date().getTime() - date.getTime()) / 1000; if (span < 60) { return context.getResources().getString(R.string.time_just); } else if (span < 60 * 60) { return span / 60 + context.getResources().getString(R.string.time_minute_ago); } else if (span < 60 * 60 * 24) { int h = (int) span / 3600; // int m = (int) (span - h * 3600) / 60; return h + context.getResources().getString(R.string.time_hour) + context.getResources().getString(R.string.time_ago); } else if (span < 60 * 60 * 24 * 3) { int d = (int) (span / (60 * 60 * 24)); if (d == 1) return context.getResources().getString(R.string.time_yesterday); else return context.getResources().getString(R.string.time_day_before_yesterday); } return St.getDateString(date, "yyyy-MM-dd"); }
@Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = inflater.inflate(R.layout.xlistview_item, null); convertView.setTag(position); } Json item = data[position]; aq = new AQuery(convertView); // 查询数据是否已读,设置文字颜色 if (Db.findFromRead(item.getString("newsid"))) { aq.id(R.id.news_content) .textColor(context.getResources().getColor(R.color.news_content_read)); } else { aq.id(R.id.news_content).textColor(context.getResources().getColor(R.color.news_content)); } aq.id(R.id.main_layout).tag(item); aq.id(R.id.main_layout) .clicked( new OnClickListener() { @Override public void onClick(View v) { MainActivity.check_mask = false; Json item = (Json) v.getTag(); Intent intent = new Intent(context, ContentActivity.class); // 在本地记录为已浏览 // if (TextUtils.isEmpty(Db.getValue(item.getString("url") // + "read", "1"))) { // Db.setValue(item.getString("url") + "read", "1"); // } // 添加至已读表 // BaseTools.setReadNewsIds(item.getString("newsid")); intent.putExtra("url", item.getString("url")); intent.putExtra("json", item.toString()); intent.putExtra("back", 1); context.startActivity(intent); context.overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left); new Handler() .postDelayed( new Runnable() { @Override public void run() { notifyDataSetChanged(); } }, 1000); // St.onEvent(context, "点击新闻", // item.getString("title").replace(" ", " "), // item.getString("url"));// 统计----------------------- } }); if (WebClient.getAPNType(context) != -1) { // 网络是否可用 // .image(item.getString("image")); // aq.id(R.id.news_image).image(bm) aq.id(R.id.news_image).image(R.drawable.defaultpic); ImageLoader.image(aq.id(R.id.news_image).getImageView(), item.getString("image")); } else { aq.id(R.id.news_image).image(R.drawable.defaultpic); } aq.id(R.id.news_content).text(item.getString("title").replace(" ", " ")); // 显示日期或穿越标记 if (((TimeModeAP) context).getTimeModeAP()) { aq.id(R.id.news_time).background(R.drawable.item_time_travel); } else { aq.id(R.id.news_time).text(tranTime(St.getDate(item.getString("addtime")))); } ArrayList<Json> list = new ArrayList<Json>(); for (int i = 0; i < data.length; i++) { list.add(data[i]); } data = list.toArray(new Json[data.length]); setNewData(data); return convertView; }