package app.brest.testmin3d;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import app.brest.app.brest.ui.CustomListView;
import app.brest.app.brest.ui.ResourceArrayAdapter;
import app.brest.utils.app.brest.game.Game;
import app.brest.utils.app.brest.game.Resource;

/**
 * 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 Game mGame;
    protected ListView mList;

    /*
    protected void addStage(ArrayList<Object> ar, int stage)
    {
        LinearLayout nl = new LinearLayout(this);
        CustomListView lv = new CustomListView(this);
        ScrollView sv = new ScrollView(this);
        TextView b = new TextView(this);
        ResourceArrayAdapter aa;
        b.setText("Etape "+stage);
        b.setTextColor(Color.rgb(0x33, 0xb5, 0xe5));
        b.setTextSize(30);
        b.setTypeface(null, Typeface.BOLD);

        aa = new ResourceArrayAdapter(this, android.R.layout.simple_list_item_1, ar);
        lv.setOnItemClickListener(aa);

        lv.setAdapter(aa);

        nl.setOrientation(LinearLayout.VERTICAL);
        nl.addView(b);
        nl.addView(sv);
        sv.addView(lv);
        //lv.setLayoutParams(new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT,  LinearLayout.LayoutParams.MATCH_PARENT));
        mLayout.addView(nl);
    }

    protected void fill()
    {
        if(mGame!=null)
        {
            ArrayList< ArrayList<Resource> > resources = mGame.getResourceByStage();
            for(int i = 0; i< resources.size(); i++)
                addStage(resources.get(i), i);
        }
    }*/


    protected void fill()
    {
        if(mGame!=null)
        {
            ArrayList< ArrayList<Resource> > resources = mGame.getResourceByStage();
            ArrayList<Object> obs = new ArrayList<Object>();
            for(int i = 0; i< resources.size(); i++) {
                obs.add("Étape "+i);
                for(int j=0; j<resources.get(i).size(); j++)
                    obs.add(resources.get(i).get(j));
            }
            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);
        mGame = (Game)getIntent().getSerializableExtra("game");

        mList = (ListView) findViewById(R.id.list_layout);
        fill();
    }


}
