content: package im.actor.sdk.controllers.root;
  
  import android.Manifest;
  import android.content.Intent;
  import android.content.pm.PackageManager;
  import android.graphics.drawable.ColorDrawable;
  import android.os.Bundle;
  import android.support.v13.app.ActivityCompat;
  import android.support.v4.app.Fragment;
  import android.support.v4.content.ContextCompat;
  import android.support.v7.widget.Toolbar;
  
  import im.actor.core.viewmodel.AppStateVM;
  import im.actor.sdk.ActorSDK;
  import im.actor.sdk.R;
  import im.actor.sdk.controllers.activity.BaseFragmentActivity;
  import im.actor.sdk.controllers.tools.InviteHandler;
  
  /**
   * Root Activity of Application
   */
  public class RootActivity extends BaseFragmentActivity {
  
      private static final int PERMISSIONS_REQUEST_READ_CONTACTS = 1;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_root);
  
          if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
              ActivityCompat.requestPermissions(this,
                      new String[]{Manifest.permission.READ_CONTACTS},
                      PERMISSIONS_REQUEST_READ_CONTACTS);
          }
  
          //
          // Configure Toolbar
          //
          Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
          assert toolbar != null;
          setSupportActionBar(toolbar);
          if (ActorSDK.sharedActor().style.getToolBarColor() != 0) {
              toolbar.setBackgroundDrawable(new ColorDrawable(ActorSDK.sharedActor().style.getToolBarColor()));
          }
  
          if (savedInstanceState == null) {
              Fragment fragment = ActorSDK.sharedActor().getDelegate().fragmentForRoot();
              if (fragment == null) {
                  fragment = new RootFragment();
              }
              getSupportFragmentManager().beginTransaction()
                      .add(R.id.root, fragment)
                      .commit();
          }
  
          InviteHandler.handleIntent(this, getIntent());
      }
  
      @Override
      protected void onNewIntent(Intent intent) {
          super.onNewIntent(intent);
          InviteHandler.handleIntent(this, intent);
      }
  
      @Override
      public void onRequestPermissionsResult(int requestCode,
                                             String permissions[], int[] grantResults) {
          switch (requestCode) {
              case PERMISSIONS_REQUEST_READ_CONTACTS: {
                  // If request is cancelled, the result arrays are empty.
                  if (grantResults.length > 0
                          && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
  
                      AppStateVM appStateVM = ActorSDK.sharedActor().getMessenger().getAppStateVM();
                      if (appStateVM.isDialogsLoaded() && appStateVM.isContactsLoaded() && appStateVM.isSettingsLoaded()) {
                          ActorSDK.sharedActor().getMessenger().startImport();
                      }
  
                  }
              }
  
          }
      }
  }
  