Skip to content

Commit 4e0207a

Browse files
author
Fran Montiel
committed
Add showUserFeedback to Android native implementation and change signature of the method
1 parent b91c37c commit 4e0207a

3 files changed

Lines changed: 164 additions & 120 deletions

File tree

android/src/main/java/com/bugfender/react/RNBugfenderModule.java

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
package com.bugfender.react;
22

3+
import android.app.Activity;
34
import android.app.Application;
4-
5+
import android.content.Intent;
56
import com.bugfender.sdk.Bugfender;
67
import com.bugfender.sdk.LogLevel;
8+
import com.bugfender.sdk.ui.FeedbackActivity;
9+
import com.facebook.react.bridge.ActivityEventListener;
710
import com.facebook.react.bridge.Promise;
811
import com.facebook.react.bridge.ReactApplicationContext;
912
import com.facebook.react.bridge.ReactContextBaseJavaModule;
1013
import com.facebook.react.bridge.ReactMethod;
1114

1215
import java.net.URL;
1316

14-
public class RNBugfenderModule extends ReactContextBaseJavaModule {
17+
public class RNBugfenderModule extends ReactContextBaseJavaModule implements ActivityEventListener {
18+
19+
private Promise pendingPromise; // Promise that is waiting information that will be available in onActivityResult
1520

1621
public RNBugfenderModule(ReactApplicationContext rc) {
1722
super(rc);
23+
this.getReactApplicationContext().addActivityEventListener(this);
1824
}
1925

2026
@Override
@@ -148,6 +154,21 @@ public void getSessionUrl(Promise promise) {
148154
promise.resolve(url != null ? url.toString() : null);
149155
}
150156

157+
private static final int SHOW_USER_FEEDBACK_REQUEST_CODE = 10001;
158+
159+
@ReactMethod
160+
public void showUserFeedback(String title, String hint, String subjectHint, String messageHint, String sendButtonText, String cancelButtonText,
161+
Promise promise) {
162+
getCurrentActivity().startActivityForResult(
163+
Bugfender.getUserFeedbackActivityIntent(getApplication(), title, hint, subjectHint, messageHint, sendButtonText), SHOW_USER_FEEDBACK_REQUEST_CODE
164+
);
165+
pendingPromise = promise;
166+
}
167+
168+
private Application getApplication() {
169+
return (Application) getReactApplicationContext().getApplicationContext();
170+
}
171+
151172
private static LogLevel parseLogLevel(String loglevel) {
152173
switch (loglevel) {
153174
case "Debug":
@@ -160,4 +181,19 @@ private static LogLevel parseLogLevel(String loglevel) {
160181
return null;
161182
}
162183
}
184+
185+
@Override public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
186+
if (requestCode == SHOW_USER_FEEDBACK_REQUEST_CODE && pendingPromise != null) {
187+
if (resultCode == Activity.RESULT_OK) {
188+
pendingPromise.resolve(data.getStringExtra(FeedbackActivity.RESULT_FEEDBACK_URL));
189+
} else {
190+
pendingPromise.reject("0", "Feedback not sent");
191+
}
192+
pendingPromise = null;
193+
}
194+
}
195+
196+
@Override public void onNewIntent(Intent intent) {
197+
// Nothing to do
198+
}
163199
}

bugfender.js

Lines changed: 117 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -12,198 +12,206 @@ export default {
1212
* @readonly
1313
* @enum {LogLevel}
1414
*/
15-
LogLevel : {DEBUG:"Debug", WARNING:"Warning", ERROR:"Error"},
15+
LogLevel: {DEBUG: "Debug", WARNING: "Warning", ERROR: "Error"},
1616

1717
/**
18-
* Initialize the Bugfender SDK with a specific application token.
19-
*/
20-
init: (token, debug = true) => {
18+
* Initialize the Bugfender SDK with a specific application token.
19+
*/
20+
init: (token, debug = true) => {
2121
// Library initialization
2222
Platform.OS === 'ios' ? Bugfender.activateLogger(token) : Bugfender.init(token, debug)
2323
},
2424

2525
/**
26-
* Sets the URL of the API
26+
* Sets the URL of the API
2727
*
28-
* Usage of this function is not necessary in the general use case. Please use exclusively when
29-
* directed from technical support. This method must be called before Bugfender.init().
28+
* Usage of this function is not necessary in the general use case. Please use exclusively when
29+
* directed from technical support. This method must be called before Bugfender.init().
3030
* @param {string} url - base URL of the Bugfender's dashboard
3131
*/
3232
setApiUrl: apiUrl => Bugfender.setApiUrl(apiUrl),
3333

3434
/**
35-
* Sets the URL of the Bugfender Dashboard
35+
* Sets the URL of the Bugfender Dashboard
3636
*
37-
* Usage of this function is not necessary in the general use case. Please use exclusively when
38-
* directed from technical support. This method must be called before Bugfender.init().
37+
* Usage of this function is not necessary in the general use case. Please use exclusively when
38+
* directed from technical support. This method must be called before Bugfender.init().
3939
* @param {string} url - base URL of the Bugfender's dashboard
4040
*/
4141
setBaseUrl: baseUrl => Bugfender.setBaseUrl(baseUrl),
4242

4343
/**
44-
* Sets the name for the device. If the Device Name is not set, then the platform standard device name will be automatically sent
44+
* Sets the name for the device. If the Device Name is not set, then the platform standard device name will be automatically sent
4545
*
46-
* @note This method has to be called prior to activate logger. Otherwise, an exception will be thrown
46+
* @note This method has to be called prior to activate logger. Otherwise, an exception will be thrown
4747
* @param {string} deviceName - Device name that will be send to Bugfender.
4848
*/
4949
overrideDeviceName: value => Bugfender.overrideDeviceName(value),
5050

5151
/**
52-
* Synchronizes all logs and issues with the server all the time, regardless if this device is enabled or not.
53-
*
54-
* Logs and issues are synchronized continuously while forceEnabled is active.
55-
*
56-
* @param {boolean} enabled - Whether logs and issues should be sent regardless of the Bugfender Console settings.
57-
*/
52+
* Synchronizes all logs and issues with the server all the time, regardless if this device is enabled or not.
53+
*
54+
* Logs and issues are synchronized continuously while forceEnabled is active.
55+
*
56+
* @param {boolean} enabled - Whether logs and issues should be sent regardless of the Bugfender Console settings.
57+
*/
5858
setForceEnabled: value => Bugfender.setForceEnabled(value),
5959

6060
/**
61-
* Set the maximum size to store local log files.
62-
*
63-
* By default, the limit is 5 MB.
64-
*
65-
* @param {number} sizeInBytes Maximum size in bytes. Range accepted is from 1 byte to 50 MB. If the value provided is outside this range, it will be set to 50 MB.
66-
*/
61+
* Set the maximum size to store local log files.
62+
*
63+
* By default, the limit is 5 MB.
64+
*
65+
* @param {number} sizeInBytes Maximum size in bytes. Range accepted is from 1 byte to 50 MB. If the value provided is outside this range, it will be set to 50 MB.
66+
*/
6767
setMaximumLocalStorageSize: sizeInBytes => Bugfender.setMaximumLocalStorageSize(sizeInBytes),
6868

6969
/**
70-
* Remove a device detail.
71-
*
72-
* @param {string} key - key.
73-
*/
70+
* Remove a device detail.
71+
*
72+
* @param {string} key - key.
73+
*/
7474
removeDeviceKey: key => Bugfender.removeDeviceKey(key),
7575

7676
/**
77-
* Logs all logs written via Logcat.
78-
*/
77+
* Logs all logs written via Logcat.
78+
*/
7979
enableLogcatLogging: () => Bugfender.enableLogcatLogging(),
8080

8181
/**
82-
* Enable crash reporting tool functionality
83-
*/
82+
* Enable crash reporting tool functionality
83+
*/
8484
enableCrashReporting: () => Bugfender.enableCrashReporting(),
8585

8686
/**
87-
* Logs all actions performed and screen changes in the application, such as button touches, etc...
88-
*/
87+
* Logs all actions performed and screen changes in the application, such as button touches, etc...
88+
*/
8989
enableUIEventLogging: () => Bugfender.enableUIEventLogging(),
9090

9191
/**
92-
* Sets a device detail with boolean type.
93-
*
94-
* @param {string} key - key.
95-
* @param {boolean} value - A boolean value.
96-
*/
92+
* Sets a device detail with boolean type.
93+
*
94+
* @param {string} key - key.
95+
* @param {boolean} value - A boolean value.
96+
*/
9797
setDeviceBoolean: (key, value) => Bugfender.setDeviceBoolean(key, value),
9898

9999
/**
100-
* Sets a device detail with string type.
101-
*
102-
* @param {string} key - key.
103-
* @param {string} value - A string value.
104-
*/
100+
* Sets a device detail with string type.
101+
*
102+
* @param {string} key - key.
103+
* @param {string} value - A string value.
104+
*/
105105
setDeviceString: (key, value) => Bugfender.setDeviceString(key, value),
106106

107107
/**
108-
* Sets a device detail with integer type.
109-
*
110-
* @param {string} key - key.
111-
* @param {number} value - A integer value.
112-
*/
108+
* Sets a device detail with integer type.
109+
*
110+
* @param {string} key - key.
111+
* @param {number} value - A integer value.
112+
*/
113113
setDeviceInteger: (key, value) => Bugfender.setDeviceInteger(key, value),
114114

115115
/**
116-
* Sets a device detail with double type.
117-
*
118-
* @param {string} key - key.
119-
* @param {number} value - A double value.
120-
*/
116+
* Sets a device detail with double type.
117+
*
118+
* @param {string} key - key.
119+
* @param {number} value - A double value.
120+
*/
121121
setDeviceFloat: (key, value) => Bugfender.setDeviceFloat(key, value),
122122

123123
/**
124-
* Default Bugfender log method.
125-
*
126-
* @param {string} tag - String with the tag.
127-
* @param {string} message - String with the message.
128-
*/
124+
* Default Bugfender log method.
125+
*
126+
* @param {string} tag - String with the tag.
127+
* @param {string} message - String with the message.
128+
*/
129129
d: (tag, text) => Bugfender.debug(tag, text),
130130

131131
/**
132-
* Warning Bugfender log method.
133-
*
134-
* @param {string} tag - String with the tag.
135-
* @param {string} message - String with the message.
136-
*/
132+
* Warning Bugfender log method.
133+
*
134+
* @param {string} tag - String with the tag.
135+
* @param {string} message - String with the message.
136+
*/
137137
w: (tag, text) => Bugfender.warning(tag, text),
138138

139-
/**
140-
* Error Bugfender log method.
141-
*
142-
* @param {string} tag - String with the tag.
143-
* @param {string} message - String with the message.
144-
*/
139+
/**
140+
* Error Bugfender log method.
141+
*
142+
* @param {string} tag - String with the tag.
143+
* @param {string} message - String with the message.
144+
*/
145145
e: (tag, text) => Bugfender.error(tag, text),
146146

147147
/**
148-
* Bugfender interface for logging, which takes a simple string as log message.
149-
*
150-
* @param {number} lineNumber - The line number of the log.
151-
* @param {string} method - The method where the log has happened.
152-
* @param {string} file - The file where the log has happened.
153-
* @param {LogLevel} loglevel - Log level.
154-
* @param {string} tag - Tag to be applied to the log line.
155-
* @param {string} message - Message to be logged. The message will be logged verbatim, no interpretation will be performed.
156-
**/
148+
* Bugfender interface for logging, which takes a simple string as log message.
149+
*
150+
* @param {number} lineNumber - The line number of the log.
151+
* @param {string} method - The method where the log has happened.
152+
* @param {string} file - The file where the log has happened.
153+
* @param {LogLevel} loglevel - Log level.
154+
* @param {string} tag - Tag to be applied to the log line.
155+
* @param {string} message - Message to be logged. The message will be logged verbatim, no interpretation will be performed.
156+
**/
157157
log: (lineNumber, method, file, loglevel, tag, message) => Bugfender.log(lineNumber, method, file, loglevel, tag, message),
158158

159159
/**
160-
* Sends an issue
161-
*
162-
* @param {string} title - Short description of the issue.
163-
* @param {string} text - Full details of the issue. Markdown format is accepted.
164-
* @return {Promise<string>} A Promise with the URL pointing to the issue on the Bugfender dashboard or null if SDK is not initialized.
165-
*/
160+
* Sends an issue
161+
*
162+
* @param {string} title - Short description of the issue.
163+
* @param {string} text - Full details of the issue. Markdown format is accepted.
164+
* @return {Promise<string>} A Promise with the URL pointing to the issue on the Bugfender dashboard or null if SDK is not initialized.
165+
*/
166166
sendIssue: (title, text) => Bugfender.sendIssue(title, text),
167167

168168
/**
169-
* Send a crash. Useful for controlled Exceptions
169+
* Send a crash. Useful for controlled Exceptions
170170
*
171-
* @param {string} title - Title for the crash.
172-
* @param {string} text - Additional info for the crash, p.e. the Stack trace. Markdown format is accepted
173-
* @return A Promise with the URL pointing to the crash information on the Bugfender dashboard or null if SDK is not initialized.
174-
*/
171+
* @param {string} title - Title for the crash.
172+
* @param {string} text - Additional info for the crash, p.e. the Stack trace. Markdown format is accepted
173+
* @return A Promise with the URL pointing to the crash information on the Bugfender dashboard or null if SDK is not initialized.
174+
*/
175175
sendCrash: (title, text) => Bugfender.sendCrash(title, text),
176176

177177
/**
178-
* Sends user feedback
178+
* Sends user feedback
179179
*
180-
* @param {string} title - Title for the feedback.
181-
* @param {string} message - Feedback message. Markdown format is accepted
182-
* @return {Promise<string>} A Promise with the URL pointing to the feedback information on the Bugfender dashboard or null if SDK is not initialized.
183-
*/
180+
* @param {string} title - Title for the feedback.
181+
* @param {string} message - Feedback message. Markdown format is accepted
182+
* @return {Promise<string>} A Promise with the URL pointing to the feedback information on the Bugfender dashboard or null if SDK is not initialized.
183+
*/
184184
sendUserFeedback: (title, text) => Bugfender.sendUserFeedback(title, text),
185185

186186
/**
187-
* Synchronizes all logs and issues with the server once, regardless if this device is enabled or not.
188-
*
189-
* Logs and issues are synchronized only once. After that, the logs are again sent according to the enabled flag
190-
* in the Bugfender Console.
191-
*/
187+
* Synchronizes all logs and issues with the server once, regardless if this device is enabled or not.
188+
*
189+
* Logs and issues are synchronized only once. After that, the logs are again sent according to the enabled flag
190+
* in the Bugfender Console.
191+
*/
192192
forceSendOnce: () => Bugfender.forceSendOnce(),
193193

194194
/**
195-
* Get a URL pointing to the Bugfender dashboard page for the device.
196-
* @return {Promise<string>} A Promise with the URL to the page if the Bugfender sdk is initialized otherwise return null.
197-
*/
195+
* Get a URL pointing to the Bugfender dashboard page for the device.
196+
* @return {Promise<string>} A Promise with the URL to the page if the Bugfender sdk is initialized otherwise return null.
197+
*/
198198
getDeviceUrl: () => Bugfender.getDeviceUrl(),
199199

200200
/**
201-
* Get a URL pointing to the Bugfender dashboard page for the device and current session.
202-
* @return {Promise<string>} A Promise with the URL to the page if the Bugfender sdk is initialized otherwise return null.
203-
*/
201+
* Get a URL pointing to the Bugfender dashboard page for the device and current session.
202+
* @return {Promise<string>} A Promise with the URL to the page if the Bugfender sdk is initialized otherwise return null.
203+
*/
204204
getSessionUrl: () => Bugfender.getSessionUrl(),
205205

206-
// working on
207-
// @return {Promise<string>} A Promise with the URL pointing to the feedback information on the Bugfender dashboard or null if SDK is not initialized.
208-
showUserFeedback: () => Bugfender.showUserFeedback()
206+
/**
207+
* Open a screen to gather the feedback of the users and sent it to Bugfender.
208+
* @param title
209+
* @param hint
210+
* @param subjectHint
211+
* @param messageHint
212+
* @param sendButtonText
213+
* @param cancelButtonText
214+
* @returns {Promise<string>} A Promise with the URL to the feedback information on the Bugfender dashboard. If the user cancels then the Promise is rejected
215+
*/
216+
showUserFeedback: (title, hint, subjectHint, messageHint, sendButtonText, cancelButtonText) => Bugfender.showUserFeedback(title, hint, subjectHint, messageHint, sendButtonText, cancelButtonText)
209217
};

0 commit comments

Comments
 (0)