<commit_before>package org.worshipsongs.task;

import android.app.ProgressDialog;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;

import org.worshipsongs.CommonConstants;
import org.worshipsongs.R;
import org.worshipsongs.fragment.AlertDialogFragment;
import org.worshipsongs.parser.CommitMessageParser;
import org.worshipsongs.parser.ICommitMessageParser;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * Author : Madasamy
 * Version : 3.x
 */

public class HttpAsyncTask extends AsyncTask<String, String, String> implements AlertDialogFragment.DialogListener
{
    private static final String CLASS_NAME = HttpAsyncTask.class.getSimpleName();
    public static final String REQUEST_METHOD = "GET";
    public static final int READ_TIMEOUT = 15000;
    public static final int CONNECTION_TIMEOUT = 15000;

    private ProgressDialog progressDialog;
    private AppCompatActivity context;
    private SharedPreferences sharedPreferences;
    private ICommitMessageParser commitMessageParser = new CommitMessageParser();

    public HttpAsyncTask(AppCompatActivity context)
    {
        this.context = context;
        sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
        progressDialog = new ProgressDialog(context);
    }

    @Override
    protected void onPreExecute()
    {
        super.onPreExecute();
        progressDialog.setMessage(context.getString(R.string.check_update_message));
        progressDialog.setIndeterminate(true);
        progressDialog.setCancelable(false);
        progressDialog.show();
    }

    @Override
    protected String doInBackground(String... params)
    {
        String stringUrl = params[0];
        String result;
        String inputLine;
        try {
            URL myUrl = new URL(stringUrl);
            HttpURLConnection connection = (HttpURLConnection) myUrl.openConnection();
            connection.setRequestMethod(REQUEST_METHOD);
            connection.setReadTimeout(READ_TIMEOUT);
            connection.setConnectTimeout(CONNECTION_TIMEOUT);

            //Connect to our url
            connection.connect();
            //Create a new InputStreamReader
            InputStreamReader streamReader = new InputStreamReader(connection.getInputStream());
            //Create a new buffered reader and String Builder
            BufferedReader reader = new BufferedReader(streamReader);
            StringBuilder stringBuilder = new StringBuilder();
            //Check if the line we are reading is not null
            while ((inputLine = reader.readLine()) != null) {
                stringBuilder.append(inputLine);
            }
            //Close our InputStream and Buffered reader
            reader.close();
            streamReader.close();
            //Set our result equal to our stringBuilder
            result = stringBuilder.toString();
            return result;
        } catch (Exception e) {
            return null;
        }
    }

    @Override
    protected void onPostExecute(String jsonObject)
    {
        super.onPostExecute(jsonObject);
        final String shaKey = commitMessageParser.getShaKey(jsonObject);
        String existingShaKey = sharedPreferences.getString(CommonConstants.COMMIT_SHA_KEY, "");
        progressDialog.hide();
        Bundle bundle = new Bundle();
        bundle.putString(CommonConstants.COMMIT_SHA_KEY, shaKey);
        bundle.putString(CommonConstants.TITLE_KEY, context.getString(R.string.updates_title));
        if (existingShaKey.equalsIgnoreCase(shaKey)) {
            bundle.putString(CommonConstants.MESSAGE_KEY, context.getString(R.string.message_no_update));
            AlertDialogFragment alertDialogFragment = AlertDialogFragment.newInstance(bundle);
            alertDialogFragment.setCancelable(false);
            alertDialogFragment.setVisibleNegativeButton(false);
            alertDialogFragment.setDialogListener(this);
            alertDialogFragment.show(context.getFragmentManager(), "NoUpdateFragment");
        } else {
            bundle.putString(CommonConstants.MESSAGE_KEY, context.getString(R.string.message_update_available));
            AlertDialogFragment alertDialogFragment = AlertDialogFragment.newInstance(bundle);
            alertDialogFragment.setCancelable(false);
            alertDialogFragment.setDialogListener(this);<commit_msg>#428 Dismiss dialog instead hide<commit_after>package org.worshipsongs.task;

import android.app.ProgressDialog;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v7.app.AppCompatActivity;

import org.worshipsongs.CommonConstants;
import org.worshipsongs.R;
import org.worshipsongs.WorshipSongApplication;
import org.worshipsongs.fragment.AlertDialogFragment;
import org.worshipsongs.parser.CommitMessageParser;
import org.worshipsongs.parser.ICommitMessageParser;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * Author : Madasamy
 * Version : 3.x
 */

public class HttpAsyncTask extends AsyncTask<String, String, String> implements AlertDialogFragment.DialogListener
{
    private static final String CLASS_NAME = HttpAsyncTask.class.getSimpleName();
    public static final String REQUEST_METHOD = "GET";
    public static final int READ_TIMEOUT = 15000;
    public static final int CONNECTION_TIMEOUT = 15000;

    private ProgressDialog progressDialog;
    private AppCompatActivity context;
    private SharedPreferences sharedPreferences;
    private ICommitMessageParser commitMessageParser = new CommitMessageParser();

    public HttpAsyncTask(AppCompatActivity context)
    {
        this.context = context;
        sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
        progressDialog = new ProgressDialog(context);
    }

    @Override
    protected void onPreExecute()
    {
        super.onPreExecute();
        progressDialog.setMessage(context.getString(R.string.check_update_message));
        progressDialog.setIndeterminate(true);
        progressDialog.setCancelable(false);
        progressDialog.show();
    }

    @Override
    protected String doInBackground(String... params)
    {
        String stringUrl = params[0];
        String result;
        String inputLine;
        try {
            URL myUrl = new URL(stringUrl);
            HttpURLConnection connection = (HttpURLConnection) myUrl.openConnection();
            connection.setRequestMethod(REQUEST_METHOD);
            connection.setReadTimeout(READ_TIMEOUT);
            connection.setConnectTimeout(CONNECTION_TIMEOUT);

            //Connect to our url
            connection.connect();
            //Create a new InputStreamReader
            InputStreamReader streamReader = new InputStreamReader(connection.getInputStream());
            //Create a new buffered reader and String Builder
            BufferedReader reader = new BufferedReader(streamReader);
            StringBuilder stringBuilder = new StringBuilder();
            //Check if the line we are reading is not null
            while ((inputLine = reader.readLine()) != null) {
                stringBuilder.append(inputLine);
            }
            //Close our InputStream and Buffered reader
            reader.close();
            streamReader.close();
            //Set our result equal to our stringBuilder
            result = stringBuilder.toString();
            return result;
        } catch (Exception e) {
            return null;
        }
    }

    @Override
    protected void onPostExecute(String jsonObject)
    {
        super.onPostExecute(jsonObject);
        final String shaKey = commitMessageParser.getShaKey(jsonObject);
        String existingShaKey = sharedPreferences.getString(CommonConstants.COMMIT_SHA_KEY, "");
        progressDialog.dismiss();
        Bundle bundle = new Bundle();
        bundle.putString(CommonConstants.COMMIT_SHA_KEY, shaKey);
        bundle.putString(CommonConstants.TITLE_KEY, context.getString(R.string.updates_title));
        if (existingShaKey.equalsIgnoreCase(shaKey)) {
            bundle.putString(CommonConstants.MESSAGE_KEY, context.getString(R.string.message_no_update));
            AlertDialogFragment alertDialogFragment = AlertDialogFragment.newInstance(bundle);
            alertDialogFragment.setCancelable(false);
            alertDialogFragment.setVisibleNegativeButton(false);
            alertDialogFragment.setDialogListener(this);
            alertDialogFragment.show(context.getFragmentManager(), "NoUpdateFragment");
        } else {
            bundle.putString(CommonConstants.MESSAGE_KEY, context.getString(R.string.message_update_available));
            AlertDialogFragment alertDialogFragment = AlertDialogFragment.newInstance(bundle);
            alertDialogFragment.setCancelable(false);
            alertDialogFragment.setDialogListener(this);
{'fraction_non_alphanumeric': 0.0791712104689204, 'fraction_numerical': 0.0031624863685932388, 'mean_word_length': 3.236027713625866, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6199872', 'n_tokens_mistral': 2265, 'n_tokens_neox': 2219, 'n_words': 477}