diff --git a/CHANGELOG.md b/CHANGELOG.md index 75bbf07f4..ebb5a9d40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## Master + +* Adds Chats Api mappings +* Adds FeatureRequests Api mappings. + ## Version 0.0.4 (2019-04-14) * Adds hasRespondedToSurvey API mapping. diff --git a/README.md b/README.md index a75022926..6ab79edea 100644 --- a/README.md +++ b/README.md @@ -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)`
`+ showSurveyWithToken:` | | `hasRespondedToSurvey(String surveyToken, Function function)` | `hasRespondToSurvey(String token)`
`+ hasRespondedToSurveyWithToken:` | +#### `FeatureRequests` + +| API Method | Native Equivalent (Android/iOS) | +|-----------------------------------------------|--------------------------------------------------------------| +| `show() ` | `show()`
`+ show` | +| `setEmailFieldRequired(bool isEmailFieldRequired, List actionTypes)` | `setEmailFieldRequired(boolean isEmailRequired, ActionTypes actions)`
`+ setEmailFieldRequired:forAction:` | + + +#### `Chats` + +| API Method | Native Equivalent (Android/iOS) | +|-----------------------------------------------|--------------------------------------------------------------| +| `show()` | `show()`
`+ show` | +| `setEnabled(bool isEnabled)` | `setState(Feature.State state)`
`enabled` | + ## Integration Creating a Flutter app on the Instabug dashboard isn't possible yet. Create a React Native app instead. diff --git a/android/src/main/java/com/instabug/instabugflutter/ArgsRegistry.java b/android/src/main/java/com/instabug/instabugflutter/ArgsRegistry.java index f51d93233..15dd957db 100644 --- a/android/src/main/java/com/instabug/instabugflutter/ArgsRegistry.java +++ b/android/src/main/java/com/instabug/instabugflutter/ArgsRegistry.java @@ -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; @@ -60,6 +61,7 @@ final class ArgsRegistry { registerCustomTextPlaceHolderKeysArgs(ARGS); registerInstabugReportTypesArgs(ARGS); registerInstabugExtendedBugReportModeArgs(ARGS); + registerInstabugActionTypesArgs(ARGS); } /** @@ -214,4 +216,13 @@ static void registerInstabugExtendedBugReportModeArgs(Map args) args.put("ExtendedBugReportMode.enabledWithOptionalFields", ExtendedBugReport.State.ENABLED_WITH_OPTIONAL_FIELDS); args.put("ExtendedBugReportMode.disabled",ExtendedBugReport.State.DISABLED); } + + @VisibleForTesting + static void registerInstabugActionTypesArgs(Map 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); + } + } diff --git a/android/src/main/java/com/instabug/instabugflutter/InstabugFlutterPlugin.java b/android/src/main/java/com/instabug/instabugflutter/InstabugFlutterPlugin.java index 6f93f340f..423b1ffc0 100644 --- a/android/src/main/java/com/instabug/instabugflutter/InstabugFlutterPlugin.java +++ b/android/src/main/java/com/instabug/instabugflutter/InstabugFlutterPlugin.java @@ -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; @@ -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 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); + } + } + }); + } + + } diff --git a/example/lib/main.dart b/example/lib/main.dart index 0a617fd31..ab19df60a 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -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()); @@ -123,8 +125,13 @@ class _MyAppState extends State { // Surveys.getAvailableSurveys(getSurveys); // Surveys.showSurveyIfAvailable(); // Surveys.setShouldShowWelcomeScreen(true); - Surveys.showSurvey("BHJI1iaKYhr4CYHHcUAaTg"); + //Surveys.showSurvey("BHJI1iaKYhr4CYHHcUAaTg"); //BugReporting.showWithOptions(ReportType.bug, [InvocationOption.emailFieldHidden]); + // FeatureRequests.setEmailFieldRequired(false, [ActionType.allActions]); + // FeatureRequests.show(); + Chats.setEnabled(true); + Chats.show(); + } void invokeWithMode() { diff --git a/ios/Classes/InstabugFlutterPlugin.m b/ios/Classes/InstabugFlutterPlugin.m index 70fd3fcfa..06db9f942 100644 --- a/ios/Classes/InstabugFlutterPlugin.m +++ b/ios/Classes/InstabugFlutterPlugin.m @@ -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 @{ @@ -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), }; }; diff --git a/lib/Chats.dart b/lib/Chats.dart new file mode 100644 index 000000000..a1a2271ea --- /dev/null +++ b/lib/Chats.dart @@ -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 get platformVersion async { + final String version = await _channel.invokeMethod('getPlatformVersion'); + return version; + } + + ///Manual invocation for chats view. + static void show() async { + await _channel.invokeMethod('showChats'); + } + + /// Enables and disables everything related to creating new chats. + /// [boolean] isEnabled + static void setEnabled(bool isEnabled) async { + final List params = [isEnabled]; + await _channel.invokeMethod('setChatsEnabled:', params); + } + +} diff --git a/lib/FeatureRequests.dart b/lib/FeatureRequests.dart new file mode 100644 index 000000000..8b2796523 --- /dev/null +++ b/lib/FeatureRequests.dart @@ -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 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('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 actionTypes) async { + List actionTypesStrings = []; + if (actionTypes != null) { + actionTypes.forEach((e) { + actionTypesStrings.add(e.toString()); + }); + } + final List params = [isEmailFieldRequired, actionTypesStrings]; + await _channel.invokeMethod('setEmailFieldRequiredForFeatureRequests:forAction:',params); + } + +} diff --git a/test/instabug_flutter_test.dart b/test/instabug_flutter_test.dart index 61e7d65c3..d5e3ac2cf 100644 --- a/test/instabug_flutter_test.dart +++ b/test/instabug_flutter_test.dart @@ -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() { @@ -532,6 +534,44 @@ test('startWithToken:invocationEvents: Test', () async { ]); }); + test('showFeatureRequests Test', () async { + FeatureRequests.show(); + expect(log, [ + isMethodCall('showFeatureRequests' + ) + ]); + }); + + test('setEmailFieldRequiredForFeatureRequests:forAction: Test', () async { + bool isEmailFieldRequired = false; + final List args = [isEmailFieldRequired, [ActionType.allActions.toString()]]; + FeatureRequests.setEmailFieldRequired(isEmailFieldRequired, [ActionType.allActions]); + expect(log, [ + isMethodCall('setEmailFieldRequiredForFeatureRequests:forAction:', + arguments: args, + ) + ]); + }); + + test('showChats Test', () async { + Chats.show(); + expect(log, [ + isMethodCall('showChats' + ) + ]); + }); + + test('setChatsEnabled: Test', () async { + bool isEnabled = false; + final List args = [isEnabled]; + Chats.setEnabled(isEnabled); + expect(log, [ + isMethodCall('setChatsEnabled:', + arguments: args, + ) + ]); + }); + }