Files
assistant-android/app/src/main/java/com/gh/common/util/NewsUtils.java
huangzhuanghua efc19441cd 文件整理
2016-08-31 14:41:42 +08:00

84 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.android.volley.Response;
import com.android.volley.VolleyError;
import com.gh.base.AppController;
import com.gh.gamecenter.NewsActivity;
import com.gh.gamecenter.R;
import com.gh.gamecenter.entity.NewsDetailsEntity;
import com.gh.gamecenter.entity.NewsEntity;
import com.gh.gamecenter.volley.extended.JsonObjectExtendedRequest;
import org.json.JSONObject;
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, NewsActivity.class);
NewsDetailsEntity entity = new NewsDetailsEntity();
entity.setId(newsEntity.getId());
entity.setTitle(newsEntity.getTitle());
entity.setType(newsEntity.getType());
entity.setTime(newsEntity.getPublishOn());
intent.putExtra("entity", entity);
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 = "http://data.ghzhushou.com/news/stat?news_id=" + news_id;
JsonObjectExtendedRequest request = new JsonObjectExtendedRequest(
Request.Method.POST, url,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
request.setShouldCache(false);
AppController.addToRequestQueue(request, NewsUtils.class);
}
}