package ca.ualberta.smaccr.giftcarder;

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

public class MainActivity extends Activity {
    public final static String EXTRA_USERNAME= "ca.ualberta.smaccr.giftcarder.USERNAME";
    Inventory inv;
    String username;

    //getter for UI testing
    public EditText getEtUsername() {return (EditText) findViewById(R.id.enterUsername);}
    User user = new User();

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


        //update the user's modified inventory
        inv = (Inventory)getIntent().getSerializableExtra("inventorySettings1");
        username = (String)getIntent().getStringExtra("userSettings1");

        if (user != null){
            //Toast.makeText(getApplicationContext(), username, Toast.LENGTH_LONG).show();

        }
        if (inv != null){
            Toast.makeText(getApplicationContext(), inv.getInvList().get(0).getMerchant(), Toast.LENGTH_LONG).show();
        }

        if (username != null && inv != null){
            Toast.makeText(getApplicationContext(), inv.getInvList().get(0).getMerchant(), Toast.LENGTH_LONG).show();
            UserRegistrationController uc= new UserRegistrationController();
            uc.editUserInventory(username,inv);

        }



        user.setUsername("t");
        user.setCity("Edmo");
        user.setPhone("012-345-6789");
        user.setEmail("t@g.c");
        UserRegistrationController.getUserList().addUser(user);

    }

    @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 void onBackPressed() {
        //Back button disabled
    }

    /**
     * Called when user presses Register button
     *
     * @param  view  view that is clicked
     */
    public void registerNewUser(View view){
        Intent intent = new Intent(this, RegisterActivity.class);
        startActivity(intent);
    }

    /**
     * Called when user presses Login button.
     * <p>
     * Checks to see if user-entered username is an already registered user.  If not, it prompts
     * the user to register.
     *
     * @param  view  view that is clicked
     */
    public void logInUser(View view) {
        EditText etUsername = (EditText) findViewById(R.id.enterUsername);
        String username = etUsername.getText().toString().trim();

        UserRegistrationController urc = new UserRegistrationController();

        if (Validation.hasText(etUsername)) {
            if (urc.checkForUser(username)) {
                Intent intent = new Intent(this, InventoryActivity.class);
                intent.putExtra(EXTRA_USERNAME, username);
                startActivity(intent);

            } else {
                Toast.makeText(this, "User not found. Register a new account.", Toast.LENGTH_LONG).show();

            }
        }
    }

}

@@ -1618,16 +1618,26 @@
     %7D%0A%0A%0A
+        /*
 %0A       
@@ -1825,16 +1825,26 @@
 (user);%0A
+        */
 %0A    %7D%0A%0A

comment out the autolog info