Files
assistant-android/app/src/main/java/com/gh/common/util/NewsUtils.java
2016-09-14 15:59:18 +08:00

68 lines
1.9 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.NewsDetailActivity;
import com.gh.gamecenter.R;
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, 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);
}
/**
* 统计阅读量
* @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, null, null);
request.setShouldCache(false);
AppController.addToRequestQueue(request, NewsUtils.class);
}
}