<commit_before>package com.wrgardnersoft.watchftc;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;
import android.widget.Toast;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.util.ArrayList;


public class FtcRankingsActivity extends ActionBarActivity implements AsyncResponse {

    private ArrayList<TeamFtcRanked> team;
    private ListView listView;
    TeamsTask teamsTask;

    public FtcRankingsActivity() {
        team = new ArrayList<TeamFtcRanked>();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        MyApp myApp = (MyApp) getApplication();

        //     team = new ArrayList<Team>();

        if (myApp.dualDivision()) {
            setTitle(" " + getString(R.string.ftcRankings) + ", Division " + Integer.toString(myApp.division() + 1));
        } else {
            setTitle(" " + getString(R.string.ftcRankings));
        }
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        getSupportActionBar().setIcon(R.drawable.ic_launcher);
        setContentView(R.layout.activity_ftc_rankings);

        teamsTask = new TeamsTask();
        teamsTask.delegate = this;
        teamsTask.execute();

    }

    private void inflateMe() {
        FtcRankingsListAdapter adapter = new FtcRankingsListAdapter(this,
                R.layout.list_item_ftc_ranking, team);
        listView = (ListView) findViewById(R.id.ftc_rankings_list_view);
        listView.setAdapter(adapter);
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        setContentView(R.layout.activity_ftc_rankings);
        if (team.size() > 0) {
            inflateMe();
        }
    }

    public void processFinish(int result) {
        //this you will received result fired from async class of onPostExecute(result) method.
 /*      TableLayout teamsTableLayout = (TableLayout) findViewById(R.id.teams_tableLayout);

        teamsTableLayout.removeAllViews();
        BuildTeamsTable(team);*/

        if (team.size() > 0) {
            inflateMe();
        } else {
            Context context = getApplicationContext();
            CharSequence text = "Could not download data from server";
            int duration = Toast.LENGTH_LONG;

            Toast.makeText(context, text, duration).show();
        }

    }

    // AsyncTask
    public class TeamsTask extends AsyncTask<Void, Void, Void> {
        public AsyncResponse delegate;

        ProgressDialog mProgressDialog;

        String title;
        boolean serverOK;

        MyApp myApp = (MyApp) getApplication();

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            mProgressDialog = new ProgressDialog(FtcRankingsActivity.this);
            mProgressDialog.setTitle("Watch FTC");
            mProgressDialog.setMessage("Accessing server...");
            mProgressDialog.setIndeterminate(false);
            mProgressDialog.show();
        }

        @Override
        protected Void doInBackground(Void... params) {
            String teamsUrl;
            String[] urlSuffix = {"", ":8080"};
            String pageSuffix = "Rankings";

            serverOK = false;

            for (int i = 0; (i < urlSuffix.length) && (!serverOK); i++) {

                teamsUrl = "http://" + myApp.serverAddressString(myApp.division()) +
                        urlSuffix[i] + "/" + pageSuffix;
                Document teamsDocument;
                try {
                    // Connect to the web site
                    Document document = Jsoup.connect(teamsUrl).get();
                    // Get the html document title
                    title = document.title();
                    serverOK = true;
                    teamsDocument = document;

                    Element table = document.select("table").get(0); //select the first table.<commit_msg>Added clickable team selection from FTC Rank screen. Changed async task name to ClientTask removed unused document variable<commit_after>package com.wrgardnersoft.watchftc;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.util.ArrayList;


public class FtcRankingsActivity extends ActionBarActivity implements AsyncResponse {

    private ArrayList<TeamFtcRanked> team;
    private ListView listView;
    ClientTask clientTask;

    public FtcRankingsActivity() {
        team = new ArrayList<TeamFtcRanked>();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        MyApp myApp = (MyApp) getApplication();

        //     team = new ArrayList<Team>();

        if (myApp.dualDivision()) {
            setTitle(" " + getString(R.string.ftcRankings) + ", Division " + Integer.toString(myApp.division() + 1));
        } else {
            setTitle(" " + getString(R.string.ftcRankings));
        }
        getSupportActionBar().setDisplayShowHomeEnabled(true);
        getSupportActionBar().setIcon(R.drawable.ic_launcher);
        setContentView(R.layout.activity_ftc_rankings);

        clientTask = new ClientTask();
        clientTask.delegate = this;
        clientTask.execute();

    }

    private void inflateMe() {
        FtcRankingsListAdapter adapter = new FtcRankingsListAdapter(this,
                R.layout.list_item_ftc_ranking, team);
        listView = (ListView) findViewById(R.id.ftc_rankings_list_view);
        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                TeamFtcRanked teamPicked = (TeamFtcRanked) parent.getItemAtPosition(position);

                MyApp myApp = (MyApp) getApplication();

                if (myApp.selectedTeams.contains(teamPicked.number)) {
                    myApp.selectedTeams.remove(Integer.valueOf(teamPicked.number));
                } else {
                    myApp.selectedTeams.add(teamPicked.number);
                }
                listView.invalidateViews();
            }
        });


    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        setContentView(R.layout.activity_ftc_rankings);
        if (team.size() > 0) {
            inflateMe();
        }
    }

    public void processFinish(int result) {
        //this you will received result fired from async class of onPostExecute(result) method.
 /*      TableLayout teamsTableLayout = (TableLayout) findViewById(R.id.teams_tableLayout);

        teamsTableLayout.removeAllViews();
        BuildTeamsTable(team);*/

        if (team.size() > 0) {
            inflateMe();
        } else {
            Context context = getApplicationContext();
            CharSequence text = "Could not download data from server";
            int duration = Toast.LENGTH_LONG;

            Toast.makeText(context, text, duration).show();
        }

    }

    // AsyncTask
    public class ClientTask extends AsyncTask<Void, Void, Void> {
        public AsyncResponse delegate;

        ProgressDialog mProgressDialog;

        String title;
        boolean serverOK;

        MyApp myApp = (MyApp) getApplication();

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            mProgressDialog = new ProgressDialog(FtcRankingsActivity.this);
            mProgressDialog.setTitle("Watch FTC");
            mProgressDialog.setMessage("Accessing server...");
            mProgressDialog.setIndeterminate(false);
            mProgressDialog.show();
        }

        @Override
        protected Void doInBackground(Void... params) {
            String teamsUrl;
            String[] urlSuffix = {"", ":8080"};
            String pageSuffix = "Rankings";

            serverOK = false;

            for (int i = 0; (i < urlSuffix.length) && (!serverOK); i++) {

                teamsUrl = "http://" + myApp.serverAddressString(myApp.division()) +
                        urlSuffix[i] + "/" + pageSuffix;
                try {
                    // Connect to the web site
                    Document document = Jsoup.connect(teamsUrl).get();
                    // Get the html document title
                    title = document.title();
                    serverOK = true;

                    Element table = document.select("table").get(0); //select the first table.
{'fraction_non_alphanumeric': 0.09966180511519764, 'fraction_numerical': 0.002113718030014796, 'mean_word_length': 2.3736185383244206, 'pattern_counts': {'":': 2, '<': 14, '<?xml version=': 0, '>': 16, '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': '6440907', 'n_tokens_mistral': 2591, 'n_tokens_neox': 2456, 'n_words': 539}