Skip to content

[Mob 3372] , [MOB-3377], [Mob 3382] , [MOB-3387]: Flutter API [FeatureRequests], [Chats] #61

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 15 commits into from
Apr 14, 2019
Merged
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## Master

* Adds Chats Api mappings
* Adds FeatureRequests Api mappings.

## Version 0.0.4 (2019-04-14)

* Adds hasRespondedToSurvey API mapping.
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,21 @@ The section below contains the APIs we're planning to implement for our 1.0 rele
| `showSurvey(String surveyToken)` | `showSurvey(String token)`<br>`+ showSurveyWithToken:` |
| `hasRespondedToSurvey(String surveyToken, Function function)` | `hasRespondToSurvey(String token)`<br>`+ hasRespondedToSurveyWithToken:` |

#### `FeatureRequests`

| API Method | Native Equivalent (Android/iOS) |
|-----------------------------------------------|--------------------------------------------------------------|
| `show() ` | `show()`<br>`+ show` |
| `setEmailFieldRequired(bool isEmailFieldRequired, List<ActionType> actionTypes)` | `setEmailFieldRequired(boolean isEmailRequired, ActionTypes actions)`<br>`+ setEmailFieldRequired:forAction:` |


#### `Chats`

| API Method | Native Equivalent (Android/iOS) |
|-----------------------------------------------|--------------------------------------------------------------|
| `show()` | `show()`<br>`+ show` |
| `setEnabled(bool isEnabled)` | `setState(Feature.State state)`<br>`enabled` |

## Integration

Creating a Flutter app on the Instabug dashboard isn't possible yet. Create a React Native app instead.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.instabug.bug.BugReporting;
import com.instabug.bug.invocation.Option;
import com.instabug.library.ActionType;
import com.instabug.library.InstabugColorTheme;
import com.instabug.library.InstabugCustomTextPlaceHolder;
import com.instabug.library.extendedbugreport.ExtendedBugReport;
Expand Down Expand Up @@ -60,6 +61,7 @@ final class ArgsRegistry {
registerCustomTextPlaceHolderKeysArgs(ARGS);
registerInstabugReportTypesArgs(ARGS);
registerInstabugExtendedBugReportModeArgs(ARGS);
registerInstabugActionTypesArgs(ARGS);
}

/**
Expand Down Expand Up @@ -214,4 +216,13 @@ static void registerInstabugExtendedBugReportModeArgs(Map<String, Object> args)
args.put("ExtendedBugReportMode.enabledWithOptionalFields", ExtendedBugReport.State.ENABLED_WITH_OPTIONAL_FIELDS);
args.put("ExtendedBugReportMode.disabled",ExtendedBugReport.State.DISABLED);
}

@VisibleForTesting
static void registerInstabugActionTypesArgs(Map<String, Object> args) {
args.put("ActionType.allActions", ActionType.ALL_ACTIONS);
args.put("ActionType.reportBug", ActionType.REPORT_BUG);
args.put("ActionType.requestNewFeature",ActionType.REQUEST_NEW_FEATURE);
args.put("ActionType.addCommentToFeature",ActionType.ADD_COMMENT_TO_FEATURE);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.instabug.bug.invocation.Option;
import com.instabug.chat.Chats;
import com.instabug.chat.Replies;
import com.instabug.featuresrequest.FeatureRequests;
import com.instabug.library.Feature;
import com.instabug.library.Instabug;
import com.instabug.library.InstabugColorTheme;
Expand Down Expand Up @@ -732,4 +733,51 @@ public void hasRespondedToSurveyWithToken(String surveyToken) {
channel.invokeMethod("hasRespondedToSurveyCallback", hasResponded);
}

/**
* Shows the UI for feature requests list
*/
public void showFeatureRequests() {
FeatureRequests.show();
}

/**
* 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
*/
public void setEmailFieldRequiredForFeatureRequests(final Boolean isEmailRequired, final List<String> actionTypes) {
int[] actions = new int[actionTypes.size()];
for (int i = 0; i < actionTypes.size(); i++) {
actions[i] = ArgsRegistry.getDeserializedValue(actionTypes.get(i), Integer.class);
}
FeatureRequests.setEmailFieldRequired(isEmailRequired, actions);
}

/**
* Manual invocation for chats view.
*/
public void showChats() {
Chats.show();
}

/**
* Enables and disables everything related to creating new chats.
* @param {boolean} isEnabled
*/
public void setChatsEnabled(final boolean isEnabled) {
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
if (isEnabled) {
Chats.setState(Feature.State.ENABLED);
} else {
Chats.setState(Feature.State.DISABLED);
}
}
});
}


}
9 changes: 8 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import 'package:instabug_flutter/Instabug.dart';
import 'package:instabug_flutter/BugReporting.dart';
import 'package:instabug_flutter/InstabugLog.dart';
import 'package:instabug_flutter/Surveys.dart';
import 'package:instabug_flutter/FeatureRequests.dart';
import 'package:instabug_flutter/Chats.dart';

void main() => runApp(MyApp());

Expand Down Expand Up @@ -123,8 +125,13 @@ class _MyAppState extends State<MyApp> {
// Surveys.getAvailableSurveys(getSurveys);
// Surveys.showSurveyIfAvailable();
// Surveys.setShouldShowWelcomeScreen(true);
Surveys.showSurvey("BHJI1iaKYhr4CYHHcUAaTg");
//Surveys.showSurvey("BHJI1iaKYhr4CYHHcUAaTg");
//BugReporting.showWithOptions(ReportType.bug, <InvocationOption>[InvocationOption.emailFieldHidden]);
// FeatureRequests.setEmailFieldRequired(false, [ActionType.allActions]);
// FeatureRequests.show();
Chats.setEnabled(true);
Chats.show();

}

void invokeWithMode() {
Expand Down
45 changes: 45 additions & 0 deletions ios/Classes/InstabugFlutterPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,46 @@ + (void)hasRespondedToSurveyWithToken:(NSString *)surveyToken {
[channel invokeMethod:@"hasRespondedToSurveyCallback" arguments:boolNumber];
}

/**
* Shows the UI for feature requests list
*/
+ (void)showFeatureRequests {
[IBGFeatureRequests show];
}

/**
* 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
*/
+ (void)setEmailFieldRequiredForFeatureRequests:(NSNumber*)isEmailFieldRequired forAction:(NSArray *)actionTypesArray {
NSDictionary *constants = [self constants];
NSInteger actionTypes = 0;
for (NSString * actionType in actionTypesArray) {
actionTypes |= ((NSNumber *) constants[actionType]).integerValue;
}
BOOL boolValue = [isEmailFieldRequired boolValue];
[IBGFeatureRequests setEmailFieldRequired:boolValue forAction:actionTypes];
}

/**
* Manual invocation for chats view.
*/
+ (void)showChats {
[IBGChats show];
}

/**
* Enables and disables everything related to creating new chats.
* @param {boolean} isEnabled
*/
+ (void)setChatsEnabled:(NSNumber *)isEnabled {
BOOL boolValue = [isEnabled boolValue];
IBGChats.enabled = boolValue;
}


+ (NSDictionary *)constants {
return @{
Expand Down Expand Up @@ -696,6 +736,11 @@ + (NSDictionary *)constants {
@"ExtendedBugReportMode.enabledWithRequiredFields": @(IBGExtendedBugReportModeEnabledWithRequiredFields),
@"ExtendedBugReportMode.enabledWithOptionalFields": @(IBGExtendedBugReportModeEnabledWithOptionalFields),
@"ExtendedBugReportMode.disabled": @(IBGExtendedBugReportModeDisabled),

@"ActionType.allActions": @(IBGActionAllActions),
@"ActionType.reportBug": @(IBGActionReportBug),
@"ActionType.requestNewFeature": @(IBGActionRequestNewFeature),
@"ActionType.addCommentToFeature": @(IBGActionAddCommentToFeature),
};
};

Expand Down
28 changes: 28 additions & 0 deletions lib/Chats.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:instabug_flutter/Instabug.dart';


class Chats {

static const MethodChannel _channel = MethodChannel('instabug_flutter');

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

///Manual invocation for chats view.
static void show() async {
await _channel.invokeMethod<Object>('showChats');
}

/// Enables and disables everything related to creating new chats.
/// [boolean] isEnabled
static void setEnabled(bool isEnabled) async {
final List<dynamic> params = <dynamic>[isEnabled];
await _channel.invokeMethod<Object>('setChatsEnabled:', params);
}

}
43 changes: 43 additions & 0 deletions lib/FeatureRequests.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:instabug_flutter/Instabug.dart';

enum ActionType {
allActions,
reportBug,
requestNewFeature,
addCommentToFeature
}

class FeatureRequests {

static const MethodChannel _channel = MethodChannel('instabug_flutter');

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

///Shows the UI for feature requests list
static void show() async {
await _channel.invokeMethod<Object>('showFeatureRequests');
}

/// Sets whether users are required to enter an email address or not when sending reports.
/// Defaults to YES.
/// [isEmailFieldRequired] A boolean to indicate whether email
/// field is required or not.
/// [actionTypes] An enum that indicates which action types will have the isEmailFieldRequired
static void setEmailFieldRequired(bool isEmailFieldRequired, List<ActionType> actionTypes) async {
List<String> actionTypesStrings = <String>[];
if (actionTypes != null) {
actionTypes.forEach((e) {
actionTypesStrings.add(e.toString());
});
}
final List<dynamic> params = <dynamic>[isEmailFieldRequired, actionTypesStrings];
await _channel.invokeMethod<Object>('setEmailFieldRequiredForFeatureRequests:forAction:',params);
}

}
40 changes: 40 additions & 0 deletions test/instabug_flutter_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import 'package:instabug_flutter/InstabugLog.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:instabug_flutter/Surveys.dart';
import 'package:instabug_flutter/FeatureRequests.dart';
import 'package:instabug_flutter/Chats.dart';

void main() {

Expand Down Expand Up @@ -532,6 +534,44 @@ test('startWithToken:invocationEvents: Test', () async {
]);
});

test('showFeatureRequests Test', () async {
FeatureRequests.show();
expect(log, <Matcher>[
isMethodCall('showFeatureRequests'
)
]);
});

test('setEmailFieldRequiredForFeatureRequests:forAction: Test', () async {
bool isEmailFieldRequired = false;
final List<dynamic> args = <dynamic>[isEmailFieldRequired, <String>[ActionType.allActions.toString()]];
FeatureRequests.setEmailFieldRequired(isEmailFieldRequired, [ActionType.allActions]);
expect(log, <Matcher>[
isMethodCall('setEmailFieldRequiredForFeatureRequests:forAction:',
arguments: args,
)
]);
});

test('showChats Test', () async {
Chats.show();
expect(log, <Matcher>[
isMethodCall('showChats'
)
]);
});

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

}