Skip to content

[Mob 3193] - [Mob 3195] #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Master

* Adds setOnDismissCallback API mapping.
* Adds setOnInvokeCallback API mapping.
* Adds BugReporting.setEnabled API mapping.
* Adds setWelcomeMessageMode API mapping.
* Adds addFileAttachmentWithURL, addFileAttachmentWithData, clearFileAttachments API mapping.
* Adds setUserData API mapping.
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ The section below contains the APIs we're planning to implement for our 1.0 rele

| API Method | Native Equivalent (Android/iOS) |
|---------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------|
| `invokeWithMode(InvocationMode invocationMode, [List<InvocationOption> invocationOptions])` | `invoke(InvocationMode mode, @InvocationOption int... options)`<br>`+ invokeWithMode:options:` |
| | `setState(Feature.State state)`<br>`enabled` |
| | `setOnInvokeCallback(OnInvokeCallback onInvokeCallback)`<br>`willInvokeHandler` |
| | `setOnDismissCallback(OnSdkDismissCallback onSdkDismissedCallback)`<br>`didDismissHandler` |
| | `setInvocationEvents(InstabugInvocationEvent... invocationEvents)`<br>`invocationEvents` |
| | `setAttachmentTypesEnabled(boolean initial, boolean extra, boolean gallery, boolean recording)`<br>`enabledAttachmentTypes` |
| | `setReportTypes(@BugReporting.ReportType int... types)`<br>`promptOptionsEnabledReportTypes` |
| | `setExtendedBugReportState(ExtendedBugReport.State state)`<br>`extendedBugReportMode` |
| `invokeWithMode(InvocationMode invocationMode, [List<InvocationOption> invocationOptions])` | `invoke(InvocationMode mode, @InvocationOption int... options)`<br>`+invokeWithMode:options:`|
| `setEnabled(bool isEnabled)` | `setState(Feature.State state)`<br>`enabled` |
| `setOnInvokeCallback(Function function)` | `setOnInvokeCallback(OnInvokeCallback onInvokeCallback)`<br>`willInvokeHandler` |
| `setOnDismissCallback(Function function)` | `setOnDismissCallback(OnSdkDismissCallback onSdkDismissedCallback)`<br>`didDismissHandler` |
| | `setInvocationEvents(InstabugInvocationEvent... invocationEvents)`<br>`invocationEvents` |
| | `setAttachmentTypesEnabled(boolean initial, boolean extra, boolean gallery, boolean recording`<br>`enabledAttachmentTypes` |
| | `setReportTypes(@BugReporting.ReportType int... types)`<br>`promptOptionsEnabledReportTypes` |
| | `setExtendedBugReportState(ExtendedBugReport.State state)`<br>`extendedBugReportMode` |
| | `setOptions(@Option int... options)`<br>`bugReportingOptions`
| | `show(@BugReporting.ReportType int type)`<br>`+ showWithReportType:options:`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import com.instabug.library.Instabug;
import com.instabug.library.InstabugColorTheme;
import com.instabug.library.InstabugCustomTextPlaceHolder;
import com.instabug.library.OnSdkDismissCallback;
import com.instabug.library.invocation.InstabugInvocationEvent;
import com.instabug.library.invocation.OnInvokeCallback;
import com.instabug.library.logging.InstabugLog;
import com.instabug.library.ui.onboarding.WelcomeMessage;

Expand Down Expand Up @@ -47,11 +49,12 @@ public class InstabugFlutterPlugin implements MethodCallHandler {

private InstabugCustomTextPlaceHolder placeHolder = new InstabugCustomTextPlaceHolder();

static MethodChannel channel;
/**
* Plugin registration.
*/
public static void registerWith(Registrar registrar) {
final MethodChannel channel = new MethodChannel(registrar.messenger(), "instabug_flutter");
channel = new MethodChannel(registrar.messenger(), "instabug_flutter");
channel.setMethodCallHandler(new InstabugFlutterPlugin());
}

Expand Down Expand Up @@ -472,4 +475,51 @@ public void setWelcomeMessageMode(String welcomeMessageMode) {
Instabug.setWelcomeMessageState(resolvedWelcomeMessageMode);
}

/**
* Enables and disables manual invocation and prompt options for bug and feedback.
* @param {boolean} isEnabled
*/
public void setBugReportingEnabled(final boolean isEnabled) {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
if (isEnabled) {
BugReporting.setState(Feature.State.ENABLED);
} else {
BugReporting.setState(Feature.State.DISABLED);
}
}
});
}

/**
* Sets a block of code to be executed just before the SDK's UI is presented.
* This block is executed on the UI thread. Could be used for performing any
* UI changes before the SDK's UI is shown.
*/
public void setOnInvokeCallback() {
BugReporting.setOnInvokeCallback(new OnInvokeCallback() {
@Override
public void onInvoke() {
channel.invokeMethod("onInvokeCallback", "a");
}
});
}

/**
* Sets a block of code to be executed right after the SDK's UI is dismissed.
* This block is executed on the UI thread. Could be used for performing any
* UI changes after the SDK's UI is dismissed.
*/
public void setOnDismissCallback() {
BugReporting.setOnDismissCallback(new OnSdkDismissCallback() {
@Override
public void call(DismissType dismissType, ReportType reportType) {
HashMap<String, String> params = new HashMap<>();
params.put("dismissType", dismissType.toString());
params.put("reportType", reportType.toString());
channel.invokeMethod("onDismissCallback", params);
}
});
}
}
12 changes: 12 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class _MyAppState extends State<MyApp> {
Instabug.addFileAttachmentWithData(list, "My File");
Instabug.clearFileAttachments();
//Instabug.clearFileAttachments();
//BugReporting.setEnabled(false);
BugReporting.setOnInvokeCallback(sdkInvoked);
BugReporting.setOnDismissCallback(sdkDismissed);
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
Expand All @@ -79,6 +82,15 @@ class _MyAppState extends State<MyApp> {
Instabug.resetTags();
}

void sdkInvoked() {
debugPrint("I am called before invocation");
}

void sdkDismissed(DismissType dismissType, ReportType reportType) {
debugPrint('SDK Dismissed DismissType: ' + dismissType.toString());
debugPrint('SDK Dismissed ReportType: ' + reportType.toString());
}

void show() {
Instabug.show();
}
Expand Down
54 changes: 53 additions & 1 deletion ios/Classes/InstabugFlutterPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
@implementation InstabugFlutterPlugin


FlutterMethodChannel* channel;
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
FlutterMethodChannel* channel = [FlutterMethodChannel
channel = [FlutterMethodChannel
methodChannelWithName:@"instabug_flutter"
binaryMessenger:[registrar messenger]];
InstabugFlutterPlugin* instance = [[InstabugFlutterPlugin alloc] init];
Expand Down Expand Up @@ -359,6 +360,57 @@ + (void)setWelcomeMessageMode:(NSString *)welcomeMessageMode {
[Instabug setWelcomeMessageMode:welcomeMode];
}

/**
* Enables and disables manual invocation and prompt options for bug and feedback.
* @param {boolean} isEnabled
*/
+ (void)setBugReportingEnabled:(NSNumber *)isEnabled {
BOOL boolValue = [isEnabled boolValue];
IBGBugReporting.enabled = boolValue;
}

/**
* Sets a block of code to be executed just before the SDK's UI is presented.
* This block is executed on the UI thread. Could be used for performing any
* UI changes before the SDK's UI is shown.
*/
+ (void)setOnInvokeCallback {
IBGBugReporting.willInvokeHandler = ^{
[channel invokeMethod:@"onInvokeCallback" arguments:nil];
};
}

/**
* Sets a block of code to be executed right after the SDK's UI is dismissed.
* This block is executed on the UI thread. Could be used for performing any
* UI changes after the SDK's UI is dismissed.
*/
+ (void)setOnDismissCallback {
IBGBugReporting.didDismissHandler = ^(IBGDismissType dismissType, IBGReportType reportType) {
//parse dismiss type enum
NSString* dismissTypeString;
if (dismissType == IBGDismissTypeCancel) {
dismissTypeString = @"CANCEL";
} else if (dismissType == IBGDismissTypeSubmit) {
dismissTypeString = @"SUBMIT";
} else if (dismissType == IBGDismissTypeAddAttachment) {
dismissTypeString = @"ADD_ATTACHMENT";
}
//parse report type enum
NSString* reportTypeString;
if (reportType == IBGReportTypeBug) {
reportTypeString = @"bug";
} else if (reportType == IBGReportTypeFeedback) {
reportTypeString = @"feedback";
} else {
reportTypeString = @"other";
}
NSDictionary *result = @{ @"dismissType": dismissTypeString,
@"reportType": reportTypeString};
[channel invokeMethod:@"onDismissCallback" arguments:result];
};
}

+ (NSDictionary *)constants {
return @{
@"InvocationEvent.shake": @(IBGInvocationEventShake),
Expand Down
88 changes: 87 additions & 1 deletion lib/BugReporting.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:instabug_flutter/Instabug.dart';

Expand All @@ -9,13 +10,71 @@ enum InvocationOption {
EMAIL_FIELD_OPTIONAL
}

enum DismissType {
CANCEL,
SUBMIT,
ADD_ATTACHMENT
}

enum ReportType {
BUG,
FEEDBACK,
OTHER
}

class BugReporting {

static Function onInvokeCallback;
static Function onDismissCallback;
static const MethodChannel _channel = MethodChannel('instabug_flutter');

static Future<String> get platformVersion async {
final String version = await _channel.invokeMethod('getPlatformVersion');
return version;
}

static Future<dynamic> _handleMethod(MethodCall call) async {
switch(call.method) {
case 'onInvokeCallback':
onInvokeCallback();
return ;
case 'onDismissCallback':
Map<dynamic, dynamic> map = call.arguments;
DismissType dismissType;
ReportType reportType;
final String dismissTypeString = map['dismissType'].toUpperCase();
switch(dismissTypeString) {
case 'CANCEL':
dismissType = DismissType.CANCEL;
break;
case 'SUBMIT':
dismissType = DismissType.SUBMIT;
break;
case 'ADD_ATTACHMENT':
dismissType = DismissType.ADD_ATTACHMENT;
break;
}
final String reportTypeString = map['reportType'].toUpperCase();
switch(reportTypeString) {
case 'BUG':
reportType = ReportType.BUG;
break;
case 'FEEDBACK':
reportType = ReportType.FEEDBACK;
break;
case 'OTHER':
reportType = ReportType.OTHER;
break;
}
try {
onDismissCallback(dismissType,reportType);
}
catch(exception) {
onDismissCallback();
}
return ;
}
}
/// invoke sdk manually with desire invocation mode
/// [invocationMode] the invocation mode
/// [invocationOptions] the array of invocation options
Expand All @@ -29,4 +88,31 @@ class BugReporting {
final List<dynamic> params = <dynamic>[invocationMode.toString(), invocationOptionsStrings];
await _channel.invokeMethod<Object>('invokeWithMode:options:',params);
}
}

///Enables and disables manual invocation and prompt options for bug and feedback.
/// [boolean] isEnabled
static void setEnabled(bool isEnabled) async {
final List<dynamic> params = <dynamic>[isEnabled];
await _channel.invokeMethod<Object>('setBugReportingEnabled:', params);
}

/// Sets a block of code to be executed just before the SDK's UI is presented.
/// This block is executed on the UI thread. Could be used for performing any
/// UI changes before the SDK's UI is shown.
/// [function] A callback that gets executed before invoking the SDK
static void setOnInvokeCallback(Function function) async {
_channel.setMethodCallHandler(_handleMethod);
onInvokeCallback = function;
await _channel.invokeMethod<Object>('setOnInvokeCallback');
}

/// Sets a block of code to be executed just before the SDK's UI is presented.
/// This block is executed on the UI thread. Could be used for performing any
/// UI changes before the SDK's UI is shown.
/// [function] A callback that gets executed before invoking the SDK
static void setOnDismissCallback(Function function) async {
_channel.setMethodCallHandler(_handleMethod);
onDismissCallback = function;
await _channel.invokeMethod<Object>('setOnDismissCallback');
}
}
31 changes: 31 additions & 0 deletions test/instabug_flutter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,37 @@ test('startWithToken:invocationEvents: Test', () async {
]);
});

test('setBugReportingEnabled: Test', () async {
bool isEnabled = false;
final List<dynamic> args = <dynamic>[isEnabled];
BugReporting.setEnabled(isEnabled);
expect(log, <Matcher>[
isMethodCall('setBugReportingEnabled:',
arguments: args,
)
]);
});

test('setOnInvokeCallback Test', () async {
BugReporting.setOnInvokeCallback(()=> (){});
expect(log, <Matcher>[
isMethodCall('setOnInvokeCallback',
arguments: null,
)
]);
});

test('setOnDismissCallback Test', () async {
BugReporting.setOnDismissCallback(()=> (){});
expect(log, <Matcher>[
isMethodCall('setOnDismissCallback',
arguments: null,
)
]);
});



}