X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyCell.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacycell%2Factivities%2FPrivacyCellActivity.kt;fp=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacycell%2Factivities%2FPrivacyCellActivity.kt;h=dcdd6a3a0fb882554a66561ad2fe8ea6b29b45a6;hp=b158e057db725a5dc2eaf778a32ad9d5081b0320;hb=ff2f3992b7ecddb804a96322789bd35010529f43;hpb=ab7601a6d91b6035862bb47b1ac259855e3aba3b diff --git a/app/src/main/java/com/stoutner/privacycell/activities/PrivacyCellActivity.kt b/app/src/main/java/com/stoutner/privacycell/activities/PrivacyCellActivity.kt index b158e05..dcdd6a3 100644 --- a/app/src/main/java/com/stoutner/privacycell/activities/PrivacyCellActivity.kt +++ b/app/src/main/java/com/stoutner/privacycell/activities/PrivacyCellActivity.kt @@ -1,5 +1,5 @@ /* - * Copyright © 2021-2022 Soren Stoutner . + * Copyright 2021-2022 Soren Stoutner . * * This file is part of Privacy Cell . * @@ -54,11 +54,12 @@ import com.google.android.material.navigation.NavigationView import com.stoutner.privacycell.R import com.stoutner.privacycell.dialogs.PhonePermissionDialog +import com.stoutner.privacycell.dialogs.PhonePermissionDialog.StoragePermissionDialogListener import com.stoutner.privacycell.dialogs.WebViewDialog import com.stoutner.privacycell.helpers.ProtocolHelper import com.stoutner.privacycell.services.RealtimeMonitoringService -class PrivacyCellActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener, PhonePermissionDialog.StoragePermissionDialogListener { +class PrivacyCellActivity : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener, StoragePermissionDialogListener { // Define the class variables. private var voiceNetworkSecurityStatus = ProtocolHelper.UNPOPULATED private var dataNetworkSecurityStatus = ProtocolHelper.UNPOPULATED @@ -73,6 +74,12 @@ class PrivacyCellActivity : AppCompatActivity(), NavigationView.OnNavigationItem private lateinit var overallStatusImageView: ImageView private lateinit var overallStatusTextView: TextView + companion object { + // Define the public constants. + const val PHONE_PERMISSION_REQUEST_CODE = 0 + const val NOTIFICATION_PERMISSION_REQUEST_CODE = 1 + } + override fun onCreate(savedInstanceState: Bundle?) { // Run the default commands. super.onCreate(savedInstanceState) @@ -333,7 +340,7 @@ class PrivacyCellActivity : AppCompatActivity(), NavigationView.OnNavigationItem } else { // The phone permission has not been granted. // Check if the user has previously denied the storage permission. if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_PHONE_STATE)) { // Show a dialog explaining the request first. - // Check to see if a phone permission dialog is already displayed. This happens if the app is restarted when the dialog is shown. + // Check to see if a phone permission dialog is already displayed. This happens if the app is restarted while the dialog is shown. if (supportFragmentManager.findFragmentByTag(getString(R.string.phone_permission)) == null) { // No dialog is currently shown. // Instantiate the phone permission dialog fragment. val phonePermissionDialogFragment = PhonePermissionDialog() @@ -342,8 +349,8 @@ class PrivacyCellActivity : AppCompatActivity(), NavigationView.OnNavigationItem phonePermissionDialogFragment.show(supportFragmentManager, getString(R.string.phone_permission)) } } else { // Show the permission request directly. - // Request the read phone state permission. There is only one permission request in the app, so it has a request code of 0. - ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.READ_PHONE_STATE), 0) + // Request the read phone state permission. + ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.READ_PHONE_STATE), PHONE_PERMISSION_REQUEST_CODE) } } } @@ -490,16 +497,16 @@ class PrivacyCellActivity : AppCompatActivity(), NavigationView.OnNavigationItem } override fun onCloseStoragePermissionDialog() { - // Request the read phone state permission. There is only one permission request in the app, so it has a request code of 0. - ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.READ_PHONE_STATE), 0) + // Request the read phone state permission. + ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.READ_PHONE_STATE), PHONE_PERMISSION_REQUEST_CODE) } override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { // Run the default commands. super.onRequestPermissionsResult(requestCode, permissions, grantResults) - //Only process the results if they exist (this method is triggered when a dialog is presented the first time for an app, but no grant results are included). - if (grantResults.isNotEmpty()) { + // Only process the results if they exist (this method is triggered when a dialog is presented the first time for an app, but no grant results are included) and the result is for the phone permission. + if (grantResults.isNotEmpty() && (requestCode == PHONE_PERMISSION_REQUEST_CODE)) { // Check to see if the read phone state permission was granted. If the dialog was canceled the grant results will be empty. if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { // The read phone state permission was granted. // Populate Privacy Cell. @@ -571,4 +578,4 @@ class PrivacyCellActivity : AppCompatActivity(), NavigationView.OnNavigationItem stingrayDialogFragment.show(supportFragmentManager, getString(R.string.stingrays)) } } -} \ No newline at end of file +}