admin
2021-04-07 cbb88109494ffc7916f6639c20ce05c0cec941a9
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package com.lcjian.library.okhttp.callback;
 
import okhttp3.Call;
import okhttp3.Request;
import okhttp3.Response;
 
public abstract class Callback<T>
{
    /**
     * UI Thread
     *
     * @param request
     */
    public void onBefore(Request request, int id)
    {
    }
 
    /**
     * UI Thread
     *
     * @param
     */
    public void onAfter(int id)
    {
    }
 
    /**
     * UI Thread
     *
     * @param progress
     */
    public void inProgress(float progress, long total , int id)
    {
 
    }
 
    /**
     * if you parse reponse code in parseNetworkResponse, you should make this method return true.
     *
     * @param response
     * @return
     */
    public boolean validateReponse(Response response, int id)
    {
        return response.isSuccessful();
    }
 
    /**
     * Thread Pool Thread
     *
     * @param response
     */
    public abstract T parseNetworkResponse(Response response, int id) throws Exception;
 
    public abstract void onError(Call call, Exception e, int id);
 
    public abstract void onResponse(T response, int id);
 
 
    public static Callback CALLBACK_DEFAULT = new Callback()
    {
 
        @Override
        public Object parseNetworkResponse(Response response, int id) throws Exception
        {
            return null;
        }
 
        @Override
        public void onError(Call call, Exception e, int id)
        {
 
        }
 
        @Override
        public void onResponse(Object response, int id)
        {
 
        }
    };
 
}