Use view binding in ReCaptchaActivity.
This commit is contained in:
parent
a65ed7e914
commit
a1a70a94a8
1 changed files with 14 additions and 15 deletions
|
@ -18,10 +18,10 @@ import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.RequiresApi;
|
import androidx.annotation.RequiresApi;
|
||||||
import androidx.appcompat.app.ActionBar;
|
import androidx.appcompat.app.ActionBar;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
|
||||||
import androidx.core.app.NavUtils;
|
import androidx.core.app.NavUtils;
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
|
|
||||||
|
import org.schabi.newpipe.databinding.ActivityRecaptchaBinding;
|
||||||
import org.schabi.newpipe.util.ThemeHelper;
|
import org.schabi.newpipe.util.ThemeHelper;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
@ -62,30 +62,28 @@ public class ReCaptchaActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ActivityRecaptchaBinding recaptchaBinding;
|
||||||
private WebView webView;
|
|
||||||
private String foundCookies = "";
|
private String foundCookies = "";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(final Bundle savedInstanceState) {
|
protected void onCreate(final Bundle savedInstanceState) {
|
||||||
ThemeHelper.setTheme(this);
|
ThemeHelper.setTheme(this);
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_recaptcha);
|
|
||||||
final Toolbar toolbar = findViewById(R.id.toolbar);
|
recaptchaBinding = ActivityRecaptchaBinding.inflate(getLayoutInflater());
|
||||||
setSupportActionBar(toolbar);
|
setContentView(recaptchaBinding.getRoot());
|
||||||
|
setSupportActionBar(recaptchaBinding.toolbar);
|
||||||
|
|
||||||
final String url = sanitizeRecaptchaUrl(getIntent().getStringExtra(RECAPTCHA_URL_EXTRA));
|
final String url = sanitizeRecaptchaUrl(getIntent().getStringExtra(RECAPTCHA_URL_EXTRA));
|
||||||
// set return to Cancel by default
|
// set return to Cancel by default
|
||||||
setResult(RESULT_CANCELED);
|
setResult(RESULT_CANCELED);
|
||||||
|
|
||||||
webView = findViewById(R.id.reCaptchaWebView);
|
|
||||||
|
|
||||||
// enable Javascript
|
// enable Javascript
|
||||||
final WebSettings webSettings = webView.getSettings();
|
final WebSettings webSettings = recaptchaBinding.reCaptchaWebView.getSettings();
|
||||||
webSettings.setJavaScriptEnabled(true);
|
webSettings.setJavaScriptEnabled(true);
|
||||||
webSettings.setUserAgentString(DownloaderImpl.USER_AGENT);
|
webSettings.setUserAgentString(DownloaderImpl.USER_AGENT);
|
||||||
|
|
||||||
webView.setWebViewClient(new WebViewClient() {
|
recaptchaBinding.reCaptchaWebView.setWebViewClient(new WebViewClient() {
|
||||||
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
|
||||||
@Override
|
@Override
|
||||||
public boolean shouldOverrideUrlLoading(final WebView view,
|
public boolean shouldOverrideUrlLoading(final WebView view,
|
||||||
|
@ -117,16 +115,16 @@ public class ReCaptchaActivity extends AppCompatActivity {
|
||||||
});
|
});
|
||||||
|
|
||||||
// cleaning cache, history and cookies from webView
|
// cleaning cache, history and cookies from webView
|
||||||
webView.clearCache(true);
|
recaptchaBinding.reCaptchaWebView.clearCache(true);
|
||||||
webView.clearHistory();
|
recaptchaBinding.reCaptchaWebView.clearHistory();
|
||||||
final android.webkit.CookieManager cookieManager = CookieManager.getInstance();
|
final CookieManager cookieManager = CookieManager.getInstance();
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
cookieManager.removeAllCookies(value -> { });
|
cookieManager.removeAllCookies(value -> { });
|
||||||
} else {
|
} else {
|
||||||
cookieManager.removeAllCookie();
|
cookieManager.removeAllCookie();
|
||||||
}
|
}
|
||||||
|
|
||||||
webView.loadUrl(url);
|
recaptchaBinding.reCaptchaWebView.loadUrl(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -158,7 +156,8 @@ public class ReCaptchaActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveCookiesAndFinish() {
|
private void saveCookiesAndFinish() {
|
||||||
handleCookiesFromUrl(webView.getUrl()); // try to get cookies of unclosed page
|
// try to get cookies of unclosed page
|
||||||
|
handleCookiesFromUrl(recaptchaBinding.reCaptchaWebView.getUrl());
|
||||||
if (MainActivity.DEBUG) {
|
if (MainActivity.DEBUG) {
|
||||||
Log.d(TAG, "saveCookiesAndFinish: foundCookies=" + foundCookies);
|
Log.d(TAG, "saveCookiesAndFinish: foundCookies=" + foundCookies);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue