package www.immacbytes.com.chatlist;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.baoyz.swipemenulistview.SwipeMenu;
import com.baoyz.swipemenulistview.SwipeMenuCreator;
import com.baoyz.swipemenulistview.SwipeMenuItem;
import com.baoyz.swipemenulistview.SwipeMenuListView;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    private SwipeMenuListView listView;
    private ArrayList<list> dataArrayList;
    private adapter listAdapter;
    private list data;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        listView = (SwipeMenuListView) findViewById(R.id.listview);
        dataArrayList = new ArrayList<>();


        dataArrayList.add(data = new list("Jenni", "Where are you boy?",R.drawable.girl));
        dataArrayList.add(data = new list("Christa", "I am here dude",R.drawable.girl2));
        dataArrayList.add(data = new list("Lopez", "Tonight at 9pm?",R.drawable.girl3));
        dataArrayList.add(data = new list("Jesse", "Girls night???",R.drawable.girl));
        dataArrayList.add(data = new list("Yokome", "Gonna packup tommorrow",R.drawable.girl2));
        dataArrayList.add(data = new list("Shelly", "Dinner outside? I am not cooking!",R.drawable.girl3));
        dataArrayList.add(data = new list("Jane", "I am coming. Text me right away!",R.drawable.girl));

        listAdapter = new adapter(this, dataArrayList);
        listView.setAdapter(listAdapter);

        listView.setMenuCreator(creator);

        listView.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
                switch (index) {
                    case 0:

                        Toast.makeText(MainActivity.this, "Deleted!", Toast.LENGTH_SHORT).show();
                        dataArrayList.remove(position);
                        listAdapter.notifyDataSetChanged();

                        break;
                    case 1:
                        break;
                }
                return false;
            }
        });

    }


    SwipeMenuCreator creator = new SwipeMenuCreator() {

        @Override
        public void create(SwipeMenu menu) {
            // create "delete" item
            SwipeMenuItem deleteItem = new SwipeMenuItem(
                    getApplicationContext());
            // set item background
            deleteItem.setBackground(new ColorDrawable(Color.parseColor("#F45557")));
            // set item width
            deleteItem.setWidth(150);
            deleteItem.setTitle("x");
            deleteItem.setTitleColor(Color.WHITE);
            deleteItem.setTitleSize(15);
            // add to menu
            menu.addMenuItem(deleteItem);
        }
    };
}
