package io.zetaphase.chewsnap;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

/**
 * Created by Dave Ho on 3/6/2017.
 */

public class MealListFragment extends Fragment {

    private ListView mealListView;
    //private MealAdapter<Meal> listAdapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        //FragmentTransaction ft = getFragmentManager().beginTransaction();
        //ft.add(this, "mealListView");
        //ft.commit();
        MainActivity superActivity = (MainActivity) getActivity();
        View view = inflater.inflate(R.layout.meal_list_fragment, container , false);
        mealListView = (ListView) view.findViewById(R.id.mealList);
        mealListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
                Intent intent = new Intent(getActivity(), ViewMealPopup.class);
                intent.putExtra("CLICKPOSITION", ""+position);
                startActivity(intent);
            }
        });
        //String[] meals = new String[] {"apple", "steak"};
        //ArrayList<String> mealList = new ArrayList<>();
        //mealList.addAll(Arrays.asList(meals));
        //superActivity.mealList.add(new Meal("Steak", "This Steak is delicious", 5));
        MainActivity.mealAdapter = new MealAdapter(getActivity(), 0, superActivity.mealList);
        mealListView.setAdapter(MainActivity.mealAdapter);
        return view;
    }


}

@@ -25,16 +25,88 @@
 wsnap;%0A%0A
+import android.app.AlertDialog;%0Aimport android.content.DialogInterface;%0A
 import a
@@ -1499,16 +1499,1209 @@
     %7D);%0A
+        mealListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() %7B%0A            @Override%0A            public boolean onItemLongClick(AdapterView%3C?%3E adapterView, View view, int pos, long l) %7B%0A                final CharSequence%5B%5D items = %7B %22Delete%22, %22Share%22, %22Cancel%22 %7D;%0A%0A                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());%0A                builder.setTitle(MainActivity.mealList.get(pos).getTitle().toUpperCase());%0A                final int position = pos;%0A                builder.setItems(items, new DialogInterface.OnClickListener() %7B%0A                    @Override%0A                    public void onClick(DialogInterface dialog, int item) %7B%0A                        if (items%5Bitem%5D.equals(%22Delete%22)) %7B%0A                            MainActivity.mealList.remove(position);%0A                            MainActivity.mealAdapter.updateMealList(MainActivity.mealList);%0A                            MainActivity.mealAdapter.notifyDataSetChanged();%0A                        %7D%0A                        dialog.dismiss();%0A                    %7D%0A                %7D);%0A                builder.show();%0A                return true;%0A            %7D%0A        %7D);%0A
         

add long item click listener to meal list fragment