<commit_before>package com.permutassep.ui;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.lalongooo.permutassep.R;
import com.permutassep.BaseFragment;
import com.permutassep.adapter.PostAdapter;
import com.permutassep.config.Config;
import com.permutassep.model.Post;
import com.permutassep.rest.permutassep.PermutasSEPRestClient;
import com.permutassep.utils.Utils;

import java.util.List;

import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;
import retrofit.converter.GsonConverter;

public class FragmentNewsFeed extends BaseFragment {

    private ProgressDialog pDlg;
    private PostAdapter adapter;
    private FragmentPostDetail.OnPostItemSelectedListener onPostItemSelectedListener;


    private OnFirstLoadCompleteListener onFirstLoadCompleteListener;
    public interface OnFirstLoadCompleteListener {
        public void firstLoadCompleted();
    }

    public void onAttach(Activity activity) {
        super.onAttach(activity);

        if(!(getActivity() instanceof FragmentPostDetail.OnPostItemSelectedListener)) {
            throw new ClassCastException("Activity must implement OnPostItemSelectedListener");
        } else {
            onPostItemSelectedListener = (FragmentPostDetail.OnPostItemSelectedListener) getActivity();
        }

        if(!(getActivity() instanceof OnFirstLoadCompleteListener)) {
            throw new ClassCastException("Activity must implement OnFirstLoadCompleteListener");
        } else {
            onFirstLoadCompleteListener = (OnFirstLoadCompleteListener) getActivity();
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_news_feed, container, false);
        getActivity().setTitle(R.string.app_name);
        getActivity().invalidateOptionsMenu();
        getActivity().getSupportFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
        final ListView lv = (ListView) rootView.findViewById(R.id.news_feed_list);

        if(!Utils.isNetworkAvailable(getActivity())){
            Utils.showSimpleDialog(R.string.network_availability_dlg_text, R.string.accept, getActivity(), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    getActivity().finish();
                }
            });
            return rootView;
        }

        if(adapter == null){
            showDialog(getString(R.string.app_news_feed_dlg_title), getString(R.string.app_news_feed_dlg_text));
            GsonBuilder gsonBuilder = new GsonBuilder()
                    .setDateFormat(Config.APP_DATE_FORMAT);
            Gson gson = gsonBuilder.create();
            new PermutasSEPRestClient(new GsonConverter(gson)).get().getPosts(new Callback<List<Post>>() {
                // new PermutasSEPRestClient().get().getPosts(new Callback<List<Post>>() {
                @Override
                public void success(List<Post> posts, Response response) {
                    if(!posts.isEmpty()){
                        adapter = new PostAdapter(getActivity(), posts);
                        lv.setAdapter(adapter);
                        hideDialog();
                        onFirstLoadCompleteListener.firstLoadCompleted();
                    }else{<commit_msg>Moved the internal callback interface to com.permutassep.interfaces.FirstLaunchCompleteListener<commit_after>package com.permutassep.ui;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.lalongooo.permutassep.R;
import com.permutassep.BaseFragment;
import com.permutassep.adapter.PostAdapter;
import com.permutassep.config.Config;
import com.permutassep.interfaces.FirstLaunchCompleteListener;
import com.permutassep.model.Post;
import com.permutassep.rest.permutassep.PermutasSEPRestClient;
import com.permutassep.utils.Utils;

import java.util.List;

import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;
import retrofit.converter.GsonConverter;

public class FragmentNewsFeed extends BaseFragment {

    private ProgressDialog pDlg;
    private PostAdapter adapter;
    private FragmentPostDetail.OnPostItemSelectedListener onPostItemSelectedListener;
    private FirstLaunchCompleteListener firstLaunchCompleteListener;

    public void onAttach(Activity activity) {
        super.onAttach(activity);

        if(!(getActivity() instanceof FragmentPostDetail.OnPostItemSelectedListener)) {
            throw new ClassCastException("Activity must implement OnPostItemSelectedListener");
        } else {
            onPostItemSelectedListener = (FragmentPostDetail.OnPostItemSelectedListener) getActivity();
        }

        if(!(getActivity() instanceof FirstLaunchCompleteListener)) {
            throw new ClassCastException("Activity must implement OnFirstLoadCompleteListener");
        } else {
            firstLaunchCompleteListener = (FirstLaunchCompleteListener) getActivity();
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_news_feed, container, false);
        getActivity().setTitle(R.string.app_name);
        getActivity().invalidateOptionsMenu();
        getActivity().getSupportFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
        final ListView lv = (ListView) rootView.findViewById(R.id.news_feed_list);

        if(!Utils.isNetworkAvailable(getActivity())){
            Utils.showSimpleDialog(R.string.network_availability_dlg_text, R.string.accept, getActivity(), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    getActivity().finish();
                }
            });
            return rootView;
        }

        if(adapter == null){
            showDialog(getString(R.string.app_news_feed_dlg_title), getString(R.string.app_news_feed_dlg_text));
            GsonBuilder gsonBuilder = new GsonBuilder()
                    .setDateFormat(Config.APP_DATE_FORMAT);
            Gson gson = gsonBuilder.create();
            new PermutasSEPRestClient(new GsonConverter(gson)).get().getPosts(new Callback<List<Post>>() {
                // new PermutasSEPRestClient().get().getPosts(new Callback<List<Post>>() {
                @Override
                public void success(List<Post> posts, Response response) {
                    if(!posts.isEmpty()){
                        adapter = new PostAdapter(getActivity(), posts);
                        lv.setAdapter(adapter);
                        hideDialog();
                        firstLaunchCompleteListener.onFirstLaunchComplete();
                    }else{
{'fraction_non_alphanumeric': 0.08887141171844279, 'fraction_numerical': 0.00026215755669157164, 'mean_word_length': 3.288926363125351, 'pattern_counts': {'":': 0, '<': 13, '<?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': '528931', 'n_tokens_mistral': 2038, 'n_tokens_neox': 1947, 'n_words': 357}