package com.lc.myapplication.security.locks.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import androidx.appcompat.app.AppCompatActivity;

import com.lc.myapplication.security.locks.dialog.PermissionDialog;
import com.lc.myapplication.security.locks.dialog.SettingDialog;
import com.lc.myapplication.security.locks.tool.LockPremission;
import com.lc.myapplication.security.locks.R;
import com.lc.myapplication.security.locks.tool.MyService;


public class MainActivity extends AppCompatActivity {
 private LinearLayout main_lin;
 private LockPremission lockPremission;

 private RelativeLayout main_re_lay1;
 private RelativeLayout main_re2_lay1;
 private RelativeLayout main_re2_lay2;
 private ImageView main_set;
 private ImageView main_sourch;
 private PermissionDialog permissionDialog;
 private SettingDialog settingDialog;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initfindview();
        startService(new Intent(this, MyService.class));
        initpaperbackground();
        onMyClick();
        getPremission();
    }

    private void onMyClick() {
        main_re_lay1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this,LockedAppActivity.class);
                startActivity(intent);

            }
        });
        main_re2_lay1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this,TestimonialsActivity.class);
                startActivity(intent);

            }
        });
        main_re2_lay2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this,AllAppActivity.class);
                startActivity(intent);
            }
        });
        main_set.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getsettingDialog();
            }
        });
        main_sourch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this,SearchActivity.class);
                startActivity(intent);
            }
        });
    }

    private void getsettingDialog() {
        if (settingDialog == null){
            settingDialog = new SettingDialog(this);
        }
        settingDialog.show(getSupportFragmentManager(),"-----settingdialog");
    }

    private void getPremission() {
        boolean ispracy = LockPremission.privacysuccess(MainActivity.this);
        boolean isshowon = LockPremission.showonsuccess(MainActivity.this);
        if (ispracy && isshowon) {
               hidedialog();
        } else {
            if (permissionDialog == null) {
                permissionDialog = new PermissionDialog(this);
            }
            permissionDialog.show(getSupportFragmentManager(), "permissiondialog");
        }
    }

    private void hidedialog() {
        if (LockPremission.allpermiss(this)) {
            if (permissionDialog != null) {
                permissionDialog.dismiss();
            }
        }
    }


    private void initfindview() {
        main_lin = findViewById(R.id.main_lin);
        main_set = findViewById(R.id.main_set);
        main_re_lay1 = findViewById(R.id.main_re_lay1);
        main_re2_lay1 = findViewById(R.id.main_re2_lay1);
        main_re2_lay2 = findViewById(R.id.main_re2_lay2);
        main_sourch = findViewById(R.id.main_sourch);
    }

    private void initpaperbackground() {
        Window window = getWindow();
        window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        main_lin.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (settingDialog != null) {
            settingDialog.dismiss();
        }
    }
}