X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fdialogs%2FDownloadLocationPermissionDialog.java;h=a8ebd73e2560d699341093a62fb230425b5f1d03;hp=a232058886580ef5eea61260e648ad0f63233eba;hb=ca7516a7edb9e06d0f9fe9186513986cd82be716;hpb=64fe50abeacf25f6fde5d3b3de11801f1618987b diff --git a/app/src/main/java/com/stoutner/privacybrowser/dialogs/DownloadLocationPermissionDialog.java b/app/src/main/java/com/stoutner/privacybrowser/dialogs/DownloadLocationPermissionDialog.java index a2320588..a8ebd73e 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/dialogs/DownloadLocationPermissionDialog.java +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/DownloadLocationPermissionDialog.java @@ -1,5 +1,5 @@ /* - * Copyright © 2018 Soren Stoutner . + * Copyright © 2018-2019 Soren Stoutner . * * This file is part of Privacy Browser . * @@ -21,14 +21,17 @@ package com.stoutner.privacybrowser.dialogs; import android.app.AlertDialog; import android.app.Dialog; -import android.app.DialogFragment; import android.content.Context; import android.content.DialogInterface; +import android.content.SharedPreferences; import android.os.Bundle; +import android.preference.PreferenceManager; import android.view.WindowManager; import com.stoutner.privacybrowser.R; -import com.stoutner.privacybrowser.activities.MainWebViewActivity; + +import androidx.annotation.NonNull; +import androidx.fragment.app.DialogFragment; // The AndroidX dialog fragment must be used or an error is produced on API <=22. public class DownloadLocationPermissionDialog extends DialogFragment { // The constants are used to differentiate between the two download types. @@ -44,7 +47,7 @@ public class DownloadLocationPermissionDialog extends DialogFragment { } @Override - public void onAttach(Context context) { + public void onAttach(@NonNull Context context) { // Run the default commands. super.onAttach(context); @@ -65,16 +68,27 @@ public class DownloadLocationPermissionDialog extends DialogFragment { return thisDownloadLocationPermissionDialog; } + @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { + // Remove the incorrect lint warning below that `getArguments().getInt()` might be null. + assert getArguments() != null; + // Store the download type in a local variable. int downloadType = getArguments().getInt("download_type"); // Use a builder to create the alert dialog. AlertDialog.Builder dialogBuilder; + // 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); + // Set the style and the icon according to the theme. - if (MainWebViewActivity.darkTheme) { + if (darkTheme) { dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogDark); dialogBuilder.setIcon(R.drawable.downloads_dark); } else { @@ -98,7 +112,7 @@ public class DownloadLocationPermissionDialog extends DialogFragment { final AlertDialog alertDialog = dialogBuilder.create(); // Disable screenshots if not allowed. - if (!MainWebViewActivity.allowScreenshots) { + if (!allowScreenshots) { // Remove the warning below that `getWindow()` might be null. assert alertDialog.getWindow() != null;