]> gitweb.stoutner.com Git - PrivacyCell.git/blob - app/src/main/java/com/stoutner/privacycell/dialogs/PhonePermissionDialog.kt
Release 1.10.
[PrivacyCell.git] / app / src / main / java / com / stoutner / privacycell / dialogs / PhonePermissionDialog.kt
1 /*
2  * Copyright 2021-2022 Soren Stoutner <soren@stoutner.com>.
3  *
4  * This file is part of Privacy Cell <https://www.stoutner.com/privacy-cell>.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 package com.stoutner.privacycell.dialogs
21
22 import android.app.Dialog
23 import android.content.Context
24 import android.content.DialogInterface
25 import android.os.Bundle
26
27 import androidx.appcompat.app.AlertDialog
28 import androidx.fragment.app.DialogFragment
29
30 import com.stoutner.privacycell.R
31
32 class PhonePermissionDialog : DialogFragment() {
33     // Declare the listener.
34     private lateinit var storagePermissionDialogListener: StoragePermissionDialogListener
35
36     // The public interface is used to send information back to the parent activity.
37     interface StoragePermissionDialogListener {
38         fun onCloseStoragePermissionDialog()
39     }
40
41     override fun onAttach(context: Context) {
42         // Run the default commands.
43         super.onAttach(context)
44
45         // Get a handle for the listener from the launching context.
46         storagePermissionDialogListener = context as StoragePermissionDialogListener
47     }
48
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)
52
53         // Set the icon.
54         dialogBuilder.setIcon(R.drawable.phone_permission)
55
56         // Set the title.
57         dialogBuilder.setTitle(R.string.phone_permission)
58
59         // Set the text.
60         dialogBuilder.setMessage(R.string.phone_permission_text)
61
62         // Set the close button listener.
63         dialogBuilder.setNegativeButton(R.string.ok) { _: DialogInterface, _: Int ->
64             // Call the storage permission dialog listener.
65             storagePermissionDialogListener.onCloseStoragePermissionDialog()
66         }
67
68         // Return the alert dialog.
69         return dialogBuilder.create()
70     }
71 }