-
Notifications
You must be signed in to change notification settings - Fork 100
/
Copy pathRNInstabugFeatureRequestsModule.java
98 lines (86 loc) · 3.11 KB
/
RNInstabugFeatureRequestsModule.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
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
package com.instabug.reactlibrary;
import android.annotation.SuppressLint;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableArray;
import com.instabug.featuresrequest.FeatureRequests;
import com.instabug.library.Feature;
import com.instabug.reactlibrary.utils.ArrayUtil;
import com.instabug.reactlibrary.utils.MainThreadHandler;
import java.util.ArrayList;
import javax.annotation.Nonnull;
public class RNInstabugFeatureRequestsModule extends ReactContextBaseJavaModule {
public RNInstabugFeatureRequestsModule(ReactApplicationContext reactApplicationContext) {
super(reactApplicationContext);
}
@Nonnull
@Override
public String getName() {
return "IBGFeatureRequests";
}
/**
* Sets whether email field is required or not when submitting
* new-feature-request/new-comment-on-feature
*
* @param isEmailRequired set true to make email field required
* @param actionTypes Bitwise-or of actions
*/
@ReactMethod
public void setEmailFieldRequiredForFeatureRequests(final boolean isEmailRequired, final ReadableArray actionTypes) {
MainThreadHandler.runOnMainThread(new Runnable() {
@SuppressLint("WrongConstant")
@Override
public void run() {
try {
final ArrayList<String> keys = ArrayUtil.parseReadableArrayOfStrings(actionTypes);
final ArrayList<Integer> types = ArgsRegistry.actionTypes.getAll(keys);
final int[] typesInts = new int[types.size()];
for (int i = 0; i < types.size(); i++) {
typesInts[i] = types.get(i);
}
FeatureRequests.setEmailFieldRequired(isEmailRequired, typesInts);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Shows the UI for feature requests list
*/
@ReactMethod
public void show() {
MainThreadHandler.runOnMainThread(new Runnable() {
@Override
public void run() {
try {
FeatureRequests.show();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Enables or disables feature requests.
* @param isEnabled boolean indicating enabled or disabled.
*/
@ReactMethod
public void setEnabled(final boolean isEnabled) {
MainThreadHandler.runOnMainThread(new Runnable() {
@Override
public void run() {
try {
if (isEnabled) {
FeatureRequests.setState(Feature.State.ENABLED);
} else {
FeatureRequests.setState(Feature.State.DISABLED);
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}