// Bug workaround: WebView crashes when dropdown is shown on
// a Nougat emulator. Haven't tested on other devices.
@Override
  @SuppressLint("SetJavaScriptEnabled")
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    Dank.dependencyInjector().inject(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    ButterKnife.bind(this);
    findAndSetupToolbar();
    toolbar.setBackground(null);
    toolbar.setTitle(R.string.login);
    contentViewGroup.setClipToOutline(true);
    // Setup WebView.
    CookieManager.getInstance().removeAllCookies(null);
    webView.setWebChromeClient(new WebChromeClient() {
      @Override
      public void onProgressChanged(WebView view, int newProgress) {
        if (!loggedIn) {
          boolean shouldShowProgress = newProgress < 75;
          setProgressVisible(shouldShowProgress);
        }
      }
    });
    webView.setWebViewClient(new WebViewClient() {
      @Override
      public void onPageStarted(WebView view, String url, Bitmap favicon) {
        if (url.contains("code=")) {
          // We've detected the redirect URL.
          webView.stopLoading();
          loggedIn = true;
          handleOnPermissionGranted(url);
        } else if (url.contains("error=")) {
          Toast.makeText(LoginActivity.this, R.string.login_error_oauth_permission_rejected, Toast.LENGTH_LONG).show();
          webView.stopLoading();
          setResult(RESULT_CANCELED);
          finish();
        }
      }
    });
    // Bug workaround: WebView crashes when dropdown is shown on
    // a Nougat emulator. Haven't tested on other devices.
    webView.clearFormData();
    webView.getSettings().setSaveFormData(false);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setDomStorageEnabled(true);
    userLoginHelper = reddit.get().login().loginHelper();
    webView.loadUrl(userLoginHelper.authorizationUrl());
  }
}
});
// Bug workaround: WebView crashes when dropdown is shown on
// a Nougat emulator. Haven't tested on other devices.
webView.clearFormData();
webView.getSettings().setSaveFormData(false);
loggedIn = true;
handleOnPermissionGranted(url);
} else if (url.contains("error=")) {
Toast.makeText(LoginActivity.this, R.string.login_error_oauth_permission_rejected, Toast.LENGTH_LONG).show();
webView.stopLoading();
setResult(RESULT_CANCELED);
finish();
}
}
});
// Bug workaround: WebView crashes when dropdown is shown on
// a Nougat emulator. Haven't tested on other devices.
webView.clearFormData();
webView.getSettings().setSaveFormData(false);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
userLoginHelper = reddit.get().login().loginHelper();
webView.loadUrl(userLoginHelper.authorizationUrl());
}
setProgressVisible(shouldShowProgress);
}
}
});
webView.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
if (url.contains("code=")) {
// We've detected the redirect URL.
webView.stopLoading();
loggedIn = true;
handleOnPermissionGranted(url);
} else if (url.contains("error=")) {
Toast.makeText(LoginActivity.this, R.string.login_error_oauth_permission_rejected, Toast.LENGTH_LONG).show();
webView.stopLoading();
setResult(RESULT_CANCELED);
finish();
}
}
});
// Bug workaround: WebView crashes when dropdown is shown on
// a Nougat emulator. Haven't tested on other devices.
webView.clearFormData();
webView.getSettings().setSaveFormData(false);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
userLoginHelper = reddit.get().login().loginHelper();
webView.loadUrl(userLoginHelper.authorizationUrl());
}