package oko.tm.oko_pro_classic;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;

import static android.content.ContentValues.TAG;
import static oko.tm.oko_pro_classic.StartActivity.START_PREFERENCES_APPPASSWORD;

/**
 * Created by Boby on 21.12.2017.
 */

public class PasswordActivity extends Activity {

    SharedPreferences mSettings;

    EditText txtPassword_;

    Button button_password;


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

        //----------- работа с файлом, содержащий настройки
        mSettings = getSharedPreferences(StartActivity.START_PREFERENCES, Context.MODE_PRIVATE);


        txtPassword_ = (EditText) findViewById(R.id.txtPassword_);
        button_password = (Button) findViewById(R.id.button_password);

        //--------------------------- обработчик события нажатия кнопки
        button_password.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Log.d(TAG, "Нажата кнопка Password");

                try {
                    String app_pass="";
                    if (mSettings.contains(START_PREFERENCES_APPPASSWORD)) {
                        app_pass=mSettings.getString(START_PREFERENCES_APPPASSWORD, "");
                    }

                    String password_ = txtPassword_.getText().toString();
                    if (password_.equals(app_pass)) {
                        StartActivity.need_check_password=false;
                        //finish();
                    }

                    finish();

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        //-------------------------------------------
    }

    @Override
    protected void onResume()
    {
        // TODO Auto-generated method stub
        super.onResume();
        Log.d(TAG, "PasswordActivity onResume");
        if (StartActivity.need_check_password == false) finish();

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //destroid application

        Log.d(TAG, "PasswordActivity onDestroy");

    }

    @Override
    protected void onPause()
    {
        // TODO Auto-generated method stub
        super.onPause();
        Log.d(TAG, "PasswordActivity onPause");

    }

    @Override
    public void onStop() {
        super.onStop();
        Log.d(TAG, "PasswordActivity onStop");
        //hidden application

    }
}
