Skip to content

Commit 1497a34

Browse files
Merge pull request #1309 from Instabug/feat/customizing-app-with-Dream11-configuration
feat: customizing app with dream11 configuration
2 parents 3ca4e81 + b2a03fe commit 1497a34

File tree

16 files changed

+1104
-81
lines changed

16 files changed

+1104
-81
lines changed

examples/hybrid/App.tsx

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
/* eslint-disable react-native/no-inline-styles */
22
import { ReactNode, useEffect } from 'react';
33
import React from 'react';
4-
import { Button, Image, SafeAreaView, Text } from 'react-native';
4+
import CodePush from 'react-native-code-push';
5+
import axios from 'axios';
6+
import { Button, Image, Platform, SafeAreaView, Text } from 'react-native';
57
import Instabug, {
68
CrashReporting,
79
InvocationEvent,
810
LogLevel,
11+
NetworkInterceptionMode,
912
ReproStepsMode,
1013
} from 'instabug-reactnative';
1114

@@ -23,13 +26,47 @@ const throwUnhandled = () => {
2326
throw Error('This is an unhandled JS Crash');
2427
};
2528

29+
const sendGraphQLRequest = async () => {
30+
try {
31+
const response = await axios.post(
32+
'https://countries.trevorblades.com/graphql',
33+
{
34+
query: `
35+
query GetCountry {
36+
country(code: "EG") {
37+
emoji
38+
name
39+
}
40+
}
41+
`,
42+
},
43+
{
44+
headers: {
45+
'Content-Type': 'application/json',
46+
'ibg-graphql-header': 'GetCountry',
47+
},
48+
},
49+
);
50+
console.log('Response:', response.data.data);
51+
} catch (error) {
52+
console.error('Error:', error);
53+
}
54+
};
55+
2656
const App: () => ReactNode = () => {
2757
useEffect(() => {
2858
Instabug.init({
29-
token: 'deb1910a7342814af4e4c9210c786f35',
59+
token: '0fcc87b8bf731164828cc411eccc802a',
3060
invocationEvents: [InvocationEvent.floatingButton],
61+
networkInterceptionMode:
62+
Platform.OS === 'ios' ? NetworkInterceptionMode.native : NetworkInterceptionMode.javascript,
3163
debugLogsLevel: LogLevel.verbose,
3264
});
65+
CodePush.getUpdateMetadata().then((metadata) => {
66+
if (metadata) {
67+
Instabug.setCodePushVersion(metadata.label);
68+
}
69+
});
3370
CrashReporting.setNDKCrashesEnabled(true);
3471
Instabug.setReproStepsConfig({
3572
all: ReproStepsMode.enabled,
@@ -55,6 +92,7 @@ const App: () => ReactNode = () => {
5592
<Text style={{ fontSize: 21, fontWeight: '700' }}>React Native App</Text>
5693
<Button title="Handled Crash" onPress={throwHandled} />
5794
<Button title="Unhandled Crash" onPress={throwUnhandled} />
95+
<Button title="Send GQL Request" onPress={sendGraphQLRequest} />
5896
</SafeAreaView>
5997
);
6098
};

examples/hybrid/android/app/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ plugins {
55

66
}
77

8+
apply from: "../../node_modules/instabug-reactnative/android/native.gradle"
89
android {
910
signingConfigs {
1011
debug {
@@ -57,6 +58,7 @@ dependencies {
5758
def composeBom = platform('androidx.compose:compose-bom:2023.10.00')
5859
implementation composeBom
5960
androidTestImplementation composeBom
61+
implementation project(':react-native-code-push')
6062

6163
// Compose dependencies
6264
implementation "androidx.compose.ui:ui"
@@ -72,7 +74,7 @@ dependencies {
7274
implementation libs.androidx.annotation.experimental
7375
implementation "com.facebook.react:react-android"
7476
implementation "com.facebook.react:hermes-android"
75-
// Other dependencies...
77+
implementation "com.instabug.library:instabug-with-okhttp-interceptor:${project.ext.instabug.version}"
7678
}
7779
configurations.all {
7880
resolutionStrategy {

examples/hybrid/android/app/src/main/java/com/instabug/hybridsampleapp/HybridApplication.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,40 @@
11
package com.instabug.hybridsampleapp;
2+
import com.facebook.react.ReactNativeHost;
3+
import com.facebook.react.ReactPackage;
24
import com.instabug.reactlibrary.RNInstabug;
35

46
import android.app.Application;
57
import android.util.Log;
68
import com.instabug.library.LogLevel;
79
import com.instabug.library.invocation.InstabugInvocationEvent;
10+
import com.microsoft.codepush.react.CodePush;
11+
12+
import java.util.Collections;
13+
import java.util.List;
814

915
public class HybridApplication extends Application {
16+
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
17+
@Override
18+
protected String getJSBundleFile() {
19+
return CodePush.getJSBundleFile();
20+
}
21+
22+
@Override
23+
public boolean getUseDeveloperSupport() {
24+
return false;
25+
}
26+
27+
@Override
28+
protected List<ReactPackage> getPackages() {
29+
return Collections.emptyList();
30+
}
31+
};
1032
@Override
1133
public void onCreate() {
1234
super.onCreate();
1335
Log.v("Instabug-Hybrid", "starting from native");
1436

15-
new RNInstabug.Builder(this, "deb1910a7342814af4e4c9210c786f35")
37+
new RNInstabug.Builder(this, "0fcc87b8bf731164828cc411eccc802a")
1638
.setInvocationEvents(InstabugInvocationEvent.SHAKE, InstabugInvocationEvent.FLOATING_BUTTON)
1739
.build();
1840
}

examples/hybrid/android/app/src/main/java/com/instabug/hybridsampleapp/MainActivity.java

Lines changed: 100 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,62 @@
11
package com.instabug.hybridsampleapp;
22

3+
import com.instabug.library.logging.listeners.networklogs.NetworkLogListener;
4+
import com.instabug.library.logging.listeners.networklogs.NetworkLogSnapshot;
5+
import com.microsoft.codepush.react.CodePush;
36
import android.content.Intent;
47
import android.os.Bundle;
8+
import android.widget.Toast;
9+
import android.util.Log;
10+
511
import androidx.appcompat.app.AppCompatActivity;
612
import com.instabug.crash.CrashReporting;
713
import com.instabug.crash.models.IBGNonFatalException;
814
import com.instabug.hybridsampleapp.databinding.ActivityMainBinding;
15+
import com.instabug.library.okhttplogger.InstabugOkhttpInterceptor;
16+
17+
import org.json.JSONObject;
18+
19+
import java.io.IOException;
920
import java.util.HashMap;
1021
import java.util.Map;
1122

23+
import okhttp3.Call;
24+
import okhttp3.Callback;
25+
import okhttp3.MediaType;
26+
import okhttp3.OkHttpClient;
27+
import okhttp3.Request;
28+
import okhttp3.RequestBody;
29+
import okhttp3.Response;
30+
1231
public class MainActivity extends AppCompatActivity {
32+
private static final String TAG = "MainActivity";
33+
private ActivityMainBinding binding;
34+
private final OkHttpClient client; // Make it final
35+
NetworkLogListener networkLogListener = new NetworkLogListener() {
36+
@Override
37+
public NetworkLogSnapshot onNetworkLogCaptured(NetworkLogSnapshot networkLog) {
38+
return networkLog;
39+
}
40+
};
41+
public MainActivity() {
42+
InstabugOkhttpInterceptor instabugOkhttpInterceptor = new InstabugOkhttpInterceptor();
43+
instabugOkhttpInterceptor.registerNetworkLogsListener(networkLogListener);
44+
client = new OkHttpClient.Builder()
45+
.addInterceptor(instabugOkhttpInterceptor)
46+
.build();
47+
}
1348

1449
@Override
1550
protected void onCreate(Bundle savedInstanceState) {
1651
super.onCreate(savedInstanceState);
17-
18-
ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater());
52+
binding = ActivityMainBinding.inflate(getLayoutInflater());
1953
setContentView(binding.getRoot());
2054

2155
binding.buttonReactNative.setOnClickListener(view -> {
2256
Intent intent = new Intent(MainActivity.this, ReactNativeAppActivity.class);
2357
startActivity(intent);
2458
});
25-
59+
2660

2761
binding.buttonHandled.setOnClickListener(view -> {
2862
Map<String, String> attributes = new HashMap<>();
@@ -39,5 +73,67 @@ protected void onCreate(Bundle savedInstanceState) {
3973
binding.buttonUnhandled.setOnClickListener(view -> {
4074
throw new Error("Unhandled Java Crash");
4175
});
76+
77+
binding.buttonGraphQL.setOnClickListener(view -> {
78+
if (client != null) {
79+
sendGraphQLRequest();
80+
} else {
81+
Log.e(TAG, "OkHttpClient is null");
82+
Toast.makeText(this, "Error: HTTP Client not initialized", Toast.LENGTH_SHORT).show();
83+
}
84+
});
85+
}
86+
87+
private void sendGraphQLRequest() {
88+
String graphqlQuery = "{"
89+
+ "\"query\": \"query GetCountry { "
90+
+ " country(code: \\\"EG\\\") { "
91+
+ " emoji "
92+
+ " name "
93+
+ " }"
94+
+ "}\""
95+
+ "}";
96+
97+
MediaType JSON = MediaType.parse("application/json; charset=utf-8");
98+
RequestBody body = RequestBody.create(JSON, graphqlQuery);
99+
100+
Request request = new Request.Builder()
101+
.url("https://countries.trevorblades.com/graphql")
102+
.post(body)
103+
.addHeader("Content-Type", "application/json")
104+
.addHeader("ibg-graphql-header", "GetCountry")
105+
.build();
106+
107+
client.newCall(request).enqueue(new Callback() {
108+
@Override
109+
public void onFailure(Call call, IOException e) {
110+
Log.e(TAG, "Request failed: " + e.getMessage());
111+
runOnUiThread(() -> {
112+
Toast.makeText(MainActivity.this,
113+
"Error: " + e.getMessage(),
114+
Toast.LENGTH_SHORT).show();
115+
});
116+
}
117+
118+
@Override
119+
public void onResponse(Call call, Response response) throws IOException {
120+
final String responseData = response.body().string();
121+
runOnUiThread(() -> {
122+
try {
123+
JSONObject jsonObject = new JSONObject(responseData);
124+
String result = jsonObject.getJSONObject("data").toString();
125+
Toast.makeText(MainActivity.this,
126+
"Response: " + result,
127+
Toast.LENGTH_SHORT).show();
128+
} catch (Exception e) {
129+
Log.e(TAG, "Error parsing response: " + e.getMessage());
130+
Toast.makeText(MainActivity.this,
131+
"Error parsing response: " + e.getMessage(),
132+
Toast.LENGTH_SHORT).show();
133+
}
134+
});
135+
response.close();
136+
}
137+
});
42138
}
43-
}
139+
}

examples/hybrid/android/app/src/main/res/layout/activity_main.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,9 @@
3838
android:layout_width="wrap_content"
3939
android:layout_height="wrap_content"
4040
android:text="Unhandled Crash" />
41+
<Button
42+
android:id="@+id/buttonGraphQL"
43+
android:layout_width="wrap_content"
44+
android:layout_height="wrap_content"
45+
android:text="Send GraphQL Request" />
4146
</LinearLayout>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<resources>
22
<string name="app_name">HybridSampleApp</string>
3+
<string moduleConfig="true" name="CodePushDeploymentKey">DeploymentKey</string>
34
</resources>

examples/hybrid/android/settings.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ include ':app'
44
includeBuild('../node_modules/@react-native/gradle-plugin')
55

66

7+
8+
include ':app', ':react-native-code-push'
9+
project(':react-native-code-push').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-code-push/android/app')

0 commit comments

Comments
 (0)