Skip to content

Commit 5c5ca7e

Browse files
authored
[Mob 3372] , [MOB-3377], [Mob 3382] , [MOB-3387]: Flutter API [FeatureRequests], [Chats] (#61)
* Android API & Enums Mappings * IOS API & Enums Mapping * Flutter API Mapping * Adds tests for new API * updates Readme * updated Changelog ## Mapped APIs: * showFeatureRequests * setEmailFieldRequiredForFeatureRequests * showChats * setChatsEnabled
1 parent 39d884a commit 5c5ca7e

File tree

9 files changed

+243
-1
lines changed

9 files changed

+243
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## Master
2+
3+
* Adds Chats Api mappings
4+
* Adds FeatureRequests Api mappings.
5+
16
## Version 0.0.4 (2019-04-14)
27

38
* Adds hasRespondedToSurvey API mapping.

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,21 @@ The section below contains the APIs we're planning to implement for our 1.0 rele
9191
| `showSurvey(String surveyToken)` | `showSurvey(String token)`<br>`+ showSurveyWithToken:` |
9292
| `hasRespondedToSurvey(String surveyToken, Function function)` | `hasRespondToSurvey(String token)`<br>`+ hasRespondedToSurveyWithToken:` |
9393

94+
#### `FeatureRequests`
95+
96+
| API Method | Native Equivalent (Android/iOS) |
97+
|-----------------------------------------------|--------------------------------------------------------------|
98+
| `show() ` | `show()`<br>`+ show` |
99+
| `setEmailFieldRequired(bool isEmailFieldRequired, List<ActionType> actionTypes)` | `setEmailFieldRequired(boolean isEmailRequired, ActionTypes actions)`<br>`+ setEmailFieldRequired:forAction:` |
100+
101+
102+
#### `Chats`
103+
104+
| API Method | Native Equivalent (Android/iOS) |
105+
|-----------------------------------------------|--------------------------------------------------------------|
106+
| `show()` | `show()`<br>`+ show` |
107+
| `setEnabled(bool isEnabled)` | `setState(Feature.State state)`<br>`enabled` |
108+
94109
## Integration
95110

96111
Creating a Flutter app on the Instabug dashboard isn't possible yet. Create a React Native app instead.

android/src/main/java/com/instabug/instabugflutter/ArgsRegistry.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import com.instabug.bug.BugReporting;
77
import com.instabug.bug.invocation.Option;
8+
import com.instabug.library.ActionType;
89
import com.instabug.library.InstabugColorTheme;
910
import com.instabug.library.InstabugCustomTextPlaceHolder;
1011
import com.instabug.library.extendedbugreport.ExtendedBugReport;
@@ -60,6 +61,7 @@ final class ArgsRegistry {
6061
registerCustomTextPlaceHolderKeysArgs(ARGS);
6162
registerInstabugReportTypesArgs(ARGS);
6263
registerInstabugExtendedBugReportModeArgs(ARGS);
64+
registerInstabugActionTypesArgs(ARGS);
6365
}
6466

6567
/**
@@ -214,4 +216,13 @@ static void registerInstabugExtendedBugReportModeArgs(Map<String, Object> args)
214216
args.put("ExtendedBugReportMode.enabledWithOptionalFields", ExtendedBugReport.State.ENABLED_WITH_OPTIONAL_FIELDS);
215217
args.put("ExtendedBugReportMode.disabled",ExtendedBugReport.State.DISABLED);
216218
}
219+
220+
@VisibleForTesting
221+
static void registerInstabugActionTypesArgs(Map<String, Object> args) {
222+
args.put("ActionType.allActions", ActionType.ALL_ACTIONS);
223+
args.put("ActionType.reportBug", ActionType.REPORT_BUG);
224+
args.put("ActionType.requestNewFeature",ActionType.REQUEST_NEW_FEATURE);
225+
args.put("ActionType.addCommentToFeature",ActionType.ADD_COMMENT_TO_FEATURE);
226+
}
227+
217228
}

android/src/main/java/com/instabug/instabugflutter/InstabugFlutterPlugin.java

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.instabug.bug.invocation.Option;
1111
import com.instabug.chat.Chats;
1212
import com.instabug.chat.Replies;
13+
import com.instabug.featuresrequest.FeatureRequests;
1314
import com.instabug.library.Feature;
1415
import com.instabug.library.Instabug;
1516
import com.instabug.library.InstabugColorTheme;
@@ -732,4 +733,51 @@ public void hasRespondedToSurveyWithToken(String surveyToken) {
732733
channel.invokeMethod("hasRespondedToSurveyCallback", hasResponded);
733734
}
734735

736+
/**
737+
* Shows the UI for feature requests list
738+
*/
739+
public void showFeatureRequests() {
740+
FeatureRequests.show();
741+
}
742+
743+
/**
744+
* Sets whether email field is required or not when submitting
745+
* new-feature-request/new-comment-on-feature
746+
*
747+
* @param isEmailRequired set true to make email field required
748+
* @param actionTypes Bitwise-or of actions
749+
*/
750+
public void setEmailFieldRequiredForFeatureRequests(final Boolean isEmailRequired, final List<String> actionTypes) {
751+
int[] actions = new int[actionTypes.size()];
752+
for (int i = 0; i < actionTypes.size(); i++) {
753+
actions[i] = ArgsRegistry.getDeserializedValue(actionTypes.get(i), Integer.class);
754+
}
755+
FeatureRequests.setEmailFieldRequired(isEmailRequired, actions);
756+
}
757+
758+
/**
759+
* Manual invocation for chats view.
760+
*/
761+
public void showChats() {
762+
Chats.show();
763+
}
764+
765+
/**
766+
* Enables and disables everything related to creating new chats.
767+
* @param {boolean} isEnabled
768+
*/
769+
public void setChatsEnabled(final boolean isEnabled) {
770+
new Handler(Looper.getMainLooper()).post(new Runnable() {
771+
@Override
772+
public void run() {
773+
if (isEnabled) {
774+
Chats.setState(Feature.State.ENABLED);
775+
} else {
776+
Chats.setState(Feature.State.DISABLED);
777+
}
778+
}
779+
});
780+
}
781+
782+
735783
}

example/lib/main.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import 'package:instabug_flutter/Instabug.dart';
77
import 'package:instabug_flutter/BugReporting.dart';
88
import 'package:instabug_flutter/InstabugLog.dart';
99
import 'package:instabug_flutter/Surveys.dart';
10+
import 'package:instabug_flutter/FeatureRequests.dart';
11+
import 'package:instabug_flutter/Chats.dart';
1012

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

@@ -123,8 +125,13 @@ class _MyAppState extends State<MyApp> {
123125
// Surveys.getAvailableSurveys(getSurveys);
124126
// Surveys.showSurveyIfAvailable();
125127
// Surveys.setShouldShowWelcomeScreen(true);
126-
Surveys.showSurvey("BHJI1iaKYhr4CYHHcUAaTg");
128+
//Surveys.showSurvey("BHJI1iaKYhr4CYHHcUAaTg");
127129
//BugReporting.showWithOptions(ReportType.bug, <InvocationOption>[InvocationOption.emailFieldHidden]);
130+
// FeatureRequests.setEmailFieldRequired(false, [ActionType.allActions]);
131+
// FeatureRequests.show();
132+
Chats.setEnabled(true);
133+
Chats.show();
134+
128135
}
129136

130137
void invokeWithMode() {

ios/Classes/InstabugFlutterPlugin.m

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,46 @@ + (void)hasRespondedToSurveyWithToken:(NSString *)surveyToken {
614614
[channel invokeMethod:@"hasRespondedToSurveyCallback" arguments:boolNumber];
615615
}
616616

617+
/**
618+
* Shows the UI for feature requests list
619+
*/
620+
+ (void)showFeatureRequests {
621+
[IBGFeatureRequests show];
622+
}
623+
624+
/**
625+
* Sets whether email field is required or not when submitting
626+
* new-feature-request/new-comment-on-feature
627+
*
628+
* @param isEmailRequired set true to make email field required
629+
* @param actionTypes Bitwise-or of actions
630+
*/
631+
+ (void)setEmailFieldRequiredForFeatureRequests:(NSNumber*)isEmailFieldRequired forAction:(NSArray *)actionTypesArray {
632+
NSDictionary *constants = [self constants];
633+
NSInteger actionTypes = 0;
634+
for (NSString * actionType in actionTypesArray) {
635+
actionTypes |= ((NSNumber *) constants[actionType]).integerValue;
636+
}
637+
BOOL boolValue = [isEmailFieldRequired boolValue];
638+
[IBGFeatureRequests setEmailFieldRequired:boolValue forAction:actionTypes];
639+
}
640+
641+
/**
642+
* Manual invocation for chats view.
643+
*/
644+
+ (void)showChats {
645+
[IBGChats show];
646+
}
647+
648+
/**
649+
* Enables and disables everything related to creating new chats.
650+
* @param {boolean} isEnabled
651+
*/
652+
+ (void)setChatsEnabled:(NSNumber *)isEnabled {
653+
BOOL boolValue = [isEnabled boolValue];
654+
IBGChats.enabled = boolValue;
655+
}
656+
617657

618658
+ (NSDictionary *)constants {
619659
return @{
@@ -696,6 +736,11 @@ + (NSDictionary *)constants {
696736
@"ExtendedBugReportMode.enabledWithRequiredFields": @(IBGExtendedBugReportModeEnabledWithRequiredFields),
697737
@"ExtendedBugReportMode.enabledWithOptionalFields": @(IBGExtendedBugReportModeEnabledWithOptionalFields),
698738
@"ExtendedBugReportMode.disabled": @(IBGExtendedBugReportModeDisabled),
739+
740+
@"ActionType.allActions": @(IBGActionAllActions),
741+
@"ActionType.reportBug": @(IBGActionReportBug),
742+
@"ActionType.requestNewFeature": @(IBGActionRequestNewFeature),
743+
@"ActionType.addCommentToFeature": @(IBGActionAddCommentToFeature),
699744
};
700745
};
701746

lib/Chats.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import 'dart:async';
2+
import 'package:flutter/foundation.dart';
3+
import 'package:flutter/services.dart';
4+
import 'package:instabug_flutter/Instabug.dart';
5+
6+
7+
class Chats {
8+
9+
static const MethodChannel _channel = MethodChannel('instabug_flutter');
10+
11+
static Future<String> get platformVersion async {
12+
final String version = await _channel.invokeMethod('getPlatformVersion');
13+
return version;
14+
}
15+
16+
///Manual invocation for chats view.
17+
static void show() async {
18+
await _channel.invokeMethod<Object>('showChats');
19+
}
20+
21+
/// Enables and disables everything related to creating new chats.
22+
/// [boolean] isEnabled
23+
static void setEnabled(bool isEnabled) async {
24+
final List<dynamic> params = <dynamic>[isEnabled];
25+
await _channel.invokeMethod<Object>('setChatsEnabled:', params);
26+
}
27+
28+
}

lib/FeatureRequests.dart

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import 'dart:async';
2+
import 'package:flutter/foundation.dart';
3+
import 'package:flutter/services.dart';
4+
import 'package:instabug_flutter/Instabug.dart';
5+
6+
enum ActionType {
7+
allActions,
8+
reportBug,
9+
requestNewFeature,
10+
addCommentToFeature
11+
}
12+
13+
class FeatureRequests {
14+
15+
static const MethodChannel _channel = MethodChannel('instabug_flutter');
16+
17+
static Future<String> get platformVersion async {
18+
final String version = await _channel.invokeMethod('getPlatformVersion');
19+
return version;
20+
}
21+
22+
///Shows the UI for feature requests list
23+
static void show() async {
24+
await _channel.invokeMethod<Object>('showFeatureRequests');
25+
}
26+
27+
/// Sets whether users are required to enter an email address or not when sending reports.
28+
/// Defaults to YES.
29+
/// [isEmailFieldRequired] A boolean to indicate whether email
30+
/// field is required or not.
31+
/// [actionTypes] An enum that indicates which action types will have the isEmailFieldRequired
32+
static void setEmailFieldRequired(bool isEmailFieldRequired, List<ActionType> actionTypes) async {
33+
List<String> actionTypesStrings = <String>[];
34+
if (actionTypes != null) {
35+
actionTypes.forEach((e) {
36+
actionTypesStrings.add(e.toString());
37+
});
38+
}
39+
final List<dynamic> params = <dynamic>[isEmailFieldRequired, actionTypesStrings];
40+
await _channel.invokeMethod<Object>('setEmailFieldRequiredForFeatureRequests:forAction:',params);
41+
}
42+
43+
}

test/instabug_flutter_test.dart

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import 'package:instabug_flutter/InstabugLog.dart';
88
import 'package:flutter/services.dart';
99
import 'package:flutter_test/flutter_test.dart';
1010
import 'package:instabug_flutter/Surveys.dart';
11+
import 'package:instabug_flutter/FeatureRequests.dart';
12+
import 'package:instabug_flutter/Chats.dart';
1113

1214
void main() {
1315

@@ -532,6 +534,44 @@ test('startWithToken:invocationEvents: Test', () async {
532534
]);
533535
});
534536

537+
test('showFeatureRequests Test', () async {
538+
FeatureRequests.show();
539+
expect(log, <Matcher>[
540+
isMethodCall('showFeatureRequests'
541+
)
542+
]);
543+
});
544+
545+
test('setEmailFieldRequiredForFeatureRequests:forAction: Test', () async {
546+
bool isEmailFieldRequired = false;
547+
final List<dynamic> args = <dynamic>[isEmailFieldRequired, <String>[ActionType.allActions.toString()]];
548+
FeatureRequests.setEmailFieldRequired(isEmailFieldRequired, [ActionType.allActions]);
549+
expect(log, <Matcher>[
550+
isMethodCall('setEmailFieldRequiredForFeatureRequests:forAction:',
551+
arguments: args,
552+
)
553+
]);
554+
});
555+
556+
test('showChats Test', () async {
557+
Chats.show();
558+
expect(log, <Matcher>[
559+
isMethodCall('showChats'
560+
)
561+
]);
562+
});
563+
564+
test('setChatsEnabled: Test', () async {
565+
bool isEnabled = false;
566+
final List<dynamic> args = <dynamic>[isEnabled];
567+
Chats.setEnabled(isEnabled);
568+
expect(log, <Matcher>[
569+
isMethodCall('setChatsEnabled:',
570+
arguments: args,
571+
)
572+
]);
573+
});
574+
535575
}
536576

537577

0 commit comments

Comments
 (0)