2 * Copyright 2021-2022 Soren Stoutner <soren@stoutner.com>.
4 * This file is part of Privacy Cell <https://www.stoutner.com/privacy-cell>.
6 * Privacy Cell is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * Privacy Cell is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Privacy Cell. If not, see <http://www.gnu.org/licenses/>.
20 package com.stoutner.privacycell.dialogs
22 import android.app.Dialog
23 import android.content.Context
24 import android.content.DialogInterface
25 import android.os.Bundle
27 import androidx.appcompat.app.AlertDialog
28 import androidx.fragment.app.DialogFragment
30 import com.stoutner.privacycell.R
32 class NotificationPermissionDialog : DialogFragment() {
33 // Declare the listener.
34 private lateinit var notificationPermissionDialogListener: NotificationPermissionDialogListener
36 // The public interface is used to send information back to the parent activity.
37 interface NotificationPermissionDialogListener {
38 fun onCloseNotificationPermissionDialog()
41 override fun onAttach(context: Context) {
42 // Run the default commands.
43 super.onAttach(context)
45 // Get a handle for the listener from the launching context.
46 notificationPermissionDialogListener = context as NotificationPermissionDialogListener
49 override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
50 // Use a builder to create the alert dialog.
51 val dialogBuilder = AlertDialog.Builder(requireContext(), R.style.Theme_PrivacyCellAlertDialog)
54 dialogBuilder.setIcon(R.drawable.notification_permission)
57 dialogBuilder.setTitle(R.string.notification_permission)
60 dialogBuilder.setMessage(R.string.notification_permission_text)
62 // Set the close button listener.
63 dialogBuilder.setNegativeButton(R.string.ok) { _: DialogInterface, _: Int ->
64 // Call the notification permission dialog listener.
65 notificationPermissionDialogListener.onCloseNotificationPermissionDialog()
68 // Return the alert dialog.
69 return dialogBuilder.create()