package macampcorp.macamp.activities.viewers;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;

import macampcorp.macamp.game.Game;
import macampcorp.macamp.game.Inventaire;
import java.util.ArrayList;

import macampcorp.macamp.activities.R;
import macampcorp.macamp.game.Resource;
import macampcorp.macamp.ui.ResourceArrayAdapter;
import macampcorp.macamp.utils.L;

/**
 * An example full-screen activity that shows and hides the system UI (i.e.
 * status bar and navigation/system bar) with user interaction.
 */
public class ResourceListActivity extends Activity {
    protected Inventaire mInventaire;
    protected ListView mList;


    protected void fill()
    {
        if(mInventaire!=null)
        {
            ArrayList<Resource> resources = mInventaire.getDisplayResources();
            ArrayList<Object> obs = new ArrayList<Object>();
            for(int i = 0; i< resources.size(); i++) {
                obs.add(resources.get(i));
            }
            ResourceArrayAdapter aa;
            aa = new ResourceArrayAdapter(this, android.R.layout.simple_list_item_1, obs);
            mList.setOnItemClickListener(aa);
            mList.setAdapter(aa);
        }
    }

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

        mInventaire = (Inventaire)getIntent().getSerializableExtra("inventaire");
        mList = (ListView) findViewById(R.id.list_layout);
        fill();
    }

    public static void start(Activity a)
    {
        Intent intent = new Intent(a, ResourceListActivity.class);
        intent.putExtra("inventaire", Game.game().getInventaire());
        a.startActivity(intent);
    }
}