<commit_before>package rxreddit.android;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

import java.util.Map;

import rxreddit.RxRedditUtil;

public class SignInFragment extends Fragment {

  private static final String ARG_AUTH_URL = "arg_url";

  private String mAuthorizationUrl;
  private String mRedirectUri;
  private WebView mWebView;

  public static SignInFragment newInstance(String url) {
    Bundle args = new Bundle();
    args.putString(ARG_AUTH_URL, url);
    SignInFragment fragment = new SignInFragment();
    fragment.setArguments(args);
    return fragment;
  }

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRetainInstance(true);
    setHasOptionsMenu(true);

    Bundle args = getArguments();

    mAuthorizationUrl = args.getString(ARG_AUTH_URL);
    Map<String, String> params = RxRedditUtil.getQueryParametersFromUrl(mAuthorizationUrl);
    mRedirectUri = params.get("redirect_uri");
  }

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

    mWebView = (WebView) v.findViewById(R.id.rxr_web_view);

    final ProgressBar progressBar = (ProgressBar) v.findViewById(R.id.rxr_progress_bar);
    progressBar.setMax(100);

    mWebView.setWebViewClient(new WebViewClient() {
      @Override
      public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (url.contains(mRedirectUri)
            && !url.equals(mAuthorizationUrl)) {
          Intent data = new Intent();
          data.putExtra(SignInActivity.EXTRA_CALLBACK_URL, url);
          getActivity().setResult(Activity.RESULT_OK, data);
          getActivity().finish();
          return true;
        }
        return false;
      }
    });

    mWebView.setWebChromeClient(new WebChromeClient() {
      @Override
      public void onProgressChanged(WebView view, int progress) {
        if (progress == 100) {
          progressBar.setVisibility(View.INVISIBLE);
        } else {
          progressBar.setVisibility(View.VISIBLE);
          progressBar.setProgress(progress);
        }
      }
    });

    mWebView.setOnKeyListener(new View.OnKeyListener() {
      @Override
      public boolean onKey(View v, int keyCode, KeyEvent event) {
        // Check if the key event was the Back button and if there's history
        if (event.getAction() == KeyEvent.ACTION_UP
            && (keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
          mWebView.goBack();
          return true;
        }
        return false;
      }
    });

    mWebView.loadUrl(mAuthorizationUrl);

    return v;
  }

  @Override
  public void onDestroyView() {
    if (mWebView != null) {
      ((ViewGroup) mWebView.getParent()).removeView(mWebView);
      mWebView.removeAllViews();
      mWebView.destroy();
    }
    super.onDestroyView();
  }

  @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.rxr_web_view, menu);
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    int i = item.getItemId();
    if (i == R.id.action_refresh) {
      mWebView.reload();
      return true;
    }<commit_msg>Added code to remove cookies on loading SignInFragment<commit_after>package rxreddit.android;

import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.CookieManager;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

import java.util.Map;

import rxreddit.RxRedditUtil;

import static android.app.Activity.RESULT_OK;
import static android.view.View.INVISIBLE;
import static android.view.View.VISIBLE;

public class SignInFragment extends Fragment {

  private static final String ARG_AUTH_URL = "ARG_AUTH_URL";

  private String mAuthorizationUrl;
  private String mRedirectUri;
  private WebView mWebView;

  public static SignInFragment newInstance(String url) {
    Bundle args = new Bundle();
    args.putString(ARG_AUTH_URL, url);
    SignInFragment fragment = new SignInFragment();
    fragment.setArguments(args);
    return fragment;
  }

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRetainInstance(true);
    setHasOptionsMenu(true);

    Bundle args = getArguments();

    mAuthorizationUrl = args.getString(ARG_AUTH_URL);
    Map<String, String> params = RxRedditUtil.getQueryParametersFromUrl(mAuthorizationUrl);
    mRedirectUri = params.get("redirect_uri");
  }

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

    mWebView = (WebView) v.findViewById(R.id.rxr_web_view);
    configureWebView(mWebView);

    final ProgressBar progressBar = (ProgressBar) v.findViewById(R.id.rxr_progress_bar);
    progressBar.setMax(100);

    mWebView.setWebViewClient(new WebViewClient() {
      @Override
      public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (url.contains(mRedirectUri)
            && !url.equals(mAuthorizationUrl)) {
          Intent data = new Intent();
          data.putExtra(SignInActivity.EXTRA_CALLBACK_URL, url);
          getActivity().setResult(RESULT_OK, data);
          getActivity().finish();
          return true;
        }
        return false;
      }
    });

    mWebView.setWebChromeClient(new WebChromeClient() {
      @Override
      public void onProgressChanged(WebView view, int progress) {
        if (progress == 100) {
          progressBar.setVisibility(INVISIBLE);
        } else {
          progressBar.setVisibility(VISIBLE);
          progressBar.setProgress(progress);
        }
      }
    });

    mWebView.setOnKeyListener(new View.OnKeyListener() {
      @Override
      public boolean onKey(View v, int keyCode, KeyEvent event) {
        // Check if the key event was the Back button and if there's history
        if (event.getAction() == KeyEvent.ACTION_UP
            && (keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
          mWebView.goBack();
          return true;
        }
        return false;
      }
    });

    mWebView.loadUrl(mAuthorizationUrl);

    return v;
  }

  private void configureWebView(@NonNull WebView webView) {
    CookieManager cookieManager = CookieManager.getInstance();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      cookieManager.removeAllCookies(null);
    }

    WebSettings ws = webView.getSettings();
    ws.setSaveFormData(false);
    ws.setSavePassword(false); // Not needed for API level 18 or greater (deprecated)
  }

  @Override
  public void onDestroyView() {
    if (mWebView != null) {
      ((ViewGroup) mWebView.getParent()).removeView(mWebView);
      mWebView.removeAllViews();
      mWebView.destroy();
    }
    super.onDestroyView();
  }

  @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.rxr_web_view, menu);
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_refresh) {
      mWebView.reload();
      return true;
    }
{'fraction_non_alphanumeric': 0.09939467312348668, 'fraction_numerical': 0.001937046004842615, 'mean_word_length': 3.477506775067751, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, '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': '3519596', 'n_tokens_mistral': 2495, 'n_tokens_neox': 2398, 'n_words': 515}