X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fdialogs%2FWaitingForProxyDialog.java;h=d87385db5666f7fb7ea44a1a8298f08d29d20190;hp=08e39212a6418bda7526c3f5a32bdc583dd69887;hb=f3b9172adedd74f705ddc0beac80798ae84f2920;hpb=81179d84ced6b43360d42a4b44eb8fb329532ff4 diff --git a/app/src/main/java/com/stoutner/privacybrowser/dialogs/WaitingForProxyDialog.java b/app/src/main/java/com/stoutner/privacybrowser/dialogs/WaitingForProxyDialog.java index 08e39212..d87385db 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/dialogs/WaitingForProxyDialog.java +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/WaitingForProxyDialog.java @@ -1,5 +1,5 @@ /* - * Copyright © 2019 Soren Stoutner . + * Copyright © 2019-2020 Soren Stoutner . * * This file is part of Privacy Browser . * @@ -20,7 +20,6 @@ package com.stoutner.privacybrowser.dialogs; import android.annotation.SuppressLint; -import android.app.Activity; import android.app.Dialog; import android.content.Context; import android.content.SharedPreferences; @@ -36,38 +35,19 @@ import androidx.preference.PreferenceManager; import com.stoutner.privacybrowser.R; public class WaitingForProxyDialog extends DialogFragment { - // `@SuppressLing("InflateParams")` removes the warning about using `null` as the parent view group when inflating the alert dialog. + // `@SuppressLint("InflateParams")` removes the warning about using `null` as the parent view group when inflating the alert dialog. @SuppressLint("InflateParams") @Override @NonNull public Dialog onCreateDialog(Bundle savedInstanceState) { - // Get the context and the activity. - Context context = getContext(); - Activity activity = getActivity(); - - // Remove the incorrect lint warnings below that the context or the activity might be null. - assert context != null; - assert activity != null; + // Get a handle for the context. + Context context = requireContext(); // Get the activity's layout inflater. - LayoutInflater layoutInflater = activity.getLayoutInflater(); - - // Get a handle for the shared preferences. - SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); - - // Get the screenshot and theme preferences. - boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false); - boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false); + LayoutInflater layoutInflater = requireActivity().getLayoutInflater(); // Use a builder to create the alert dialog. - AlertDialog.Builder dialogBuilder; - - // Set the style according to the theme. - if (darkTheme) { - dialogBuilder = new AlertDialog.Builder(activity, R.style.PrivacyBrowserAlertDialogDark); - } else { - dialogBuilder = new AlertDialog.Builder(activity, R.style.PrivacyBrowserAlertDialogLight); - } + AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(context, R.style.PrivacyBrowserAlertDialog); // Set the layout. The parent view is `null` because it will be assigned by the alert dialog. dialogBuilder.setView(layoutInflater.inflate(R.layout.waiting_for_proxy_dialog, null)); @@ -75,6 +55,12 @@ public class WaitingForProxyDialog extends DialogFragment { // Create an alert dialog from the alert dialog builder. AlertDialog alertDialog = dialogBuilder.create(); + // Get a handle for the shared preferences. + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); + + // Get the screenshot preference. + boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false); + // Disable screenshots if not allowed. if (!allowScreenshots) { // Remove the warning below that `getWindow()` might be null.