admin
2021-07-08 1764c1784a4cf1a6afd25fcf1a0eef6187a84218
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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.JdSpecialContract;
import com.tejia.lijin.app.entity.HotSearch;
 
import org.apache.http.Header;
import org.json.JSONObject;
 
import java.util.ArrayList;
 
/**
 * 拼多多activity Model
 */
public class PddSpecialModel {
    private Context mContext;
 
    public PddSpecialModel(Context mContext) {
        this.mContext = mContext;
    }
 
    /**
     * 京东专题分类
     *
     * @param callBack
     */
    public void getPddClass(final JdSpecialContract.JdSpecialCallBack callBack) {
        ShoppingApi.getPddsClass(mContext, 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(list, jsonObject);
                }
            }
 
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
                callBack.onFail("请检查网络");
            }
        });
    }
}