X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fdialogs%2FDownloadLocationPermissionDialog.java;h=c5059732b068bd352181986915367e1d36e9960e;hb=fc54425aa869d2672a02e475ce3cd547fc157718;hp=117f000bef2cfdf9f5d958594d3da4c3d3637cb1;hpb=012e5595c82d6e8d0b8a46f1ef18a02a56341182;p=PrivacyBrowserAndroid.git 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 117f000b..c5059732 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,7 +21,6 @@ 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.os.Bundle; @@ -30,11 +29,15 @@ 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. public static final int DOWNLOAD_FILE = 1; public static final int DOWNLOAD_IMAGE = 2; - // `downloadLocationPermissionDialogListener` is used in `onAttach()` and `onCreateDialog()`. + // The listener is used in `onAttach()` and `onCreateDialog()`. private DownloadLocationPermissionDialogListener downloadLocationPermissionDialogListener; // The public interface is used to send information back to the parent activity. @@ -47,7 +50,7 @@ public class DownloadLocationPermissionDialog extends DialogFragment { // Run the default commands. super.onAttach(context); - // Get a handle for `DownloadLocationPermissionDialogListener` from the launching context. + // Get a handle for the listener from the launching context. downloadLocationPermissionDialogListener = (DownloadLocationPermissionDialogListener) context; } @@ -56,18 +59,22 @@ public class DownloadLocationPermissionDialog extends DialogFragment { Bundle argumentsBundle = new Bundle(); // Store the download type in the bundle. - argumentsBundle.putInt("Download_Type", type); + argumentsBundle.putInt("download_type", type); - // Add the arguments bundle to this instance of `DownloadLocationPermissionDialog`. + // Add the arguments bundle to this instance of the dialog. DownloadLocationPermissionDialog thisDownloadLocationPermissionDialog = new DownloadLocationPermissionDialog(); thisDownloadLocationPermissionDialog.setArguments(argumentsBundle); return thisDownloadLocationPermissionDialog; } + @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { - // Store the download type in the local class variable. - int downloadType = getArguments().getInt("Download_Type"); + // 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; @@ -81,19 +88,19 @@ public class DownloadLocationPermissionDialog extends DialogFragment { dialogBuilder.setIcon(R.drawable.downloads_light); } - // Set an `onClick` listener on the negative button. Using `null` as the listener closes the dialog without doing anything else. - dialogBuilder.setNegativeButton(R.string.ok, (DialogInterface dialog, int which) -> { - // Inform the parent activity that the dialog was closed. - downloadLocationPermissionDialogListener.onCloseDownloadLocationPermissionDialog(downloadType); - }); - // Set the title. dialogBuilder.setTitle(R.string.download_location); // Set the text. dialogBuilder.setMessage(R.string.download_location_message); - // Create an alert dialog from the alert dialog builder. + // Set an `onClick` listener on the negative button. + dialogBuilder.setNegativeButton(R.string.ok, (DialogInterface dialog, int which) -> { + // Inform the parent activity that the dialog was closed. + downloadLocationPermissionDialogListener.onCloseDownloadLocationPermissionDialog(downloadType); + }); + + // Create an alert dialog from the builder. final AlertDialog alertDialog = dialogBuilder.create(); // Disable screenshots if not allowed. @@ -105,7 +112,7 @@ public class DownloadLocationPermissionDialog extends DialogFragment { alertDialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE); } - // `onCreateDialog` requires the return of an `AlertDialog`. + // `onCreateDialog()` requires the return of an `AlertDialog`. return alertDialog; } } \ No newline at end of file