/*
- * Copyright © 2021-2022 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2021-2022 Soren Stoutner <soren@stoutner.com>.
*
* This file is part of Privacy Cell <https://www.stoutner.com/privacy-cell>.
*
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
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)
} 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()
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)
}
}
}
}
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<out String>, 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.
stingrayDialogFragment.show(supportFragmentManager, getString(R.string.stingrays))
}
}
-}
\ No newline at end of file
+}