X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyCell.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacycell%2Fdialogs%2FNotificationPermissionDialog.kt;fp=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacycell%2Fdialogs%2FNotificationPermissionDialog.kt;h=9989945e9a4990d1fc5b246f05c0436d7090d6b9;hp=0000000000000000000000000000000000000000;hb=ff2f3992b7ecddb804a96322789bd35010529f43;hpb=ab7601a6d91b6035862bb47b1ac259855e3aba3b diff --git a/app/src/main/java/com/stoutner/privacycell/dialogs/NotificationPermissionDialog.kt b/app/src/main/java/com/stoutner/privacycell/dialogs/NotificationPermissionDialog.kt new file mode 100644 index 0000000..9989945 --- /dev/null +++ b/app/src/main/java/com/stoutner/privacycell/dialogs/NotificationPermissionDialog.kt @@ -0,0 +1,71 @@ +/* + * Copyright 2021-2022 Soren Stoutner . + * + * This file is part of Privacy Cell . + * + * Privacy Cell 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 Cell 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 Cell. If not, see . + */ + +package com.stoutner.privacycell.dialogs + +import android.app.Dialog +import android.content.Context +import android.content.DialogInterface +import android.os.Bundle + +import androidx.appcompat.app.AlertDialog +import androidx.fragment.app.DialogFragment + +import com.stoutner.privacycell.R + +class NotificationPermissionDialog : DialogFragment() { + // Declare the listener. + private lateinit var notificationPermissionDialogListener: NotificationPermissionDialogListener + + // The public interface is used to send information back to the parent activity. + interface NotificationPermissionDialogListener { + fun onCloseNotificationPermissionDialog() + } + + override fun onAttach(context: Context) { + // Run the default commands. + super.onAttach(context) + + // Get a handle for the listener from the launching context. + notificationPermissionDialogListener = context as NotificationPermissionDialogListener + } + + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + // Use a builder to create the alert dialog. + val dialogBuilder = AlertDialog.Builder(requireContext(), R.style.Theme_PrivacyCellAlertDialog) + + // Set the icon. + dialogBuilder.setIcon(R.drawable.notification_permission) + + // Set the title. + dialogBuilder.setTitle(R.string.notification_permission) + + // Set the text. + dialogBuilder.setMessage(R.string.notification_permission_text) + + // Set the close button listener. + dialogBuilder.setNegativeButton(R.string.ok) { _: DialogInterface, _: Int -> + // Call the notification permission dialog listener. + notificationPermissionDialogListener.onCloseNotificationPermissionDialog() + } + + // Return the alert dialog. + return dialogBuilder.create() + } +}