package w.soulofpluto.camera;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

/*
 Create by Ramesh Babu
 
 */
public class LoginActivity extends AppCompatActivity implements View.OnClickListener {

    EditText user,pass;
    Button login;
    PreferenceManager preferenceManager;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        setContentView(R.layout.activity_login);
        user = findViewById(R.id.user);
        pass = findViewById(R.id.pass);
        login= findViewById(R.id.login);
        login.setOnClickListener(this);
        preferenceManager = new PreferenceManager(this);
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onClick(View view){
        if(view == login){
              if(TextUtils.isEmpty(user.getText().toString()) && TextUtils.isEmpty(pass.getText().toString())){
                  Toast.makeText(LoginActivity.this, "Enter User,Password", Toast.LENGTH_SHORT).show();
              }else if(TextUtils.isEmpty(user.getText().toString())){
                  Toast.makeText(LoginActivity.this, "Enter User", Toast.LENGTH_SHORT).show();
              }else if(TextUtils.isEmpty(pass.getText().toString())){
                  Toast.makeText(LoginActivity.this, "Enter Password", Toast.LENGTH_SHORT).show();
              }else if (user.getText().toString().equalsIgnoreCase("user") && pass.getText().toString().equalsIgnoreCase("123")){
                  preferenceManager.setUserId(user.getText().toString());
                  preferenceManager.setPassword(pass.getText().toString());
                  preferenceManager.setLogged(true);

                  Intent intent = new Intent(LoginActivity.this, MainActivity.class);
                  intent.putExtra("key","success");
                  startActivity(intent);
                  finish();
              }else{
                  Toast.makeText(LoginActivity.this, "Enter Valid User,Password", Toast.LENGTH_SHORT).show();
              }
        }
    }
}
