-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathRNFyberUserModule.java
More file actions
61 lines (53 loc) · 1.97 KB
/
RNFyberUserModule.java
File metadata and controls
61 lines (53 loc) · 1.97 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
package co.squaretwo.rnfyber;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import com.fyber.Fyber;
import com.fyber.user.User;
/**
* Created by Heiko Weber on 17/05/2018.
*/
public class RNFyberUserModule extends ReactContextBaseJavaModule {
private static final String TAG = "RNFyberUser";
private ReactApplicationContext mContext;
public RNFyberUserModule(ReactApplicationContext reactContext) {
super(reactContext);
mContext = reactContext;
}
@Override
public String getName() {
return TAG;
}
@ReactMethod
public void set(final ReadableMap uprops) {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
try {
if (uprops.hasKey("age")) {
User.setAge(uprops.getInt("age"));
}
if (uprops.hasKey("custom")) {
ReadableMap custom = uprops.getMap("custom");
String[] pubs = { "pub0","pub1","pub2","pub3", "pub4", "pub5", "pub6", "pub7", "pub8", "pub9" };
for (String s: pubs) {
if (custom.hasKey(s)) {
User.addCustomValue(s, custom.getString(s));
}
}
}
} catch (Exception e) {
}
}
});
}
@ReactMethod
public void startFyberSDK(final String appId, final String securityToken, final String userId) {
Log.d(TAG, "startFyberSDK for appId:" + appId);
Fyber.with(appId, getCurrentActivity()).withUserId(userId).withSecurityToken(securityToken).start();
}
}