package com.example.qyu4.theallswap.View;

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.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import com.example.qyu4.theallswap.Model.User;
import com.example.qyu4.theallswap.R;
import com.example.qyu4.theallswap.Controller.UserController;

import java.util.ArrayList;

public class UserFriends extends ActionBarActivity {
    private UserFriends activity = this;
    private UserController uc = new UserController();
    private ArrayList<User> userList= new ArrayList<User>();
    private ArrayAdapter<User> adapter;
    private ListView friendList;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_friends);
        friendList = (ListView)findViewById(R.id.lv_user_friends);
        friendList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //TODO: some stuff
                uc.makeInvalidUserToast(activity);
            }


        });
    }
    @Override
    protected void onStart() {
        // TODO Auto-generated method stub
        super.onStart();
        //loadFromFile();oldTweetsList.setAdapter(adapter);
        /***************************************************
         TODO: add loading friends list method.
         *************************************************/
        User sampleUser = new User();
        sampleUser.setUserId("123");
        userList.add(sampleUser);
        /***************************************************
         TODO: add loading friends list method.
         *************************************************/

        adapter = new ArrayAdapter<User>(this, R.layout.list_item, userList);
        friendList.setAdapter(adapter);
        adapter.notifyDataSetChanged();
    }

    @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_user_main_viewing, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    public void userMyInventorySelected(MenuItem menu){
        uc.classIntent(UserInventory.class, activity);
    }
    public void userMyTradeSelected(MenuItem menu){

        uc.classIntent(UserTrade.class, activity);
    }
    public void userMyFriendsSelected(MenuItem menu){
        uc.classIntent(UserFriends.class, activity);
    }
    public void userMyProfileSelected(MenuItem menu){
        uc.classIntent(UserProfile.class, activity);
    }
    public void userSearchSelected(MenuItem menu){
        uc.classIntent(Search.class, activity);
    }
    public void userPreviousBrowseSelected(MenuItem menu){
        uc.classIntent(PreviousBrowsedTrade.class, activity);
    }
    public void userLogoutSelected(MenuItem menu){
        uc.classIntent(UserLogin.class, activity);
    }


}
@@ -739,24 +739,86 @@
 st%3CUser%3E();%0A
+    private static final String FILENAME = %22userProfile.txt%22;%0A
     private 
@@ -878,16 +878,70 @@
 ndList;%0A
+    private ArrayList resultList = new ArrayList%3C%3E();%0A
     @Ove
@@ -1592,57 +1592,67 @@
     
-//loadFromFile();oldTweetsList.setAdapter(adapter
+userList = uc.loadUserFromFile(activity, FILENAME, userList
 );%0A 
@@ -1831,106 +1831,64 @@
     
-User sampleUser = new User();%0A        sampleUser.setUserId(%22123%22);%0A        userList.add(sampleUser
+resultList = uc.convertUserToString(userList, resultList
 );%0A 
@@ -2123,20 +2123,22 @@
 t_item, 
-user
+result
 List);%0A 
@@ -3761,8 +3761,9 @@
    %7D%0A%0A%0A%7D
+%0A

move default user main page to friend list and start changing default activity