package com.dbs.mplus.knuh;

import androidx.appcompat.app.AppCompatActivity;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.widget.Toast;

import com.dbs.mplus.knuh.activity.LoginActivity;
import com.gun0912.tedpermission.PermissionListener;
import com.gun0912.tedpermission.TedPermission;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

  private static final String TAG = "MainActivity";

  private AppCompatActivity mActivity;
  private Context mContext;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    init();
  }

  private void init() {
    mActivity = this;
    mContext  = this;

    permissionCheck();
  }

  private void permissionCheck() {
    PermissionListener permissionListener = new PermissionListener() {
      @Override
      public void onPermissionGranted() {
        nextActivity();
      }

      @Override
      public void onPermissionDenied(ArrayList<String> deniedPermissions) {
        finishAffinity();
      }
    };
    TedPermission.with(mContext)
        .setPermissionListener(permissionListener)
        .setRationaleMessage(getString(R.string.permissionCheck))
        .setDeniedMessage(getString(R.string.permissionDenied))
        .setPermissions(android.Manifest.permission.READ_EXTERNAL_STORAGE, android.Manifest.permission.WRITE_EXTERNAL_STORAGE, android.Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.READ_PHONE_STATE)
        .check();
  }


  private void nextActivity() {
    new Handler().postDelayed(new Runnable() {
      @Override
      public void run() {
        // 수행할 내용 입력
        Intent intent = new Intent(mContext, LoginActivity.class);
        startActivity(intent);
        finish();
      }
    }, 2000); // 2초 뒤에 수행할 내용에 입력된게 실행됨, 시간은 사용자에 맞게 변경하면됨
  }

  @Override
  public void onBackPressed() {
    // 뒤로가기 막음
  }

  @Override
  protected void onDestroy() {
    super.onDestroy();
  }
}
