<commit_before>package fr.insapp.insapp.fragments;

import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bumptech.glide.Glide;

import java.util.Calendar;
import java.util.Date;

import de.hdodenhof.circleimageview.CircleImageView;
import fr.insapp.insapp.R;
import fr.insapp.insapp.activities.EventActivity;
import fr.insapp.insapp.adapters.CommentRecyclerViewAdapter;
import fr.insapp.insapp.listeners.EventCommentLongClickListener;
import fr.insapp.insapp.models.Event;
import fr.insapp.insapp.models.User;
import fr.insapp.insapp.utility.CommentEditText;
import fr.insapp.insapp.utility.Utils;

/**
 * Created by thomas on 25/02/2017.
 */

public class CommentsEventFragment extends Fragment {

    private CommentRecyclerViewAdapter adapter;

    private Event event;

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

        // arguments

        final Bundle bundle = getArguments();
        if (bundle != null) {
            this.event = bundle.getParcelable("event");
        }

        // adapter

        this.adapter = new CommentRecyclerViewAdapter(getContext(), Glide.with(this), event.getComments());
        adapter.setOnItemLongClickListener(new EventCommentLongClickListener(getContext(), event, adapter));
    }

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

        CircleImageView circleImageView = (CircleImageView) view.findViewById(R.id.comment_event_username_avatar);

        // edit comment

        CommentEditText commentEditText = (CommentEditText) view.findViewById(R.id.comment_event_input);
        commentEditText.setupComponent(adapter, event);

        // recycler view

        RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recyclerview_comments_event);
        recyclerView.setHasFixedSize(true);
        recyclerView.setNestedScrollingEnabled(false);

        LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(layoutManager);

        recyclerView.setAdapter(adapter);

        // retrieve the avatar of the user

        final User user = Utils.getUser();

        final int id = getResources().getIdentifier(Utils.drawableProfileName(user.getPromotion(), user.getGender()), "drawable", getContext().getPackageName());
        Glide
                .with(getContext())
                .load(id)
                .crossFade()
                .into(circleImageView);

        // animation on focus

        commentEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    ((EventActivity) getActivity()).getAppBarLayout().setExpanded(false, true);
                    ((EventActivity) getActivity()).getFloatingActionMenu().hideMenu(false);
                }
                else {
                    final Date atm = Calendar.getInstance().getTime();

                    if (event.getDateEnd().getTime() >= atm.getTime()) {
                        final Handler handler = new Handler();
                        handler.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                ((EventActivity) getActivity()).getFloatingActionMenu().showMenu(true);
                            }
                        }, 500);
                    }
                }
            }
        });

        return view;
    }
}<commit_msg>Bugfix: null EventActivity in rare cases<commit_after>package fr.insapp.insapp.fragments;

import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bumptech.glide.Glide;

import java.util.Calendar;
import java.util.Date;

import de.hdodenhof.circleimageview.CircleImageView;
import fr.insapp.insapp.R;
import fr.insapp.insapp.activities.EventActivity;
import fr.insapp.insapp.adapters.CommentRecyclerViewAdapter;
import fr.insapp.insapp.listeners.EventCommentLongClickListener;
import fr.insapp.insapp.models.Event;
import fr.insapp.insapp.models.User;
import fr.insapp.insapp.utility.CommentEditText;
import fr.insapp.insapp.utility.Utils;

/**
 * Created by thomas on 25/02/2017.
 */

public class CommentsEventFragment extends Fragment {

    private CommentRecyclerViewAdapter adapter;

    private Event event;

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

        // arguments

        final Bundle bundle = getArguments();
        if (bundle != null) {
            this.event = bundle.getParcelable("event");
        }

        // adapter

        this.adapter = new CommentRecyclerViewAdapter(getContext(), Glide.with(this), event.getComments());
        adapter.setOnItemLongClickListener(new EventCommentLongClickListener(getContext(), event, adapter));
    }

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

        CircleImageView circleImageView = (CircleImageView) view.findViewById(R.id.comment_event_username_avatar);

        // edit comment

        CommentEditText commentEditText = (CommentEditText) view.findViewById(R.id.comment_event_input);
        commentEditText.setupComponent(adapter, event);

        // recycler view

        RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recyclerview_comments_event);
        recyclerView.setHasFixedSize(true);
        recyclerView.setNestedScrollingEnabled(false);

        LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(layoutManager);

        recyclerView.setAdapter(adapter);

        // retrieve the avatar of the user

        final User user = Utils.getUser();

        final int id = getResources().getIdentifier(Utils.drawableProfileName(user.getPromotion(), user.getGender()), "drawable", getContext().getPackageName());
        Glide
                .with(getContext())
                .load(id)
                .crossFade()
                .into(circleImageView);

        // animation on focus

        commentEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    ((EventActivity) getActivity()).getAppBarLayout().setExpanded(false, true);
                    ((EventActivity) getActivity()).getFloatingActionMenu().hideMenu(false);
                }
                else {
                    final Date atm = Calendar.getInstance().getTime();

                    if (event.getDateEnd().getTime() >= atm.getTime()) {
                        final Handler handler = new Handler();
                        handler.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                final EventActivity eventActivity = (EventActivity) getActivity();

                                if (eventActivity != null) {
                                    eventActivity.getFloatingActionMenu().showMenu(true);
                                }
                            }
                        }, 500);
                    }
                }
            }
        });

        return view;
    }
}
{'fraction_non_alphanumeric': 0.0958251953125, 'fraction_numerical': 0.00341796875, 'mean_word_length': 2.483418367346939, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '376795', 'n_tokens_mistral': 2219, 'n_tokens_neox': 2058, 'n_words': 394}