7
7
import android .net .Uri ;
8
8
import android .graphics .Typeface ;
9
9
import android .util .Log ;
10
+
10
11
import androidx .annotation .NonNull ;
11
12
import androidx .annotation .Nullable ;
12
13
import androidx .annotation .VisibleForTesting ;
14
+
13
15
import com .instabug .flutter .generated .InstabugPigeon ;
14
16
import com .instabug .flutter .util .ArgsRegistry ;
15
17
import com .instabug .flutter .util .Reflection ;
31
33
import com .instabug .library .invocation .InstabugInvocationEvent ;
32
34
import com .instabug .library .model .NetworkLog ;
33
35
import com .instabug .library .ui .onboarding .WelcomeMessage ;
36
+
34
37
import io .flutter .FlutterInjector ;
35
38
import io .flutter .embedding .engine .loader .FlutterLoader ;
36
39
import io .flutter .plugin .common .BinaryMessenger ;
40
+
37
41
import org .jetbrains .annotations .NotNull ;
38
42
import org .json .JSONObject ;
39
43
@@ -103,10 +107,12 @@ public Boolean isEnabled() {
103
107
104
108
@ NotNull
105
109
@ Override
106
- public Boolean isBuilt () { return Instabug .isBuilt (); }
110
+ public Boolean isBuilt () {
111
+ return Instabug .isBuilt ();
112
+ }
107
113
108
114
@ Override
109
- public void init (@ NonNull String token , @ NonNull List <String > invocationEvents , @ NonNull String debugLogsLevel ) {
115
+ public void init (@ NonNull String token , @ NonNull List <String > invocationEvents , @ NonNull String debugLogsLevel , @ Nullable String appVariant ) {
110
116
setCurrentPlatform ();
111
117
112
118
InstabugInvocationEvent [] invocationEventsArray = new InstabugInvocationEvent [invocationEvents .size ()];
@@ -117,11 +123,14 @@ public void init(@NonNull String token, @NonNull List<String> invocationEvents,
117
123
118
124
final Application application = (Application ) context ;
119
125
final int parsedLogLevel = ArgsRegistry .sdkLogLevels .get (debugLogsLevel );
120
-
121
- new Instabug .Builder (application , token )
126
+ Instabug .Builder builder = new Instabug .Builder (application , token )
122
127
.setInvocationEvents (invocationEventsArray )
123
- .setSdkDebugLogsLevel (parsedLogLevel )
124
- .build ();
128
+ .setSdkDebugLogsLevel (parsedLogLevel );
129
+ if (appVariant != null ) {
130
+ builder .setAppVariant (appVariant );
131
+ }
132
+
133
+ builder .build ();
125
134
126
135
Instabug .setScreenshotProvider (screenshotProvider );
127
136
}
@@ -147,6 +156,17 @@ public void setUserData(@NonNull String data) {
147
156
Instabug .setUserData (data );
148
157
}
149
158
159
+ @ Override
160
+ public void setAppVariant (@ NonNull String appVariant ) {
161
+ try {
162
+ Instabug .setAppVariant (appVariant );
163
+
164
+ } catch (Exception e ) {
165
+ e .printStackTrace ();
166
+ }
167
+
168
+ }
169
+
150
170
@ Override
151
171
public void logUserEvent (@ NonNull String name ) {
152
172
Instabug .logUserEvent (name );
@@ -487,14 +507,140 @@ public void willRedirectToStore() {
487
507
Instabug .willRedirectToStore ();
488
508
}
489
509
490
-
510
+
491
511
@ Override
492
512
public void setNetworkLogBodyEnabled (@ NonNull Boolean isEnabled ) {
493
- try {
494
- Instabug .setNetworkLogBodyEnabled (isEnabled );
495
- } catch (Exception e ) {
496
- e .printStackTrace ();
513
+ try {
514
+ Instabug .setNetworkLogBodyEnabled (isEnabled );
515
+ } catch (Exception e ) {
516
+ e .printStackTrace ();
517
+ }
518
+ }
519
+
520
+ @ Override
521
+ public void setTheme (@ NonNull Map <String , Object > themeConfig ) {
522
+ try {
523
+ Log .d (TAG , "setTheme called with config: " + themeConfig .toString ());
524
+
525
+ com .instabug .library .model .IBGTheme .Builder builder = new com .instabug .library .model .IBGTheme .Builder ();
526
+
527
+ if (themeConfig .containsKey ("primaryColor" )) {
528
+ builder .setPrimaryColor (getColor (themeConfig , "primaryColor" ));
529
+ }
530
+ if (themeConfig .containsKey ("secondaryTextColor" )) {
531
+ builder .setSecondaryTextColor (getColor (themeConfig , "secondaryTextColor" ));
532
+ }
533
+ if (themeConfig .containsKey ("primaryTextColor" )) {
534
+ builder .setPrimaryTextColor (getColor (themeConfig , "primaryTextColor" ));
535
+ }
536
+ if (themeConfig .containsKey ("titleTextColor" )) {
537
+ builder .setTitleTextColor (getColor (themeConfig , "titleTextColor" ));
538
+ }
539
+ if (themeConfig .containsKey ("backgroundColor" )) {
540
+ builder .setBackgroundColor (getColor (themeConfig , "backgroundColor" ));
541
+ }
542
+
543
+ if (themeConfig .containsKey ("primaryTextStyle" )) {
544
+ builder .setPrimaryTextStyle (getTextStyle (themeConfig , "primaryTextStyle" ));
545
+ }
546
+ if (themeConfig .containsKey ("secondaryTextStyle" )) {
547
+ builder .setSecondaryTextStyle (getTextStyle (themeConfig , "secondaryTextStyle" ));
548
+ }
549
+ if (themeConfig .containsKey ("ctaTextStyle" )) {
550
+ builder .setCtaTextStyle (getTextStyle (themeConfig , "ctaTextStyle" ));
551
+ }
552
+
553
+ setFontIfPresent (themeConfig , builder , "primaryFontPath" , "primaryFontAsset" , "primary" );
554
+ setFontIfPresent (themeConfig , builder , "secondaryFontPath" , "secondaryFontAsset" , "secondary" );
555
+ setFontIfPresent (themeConfig , builder , "ctaFontPath" , "ctaFontAsset" , "CTA" );
556
+
557
+ com .instabug .library .model .IBGTheme theme = builder .build ();
558
+ Instabug .setTheme (theme );
559
+ Log .d (TAG , "Theme applied successfully" );
560
+
561
+ } catch (Exception e ) {
562
+ Log .e (TAG , "Error in setTheme: " + e .getMessage ());
563
+ e .printStackTrace ();
564
+ }
565
+ }
566
+
567
+
568
+
569
+ /**
570
+ * Retrieves a color value from the Map.
571
+ *
572
+ * @param map The Map object.
573
+ * @param key The key to look for.
574
+ * @return The parsed color as an integer, or black if missing or invalid.
575
+ */
576
+ private int getColor (Map <String , Object > map , String key ) {
577
+ try {
578
+ if (map != null && map .containsKey (key ) && map .get (key ) != null ) {
579
+ String colorString = (String ) map .get (key );
580
+ return android .graphics .Color .parseColor (colorString );
581
+ }
582
+ } catch (Exception e ) {
583
+ e .printStackTrace ();
584
+ }
585
+ return android .graphics .Color .BLACK ;
586
+ }
587
+
588
+ /**
589
+ * Retrieves a text style from the Map.
590
+ *
591
+ * @param map The Map object.
592
+ * @param key The key to look for.
593
+ * @return The corresponding Typeface style, or Typeface.NORMAL if missing or invalid.
594
+ */
595
+ private int getTextStyle (Map <String , Object > map , String key ) {
596
+ try {
597
+ if (map != null && map .containsKey (key ) && map .get (key ) != null ) {
598
+ String style = (String ) map .get (key );
599
+ switch (style .toLowerCase ()) {
600
+ case "bold" :
601
+ return Typeface .BOLD ;
602
+ case "italic" :
603
+ return Typeface .ITALIC ;
604
+ case "bold_italic" :
605
+ return Typeface .BOLD_ITALIC ;
606
+ case "normal" :
607
+ default :
608
+ return Typeface .NORMAL ;
497
609
}
610
+ }
611
+ } catch (Exception e ) {
612
+ e .printStackTrace ();
613
+ }
614
+ return Typeface .NORMAL ;
615
+ }
616
+
617
+ /**
618
+ * Sets a font on the theme builder if the font configuration is present in the theme config.
619
+ *
620
+ * @param themeConfig The theme configuration map
621
+ * @param builder The theme builder
622
+ * @param fileKey The key for font file path
623
+ * @param assetKey The key for font asset path
624
+ * @param fontType The type of font (for logging purposes)
625
+ */
626
+ private void setFontIfPresent (Map <String , Object > themeConfig , com .instabug .library .model .IBGTheme .Builder builder ,
627
+ String fileKey , String assetKey , String fontType ) {
628
+ if (themeConfig .containsKey (fileKey ) || themeConfig .containsKey (assetKey )) {
629
+ Typeface typeface = getTypeface (themeConfig , fileKey , assetKey );
630
+ if (typeface != null ) {
631
+ switch (fontType ) {
632
+ case "primary" :
633
+ builder .setPrimaryTextFont (typeface );
634
+ break ;
635
+ case "secondary" :
636
+ builder .setSecondaryTextFont (typeface );
637
+ break ;
638
+ case "CTA" :
639
+ builder .setCtaTextFont (typeface );
640
+ break ;
641
+ }
642
+ }
643
+ }
498
644
}
499
645
500
646
@ Override
@@ -648,5 +794,17 @@ private Typeface getTypeface(Map<String, Object> map, String fileKey, String ass
648
794
}
649
795
}
650
796
797
+ /**
798
+ * Enables or disables displaying in full-screen mode, hiding the status and navigation bars.
799
+ * @param isEnabled A boolean to enable/disable setFullscreen.
800
+ */
801
+ @ Override
802
+ public void setFullscreen (@ NonNull final Boolean isEnabled ) {
803
+ try {
804
+ Instabug .setFullscreen (isEnabled );
805
+ } catch (Exception e ) {
806
+ e .printStackTrace ();
807
+ }
808
+ }
651
809
652
810
}
0 commit comments