package com.kuckovsky.richard.home;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

import static android.R.color.black;

/**
 * Created by richard on 4.6.17.
 */

public class roomsAdapter extends BaseAdapter {

    private Context mContext;
    private LayoutInflater mInflater;
    private JSONArray mDataSource;

    public roomsAdapter(Context context, JSONArray items) {
        mContext = context;
        mDataSource = items;
        mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        return mDataSource.length();
    }

    @Override
    public Object getItem(int position) {
        try {
            return mDataSource.getJSONObject(position);
        } catch (JSONException e) {
            return 0;
        }
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View rowView = mInflater.inflate(R.layout.list_view_room, parent, false);

        TextView title = (TextView) rowView.findViewById(R.id.room_list_title);
        try {
            JSONObject light = mDataSource.getJSONObject(position);
            String name = light.getString("name");
            title.setText(name);

        } catch (JSONException e) {
            e.printStackTrace();
        }

        title.setTextColor(Color.BLACK);
        return rowView;
    }
}
