<commit_before>package com.garpr.android.activities;


import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.ListView;
import android.widget.SearchView;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.garpr.android.R;
import com.garpr.android.misc.Constants;
import com.garpr.android.misc.FlexibleSwipeRefreshLayout;
import com.garpr.android.misc.Networking;
import com.garpr.android.models.Player;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Collections;


public class RankingsActivity extends BaseActivity implements
        AdapterView.OnItemClickListener,
        SearchView.OnQueryTextListener,
        SwipeRefreshLayout.OnRefreshListener {


    private static final String TAG = RankingsActivity.class.getSimpleName();

    private ArrayList<Player> mPlayers;
    private ArrayList<Player> mPlayersShown;
    private boolean mIsAbcOrder;
    private boolean mIsFinishedDownloading;
    private FlexibleSwipeRefreshLayout mRefreshLayout;
    private ListView mListView;
    private RankingsAdapter mAdapter;
    private RankingsFilter mFilter;
    private TextView mError;




    private void downloadRankings() {
        final Networking.Callback callback = new Networking.Callback() {
            @Override
            public void onErrorResponse(final VolleyError error) {
                Log.e(TAG, "Network exception when downloading rankings!", error);
                showError();
            }

            @Override
            public void onResponse(final JSONObject response) {
                try {
                    final ArrayList<Player> playersList = new ArrayList<Player>();
                    final JSONArray ranking = response.getJSONArray(Constants.RANKING);

                    for (int i = 0; i < ranking.length() ; ++i) {
                        final JSONObject playerJSON = ranking.getJSONObject(i);

                        try {
                            final Player player = new Player(playerJSON);
                            playersList.add(player);
                        } catch (final JSONException e) {
                            Log.e(TAG, "Exception when building Player at index " + i, e);
                        }
                    }

                    playersList.trimToSize();
                    Collections.sort(playersList, Player.RANK_ORDER);
                    mPlayers = playersList;
                    mPlayersShown = new ArrayList<Player>(mPlayers);
                    showList();
                } catch (final JSONException e) {
                    showError();
                }
            }
        };

        mRefreshLayout.setRefreshing(true);
        Networking.getRankings(this, callback);
    }


    @Override
    protected void findViews() {
        super.findViews();
        mError = (TextView) findViewById(R.id.activity_rankings_error);
        mListView = (ListView) findViewById(R.id.activity_rankings_list);
        mRefreshLayout = (FlexibleSwipeRefreshLayout) findViewById(R.id.activity_rankings_refresh);
        mRefreshLayout.setOnRefreshListener(this);
        mRefreshLayout.setScrollableView(mListView);
        mRefreshLayout.setColorSchemeResources(R.color.cyan, R.color.magenta, R.color.yellow, R.color.black);
    }


    @Override
    protected int getContentView() {
        return R.layout.activity_rankings;
    }


    @Override
    protected int getOptionsMenu() {
        return R.menu.activity_rankings;
    }


    @Override
    public boolean onOptionsItemSelected(final MenuItem item) {
        switch (item.getItemId()) {
            case R.id.activity_rankings_menu_abc:
                Collections.sort(mPlayersShown, Player.ALPHABETICAL_ORDER);
                mAdapter.notifyDataSetChanged();
                mIsAbcOrder = true;
                invalidateOptionsMenu();
                break;

            case R.id.activity_rankings_menu_rank:
                Collections.sort(mPlayersShown, Player.RANK_ORDER);
                mAdapter.notifyDataSetChanged();
                mIsAbcOrder = false;
                invalidateOptionsMenu();
                break;

            case R.id.activity_rankings_menu_tournament:
                TournamentsActivity.start(this);
                break;

            default:
                return super.onOptionsItemSelected(item);
        }

        return true;
    }


    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        findViews();
        downloadRankings();
    }


    @Override
    public void onItemClick(final AdapterView<?> parent, final View view, final int position,
            final long id) {
        final Player player = mPlayers.get(position);
        PlayerActivity.start(this, player);
    }<commit_msg>tiny cleanup in RankingsActivity<commit_after>package com.garpr.android.activities;


import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.ListView;
import android.widget.SearchView;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.garpr.android.R;
import com.garpr.android.misc.Constants;
import com.garpr.android.misc.FlexibleSwipeRefreshLayout;
import com.garpr.android.misc.Networking;
import com.garpr.android.models.Player;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Collections;


public class RankingsActivity extends BaseActivity implements
        AdapterView.OnItemClickListener,
        SearchView.OnQueryTextListener,
        SwipeRefreshLayout.OnRefreshListener {


    private static final String TAG = RankingsActivity.class.getSimpleName();

    private ArrayList<Player> mPlayers;
    private ArrayList<Player> mPlayersShown;
    private boolean mIsAbcOrder;
    private boolean mIsFinishedDownloading;
    private FlexibleSwipeRefreshLayout mRefreshLayout;
    private ListView mListView;
    private RankingsAdapter mAdapter;
    private RankingsFilter mFilter;
    private TextView mError;




    private void downloadRankings() {
        final Networking.Callback callback = new Networking.Callback() {
            @Override
            public void onErrorResponse(final VolleyError error) {
                Log.e(TAG, "Network exception when downloading rankings!", error);
                showError();
            }

            @Override
            public void onResponse(final JSONObject response) {
                try {
                    final ArrayList<Player> playersList = new ArrayList<Player>();
                    final JSONArray ranking = response.getJSONArray(Constants.RANKING);

                    for (int i = 0; i < ranking.length() ; ++i) {
                        final JSONObject playerJSON = ranking.getJSONObject(i);

                        try {
                            final Player player = new Player(playerJSON);
                            playersList.add(player);
                        } catch (final JSONException e) {
                            Log.e(TAG, "Exception when building Player at index " + i, e);
                        }
                    }

                    playersList.trimToSize();
                    Collections.sort(playersList, Player.RANK_ORDER);
                    mPlayers = playersList;
                    mPlayersShown = new ArrayList<Player>(mPlayers);
                    showList();
                } catch (final JSONException e) {
                    showError();
                }
            }
        };

        mRefreshLayout.setRefreshing(true);
        Networking.getRankings(this, callback);
    }


    @Override
    protected void findViews() {
        super.findViews();
        mError = (TextView) findViewById(R.id.activity_rankings_error);
        mListView = (ListView) findViewById(R.id.activity_rankings_list);
        mRefreshLayout = (FlexibleSwipeRefreshLayout) findViewById(R.id.activity_rankings_refresh);
        mRefreshLayout.setOnRefreshListener(this);
        mRefreshLayout.setScrollableView(mListView);
        mRefreshLayout.setColorSchemeResources(R.color.cyan, R.color.magenta, R.color.yellow, R.color.black);
    }


    @Override
    protected int getContentView() {
        return R.layout.activity_rankings;
    }


    @Override
    protected int getOptionsMenu() {
        return R.menu.activity_rankings;
    }


    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        findViews();
        downloadRankings();
    }


    @Override
    public boolean onOptionsItemSelected(final MenuItem item) {
        switch (item.getItemId()) {
            case R.id.activity_rankings_menu_abc:
                Collections.sort(mPlayersShown, Player.ALPHABETICAL_ORDER);
                mAdapter.notifyDataSetChanged();
                mIsAbcOrder = true;
                invalidateOptionsMenu();
                break;

            case R.id.activity_rankings_menu_rank:
                Collections.sort(mPlayersShown, Player.RANK_ORDER);
                mAdapter.notifyDataSetChanged();
                mIsAbcOrder = false;
                invalidateOptionsMenu();
                break;

            case R.id.activity_rankings_menu_tournament:
                TournamentsActivity.start(this);
                break;

            default:
                return super.onOptionsItemSelected(item);
        }

        return true;
    }


    @Override
    public void onItemClick(final AdapterView<?> parent, final View view, final int position,
            final long id) {
        final Player player = mPlayers.get(position);
        PlayerActivity.start(this, player);
    }
{'fraction_non_alphanumeric': 0.08027588849506657, 'fraction_numerical': 0.0003831784653702462, 'mean_word_length': 2.260462211118051, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2148480', 'n_tokens_mistral': 2774, 'n_tokens_neox': 2590, 'n_words': 557}