package com.napontaratan.vibernate;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextClock;
import android.widget.TextView;

import java.util.Collections;
import java.util.List;

/**
 * Created by Aor-Nawattranakul on 15-04-06.
 */
public class vAdapter extends RecyclerView.Adapter<vAdapter.vViewHolder> {
    private LayoutInflater inflater;
    List<vInfo> data = Collections.emptyList(); // this is so that we won't be getting nullpointer exception


    public vAdapter(Context context, List<vInfo> data) {
        inflater = LayoutInflater.from(context);
        this.data = data;
    }

    // remove a row at 'position'
    public void delete(int position) {
        data.remove(position);
        notifyItemRemoved(position);
    }


    @Override
    public vViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.v_row, parent, false); // inflat xml into a view
        vViewHolder holder = new vViewHolder(view); // turn a view into viewHolder storing specified values
        return holder;
    }

    @Override
    public void onBindViewHolder(vViewHolder holder, int position) {
        vInfo current = data.get(position);
        holder.description.setText(current.descrition);
        holder.startTime.setFormat12Hour(current.startTime);
        holder.endTime.setFormat12Hour(current.endTime);
    }

    @Override
    public int getItemCount() {
        return data.size();
    }


    class vViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        TextView description;
        TextClock startTime;
        TextClock endTime;
        Button remove;


        public vViewHolder(View itemView) {
            super(itemView);
            description = (TextView) itemView.findViewById(R.id.v_description);
            startTime = (TextClock) itemView.findViewById(R.id.v_startTime);
            endTime = (TextClock) itemView.findViewById(R.id.v_endTime);
            remove = (Button) itemView.findViewById(R.id.remove_b);
            remove.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            if ( v == remove) {
                delete(getPosition());
            }
        }
    }
}

@@ -105,24 +105,57 @@
 cyclerView;%0A
+import android.view.MotionEvent;%0A
 import andro
@@ -164,24 +164,24 @@
 .view.View;%0A
-
 import andro
@@ -944,24 +944,176 @@
 on);%0A    %7D%0A%0A
+    // Add 'item' at 'position'%0A    public void addItem(vInfo item, int position) %7B%0A        data.add(item);%0A        notifyItemInserted(position);%0A    %7D%0A
 %0A    @Overri
@@ -1899,16 +1899,38 @@
 Listener
+, View.OnTouchListener
  %7B%0A     
@@ -2430,21 +2430,21 @@
 ve.setOn
-Click
+Touch
 Listener
@@ -2451,16 +2451,17 @@
 (this);%0A
+%0A
         
@@ -2515,24 +2515,281 @@
 k(View v) %7B%0A
+%0A        %7D%0A%0A%0A        @Override%0A        public boolean onTouch(View v, MotionEvent event) %7B%0A            switch (event.getAction()) %7B%0A                case MotionEvent.ACTION_DOWN:%0A                    break;%0A                case MotionEvent.ACTION_UP:%0A        
             
@@ -2804,24 +2804,32 @@
 = remove) %7B%0A
+        
             
@@ -2863,25 +2863,100 @@
             
-%7D
+        %7D%0A                    break;%0A            %7D%0A            return false;
 %0A        %7D%0A 

Apply TouchAction