package com.example.jelica.loginwithothercomponents;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

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

        CheckBox checkBox = findViewById(R.id.checkbox1);
        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    Toast.makeText(getApplicationContext(),
                            "Stiklirano",
                            Toast.LENGTH_SHORT).show();
                }
                else{
                    Toast.makeText(getApplicationContext(),
                            "Odstiklirano",
                            Toast.LENGTH_SHORT).show();
                }
            }
        });
    }

    public void login(View view){
        EditText username = findViewById(R.id.username);
        EditText password = findViewById(R.id.password);

        CheckBox checkBox = findViewById(R.id.checkbox1);

        if(username.getText().toString().equals("admin")
                && password.getText().toString().equals("admin123")
                && checkBox.isChecked()){
            Toast.makeText(getApplicationContext(),
                    "Jeej",
                    Toast.LENGTH_SHORT).show();
        }
        else{
            Toast.makeText(getApplicationContext(),
                    "Noo :((",
                    Toast.LENGTH_SHORT).show();
        }
    }

    public void radioButtonClicked(View view){
        if(view.getId()==R.id.zenski){
            if(((RadioButton) view).isChecked()){
                Toast.makeText(getApplicationContext(),
                        "Z: s",
                        Toast.LENGTH_SHORT).show();
            }
            else{
                Toast.makeText(getApplicationContext(),
                        "Z: o",
                        Toast.LENGTH_SHORT).show();
            }
        }
        else{
            Toast.makeText(getApplicationContext(),
                    "M",
                    Toast.LENGTH_SHORT).show();
        }
    }
}
