<commit_before>package org.pocketcampus.plugin.food;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.Vector;

import org.pocketcampus.R;
import org.pocketcampus.plugin.logging.Tracker;
import org.pocketcampus.shared.plugin.food.Meal;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * This class is used to make each section of a list of menus.
 * 
 */
public class RestaurantListAdapter extends BaseAdapter implements Filterable {
	private LayoutInflater mInflater_;
	private Vector<String> restaurants_;
	private FoodPlugin menusActivity_;
	private boolean[] mExpanded_;
	private HashMap<String, Vector<Meal>> mealHashMap_;

	/**
	 * Constructor
	 * 
	 * @param context
	 *            context of the application the list view is in
	 * @param resto
	 *            restaurant full menu represented in the list section.
	 */
	public RestaurantListAdapter(Vector<String> resto,
			HashMap<String, Vector<Meal>> mealHashMap, FoodPlugin menus) {
		// Cache the LayoutInflate to avoid asking for a new one each time.
		mInflater_ = LayoutInflater.from(menus.getApplicationContext());
		this.restaurants_ = resto;
		this.menusActivity_ = menus;
		this.mealHashMap_ = mealHashMap;
		this.mExpanded_ = new boolean[resto.size()];
		for (int i = 0; i < resto.size(); i++) {
			mExpanded_[i] = false;
		}
	}

	/**
	 * Make a view to hold each row.
	 * 
	 * @see android.widget.ListAdapter#getView(int, android.view.View,
	 *      android.view.ViewGroup)
	 */
	public View getView(final int position, View convertView, ViewGroup parent) {
		/*
		 * A ViewHolder keeps references to children views to avoid unnecessary
		 * calls to findViewById() on each row.
		 */
		ViewHolder holder;

		String restaurant = restaurants_.get(position);

		holder = new ViewHolder(menusActivity_, restaurant,
				mealHashMap_.get(restaurant), mExpanded_[position]);

		holder.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				toggle(position);
				menusActivity_.setSelected(position);
			}
		});

		return holder;
	}

	public void toggle(int position) {
		String restaurant = restaurants_.get(position).replace(" ", "");
		Tracker.getInstance()
				.trackPageView("food/menusListToggle" + restaurant);
		Log.d("List", "Toggling " + position + ", old: " + mExpanded_[position]
				+ ", new: " + !mExpanded_[position]);
		mExpanded_[position] = !mExpanded_[position];
		menusActivity_.notifyDataSetChanged();
	}

	public void repaint(Meal m) {
		Set<String> restaurants = mealHashMap_.keySet();
		for (String restaurant : restaurants) {
			for (Meal meal : mealHashMap_.get(restaurant)) {
				if (m.hashCode() == meal.hashCode()) {
					meal.setRating(m.getRating());
				}
			}
		}
		menusActivity_.notifyDataSetChanged();
	}

	public void toggleAll(boolean toggle) {
		for (int i = 0; i < mExpanded_.length; i++) {
			mExpanded_[i] = toggle;
		}
		menusActivity_.notifyDataSetChanged();
	}

	public Filter getFilter() {<commit_msg><food> set selected in toggle<commit_after>package org.pocketcampus.plugin.food;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.Vector;

import org.pocketcampus.R;
import org.pocketcampus.plugin.logging.Tracker;
import org.pocketcampus.shared.plugin.food.Meal;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * This class is used to make each section of a list of menus.
 * 
 */
public class RestaurantListAdapter extends BaseAdapter implements Filterable {
	private LayoutInflater mInflater_;
	private Vector<String> restaurants_;
	private FoodPlugin menusActivity_;
	private boolean[] mExpanded_;
	private HashMap<String, Vector<Meal>> mealHashMap_;

	/**
	 * Constructor
	 * 
	 * @param context
	 *            context of the application the list view is in
	 * @param resto
	 *            restaurant full menu represented in the list section.
	 */
	public RestaurantListAdapter(Vector<String> resto,
			HashMap<String, Vector<Meal>> mealHashMap, FoodPlugin menus) {
		// Cache the LayoutInflate to avoid asking for a new one each time.
		mInflater_ = LayoutInflater.from(menus.getApplicationContext());
		this.restaurants_ = resto;
		this.menusActivity_ = menus;
		this.mealHashMap_ = mealHashMap;
		this.mExpanded_ = new boolean[resto.size()];
		for (int i = 0; i < resto.size(); i++) {
			mExpanded_[i] = false;
		}
	}

	/**
	 * Make a view to hold each row.
	 * 
	 * @see android.widget.ListAdapter#getView(int, android.view.View,
	 *      android.view.ViewGroup)
	 */
	public View getView(final int position, View convertView, ViewGroup parent) {
		/*
		 * A ViewHolder keeps references to children views to avoid unnecessary
		 * calls to findViewById() on each row.
		 */
		ViewHolder holder;

		String restaurant = restaurants_.get(position);

		holder = new ViewHolder(menusActivity_, restaurant,
				mealHashMap_.get(restaurant), mExpanded_[position]);

		holder.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				toggle(position);
			}
		});

		return holder;
	}

	public void toggle(int position) {
		String restaurant = restaurants_.get(position).replace(" ", "");
		Tracker.getInstance()
				.trackPageView("food/menusListToggle" + restaurant);
		Log.d("List", "Toggling " + position + ", old: " + mExpanded_[position]
				+ ", new: " + !mExpanded_[position]);
		mExpanded_[position] = !mExpanded_[position];
		menusActivity_.notifyDataSetChanged();
		menusActivity_.setSelected(position);
	}

	public void repaint(Meal m) {
		Set<String> restaurants = mealHashMap_.keySet();
		for (String restaurant : restaurants) {
			for (Meal meal : mealHashMap_.get(restaurant)) {
				if (m.hashCode() == meal.hashCode()) {
					meal.setRating(m.getRating());
				}
			}
		}
		menusActivity_.notifyDataSetChanged();
	}

	public void toggleAll(boolean toggle) {
		for (int i = 0; i < mExpanded_.length; i++) {
			mExpanded_[i] = toggle;
		}
		menusActivity_.notifyDataSetChanged();
	}

	public Filter getFilter() {
{'fraction_non_alphanumeric': 0.1139541803034811, 'fraction_numerical': 0.0005950609937518596, 'mean_word_length': 4.256450351837373, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 18, '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': '6989554', 'n_tokens_mistral': 2224, 'n_tokens_neox': 1989, 'n_words': 512}