package com.tejia.lijin.app.model;
|
|
import android.content.Context;
|
|
import com.google.gson.Gson;
|
import com.google.gson.GsonBuilder;
|
import com.google.gson.reflect.TypeToken;
|
import com.tejia.lijin.app.BasicTextHttpResponseHandler;
|
import com.tejia.lijin.app.ShoppingApi;
|
import com.tejia.lijin.app.contract.VipShopSpecialFgContract;
|
import com.tejia.lijin.app.entity.HotSearch;
|
|
import org.apache.http.Header;
|
import org.json.JSONObject;
|
|
import java.util.ArrayList;
|
|
/**
|
* 京东Fragment Model
|
*/
|
public class VipShopSpecialFgModel {
|
private Context mContext;
|
|
public VipShopSpecialFgModel(Context mContext) {
|
this.mContext = mContext;
|
}
|
|
/**
|
* 京东专题商品
|
*
|
* @param page 页码
|
* @param cid 分类ID
|
* @param callBack 回调
|
*/
|
public void getVipShopGoodsInfo(String page, String cid, final VipShopSpecialFgContract.VipShopSpecialFgCallBack callBack) {
|
ShoppingApi.getVipShopGoodsInfo(mContext, page, cid, new BasicTextHttpResponseHandler() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
if (jsonObject.optInt("code") == 0) {
|
Gson gson = new GsonBuilder().serializeNulls().create();
|
ArrayList<HotSearch> list = gson.fromJson(jsonObject.optJSONObject("data").optJSONArray("list").toString(),
|
new TypeToken<ArrayList<HotSearch>>() {
|
}.getType());
|
callBack.onSuccess(jsonObject);
|
}
|
}
|
|
@Override
|
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
|
super.onFailure(statusCode, headers, responseString, throwable);
|
callBack.onFail("请检查网络");
|
}
|
});
|
}
|
}
|