Skip to content

Commit 17cd2ba

Browse files
Add Android native helper: IBGPlugin.setColorTheme
1 parent 4057571 commit 17cd2ba

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

sampleApp/platforms/android/app/src/test/java/com/instabug/cordova/plugin/IBGPluginTests.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import android.webkit.WebChromeClient;
1010

1111
import com.instabug.library.Instabug;
12+
import com.instabug.library.InstabugColorTheme;
1213

1314
import org.apache.cordova.CallbackContext;
1415
import org.apache.cordova.CordovaInterface;
@@ -253,5 +254,20 @@ public Boolean answer(InvocationOnMock invocation) throws Throwable {
253254
Instabug.setPrimaryColor(color);
254255
}
255256

257+
@Test
258+
public void givenArg$setColorTheme_whenQuery_thenShouldCallNativeApiWithArg() {
259+
// given
260+
PowerMockito.mockStatic(Instabug.class);
261+
String colorTheme = "dark";
262+
JSONArray args = new JSONArray();
263+
args.put(colorTheme);
264+
265+
// when
266+
cordovaModule.execute("setColorTheme", args, callbackContext);
267+
268+
// then
269+
PowerMockito.verifyStatic(VerificationModeFactory.times(1));
270+
Instabug.setColorTheme(InstabugColorTheme.InstabugColorThemeDark);
271+
}
256272

257273
}

src/android/IBGPlugin.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import com.instabug.featuresrequest.FeatureRequests;
1717
import com.instabug.library.Feature;
1818
import com.instabug.library.Instabug;
19+
import com.instabug.library.InstabugColorTheme;
1920
import com.instabug.library.OnSdkDismissCallback;
2021
import com.instabug.library.extendedbugreport.ExtendedBugReport;
2122
import com.instabug.library.internal.module.InstabugLocale;
@@ -466,6 +467,40 @@ public void run() {
466467
callbackContext.error("A colorInt must be provided.");
467468
}
468469

470+
/**
471+
* Convenience method for parsing and setting
472+
* whether the desired color theme for the SDK
473+
* invocation.
474+
*
475+
* @param callbackContext Used when calling back into JavaScript
476+
* @param args .optString(0) Theme
477+
*
478+
*/
479+
public void setColorTheme(final CallbackContext callbackContext, final JSONArray args) {
480+
final String colorTheme = args.optString(0);
481+
if (colorTheme != null) {
482+
try {
483+
new Handler(Looper.getMainLooper()).post(new Runnable() {
484+
@Override
485+
public void run() {
486+
if ("dark".equals(colorTheme)) {
487+
Instabug.setColorTheme(InstabugColorTheme.InstabugColorThemeDark);
488+
} else if ("light".equals(colorTheme)) {
489+
Instabug.setColorTheme(InstabugColorTheme.InstabugColorThemeLight);
490+
} else {
491+
callbackContext.error("Color theme value is not valid.");
492+
}
493+
}
494+
});
495+
} catch (IllegalStateException e) {
496+
e.printStackTrace();
497+
callbackContext.error(errorMsg);
498+
}
499+
} else {
500+
callbackContext.error("A color theme must be provided.");
501+
}
502+
}
503+
469504
/**
470505
* Sets the threshold value of the shake gesture on the device
471506
*

0 commit comments

Comments
 (0)