<commit_before>package com.hitanshudhawan.popcorn.fragments;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.hitanshudhawan.popcorn.R;
import com.hitanshudhawan.popcorn.adapters.MoviesSmallAdapter;
import com.hitanshudhawan.popcorn.network.ApiClient;
import com.hitanshudhawan.popcorn.network.ApiInterface;
import com.hitanshudhawan.popcorn.network.movies.Movie;
import com.hitanshudhawan.popcorn.utils.Favourite;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by hitanshu on 10/8/17.
 */

public class FavouriteMoviesFragment extends Fragment {

    private RecyclerView mFavMoviesRecyclerView;
    private List<Movie> mFavMovies;
    private MoviesSmallAdapter mFavMoviesAdapter;

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

        mFavMoviesRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view_fav_movies);
        mFavMovies = new ArrayList<>();
        mFavMoviesAdapter = new MoviesSmallAdapter(getContext(), mFavMovies);
        mFavMoviesRecyclerView.setAdapter(mFavMoviesAdapter);
        mFavMoviesRecyclerView.setLayoutManager(new GridLayoutManager(getContext(), 3));

        loadFavMovies();

        return view;
    }

    private void loadFavMovies() {
        ApiInterface apiService = ApiClient.getClient().create(ApiInterface.class);
        List<Integer> favMovieIds = Favourite.getFavMovieIds(getContext());
        for (Integer movieId : favMovieIds) {
            Call<Movie> call = apiService.getMovieDetails(movieId, getResources().getString(R.string.MOVIE_DB_API_KEY));
            call.enqueue(new Callback<Movie>() {
                @Override
                public void onResponse(Call<Movie> call, Response<Movie> response) {
                    if (!response.isSuccessful()) {
                        call.clone().enqueue(this);
                        return;
                    }

                    if (response.body().getPosterPath() != null) {
                        mFavMovies.add(response.body());
                        mFavMoviesAdapter.notifyDataSetChanged();
                    }
                }

                @Override
                public void onFailure(Call<Movie> call, Throwable t) {

                }
            });
        }
    }
}<commit_msg>enhancement: canceled network calls in FavMoviesFragment on DestroyView<commit_after>package com.hitanshudhawan.popcorn.fragments;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.hitanshudhawan.popcorn.R;
import com.hitanshudhawan.popcorn.adapters.MoviesSmallAdapter;
import com.hitanshudhawan.popcorn.network.ApiClient;
import com.hitanshudhawan.popcorn.network.ApiInterface;
import com.hitanshudhawan.popcorn.network.movies.Movie;
import com.hitanshudhawan.popcorn.utils.Favourite;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by hitanshu on 10/8/17.
 */

public class FavouriteMoviesFragment extends Fragment {

    private RecyclerView mFavMoviesRecyclerView;
    private List<Movie> mFavMovies;
    private MoviesSmallAdapter mFavMoviesAdapter;

    private List<Call<Movie>> mMovieDetailsCalls;

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

        mFavMoviesRecyclerView = (RecyclerView) view.findViewById(R.id.recycler_view_fav_movies);
        mFavMovies = new ArrayList<>();
        mFavMoviesAdapter = new MoviesSmallAdapter(getContext(), mFavMovies);
        mFavMoviesRecyclerView.setAdapter(mFavMoviesAdapter);
        mFavMoviesRecyclerView.setLayoutManager(new GridLayoutManager(getContext(), 3));

        loadFavMovies();

        return view;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (mMovieDetailsCalls != null) {
            for(Call<Movie> movieCall : mMovieDetailsCalls) {
                if(movieCall != null) movieCall.cancel();
            }
        }
    }

    private void loadFavMovies() {
        ApiInterface apiService = ApiClient.getClient().create(ApiInterface.class);
        List<Integer> favMovieIds = Favourite.getFavMovieIds(getContext());
        mMovieDetailsCalls = new ArrayList<>();
        for (int i = 0; i < favMovieIds.size(); i++) {
            final int index = i;
            mMovieDetailsCalls.add(apiService.getMovieDetails(favMovieIds.get(index), getResources().getString(R.string.MOVIE_DB_API_KEY)));
            mMovieDetailsCalls.get(index).enqueue(new Callback<Movie>() {
                @Override
                public void onResponse(Call<Movie> call, Response<Movie> response) {
                    if (!response.isSuccessful()) {
                        mMovieDetailsCalls.set(index, call.clone());
                        mMovieDetailsCalls.get(index).enqueue(this);
                        return;
                    }

                    if (response.body().getPosterPath() != null) {
                        mFavMovies.add(response.body());
                        mFavMoviesAdapter.notifyDataSetChanged();
                    }
                }

                @Override
                public void onFailure(Call<Movie> call, Throwable t) {

                }
            });
        }
    }


}
{'fraction_non_alphanumeric': 0.09576188935619541, 'fraction_numerical': 0.004043998705920414, 'mean_word_length': 2.8692115143929913, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 22, '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': '4233944', 'n_tokens_mistral': 1958, 'n_tokens_neox': 1770, 'n_words': 304}