103 lines
3.0 KiB
Java
103 lines
3.0 KiB
Java
package com.gh.common.util;
|
|
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.graphics.Color;
|
|
import android.widget.TextView;
|
|
|
|
import com.android.volley.Request;
|
|
import com.gh.base.AppController;
|
|
import com.gh.common.constant.Config;
|
|
import com.gh.gamecenter.NewsDetailActivity;
|
|
import com.gh.gamecenter.R;
|
|
import com.gh.gamecenter.entity.NewsEntity;
|
|
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
|
|
|
|
import java.util.List;
|
|
|
|
public class NewsUtils {
|
|
|
|
/**
|
|
* 根据新闻类型获取标签背景资源
|
|
*/
|
|
public static int getDrawableIdByType(String type) {
|
|
if ("活动".equals(type) || "高阶".equals(type)) {
|
|
return R.drawable.textview_red_up;
|
|
} else if ("公告".equals(type) || "中期".equals(type)) {
|
|
return R.drawable.textview_orange_up;
|
|
} else if ("新游".equals(type)) {
|
|
return R.drawable.textview_green_up;
|
|
} else {
|
|
return R.drawable.textview_blue_up;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 启动新闻详情页面
|
|
*/
|
|
public static void startNewsActivity(Context context, NewsEntity newsEntity, String entrance) {
|
|
Intent intent = new Intent(context, NewsDetailActivity.class);
|
|
intent.putExtra("id", newsEntity.getId());
|
|
intent.putExtra("title", newsEntity.getTitle());
|
|
intent.putExtra("type", newsEntity.getType());
|
|
intent.putExtra("entrance", entrance);
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
context.startActivity(intent);
|
|
}
|
|
|
|
/**
|
|
* 统计阅读量
|
|
*/
|
|
public static void statNewsViews(String news_id) {
|
|
String url = Config.DATA_HOST + "news/stat?news_id=" + news_id;
|
|
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
|
|
Request.Method.POST, url, null, null);
|
|
request.setShouldCache(false);
|
|
AppController.addToRequestQueue(request);
|
|
}
|
|
|
|
/**
|
|
* 去除与重复sourceList相同的数据
|
|
*/
|
|
public static List<NewsEntity> removeDuplicateData(List<NewsEntity> sourceList, List<NewsEntity> rawList) {
|
|
if (sourceList == null || sourceList.isEmpty()
|
|
|| rawList == null || rawList.isEmpty()) {
|
|
return rawList;
|
|
}
|
|
String id;
|
|
for (int i = 0; i < rawList.size(); i++) {
|
|
id = rawList.get(i).getId();
|
|
for (NewsEntity newsEntity : sourceList) {
|
|
if (id.equals(newsEntity.getId())) {
|
|
rawList.remove(i);
|
|
i--;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return rawList;
|
|
}
|
|
|
|
/**
|
|
* 设置新闻类型
|
|
*/
|
|
public static void setNewsType(TextView textView, String type) {
|
|
textView.setText(type);
|
|
textView.setTextColor(Color.WHITE);
|
|
if ("活动".equals(type)) {
|
|
textView.setBackgroundResource(R.drawable.textview_orange_style);
|
|
} else if ("公告".equals(type)) {
|
|
textView.setBackgroundResource(R.drawable.textview_red_style);
|
|
} else if ("评测".equals(type)) {
|
|
textView.setBackgroundResource(R.drawable.textview_red_style);
|
|
} else if ("杂谈".equals(type)) {
|
|
textView.setBackgroundResource(R.drawable.textview_orange_style);
|
|
} else if ("专题".equals(type)) {
|
|
textView.setBackgroundResource(R.drawable.textview_blue_style);
|
|
} else {
|
|
textView.setBackgroundResource(R.drawable.textview_blue_style);
|
|
}
|
|
}
|
|
|
|
}
|