<commit_before>package edu.rutgers.css.Rutgers.fragments.Food;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.androidquery.callback.AjaxStatus;

import org.jdeferred.android.AndroidDoneCallback;
import org.jdeferred.android.AndroidExecutionScope;
import org.jdeferred.android.AndroidFailCallback;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

import edu.rutgers.css.Rutgers.adapters.RMenuAdapter;
import edu.rutgers.css.Rutgers.api.ComponentFactory;
import edu.rutgers.css.Rutgers.api.Dining;
import edu.rutgers.css.Rutgers.fragments.TextDisplay;
import edu.rutgers.css.Rutgers.items.RMenuHeaderRow;
import edu.rutgers.css.Rutgers.items.RMenuItemRow;
import edu.rutgers.css.Rutgers.items.RMenuRow;
import edu.rutgers.css.Rutgers.utils.AppUtil;
import edu.rutgers.css.Rutgers2.R;

/**
 * Displays dining halls. Selecting a hall goes to meal menu.
 *
 */
public class FoodMain extends Fragment {

	private static final String TAG = "FoodMain";
    public static final String HANDLE = "food";

    private ArrayList<RMenuRow> mData;
    private RMenuAdapter mAdapter;

	public FoodMain() {
		// Required empty public constructor
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

        mData = new ArrayList<RMenuRow>(4);
        mAdapter = new RMenuAdapter(getActivity(), R.layout.row_title, R.layout.row_section_header, mData);

        final String nbCampusFullString = getResources().getString(R.string.campus_nb_full);

		// Get dining hall data and populate the top-level menu with names of the dining halls
		Dining.getDiningHalls().done(new AndroidDoneCallback<JSONArray>() {

            @Override
            public void onDone(JSONArray halls) {
                try {
                    mAdapter.add(new RMenuHeaderRow(nbCampusFullString));

                    // Add dining halls - if they have no active meals, make them unclickable
                    for (int i = 0; i < halls.length(); i++) {
                        JSONObject curHall = halls.getJSONObject(i);
                        Bundle hallBundle = new Bundle();
                        hallBundle.putString("title", curHall.getString("location_name"));
                        hallBundle.putString("location", curHall.getString("location_name"));

                        if (Dining.hasActiveMeals(curHall)) {
                            mAdapter.add(new RMenuItemRow(hallBundle));
                        } else {
                            RMenuItemRow inactiveHallItem = new RMenuItemRow(hallBundle);
                            inactiveHallItem.setClickable(false);
                            inactiveHallItem.setColorResId(R.color.light_gray);
                            mAdapter.add(inactiveHallItem);
                        }
                    }

                    loadStaticHalls();
                } catch (JSONException e) {
                    Log.w(TAG, e.getMessage());
                    Toast.makeText(getActivity(), R.string.failed_internal, Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public AndroidExecutionScope getExecutionScope() {
                return AndroidExecutionScope.UI;
            }

        }).fail(new AndroidFailCallback<AjaxStatus>() {

            @Override
            public void onFail(AjaxStatus e) {
                AppUtil.showFailedLoadToast(getActivity());
            }

            @Override
            public AndroidExecutionScope getExecutionScope() {
                return AndroidExecutionScope.UI;
            }

        });
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
		View v = inflater.inflate(R.layout.fragment_food_main, parent, false);
		ListView listView = (ListView) v.findViewById(R.id.dining_locations_list);
		Bundle args = getArguments();

        // Set title from JSON
		if(args.getString("title") != null) getActivity().setTitle(args.getString("title"));
        else getActivity().setTitle(R.string.dining_title);

		listView.setAdapter(mAdapter);
		listView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Bundle clickedArgs = ((RMenuItemRow) parent.getAdapter().getItem(position)).getArgs();

                Bundle args = new Bundle(clickedArgs);
                args.putString("component", FoodHall.HANDLE);

                ComponentFactory.getInstance().switchFragments(args);
            }

        });
		
		return v;
	}

    private void loadStaticHalls() {
        Bundle nwk = new Bundle();
        nwk.putString("component", TextDisplay.HANDLE);
        nwk.putString("title", "Stonsby Commons & Eatery");
        nwk.putString("data", "Students enjoy all-you-care-to-eat dining in a contemporary setting. This exciting location offers fresh made menu items, cutting-edge American entrees, ethnically-inspired foods, vegetarian selections and lots more... \n\nThe Commons also features upscale Premium entrees and fresh baked goods from our in house bakery or local vendors.");<commit_msg>Food: bug fix for opening static text items<commit_after>package edu.rutgers.css.Rutgers.fragments.Food;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.androidquery.callback.AjaxStatus;

import org.jdeferred.android.AndroidDoneCallback;
import org.jdeferred.android.AndroidExecutionScope;
import org.jdeferred.android.AndroidFailCallback;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

import edu.rutgers.css.Rutgers.adapters.RMenuAdapter;
import edu.rutgers.css.Rutgers.api.ComponentFactory;
import edu.rutgers.css.Rutgers.api.Dining;
import edu.rutgers.css.Rutgers.fragments.TextDisplay;
import edu.rutgers.css.Rutgers.items.RMenuHeaderRow;
import edu.rutgers.css.Rutgers.items.RMenuItemRow;
import edu.rutgers.css.Rutgers.items.RMenuRow;
import edu.rutgers.css.Rutgers.utils.AppUtil;
import edu.rutgers.css.Rutgers2.R;

/**
 * Displays dining halls. Selecting a hall goes to meal menu.
 *
 */
public class FoodMain extends Fragment {

	private static final String TAG = "FoodMain";
    public static final String HANDLE = "food";

    private ArrayList<RMenuRow> mData;
    private RMenuAdapter mAdapter;

	public FoodMain() {
		// Required empty public constructor
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

        mData = new ArrayList<RMenuRow>(4);
        mAdapter = new RMenuAdapter(getActivity(), R.layout.row_title, R.layout.row_section_header, mData);

        final String nbCampusFullString = getResources().getString(R.string.campus_nb_full);

		// Get dining hall data and populate the top-level menu with names of the dining halls
		Dining.getDiningHalls().done(new AndroidDoneCallback<JSONArray>() {

            @Override
            public void onDone(JSONArray halls) {
                try {
                    mAdapter.add(new RMenuHeaderRow(nbCampusFullString));

                    // Add dining halls - if they have no active meals, make them unclickable
                    for (int i = 0; i < halls.length(); i++) {
                        JSONObject curHall = halls.getJSONObject(i);
                        Bundle hallBundle = new Bundle();
                        hallBundle.putString("title", curHall.getString("location_name"));
                        hallBundle.putString("location", curHall.getString("location_name"));
                        hallBundle.putString("component", FoodHall.HANDLE);

                        if (Dining.hasActiveMeals(curHall)) {
                            mAdapter.add(new RMenuItemRow(hallBundle));
                        } else {
                            RMenuItemRow inactiveHallItem = new RMenuItemRow(hallBundle);
                            inactiveHallItem.setClickable(false);
                            inactiveHallItem.setColorResId(R.color.light_gray);
                            mAdapter.add(inactiveHallItem);
                        }
                    }

                    loadStaticHalls();
                } catch (JSONException e) {
                    Log.w(TAG, e.getMessage());
                    Toast.makeText(getActivity(), R.string.failed_internal, Toast.LENGTH_SHORT).show();
                }
            }

            @Override
            public AndroidExecutionScope getExecutionScope() {
                return AndroidExecutionScope.UI;
            }

        }).fail(new AndroidFailCallback<AjaxStatus>() {

            @Override
            public void onFail(AjaxStatus e) {
                AppUtil.showFailedLoadToast(getActivity());
            }

            @Override
            public AndroidExecutionScope getExecutionScope() {
                return AndroidExecutionScope.UI;
            }

        });
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
		View v = inflater.inflate(R.layout.fragment_food_main, parent, false);
		ListView listView = (ListView) v.findViewById(R.id.dining_locations_list);
		Bundle args = getArguments();

        // Set title from JSON
		if(args.getString("title") != null) getActivity().setTitle(args.getString("title"));
        else getActivity().setTitle(R.string.dining_title);

		listView.setAdapter(mAdapter);
		listView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Bundle clickedArgs = ((RMenuItemRow) parent.getAdapter().getItem(position)).getArgs();
                ComponentFactory.getInstance().switchFragments(clickedArgs);
            }

        });
		
		return v;
	}

    private void loadStaticHalls() {
        Bundle nwk = new Bundle();
        nwk.putString("component", TextDisplay.HANDLE);
        nwk.putString("title", "Stonsby Commons & Eatery");
        nwk.putString("data", "Students enjoy all-you-care-to-eat dining in a contemporary setting. This exciting location offers fresh made menu items, cutting-edge American entrees, ethnically-inspired foods, vegetarian selections and lots more... \n\nThe Commons also features upscale Premium entrees and fresh baked goods from our in house bakery or local vendors.");
{'fraction_non_alphanumeric': 0.09547332495060176, 'fraction_numerical': 0.0007185198491108317, 'mean_word_length': 2.63058363221389, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4155087', 'n_tokens_mistral': 3174, 'n_tokens_neox': 2909, 'n_words': 658}