mirror of
https://github.com/revanced/revanced-integrations.git
synced 2024-06-02 19:36:30 +02:00
refactor: Cleanup
This commit is contained in:
parent
a757b6700e
commit
96ab16a1d9
|
@ -229,35 +229,33 @@ public class ReVancedAboutPreference extends Preference {
|
|||
|
||||
{
|
||||
setOnPreferenceClickListener(pref -> {
|
||||
Context context = getContext();
|
||||
|
||||
// Show a progress spinner if the social links are not fetched yet.
|
||||
final ProgressDialog progress;
|
||||
if (fetchedLinks == null && Utils.isNetworkConnected()) {
|
||||
progress = new ProgressDialog(context);
|
||||
ProgressDialog progress = new ProgressDialog(getContext());
|
||||
progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
|
||||
progress.show();
|
||||
Utils.runOnBackgroundThread(() -> fetchLinksAndShowDialog(progress));
|
||||
} else {
|
||||
progress = null;
|
||||
// No network call required and can run now.
|
||||
fetchLinksAndShowDialog(null);
|
||||
}
|
||||
|
||||
Utils.runOnBackgroundThread(() -> {
|
||||
ReVancedSocialLink[] socialLinks = fetchSocialLinks();
|
||||
String htmlDialog = createDialogHtml(socialLinks);
|
||||
|
||||
Utils.runOnMainThread(() -> {
|
||||
if (progress != null) {
|
||||
progress.dismiss();
|
||||
}
|
||||
|
||||
new WebViewDialog(context, htmlDialog).show();
|
||||
});
|
||||
});
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
private void fetchLinksAndShowDialog(@Nullable ProgressDialog progress) {
|
||||
ReVancedSocialLink[] socialLinks = fetchSocialLinks();
|
||||
String htmlDialog = createDialogHtml(socialLinks);
|
||||
|
||||
Utils.runOnMainThreadNowOrLater(() -> {
|
||||
if (progress != null) {
|
||||
progress.dismiss();
|
||||
}
|
||||
new WebViewDialog(getContext(), htmlDialog).show();
|
||||
});
|
||||
}
|
||||
|
||||
public ReVancedAboutPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
@ -296,7 +294,6 @@ class WebViewDialog extends Dialog {
|
|||
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
ViewGroup.LayoutParams.MATCH_PARENT
|
||||
));
|
||||
// JS used to hide any broken images. No remote JS is ever loaded.
|
||||
webView.getSettings().setJavaScriptEnabled(true);
|
||||
webView.setWebViewClient(new OpenLinksExternallyWebClient());
|
||||
webView.loadDataWithBaseURL(null, htmlContent, "text/html", "utf-8", null);
|
||||
|
@ -313,7 +310,10 @@ class WebViewDialog extends Dialog {
|
|||
} catch (Exception ex) {
|
||||
Logger.printException(() -> "Open link failure", ex);
|
||||
}
|
||||
dismiss();
|
||||
// Dismiss the about dialog using a delay,
|
||||
// otherwise without a delay the UI looks hectic with the dialog dismissing
|
||||
// to show the settings while simultaneously a web browser is opening.
|
||||
Utils.runOnMainThreadDelayed(WebViewDialog.this::dismiss, 500);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user