1919import com .cometchat .javasampleapp .AppConstants ;
2020import com .cometchat .javasampleapp .AppUtils ;
2121import com .cometchat .javasampleapp .Application ;
22+ import com .cometchat .javasampleapp .BuildConfig ;
2223import com .cometchat .javasampleapp .R ;
2324import com .cometchat .chat .models .User ;
2425import com .google .android .material .card .MaterialCardView ;
2526
27+ import org .json .JSONObject ;
28+
2629public class MainActivity extends AppCompatActivity {
2730
2831 private MaterialCardView superhero1 ;
@@ -41,12 +44,13 @@ public class MainActivity extends AppCompatActivity {
4144 protected void onCreate (Bundle savedInstanceState ) {
4245 super .onCreate (savedInstanceState );
4346 setContentView (R .layout .activity_main );
44- parentView = findViewById (R .id .parent_view );
47+ parentView = findViewById (R .id .parent_view );
4548 Utils .setStatusBarColor (this , getResources ().getColor (android .R .color .white ));
4649 UIKitSettings uiKitSettings = new UIKitSettings .UIKitSettingsBuilder ().setRegion (AppConstants .REGION ).setAppId (AppConstants .APP_ID ).setAuthKey (AppConstants .AUTH_KEY ).subscribePresenceForAllUsers ().build ();
4750 CometChatUIKit .init (this , uiKitSettings , new CometChat .CallbackListener <String >() {
4851 @ Override
4952 public void onSuccess (String s ) {
53+ CometChat .setDemoMetaInfo (getAppMetadata ());
5054 if (CometChatUIKit .getLoggedInUser () != null ) {
5155 Application .addCallListener (MainActivity .this );
5256 AppUtils .fetchDefaultObjects ();
@@ -110,15 +114,29 @@ public void onError(CometChatException e) {
110114 }
111115
112116 private void setUpUI () {
113- if (AppUtils .isNightMode (this )){
114- Utils .setStatusBarColor (this , ContextCompat .getColor (this ,R .color .app_background_dark ));
115- parentView .setBackgroundTintList (ColorStateList .valueOf (ContextCompat .getColor (this ,R .color .app_background_dark )));
116- }else {
117+ if (AppUtils .isNightMode (this )) {
118+ Utils .setStatusBarColor (this , ContextCompat .getColor (this , R .color .app_background_dark ));
119+ parentView .setBackgroundTintList (ColorStateList .valueOf (ContextCompat .getColor (this , R .color .app_background_dark )));
120+ } else {
117121 Utils .setStatusBarColor (this , getResources ().getColor (R .color .app_background ));
118122 parentView .setBackgroundTintList (ColorStateList .valueOf (getResources ().getColor (R .color .app_background )));
119123 }
120124 }
121125
126+ private JSONObject getAppMetadata () {
127+ JSONObject jsonObject = new JSONObject ();
128+ try {
129+ jsonObject .put ("name" , getResources ().getString (R .string .app_name ));
130+ jsonObject .put ("type" , "sample" );
131+ jsonObject .put ("version" , BuildConfig .VERSION_NAME );
132+ jsonObject .put ("bundle" , BuildConfig .APPLICATION_ID );
133+ jsonObject .put ("platform" , "android" );
134+ } catch (Exception e ) {
135+ e .printStackTrace ();
136+ }
137+ return jsonObject ;
138+ }
139+
122140 public void createUser (View view ) {
123141 startActivity (new Intent (this , CreateUserActivity .class ));
124142 }
0 commit comments