-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds updated onReportSubmitHandler API (#30)
* ✨ add feature where a bug report can be edited before being sent to the native side
- Loading branch information
1 parent
5a298a1
commit 5f3b96d
Showing
14 changed files
with
555 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
android/src/main/java/com/instabug/reactlibrary/utils/ReportUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.instabug.reactlibrary.utils; | ||
|
||
import android.net.Uri; | ||
|
||
import com.facebook.react.bridge.ReadableArray; | ||
import com.facebook.react.bridge.ReadableMap; | ||
import com.facebook.react.bridge.ReadableMapKeySetIterator; | ||
import com.facebook.react.bridge.ReadableType; | ||
import com.facebook.react.bridge.WritableArray; | ||
import com.facebook.react.bridge.WritableMap; | ||
import com.facebook.react.bridge.WritableNativeArray; | ||
import com.instabug.library.model.Report; | ||
import com.instabug.library.model.a; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import java.util.ArrayList; | ||
|
||
|
||
/** | ||
* Created by salmaali on 8/29/18. | ||
*/ | ||
|
||
public class ReportUtil { | ||
|
||
public static Report createReport(ReadableArray tags, ReadableArray consoleLogs, String userData, ReadableMap userAttributes, ReadableMap fileAttachments) { | ||
Report report = new Report(); | ||
// map tags | ||
report.addTag(ArrayUtil.parseReadableArrayOfStrings(tags).toArray(new String[0])); | ||
|
||
// map consoleLogs | ||
for (int i = 0; i < consoleLogs.size(); i++) { | ||
ReadableType type = consoleLogs.getType(i); | ||
if (type == ReadableType.String) { | ||
report.appendToConsoleLogs(consoleLogs.getString(i)); | ||
} | ||
} | ||
|
||
// map userData | ||
report.setUserData(userData); | ||
|
||
// map userAttributes | ||
ReadableMapKeySetIterator userAttrIterator = userAttributes.keySetIterator(); | ||
while (userAttrIterator.hasNextKey()) { | ||
String key = userAttrIterator.nextKey(); | ||
ReadableType type = userAttributes.getType(key); | ||
if (type == ReadableType.String) { | ||
report.setUserAttribute(key, userAttributes.getString(key)); | ||
} | ||
|
||
} | ||
|
||
// map fileAttachments | ||
ReadableMapKeySetIterator fileAttachmentsIterator = userAttributes.keySetIterator(); | ||
while (fileAttachmentsIterator.hasNextKey()) { | ||
String key = fileAttachmentsIterator.nextKey(); | ||
ReadableType type = fileAttachments.getType(key); | ||
if (type == ReadableType.String) { | ||
Uri uri = Uri.parse(key); | ||
report.addFileAttachment(uri, fileAttachments.getString(key)); | ||
} | ||
|
||
} | ||
|
||
return report; | ||
} | ||
|
||
public static WritableArray parseConsoleLogs(ArrayList<a> consoleLogs) { | ||
WritableArray writableArray = new WritableNativeArray(); | ||
|
||
for(int i = 0; i < consoleLogs.size(); i++) { | ||
try { | ||
writableArray.pushString(consoleLogs.get(i).toJson()); | ||
} catch (JSONException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
|
||
return writableArray; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.