package app.brest.app.brest.ui;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Typeface;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.List;

import app.brest.testmin3d.ResourceListActivity;
import app.brest.testmin3d.ViewerActivity;
import app.brest.utils.app.brest.game.Resource;

/**
 * Created by ptitcois on 22/08/16.
 */
public class ResourceArrayAdapter extends ArrayAdapter<Object> implements  AdapterView.OnItemClickListener{
    protected Context mContext;
    protected List<Object> mList;
    public ResourceArrayAdapter(Context context, int resource, List<Object> objects) {
        super(context, resource, objects);
        mContext=context;
        mList=objects;
    }

    @Override
    public View getView(int position, View convertView,
                        ViewGroup parent) {
        View view =super.getView(position, convertView, parent);

        TextView textView=(TextView) view.findViewById(android.R.id.text1);

            /*YOUR CHOICE OF COLOR*/
        textView.setTextColor(Color.rgb(0x33, 0xb5, 0xe5));

        if(mList.get(position) instanceof String){
            textView.setTextSize(30);
            textView.setTypeface(null, Typeface.BOLD);
        }else{
            textView.setTextSize(15);
            textView.setTypeface(null, Typeface.NORMAL);
        }


        return view;
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        if (adapterView.getItemAtPosition(i) instanceof Resource) {
            Resource item = (Resource) adapterView.getItemAtPosition(i);

            Intent intent = new Intent(mContext, ViewerActivity.class);
            intent.putExtra("resource", item);
            mContext.startActivity(intent);

        }else if(adapterView.getItemAtPosition(i) instanceof String)
        {

        }
    }
}
