81 lines
2.2 KiB
Java
81 lines
2.2 KiB
Java
package com.gh.common.util;
|
|
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
|
|
import com.android.volley.Request;
|
|
import com.gh.base.AppController;
|
|
import com.gh.common.constant.Config;
|
|
import com.gh.gamecenter.MessageDetailActivity;
|
|
import com.gh.gamecenter.NewsDetailActivity;
|
|
import com.gh.gamecenter.R;
|
|
import com.gh.gamecenter.entity.ConcernEntity;
|
|
import com.gh.gamecenter.entity.NewsEntity;
|
|
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
|
|
|
|
public class NewsUtils {
|
|
|
|
/**
|
|
* 根据新闻类型获取标签背景资源
|
|
*
|
|
* @param type
|
|
* @return
|
|
*/
|
|
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;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 启动新闻详情页面
|
|
*
|
|
* @param context
|
|
* @param newsEntity
|
|
* @param entrance
|
|
* @return
|
|
*/
|
|
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 startMessageActivity(Context context, ConcernEntity concernEntity, String entrance) {
|
|
AppController.put("ConcernEntity", concernEntity);
|
|
Intent intent = new Intent(context, MessageDetailActivity.class);
|
|
intent.putExtra("entrance", entrance);
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
context.startActivity(intent);
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* 统计阅读量
|
|
* @param news_id
|
|
*/
|
|
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);
|
|
}
|
|
|
|
}
|