<commit_before>package ch.epfl.sweng.project.Fragments;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

import com.example.android.multidex.ch.epfl.sweng.project.AppRunnest.R;

import java.util.HashMap;
import java.util.Map;

import ch.epfl.sweng.project.Firebase.FirebaseHelper;
import ch.epfl.sweng.project.Model.Message;

/**
 * A simple {@link Fragment} subclass.
 * Activities that contain this fragment must implement the
 * {@link DisplayUserFragment.OnDisplayUserFragmentInteractionListener} interface
 * to handle interaction events.
 * Use the {@link DisplayUserFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class DisplayUserFragment extends Fragment {

    private static final String ARG_ID = "id";
    private static final String ARG_NAME = "name";
    private static final String ARG_FOUND_USERS = "foundUsers";

    private Map<String, String> mFoundUsers;
    private String mId;
    private String mName;

    private OnDisplayUserFragmentInteractionListener mListener;

    public static DisplayUserFragment newInstance(Map<String, String> foundUsers) {
        DisplayUserFragment fragment = new DisplayUserFragment();
        fragment.mFoundUsers = new HashMap<>(foundUsers);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_display_user, container, false);

        if (mFoundUsers.size() > 0) {
            for (Map.Entry<String, String> user : mFoundUsers.entrySet()) {
                displayFoundUser(view, user.getKey(), user.getValue());
            }
        } else {
            displayFoundUser(view, null, null);
        }

        return view;
    }

    private void displayFoundUser(View view, final String name, final String email) {
        TableLayout table = (TableLayout) view.findViewById(R.id.table);
        TableRow tableRow = new TableRow(this.getContext());
        TableRow.LayoutParams layoutParams = new TableRow.LayoutParams();
        layoutParams.setMargins(10, 50, 20, 10);

        String text = "No user found.";
        Boolean noUserFound = true;
        if (name != null && email != null) {
            text = name + "\n" + email;
            noUserFound = false;
        }

        TextView nameAndEmailTextView = new TextView(this.getContext());
        nameAndEmailTextView.setText(text);
        nameAndEmailTextView.setTextSize(18);
        nameAndEmailTextView.setLayoutParams(layoutParams);
        tableRow.addView(nameAndEmailTextView);

        if (!noUserFound) {
            Button challengeButton = new Button(this.getContext());
            challengeButton.setText("Challenge!");
            challengeButton.setLayoutParams(layoutParams);
            challengeButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    // Send message
                    // TODO: make profile a SideBarActivity attribute so that it can be accessible here to set the from
                    String from = "me";
                    // TODO: children names in firebase can't contain . and @
                    String to = "challengee";//mName;
                    String message = "Run with me!";
                    Message challengeRequestMessage = new Message(from, to, Message.MessageType.CHALLENGE_REQUEST, message);

                    FirebaseHelper firebaseHelper = new FirebaseHelper();
                    firebaseHelper.send(challengeRequestMessage);

                    // Go to ChallengeFragment
                    mListener.onDisplayUserFragmentInteraction(name, email);
                }
            });

            tableRow.addView(challengeButton);
        }

        table.addView(tableRow);
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        if (context instanceof OnDisplayUserFragmentInteractionListener) {
            mListener = (OnDisplayUserFragmentInteractionListener) context;
        } else {
            throw new RuntimeException(context.toString()
                    + " must implement OnFragmentInteractionListener");
        }
    }<commit_msg>Send message to correct user<commit_after>package ch.epfl.sweng.project.Fragments;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

import com.example.android.multidex.ch.epfl.sweng.project.AppRunnest.R;

import java.util.HashMap;
import java.util.Map;

import ch.epfl.sweng.project.Firebase.FirebaseHelper;
import ch.epfl.sweng.project.Model.Message;
import ch.epfl.sweng.project.Model.Profile;

/**
 * A simple {@link Fragment} subclass.
 * Activities that contain this fragment must implement the
 * {@link DisplayUserFragment.OnDisplayUserFragmentInteractionListener} interface
 * to handle interaction events.
 * Use the {@link DisplayUserFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class DisplayUserFragment extends Fragment {

    private static final String ARG_ID = "id";
    private static final String ARG_NAME = "name";
    private static final String ARG_FOUND_USERS = "foundUsers";

    private Map<String, String> mFoundUsers;
    private String mId;
    private String mName;

    private OnDisplayUserFragmentInteractionListener mListener;

    public static DisplayUserFragment newInstance(Map<String, String> foundUsers) {
        DisplayUserFragment fragment = new DisplayUserFragment();
        fragment.mFoundUsers = new HashMap<>(foundUsers);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_display_user, container, false);

        if (mFoundUsers.size() > 0) {
            for (Map.Entry<String, String> user : mFoundUsers.entrySet()) {
                displayFoundUser(view, user.getKey(), user.getValue());
            }
        } else {
            displayFoundUser(view, null, null);
        }

        return view;
    }

    private void displayFoundUser(View view, final String name, final String email) {
        TableLayout table = (TableLayout) view.findViewById(R.id.table);
        TableRow tableRow = new TableRow(this.getContext());
        TableRow.LayoutParams layoutParams = new TableRow.LayoutParams();
        layoutParams.setMargins(10, 50, 20, 10);

        String text = "No user found.";
        Boolean noUserFound = true;
        if (name != null && email != null) {
            text = name + "\n" + email;
            noUserFound = false;
        }

        TextView nameAndEmailTextView = new TextView(this.getContext());
        nameAndEmailTextView.setText(text);
        nameAndEmailTextView.setTextSize(18);
        nameAndEmailTextView.setLayoutParams(layoutParams);
        tableRow.addView(nameAndEmailTextView);

        if (!noUserFound) {
            Button challengeButton = new Button(this.getContext());
            challengeButton.setText("Challenge!");
            challengeButton.setLayoutParams(layoutParams);
            challengeButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    // Send message
                    // TODO: make profile a SideBarActivity attribute so that it can be accessible here to set the from
                    String from = "me";
                    String to = Profile.getFireBaseMail(email);
                    String message = "Run with me!";
                    Message challengeRequestMessage = new Message(from, to, Message.MessageType.CHALLENGE_REQUEST, message);

                    FirebaseHelper firebaseHelper = new FirebaseHelper();
                    firebaseHelper.send(challengeRequestMessage);

                    // Go to ChallengeFragment
                    mListener.onDisplayUserFragmentInteraction(name, email);
                }
            });

            tableRow.addView(challengeButton);
        }

        table.addView(tableRow);
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        if (context instanceof OnDisplayUserFragmentInteractionListener) {
            mListener = (OnDisplayUserFragmentInteractionListener) context;
        } else {
            throw new RuntimeException(context.toString()
                    + " must implement OnFragmentInteractionListener");
        }
    }
{'fraction_non_alphanumeric': 0.08632323015958017, 'fraction_numerical': 0.0025704187640569775, 'mean_word_length': 2.6982178217821784, 'pattern_counts': {'":': 0, '<': 11, '<?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': '4443631', 'n_tokens_mistral': 2420, 'n_tokens_neox': 2296, 'n_words': 594}