package com.example.shridev1;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class LoginActivity extends AppCompatActivity {

    Button loginButton;
    TextView username;
    String passUsername;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // Ta bort titelbaren längst upp
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getSupportActionBar().hide();
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);


        setContentView(R.layout.activity_login);
        username = (TextView) findViewById(R.id.editTextUsername);
        TextView password = (TextView) findViewById(R.id.editTextPassword);
        passUsername = username.getText().toString();

        loginButton = (Button)findViewById(R.id.loggedInButton);
        loginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (username.getText().toString().equals("fanny123") && password.getText().toString().equals("pwd")) {
                    Intent i = new Intent(getApplicationContext(), DashboardActivity.class);
                    i.putExtra("Username", username.getText().toString());
                    startActivity(i);
                    Log.d("LoginActivity", "Login successful");
                } else {
                    showToast("Wrong username or password");
                    Log.d("LoginActivity", "Login not successful");
                }

                Log.d("LoginActivity", "Button clicked");
            }
        });


    }
    /** Funktion för att skapa toast */
    private void showToast(String text) {
        Toast.makeText(LoginActivity.this, text, Toast.LENGTH_LONG).show();
    }
}