Skip to content

Commit 6082602

Browse files
feat: remove builder
1 parent be71993 commit 6082602

File tree

4 files changed

+12
-70
lines changed

4 files changed

+12
-70
lines changed

android/src/test/java/com/instabug/flutter/BugReportingApiTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,15 @@ public void testSetCommentMinimumCharacterCount() {
200200
public void testSetProactiveReportingConfigurations() {
201201
// given
202202
boolean enabled = true;
203-
long gapBetweekDialogs = 20;
203+
long gapBetweenDialogs = 20;
204204
long modeDelay = 30;
205205

206206
// when
207-
api.setProactiveReportingConfigurations(enabled, gapBetweekDialogs, modeDelay);
207+
api.setProactiveReportingConfigurations(enabled, gapBetweenDialogs, modeDelay);
208208

209209
// then
210210
mBugReporting.verify(() -> BugReporting.setProactiveReportingConfigurations(argThat(config ->
211-
config.getModalsGap() == gapBetweekDialogs &&
211+
config.getModalsGap() == gapBetweenDialogs &&
212212
config.getDetectionGap() == modeDelay &&
213213
config.isEnabled() == enabled
214214
)));

example/lib/main.dart

+1-5
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@ void main() {
5858
};
5959

6060
BugReporting.setProactiveReportingConfigurations(
61-
ProactiveReportingConfigsBuilder()
62-
.setModalDelayAfterDetection(1)
63-
.setGapBetweenModals(1)
64-
.isEnabled(true)
65-
.build());
61+
ProactiveReportingConfigs());
6662

6763
runApp(const MyApp());
6864
},

lib/src/models/proactive_reporting_config.dart

+4-57
Original file line numberDiff line numberDiff line change
@@ -5,62 +5,9 @@ class ProactiveReportingConfigs {
55
final int modalDelayAfterDetection; // Time in seconds
66
final bool enabled;
77

8-
// Private constructor to ensure it can only be created through the builder
9-
const ProactiveReportingConfigs._({
10-
required this.gapBetweenModals,
11-
required this.modalDelayAfterDetection,
12-
required this.enabled,
8+
const ProactiveReportingConfigs({
9+
this.gapBetweenModals = 24,
10+
this.modalDelayAfterDetection = 20,
11+
this.enabled = true,
1312
});
1413
}
15-
16-
// Builder class for ProactiveReportingConfigs
17-
class ProactiveReportingConfigsBuilder {
18-
int gapBetweenModals = 30; // Default: 30 seconds
19-
int modalDelayAfterDetection = 15; // Default: 15 seconds
20-
bool enabled = true; // Default: enabled
21-
22-
// Logger method to handle logging
23-
void _logWarning(String message) {
24-
if (kDebugMode) {
25-
print('Warning: $message');
26-
}
27-
}
28-
29-
/// Controls the time gap between showing 2 proactive reporting dialogs in seconds
30-
ProactiveReportingConfigsBuilder setGapBetweenModals(int gap) {
31-
if (gap <= 0) {
32-
_logWarning(
33-
'gapBetweenModals must be a positive number. Using default value of 30 seconds.',
34-
);
35-
return this;
36-
}
37-
gapBetweenModals = gap;
38-
return this;
39-
}
40-
41-
/// Controls the time gap between detecting a frustrating experience
42-
ProactiveReportingConfigsBuilder setModalDelayAfterDetection(int delay) {
43-
if (delay <= 0) {
44-
_logWarning(
45-
'modalDelayAfterDetection must be a positive number. Using default value of 15 seconds.',
46-
);
47-
return this;
48-
}
49-
modalDelayAfterDetection = delay;
50-
return this;
51-
}
52-
53-
/// Controls the state of the feature
54-
ProactiveReportingConfigsBuilder isEnabled(bool value) {
55-
enabled = value;
56-
return this;
57-
}
58-
59-
ProactiveReportingConfigs build() {
60-
return ProactiveReportingConfigs._(
61-
gapBetweenModals: gapBetweenModals,
62-
modalDelayAfterDetection: modalDelayAfterDetection,
63-
enabled: enabled,
64-
);
65-
}
66-
}

test/bug_reporting_test.dart

+4-5
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,10 @@ void main() {
203203
test('[setProactiveReportingConfigurations] should call host method',
204204
() async {
205205
await BugReporting.setProactiveReportingConfigurations(
206-
ProactiveReportingConfigsBuilder()
207-
.setGapBetweenModals(1)
208-
.setModalDelayAfterDetection(1)
209-
.isEnabled(true)
210-
.build(),
206+
const ProactiveReportingConfigs(
207+
gapBetweenModals: 1,
208+
modalDelayAfterDetection: 1,
209+
),
211210
);
212211

213212
verify(mHost.setProactiveReportingConfigurations(true, 1, 1)).called(1);

0 commit comments

Comments
 (0)