package com.example.brewchat.activities;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import com.example.brewchat.Application;
import com.example.brewchat.R;
import com.example.brewchat.UserLoggedEvent;

import butterknife.ButterKnife;
import butterknife.InjectView;
import de.greenrobot.event.EventBus;


public class LoginActivity extends AppCompatActivity implements RegisterDialogListener,
        LoginListener{
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login_screen);
        EventBus.getDefault().register(this);
        if (savedInstanceState == null) {
            Fragment fragment = new LoginFragment();

            getSupportFragmentManager().beginTransaction()
                    .add(R.id.login_screen_frame, fragment)
                    .commit();
        }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        if (id == R.id.action_settings) {
            System.out.println("You should implement some settings");
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    //Simply for navigation purposes during Dev
    public void buttonAuth(View view) {
        ((Application)getApplication()).getChatService().login(username.getText().toString(), password.getText().toString());
    }

    @SuppressWarnings("unused")
    public void goToChatFragment(UserLoggedEvent event) {
        Intent intent = new Intent(this, ChatManagerActivity.class);
        startActivity(intent);
    }

    public void error(){
        Toast.makeText(LoginActivity.this, "Error in logging in", Toast.LENGTH_LONG).show();
    }
    
    @Override
    public void onCreateAccount(String username, String password) {
        ((Application) getApplication()).getChatService().register(username, password);
    }

    public void showRegisterDialog(View view) {
        RegisterDialogFragment fragment = new RegisterDialogFragment();
        fragment.show(getSupportFragmentManager(), "RegisterDialogFragment");
    }
}

@@ -92,16 +92,56 @@
 Bundle;%0A
+import android.support.v4.app.Fragment;%0A
 import a
@@ -267,40 +267,8 @@
 ew;%0A
-import android.widget.EditText;%0A
 impo
@@ -393,16 +393,23 @@
 rewchat.
+events.
 UserLogg
@@ -421,71 +421,240 @@
 nt;%0A
-%0A
 import 
-butterknife.ButterKnife;%0Aimport butterknife.InjectView;
+com.example.brewchat.fragments.LoginFragment;%0Aimport com.example.brewchat.fragments.RegisterDialogFragment;%0Aimport com.example.brewchat.interfaces.LoginListener;%0Aimport com.example.brewchat.interfaces.RegisterDialogListener;%0A
 %0Aimp
@@ -800,20 +800,16 @@
 stener%7B%0A
-    
 %0A    @Ov
@@ -1895,25 +1895,48 @@
 tonAuth(
-View view
+String username, String password
 ) %7B%0A    
@@ -2006,60 +2006,18 @@
 name
-.getText().toString(), password.getText().toString()
+, password
 );%0A 
@@ -2074,21 +2074,12 @@
 oid 
-goToChatFragm
+onEv
 ent(
@@ -2334,20 +2334,16 @@
 ;%0A    %7D%0A
-    
 %0A    @Ov
@@ -2439,17 +2439,16 @@
 ication)
- 
 getAppli
@@ -2716,9 +2716,8 @@
 %0A    %7D%0A%7D
-%0A

Fix lint error