Skip to content

Commit 676db9b

Browse files
mzelzoghbimhmdnagy
authored andcommitted
Updating Instabug-SDK version to v8.0.2 and migrating to new APIs (#106)
1 parent 4d00c41 commit 676db9b

File tree

4 files changed

+50
-34
lines changed

4 files changed

+50
-34
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ dependencies {
5050
// TODO add the following 2 lines if you exclude io.reactivex from Instabug
5151
// implementation 'io.reactivex:rxjava:1.0.13'
5252
// implementation 'io.reactivex:rxandroid:1.0.1'
53-
implementation('com.instabug.library:instabug:4.15.0') {
53+
implementation('com.instabug.library:instabug:8.0.2') {
5454
// TODO uncomment this line to exclude RxJava from Instabug and use your own version
5555
// exclude group: 'io.reactivex'
5656

app/src/main/java/com/example/instabug/SampleApplication.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ public void onCreate() {
2727

2828
//initialing instabug
2929
new Instabug.Builder(this, "48ad905e141bc665d064945f423aa414")
30-
.setInvocationEvent(InstabugInvocationEvent.SHAKE)
30+
.setInvocationEvents(InstabugInvocationEvent.SHAKE, InstabugInvocationEvent.SCREENSHOT_GESTURE,
31+
InstabugInvocationEvent.FLOATING_BUTTON, InstabugInvocationEvent.TWO_FINGER_SWIPE_LEFT)
3132
.build();
3233

3334
//Choosing instabug theme
34-
Instabug.setTheme(InstabugColorTheme.InstabugColorThemeLight);
35+
Instabug.setColorTheme(InstabugColorTheme.InstabugColorThemeLight);
3536
//Choosing type of attachments allowed
3637
//1. initial screenshot, 2. extra screenshot, 3. image from gallery, 4. voice note
3738
//5. screen record

app/src/main/java/com/example/instabug/ui/activities/MainActivity.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@
1313
import com.example.instabug.BaseActivity;
1414
import com.example.instabug.R;
1515
import com.example.instabug.fcm.RegistrationIntentService;
16+
import com.instabug.bug.BugReporting;
17+
import com.instabug.featuresrequest.FeatureRequests;
1618
import com.instabug.library.Instabug;
1719
import com.instabug.library.logging.InstabugLog;
1820
import com.instabug.library.logging.InstabugNetworkLog;
1921
import com.instabug.library.ui.onboarding.WelcomeMessage;
22+
import com.instabug.survey.Surveys;
2023

2124
import org.json.JSONException;
2225
import org.json.JSONObject;
@@ -62,7 +65,7 @@ public void onShowBetaOnboardingMessageClicked(View view) {
6265
}
6366

6467
public void onShowInstabugClicked(View view) {
65-
Instabug.invoke();
68+
BugReporting.invoke();
6669
}
6770

6871
public void onCrashTheAppClicked(View view) {
@@ -80,15 +83,15 @@ public void onClick(DialogInterface dialog, int which) {
8083
}
8184

8285
public void showNPSSurvey(View view) {
83-
Instabug.showSurvey("ulUaFocMCejDr3Ldd8VBaA");
86+
Surveys.showSurvey("ulUaFocMCejDr3Ldd8VBaA");
8487
}
8588

8689
public void showMultipleQuestionSurvey(View view) {
87-
Instabug.showSurvey("AGI5OH47k3eEAIKj-yKDWA");
90+
Surveys.showSurvey("AGI5OH47k3eEAIKj-yKDWA");
8891
}
8992

9093
public void showFeatureRequests(View view) {
91-
Instabug.showFeatureRequests();
94+
FeatureRequests.show();
9295
}
9396

9497
public void onShowSettingsClicked(View view) {

app/src/main/java/com/example/instabug/ui/activities/SettingsActivity.java

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,24 @@
66
import android.support.v7.app.AlertDialog;
77
import android.support.v7.widget.Toolbar;
88
import android.view.View;
9-
import android.widget.ArrayAdapter;
10-
import android.widget.Toast;
119

1210
import com.example.instabug.BaseActivity;
1311
import com.example.instabug.R;
12+
import com.instabug.bug.BugReporting;
1413
import com.instabug.library.Instabug;
1514
import com.instabug.library.InstabugColorTheme;
1615
import com.instabug.library.invocation.InstabugInvocationEvent;
1716

17+
import java.util.ArrayList;
18+
import java.util.Arrays;
19+
1820
import petrov.kristiyan.colorpicker.ColorPicker;
1921

2022
public class SettingsActivity extends BaseActivity {
23+
24+
final String[] invocationEvents = getInvocationEventsNames(InstabugInvocationEvent.class);
25+
final boolean[] invocationEventsState = {false, false, false, false, false};
26+
2127
@Override
2228
protected void onCreate(@Nullable Bundle savedInstanceState) {
2329
super.onCreate(savedInstanceState);
@@ -26,37 +32,45 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
2632
Toolbar toolbar = findViewById(R.id.toolbar);
2733
setSupportActionBar(toolbar);
2834

35+
36+
for (int i = 0; i < invocationEvents.length; i++) {
37+
invocationEvents[i] = invocationEvents[i].replace("_", " ");
38+
}
2939
}
3040

3141
public void onShowInvocationEventsClicked(View view) {
32-
final CharSequence[] items = {"Shake", "Floating Button", "Screenshot", "Two Finger Swipe", "None"};
33-
42+
// reset events
43+
for (int i = 0; i < invocationEventsState.length; i++) {
44+
invocationEventsState[i] = false;
45+
}
3446
AlertDialog.Builder builder = new AlertDialog.Builder(this);
35-
builder.setTitle("Select Invocation Event");
36-
builder.setItems(items, new DialogInterface.OnClickListener() {
37-
public void onClick(DialogInterface dialog, int item) {
38-
switch (item) {
39-
case 0:
40-
Instabug.changeInvocationEvent(InstabugInvocationEvent.SHAKE);
41-
break;
42-
case 1:
43-
Instabug.changeInvocationEvent(InstabugInvocationEvent.FLOATING_BUTTON);
44-
break;
45-
case 2:
46-
Instabug.changeInvocationEvent(InstabugInvocationEvent.SCREENSHOT_GESTURE);
47-
break;
48-
case 3:
49-
Instabug.changeInvocationEvent(InstabugInvocationEvent.TWO_FINGER_SWIPE_LEFT);
50-
break;
51-
case 4:
52-
Instabug.changeInvocationEvent(InstabugInvocationEvent.NONE);
53-
break;
47+
builder.setTitle("Select Invocation Events");
48+
builder.setMultiChoiceItems(invocationEvents, null, new DialogInterface.OnMultiChoiceClickListener() {
49+
@Override
50+
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
51+
invocationEventsState[which] = isChecked;
52+
}
53+
});
54+
builder.setPositiveButton("Done", new DialogInterface.OnClickListener() {
55+
@Override
56+
public void onClick(DialogInterface dialog, int which) {
57+
ArrayList<InstabugInvocationEvent> selectedEvents = new ArrayList();
58+
for (int i = 0; i < invocationEvents.length; i++) {
59+
if (invocationEventsState[i]) {
60+
selectedEvents.add(InstabugInvocationEvent.valueOf(invocationEvents[i].toUpperCase().replace(" ", "_")));
61+
}
5462
}
63+
// set new invocation events here
64+
BugReporting.setInvocationEvents(selectedEvents.toArray(new InstabugInvocationEvent[selectedEvents.size()]));
5565
}
5666
});
5767
builder.show();
5868
}
5969

70+
public static String[] getInvocationEventsNames(Class<? extends Enum<?>> e) {
71+
return Arrays.toString(e.getEnumConstants()).replaceAll("^.|.$", "").split(", ");
72+
}
73+
6074
public void onChangeThemeClicked(View view) {
6175
final CharSequence[] items = {"Light", "Dark"};
6276

@@ -66,10 +80,10 @@ public void onChangeThemeClicked(View view) {
6680
public void onClick(DialogInterface dialog, int item) {
6781
switch (item) {
6882
case 0:
69-
Instabug.setTheme(InstabugColorTheme.InstabugColorThemeLight);
83+
Instabug.setColorTheme(InstabugColorTheme.InstabugColorThemeLight);
7084
break;
7185
case 1:
72-
Instabug.setTheme(InstabugColorTheme.InstabugColorThemeDark);
86+
Instabug.setColorTheme(InstabugColorTheme.InstabugColorThemeDark);
7387
break;
7488
}
7589
}
@@ -83,9 +97,7 @@ public void onChangePrimaryColorClicked(View view) {
8397
colorPicker.setOnChooseColorListener(new ColorPicker.OnChooseColorListener() {
8498
@Override
8599
public void onChooseColor(int position, int color) {
86-
Instabug.disable();
87100
Instabug.setPrimaryColor(color);
88-
Instabug.enable();
89101
}
90102

91103
@Override

0 commit comments

Comments
 (0)