package com.nestedworld.nestedworld.fragment.launch;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.widget.EditText;

import com.nestedworld.nestedworld.R;
import com.nestedworld.nestedworld.api.implementation.NestedWorldApi;
import com.nestedworld.nestedworld.api.models.User;
import com.nestedworld.nestedworld.fragment.base.BaseFragment;
import com.rey.material.widget.ProgressView;

import butterknife.Bind;
import butterknife.OnClick;
import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;

public class LoginFragment extends BaseFragment {

    @Bind(R.id.editText_userEmail)
    EditText etEmail;
    @Bind(R.id.editText_userPassword)
    EditText etPassword;
    ProgressView progressView;

    public static void load(final FragmentManager fragmentManager) {
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.setCustomAnimations(R.anim.fade_out, R.anim.fade_in);
        fragmentTransaction.replace(R.id.container, new LoginFragment());
        fragmentTransaction.addToBackStack("LoginFragment");
        fragmentTransaction.commit();
    }

    /*
    ** Life Cycle
     */
    @Override
    protected int getLayoutResource() {
        return R.layout.fragment_login;
    }

    @Override
    protected void initVariable(Bundle savedInstanceState) {

    }

    @Override
    protected void initData(Bundle savedInstanceState) {

    }

    /*
    ** ButterKnife
     */
    @OnClick(R.id.nav_back)
    public void back() {
        getActivity().onBackPressed();
    }

    @OnClick(R.id.button_login)
    public void login() {

        progressView.start();

        final String email = etEmail.getText().toString();
        final String password = etPassword.getText().toString();

        NestedWorldApi.getInstance(getContext()).signIn(email, password, new Callback<User>() {
            @Override
            public void success(User user, Response response) {
                progressView.stop();
            }

            @Override
            public void failure(RetrofitError error) {
                progressView.stop();
            }
        });
    }
}

@@ -202,16 +202,45 @@
 ditText;
+%0Aimport android.widget.Toast;
 %0A%0Aimport
@@ -2121,32 +2121,125 @@
 essView.stop();%0A
+                Toast.makeText(getContext(), %22Login successfull%22, Toast.LENGTH_LONG).show();%0A
             %7D%0A%0A 
@@ -2343,32 +2343,120 @@
 essView.stop();%0A
+                Toast.makeText(getContext(), %22Login failed%22, Toast.LENGTH_LONG).show();%0A
             %7D%0A  

add toast