X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fdialogs%2FDownloadLocationPermissionDialog.java;fp=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fdialogs%2FDownloadLocationPermissionDialog.java;h=0ad43d1c7a69d15e5adde01cb5a86c818c671b0b;hp=0000000000000000000000000000000000000000;hb=d420aa6be32a78b27905074edc3881a6e71d2263;hpb=4c03f0a5063c9a16e05dc2cbeb5d7ab4960a6fcc diff --git a/app/src/main/java/com/stoutner/privacybrowser/dialogs/DownloadLocationPermissionDialog.java b/app/src/main/java/com/stoutner/privacybrowser/dialogs/DownloadLocationPermissionDialog.java new file mode 100644 index 00000000..0ad43d1c --- /dev/null +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/DownloadLocationPermissionDialog.java @@ -0,0 +1,108 @@ +/* + * Copyright © 2018 Soren Stoutner . + * + * This file is part of Privacy Browser . + * + * Privacy Browser is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Privacy Browser is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Privacy Browser. If not, see . + */ + +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; + +import com.stoutner.privacybrowser.R; +import com.stoutner.privacybrowser.activities.MainWebViewActivity; + +public class DownloadLocationPermissionDialog extends DialogFragment { + public static final int DOWNLOAD_FILE = 1; + public static final int DOWNLOAD_IMAGE = 2; + + private int downloadType; + + public static DownloadLocationPermissionDialog downloadType(int type) { + // Create an arguments bundle. + Bundle argumentsBundle = new Bundle(); + + // Store the download type in the bundle. + argumentsBundle.putInt("Download_Type", type); + + // Add the arguments bundle to this instance of `DownloadLocationPermissionDialog`. + DownloadLocationPermissionDialog thisDownloadLocationPermissionDialog = new DownloadLocationPermissionDialog(); + thisDownloadLocationPermissionDialog.setArguments(argumentsBundle); + return thisDownloadLocationPermissionDialog; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Store the download type in the local class variable. + downloadType = getArguments().getInt("Download_Type"); + } + + // The public interface is used to send information back to the parent activity. + public interface DownloadLocationPermissionDialogListener { + void onCloseDownloadLocationPermissionDialog(int downloadType); + } + + // `downloadLocationPermissionDialogListener` is used in `onAttach()` and `onCreateDialog()`. + private DownloadLocationPermissionDialogListener downloadLocationPermissionDialogListener; + + @Override + public void onAttach(Context context) { + super.onAttach(context); + + // Check to make sure the parent activity implements the listener. + try { + downloadLocationPermissionDialogListener = (DownloadLocationPermissionDialogListener) context; + } catch (ClassCastException exception) { + throw new ClassCastException(context.toString() + " must implement DownloadLocationPermissionDialogListener."); + } + } + + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + // Use a builder to create the alert dialog. + AlertDialog.Builder dialogBuilder; + + // Set the style and the icon according to the theme. + if (MainWebViewActivity.darkTheme) { + dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogDark); + dialogBuilder.setIcon(R.drawable.downloads_dark); + } else { + dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogLight); + 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); + + // `onCreateDialog` requires the return of an `AlertDialog`. + return dialogBuilder.create(); + } +} \ No newline at end of file