X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyCell.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacycell%2Factivities%2FPrivacyCell.kt;h=a8863477a7bceb3a902452cd397468a6c7d3555c;hp=8f482b06a9174581905cdb25248741a69530a180;hb=578979a47d905469cfc5c7cdc748fe9b539437e2;hpb=189a089931502d9fc23533b5c2ffcaf98da8ed6c diff --git a/app/src/main/java/com/stoutner/privacycell/activities/PrivacyCell.kt b/app/src/main/java/com/stoutner/privacycell/activities/PrivacyCell.kt index 8f482b0..a886347 100644 --- a/app/src/main/java/com/stoutner/privacycell/activities/PrivacyCell.kt +++ b/app/src/main/java/com/stoutner/privacycell/activities/PrivacyCell.kt @@ -38,12 +38,13 @@ import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.content.res.AppCompatResources import androidx.appcompat.widget.Toolbar import androidx.core.app.ActivityCompat +import androidx.core.view.GravityCompat import androidx.drawerlayout.widget.DrawerLayout -import androidx.fragment.app.DialogFragment import com.google.android.material.navigation.NavigationView import com.stoutner.privacycell.R +import com.stoutner.privacycell.dialogs.PermissionsDialog import com.stoutner.privacycell.dialogs.PhonePermissionDialog class PrivacyCell : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener, PhonePermissionDialog.StoragePermissionDialogListener { @@ -53,14 +54,15 @@ class PrivacyCell : AppCompatActivity(), NavigationView.OnNavigationItemSelected private lateinit var actionBarDrawerToggle: ActionBarDrawerToggle // Declare the views. - lateinit var secureFromStingrayImageView: ImageView - lateinit var secureFromStingrayTextView: TextView - lateinit var voiceNetworkTextView: TextView - lateinit var voiceNetworkDetailsTextView: TextView - lateinit var dataNetworkTextView: TextView - lateinit var dataNetworkDetailsTextView: TextView - lateinit var additionalNetworkInfoTextView: TextView - lateinit var additionalNetworkInfoDetailsTextView: TextView + private lateinit var drawerLayout: DrawerLayout + private lateinit var secureFromStingrayImageView: ImageView + private lateinit var secureFromStingrayTextView: TextView + private lateinit var voiceNetworkTextView: TextView + private lateinit var voiceNetworkDetailsTextView: TextView + private lateinit var dataNetworkTextView: TextView + private lateinit var dataNetworkDetailsTextView: TextView + private lateinit var additionalNetworkInfoTextView: TextView + private lateinit var additionalNetworkInfoDetailsTextView: TextView override fun onCreate(savedInstanceState: Bundle?) { // Run the default commands. @@ -70,7 +72,7 @@ class PrivacyCell : AppCompatActivity(), NavigationView.OnNavigationItemSelected setContentView(R.layout.privacy_cell_drawerlayout) // Get handles for the views. - val drawerLayout = findViewById(R.id.drawerlayout) + drawerLayout = findViewById(R.id.drawerlayout) val toolbar = findViewById(R.id.toolbar) secureFromStingrayImageView = findViewById(R.id.secure_from_stingray_imageview) secureFromStingrayTextView = findViewById(R.id.secure_from_stingray_textview) @@ -147,7 +149,7 @@ class PrivacyCell : AppCompatActivity(), NavigationView.OnNavigationItemSelected // Check to see if a phone permission dialog is already displayed. This happens if the app is restarted when 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: DialogFragment = PhonePermissionDialog() + val phonePermissionDialogFragment = PhonePermissionDialog() // Show the phone permission alert dialog. The permission will be requested when the dialog is closed. phonePermissionDialogFragment.show(supportFragmentManager, getString(R.string.phone_permission)) @@ -159,6 +161,26 @@ class PrivacyCell : AppCompatActivity(), NavigationView.OnNavigationItemSelected } } + override fun onNavigationItemSelected(menuItem: MenuItem) : Boolean { + // Get the menu item ID. + val menuItemId = menuItem.itemId + + // Run the commands that correspond to the selected menu item. + if (menuItemId == R.id.permissions) { // Permissions. + // Instantiate the permissions dialog fragment. + val permissionsDialogFragment = PermissionsDialog() + + // Show the permissions alert dialog. + permissionsDialogFragment.show(supportFragmentManager, getString(R.string.phone_permission)) + } + + // Close the navigation drawer. + drawerLayout.closeDrawer(GravityCompat.START) + + // Consume the click. + return true + } + 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) @@ -269,9 +291,4 @@ class PrivacyCell : AppCompatActivity(), NavigationView.OnNavigationItemSelected else -> arrayOf(getString(R.string.error), "") } } - - override fun onNavigationItemSelected(menuItem: MenuItem) : Boolean { - // TODO. - return true - } } \ No newline at end of file