package com.jachdev.consumerprotection.ui.calories;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.jachdev.consumerprotection.R;

public class ExercisesSuggeserActivity extends AppCompatActivity {

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

        MyListData[] myListData = new MyListData[] {
                new MyListData("First Day", android.R.drawable.ic_dialog_email),
                new MyListData("Second Day", android.R.drawable.ic_dialog_info),
                new MyListData("Third Day", android.R.drawable.ic_delete),
                new MyListData("Forth Day", android.R.drawable.ic_dialog_dialer),
                new MyListData("Fifth Day", android.R.drawable.ic_dialog_alert),
                new MyListData("Sixth Day", android.R.drawable.ic_dialog_map),
                new MyListData("Seventh Day", android.R.drawable.ic_dialog_email),
                new MyListData("Ninth Day", android.R.drawable.ic_dialog_info),
                new MyListData("10 Day", android.R.drawable.ic_delete),
                new MyListData("11 Day", android.R.drawable.ic_dialog_dialer),
                new MyListData("12 Day", android.R.drawable.ic_dialog_alert),
                new MyListData("13 Day", android.R.drawable.ic_dialog_map),
        };

        RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        MyListAdapter adapter = new MyListAdapter(myListData);
        recyclerView.setHasFixedSize(true);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(adapter);
    }

    public class MyListAdapter extends RecyclerView.Adapter<MyListAdapter.ViewHolder>{
        private MyListData[] listdata;

        // RecyclerView recyclerView;
        public MyListAdapter(MyListData[] listdata) {
            this.listdata = listdata;
        }
        @Override
        public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
            View listItem= layoutInflater.inflate(R.layout.list_item, parent, false);
            ViewHolder viewHolder = new ViewHolder(listItem);
            return viewHolder;
        }

        @Override
        public void onBindViewHolder(ViewHolder holder, int position) {
            final MyListData myListData = listdata[position];
            holder.textView.setText(listdata[position].getDescription());
//            holder.imageView.setImageResource(listdata[position].getImgId());
            holder.relativeLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Toast.makeText(view.getContext(),"click on item: "+myListData.getDescription(),Toast.LENGTH_LONG).show();
                }
            });
        }


        @Override
        public int getItemCount() {
            return listdata.length;
        }

        public class ViewHolder extends RecyclerView.ViewHolder {
            public ImageView imageView;
            public TextView textView;
            public RelativeLayout relativeLayout;
            public ViewHolder(View itemView) {
                super(itemView);
                this.imageView = (ImageView) itemView.findViewById(R.id.imageView);
                this.textView = (TextView) itemView.findViewById(R.id.textView);
                relativeLayout = (RelativeLayout)itemView.findViewById(R.id.relativeLayout);
            }
        }
    }

    public class MyListData{
        private String description;
        private int imgId;
        public MyListData(String description, int imgId) {
            this.description = description;
            this.imgId = imgId;
        }
        public String getDescription() {
            return description;
        }
        public void setDescription(String description) {
            this.description = description;
        }
        public int getImgId() {
            return imgId;
        }
        public void setImgId(int imgId) {
            this.imgId = imgId;
        }
    }
}