X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fdialogs%2FDownloadImageDialog.java;h=f200d95aefabf2ae33292110b87044cf40fdbd8e;hp=eb2624f34912a4a613a119b7ba0cb0b2c6ed7100;hb=c1c9a0bf83ecef671356d554bb6e4927392b1cc8;hpb=ba40295dffd761ccdc95d3b46ca7acbad1f00d5e diff --git a/app/src/main/java/com/stoutner/privacybrowser/dialogs/DownloadImageDialog.java b/app/src/main/java/com/stoutner/privacybrowser/dialogs/DownloadImageDialog.java index eb2624f3..f200d95a 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/dialogs/DownloadImageDialog.java +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/DownloadImageDialog.java @@ -24,10 +24,11 @@ import android.app.AlertDialog; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; +import android.content.SharedPreferences; import android.net.Uri; import android.os.Bundle; +import android.preference.PreferenceManager; import android.view.KeyEvent; -import android.view.LayoutInflater; import android.view.View; import android.view.WindowManager; import android.widget.EditText; @@ -36,7 +37,6 @@ import androidx.annotation.NonNull; import androidx.fragment.app.DialogFragment; // The AndroidX dialog fragment must be used or an error is produced on API <=22. import com.stoutner.privacybrowser.R; -import com.stoutner.privacybrowser.activities.MainWebViewActivity; public class DownloadImageDialog extends DialogFragment { // `downloadImageListener` is used in `onAttach()` and `onCreateDialog()`. @@ -93,14 +93,18 @@ public class DownloadImageDialog extends DialogFragment { // Remove the warning below that `.getActivity()` might be null. assert getActivity() != null; - // Get the activity's layout inflater. - LayoutInflater layoutInflater = getActivity().getLayoutInflater(); + // Get a handle for the shared preferences. + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getContext()); + + // Get the screenshot and theme preferences. + boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false); + boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false); // Use and alert dialog builder to create the alert dialog. AlertDialog.Builder dialogBuilder; // Set the style according to the theme. - if (MainWebViewActivity.darkTheme) { + if (darkTheme) { dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogDark); } else { dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogLight); @@ -109,8 +113,18 @@ public class DownloadImageDialog extends DialogFragment { // Set the title. dialogBuilder.setTitle(R.string.save_image_as); + // Set the icon according to the theme. + if (darkTheme) { + dialogBuilder.setIcon(R.drawable.images_enabled_dark); + } else { + dialogBuilder.setIcon(R.drawable.images_enabled_light); + } + + // Remove the incorrect lint warning below that `getActivity() might be null. + assert getActivity() != null; + // Set the view. The parent view is `null` because it will be assigned by `AlertDialog`. - dialogBuilder.setView(layoutInflater.inflate(R.layout.download_image_dialog, null)); + dialogBuilder.setView(getActivity().getLayoutInflater().inflate(R.layout.download_image_dialog, null)); // Set an listener on the negative button. dialogBuilder.setNegativeButton(R.string.cancel, (DialogInterface dialog, int which) -> { @@ -131,7 +145,7 @@ public class DownloadImageDialog extends DialogFragment { assert alertDialog.getWindow() != null; // Disable screenshots if not allowed. - if (!MainWebViewActivity.allowScreenshots) { + if (!allowScreenshots) { alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE); }