-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathAuthServiceWrapper.java
42 lines (31 loc) · 1.38 KB
/
AuthServiceWrapper.java
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
package io.techery.sample.service;
import android.text.TextUtils;
import io.techery.janet.ActionHolder;
import io.techery.janet.ActionServiceWrapper;
import io.techery.janet.HttpActionService;
import io.techery.janet.JanetException;
import io.techery.sample.service.api.BaseAction;
import io.techery.sample.storage.PreferenceWrapper;
public class AuthServiceWrapper extends ActionServiceWrapper {
private final PreferenceWrapper prefs;
public AuthServiceWrapper(HttpActionService actionService, PreferenceWrapper prefs) {
super(actionService);
this.prefs = prefs;
}
@Override protected <A> boolean onInterceptSend(ActionHolder<A> holder) {
if (holder.action() instanceof BaseAction) {
String authToken = prefs.getToken();
if (!TextUtils.isEmpty(authToken)) {
((BaseAction) holder.action()).setToken(authToken);
}
}
return false;
}
@Override protected <A> void onInterceptCancel(ActionHolder<A> holder) {}
@Override protected <A> void onInterceptStart(ActionHolder<A> holder) {}
@Override protected <A> void onInterceptProgress(ActionHolder<A> holder, int progress) {}
@Override protected <A> void onInterceptSuccess(ActionHolder<A> holder) {}
@Override protected <A> boolean onInterceptFail(ActionHolder<A> holder, JanetException e) {
return false;
}
}