content: /*
   *    Copyright (C) 2018 MINDORKS NEXTGEN PRIVATE LIMITED
   *
   *    Licensed under the Apache License, Version 2.0 (the "License");
   *    you may not use this file except in compliance with the License.
   *    You may obtain a copy of the License at
   *
   *        http://www.apache.org/licenses/LICENSE-2.0
   *
   *    Unless required by applicable law or agreed to in writing, software
   *    distributed under the License is distributed on an "AS IS" BASIS,
   *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   *    See the License for the specific language governing permissions and
   *    limitations under the License.
   */
  
  package com.amitshekhar.example.ui.base;
  
  import android.annotation.TargetApi;
  import android.app.ProgressDialog;
  import android.content.pm.PackageManager;
  import android.os.Build;
  import android.support.v7.app.AppCompatActivity;
  
  import com.amitshekhar.example.MyApplication;
  import com.amitshekhar.example.injection.component.ActivityComponent;
  import com.amitshekhar.example.injection.component.DaggerActivityComponent;
  import com.amitshekhar.example.injection.module.ActivityModule;
  import com.amitshekhar.example.utils.DialogUtils;
  
  /**
   * Created by amitshekhar on 13/01/17.
   */
  
  public abstract class BaseActivity extends AppCompatActivity implements MvpView {
  
      private ActivityComponent mActivityComponent;
      private ProgressDialog progressDialog;
  
      public ActivityComponent activityComponent() {
          if (mActivityComponent == null) {
              mActivityComponent = DaggerActivityComponent.builder()
                      .activityModule(new ActivityModule(this))
                      .applicationComponent(MyApplication.get(this).getComponent())
                      .build();
          }
          return mActivityComponent;
      }
  
      @TargetApi(Build.VERSION_CODES.M)
      public void requestPermissionsSafely(String[] permissions, int requestCode) {
          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
              requestPermissions(permissions, requestCode);
          }
      }
  
      @TargetApi(Build.VERSION_CODES.M)
      public boolean hasPermission(String permission) {
          return Build.VERSION.SDK_INT < Build.VERSION_CODES.M ||
                  checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED;
      }
  
      @Override
      public void showLoading() {
          hideLoading();
          progressDialog = DialogUtils.showLoadingDialog(this);
      }
  
      @Override
      public void hideLoading() {
          if (progressDialog != null && progressDialog.isShowing()) {
              progressDialog.cancel();
          }
      }
  
  }
  