This repository was archived by the owner on Jul 28, 2026. It is now read-only.
forked from skokourov/FaceIdDemo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractFaceIdCall.java
More file actions
104 lines (80 loc) · 3.13 KB
/
Copy pathAbstractFaceIdCall.java
File metadata and controls
104 lines (80 loc) · 3.13 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package com.ipoint.faceid.lib;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import org.json.JSONObject;
/**
* Created by spe on 07.02.2017.
*/
public abstract class AbstractFaceIdCall {
public static class FaceIdCallException extends Exception {
public FaceIdCallException(String message) {
super(message);
}
public FaceIdCallException(String message, Throwable throwable) {
super(message, throwable);
}
}
interface Callback {
void onSuccess(CallResult result);
void onError(String error);
}
public abstract static class CallResult {
}
private Token token;
private JSONObject params;
private String url;
private RequestQueue queue;
private Callback callback;
public AbstractFaceIdCall(Token token, JSONObject params, String url, RequestQueue queue, Callback callback) {
this.token = token;
this.params = params;
this.url = url;
this.queue = queue;
this.callback = callback;
}
public void call() {
callApi(true);
}
protected void callApi(final boolean firstCall) {
FaceIdRequest request = new FaceIdRequest(url, params, token.getAccessToken(),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
callback.onSuccess(processResponse(response));
} catch (Exception e) {
callback.onError(e.getMessage());
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
callback.onError("Http error. Code = " + error.networkResponse.statusCode +
", data = " + String.valueOf(error.networkResponse.data));
}
},
new FaceIdRequest.TokenExpiredListener() {
@Override
public void onTokenExpired() {
if (firstCall) {
token.refreshToken(new Token.ReadyCallback() {
@Override
public void onReady() {
callApi(false);
}
@Override
public void onError(String error) {
callback.onError("Auth error token expired and refresh token failed.");
}
});
} else {
callback.onError("Auth error token expired after call refresh token.");
}
}
});
queue.add(request);
}
protected abstract CallResult processResponse(JSONObject response) throws FaceIdCallException;
}