import android.Manifest
import android.content.Context
+import android.content.Intent
import android.content.pm.PackageManager
+import android.net.Uri
import android.os.Bundle
import android.telephony.PhoneStateListener
import android.telephony.ServiceState
import android.telephony.TelephonyDisplayInfo
import android.telephony.TelephonyManager
+import android.view.MenuItem
+import android.view.View
import android.widget.ImageView
import android.widget.TextView
+import androidx.appcompat.app.ActionBar
+import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.content.res.AppCompatResources
+import androidx.appcompat.widget.Toolbar
import androidx.core.app.ActivityCompat
-import androidx.fragment.app.DialogFragment
+import androidx.core.view.GravityCompat
+import androidx.drawerlayout.widget.DrawerLayout
+
+import com.google.android.material.navigation.NavigationView
import com.stoutner.privacycell.R
import com.stoutner.privacycell.dialogs.PhonePermissionDialog
+import com.stoutner.privacycell.dialogs.WebViewDialog
-class PrivacyCell : AppCompatActivity(), PhonePermissionDialog.StoragePermissionDialogListener {
+class PrivacyCell : AppCompatActivity(), NavigationView.OnNavigationItemSelectedListener, PhonePermissionDialog.StoragePermissionDialogListener {
// Declare the class variables.
private lateinit var context: Context
private lateinit var telephonyManager: TelephonyManager
+ 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.
super.onCreate(savedInstanceState)
// Set the content view.
- setContentView(R.layout.privacy_cell_scrollview)
+ setContentView(R.layout.privacy_cell_drawerlayout)
// Get handles for the views.
+ drawerLayout = findViewById(R.id.drawerlayout)
+ val toolbar = findViewById<Toolbar>(R.id.toolbar)
secureFromStingrayImageView = findViewById(R.id.secure_from_stingray_imageview)
secureFromStingrayTextView = findViewById(R.id.secure_from_stingray_textview)
voiceNetworkTextView = findViewById(R.id.voice_network)
dataNetworkDetailsTextView = findViewById(R.id.data_network_details)
additionalNetworkInfoTextView = findViewById(R.id.additional_network_info)
additionalNetworkInfoDetailsTextView = findViewById(R.id.additional_network_info_details)
+ val navigationView = findViewById<NavigationView>(R.id.navigationview)
// Get handles for the context and the telephony manager.
context = this
telephonyManager = getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
+
+ // Set the support action bar.
+ setSupportActionBar(toolbar)
+
+ // Get a handle for the action bar.
+ val actionBar = supportActionBar!!
+
+ // Set a custom view on the action bar.
+ actionBar.setCustomView(R.layout.app_bar_textview)
+
+ // Display the custom view.
+ actionBar.displayOptions = ActionBar.DISPLAY_SHOW_CUSTOM
+
+ // Define a hamburger icon at the start of the app bar. It will be populated in `onPostCreate()`.
+ actionBarDrawerToggle = ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.open_navigation_drawer, R.string.close_navigation_drawer)
+
+ // Listen for touches on the navigation menu.
+ navigationView.setNavigationItemSelectedListener(this)
+
+ // Add a drawer listener.
+ drawerLayout.addDrawerListener(object : DrawerLayout.DrawerListener {
+ override fun onDrawerSlide(drawerView: View, slideOffset: Float) {
+ // Do nothing.
+ }
+
+ override fun onDrawerOpened(drawerView: View) {
+ // Do nothing.
+ }
+
+ override fun onDrawerClosed(drawerView: View) {
+ // Reset the drawer icon when the drawer is closed. Otherwise, it is an arrow if the drawer is open when the app is restarted.
+ actionBarDrawerToggle.syncState()
+ }
+
+ override fun onDrawerStateChanged(newState: Int) {
+ // Do nothing.
+ }
+ })
+ }
+
+ override fun onPostCreate(savedInstanceState: Bundle?) {
+ // Run the default commands.
+ super.onPostCreate(savedInstanceState)
+
+ // Sync the state of the DrawerToggle after the default `onRestoreInstanceState()` has finished. This creates the navigation drawer icon.
+ actionBarDrawerToggle.syncState()
}
override fun onResume() {
// 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))
}
}
+ override fun onNavigationItemSelected(menuItem: MenuItem) : Boolean {
+ // Run the commands that correspond to the selected menu item.
+ when (menuItem.itemId) {
+ R.id.permissions -> { // Permissions.
+ // Instantiate the permissions dialog fragment.
+ val permissionsDialogFragment = WebViewDialog().type(WebViewDialog.PERMISSIONS)
+
+ // Show the alert dialog.
+ permissionsDialogFragment.show(supportFragmentManager, getString(R.string.permissions))
+ }
+
+ R.id.privacy_policy -> { // Privacy Policy.
+ // Instantiate the privacy policy dialog fragment.
+ val privacyPolicyDialogFragment = WebViewDialog().type(WebViewDialog.PRIVACY_POLICY)
+
+ // Show the alert dialog.
+ privacyPolicyDialogFragment.show(supportFragmentManager, getString(R.string.privacy_policy))
+ }
+
+ R.id.changelog -> { // Changelog.
+ // Instantiate the changelog dialog fragment.
+ val changelogDialogFragment = WebViewDialog().type(WebViewDialog.CHANGELOG)
+
+ // Show the alert dialog.
+ changelogDialogFragment.show(supportFragmentManager, getString(R.string.changelog))
+ }
+
+ R.id.licenses -> { // Licenses.
+ // Instantiate the licenses dialog fragment.
+ val licensesDialogFragment = WebViewDialog().type(WebViewDialog.LICENSES)
+
+ // Show the alert dialog.
+ licensesDialogFragment.show(supportFragmentManager, getString(R.string.licenses))
+ }
+
+ R.id.contributors -> { // Contributors.
+ // Instantiate the contributors dialog fragment.
+ val contributorsDialogFragment = WebViewDialog().type(WebViewDialog.CONTRIBUTORS)
+
+ // Show the alert dialog.
+ contributorsDialogFragment.show(supportFragmentManager, getString(R.string.contributors))
+ }
+
+ R.id.news -> { // News.
+ // Create a news URL intent.
+ val newsUrlIntent = Intent(Intent.ACTION_VIEW)
+
+ // Add the URL to the intent.
+ newsUrlIntent.data = Uri.parse("https://www.stoutner.com/category/privacy-cell/")
+
+ // Make it so.
+ startActivity(newsUrlIntent)
+ }
+
+ R.id.roadmap -> { // Roadmap.
+ // Create a roadmap URL intent.
+ val roadmapUrlIntent = Intent(Intent.ACTION_VIEW)
+
+ // Add the URL to the intent.
+ roadmapUrlIntent.data = Uri.parse("https://www.stoutner.com/category/privacy-cell-roadmap/")
+
+ // Make it so.
+ startActivity(roadmapUrlIntent)
+ }
+
+ R.id.bug_tracker -> { // Bug tracker.
+ // Create a bug tracker URL intent.
+ val bugTrackerUrlIntent = Intent(Intent.ACTION_VIEW)
+
+ // Add the URL to the intent.
+ bugTrackerUrlIntent.data = Uri.parse("https://redmine.stoutner.com/projects/privacy-cell/issues")
+
+ // Make it so.
+ startActivity(bugTrackerUrlIntent)
+ }
+
+ R.id.forum -> { // Forum.
+ // Create a forum URL intent.
+ val forumUrlIntent = Intent(Intent.ACTION_VIEW)
+
+ // Add the URL to the intent.
+ forumUrlIntent.data = Uri.parse("https://redmine.stoutner.com/projects/privacy-cell/boards")
+
+ // Make it so.
+ startActivity(forumUrlIntent)
+ }
+
+ R.id.donations -> { // Donations.
+ // Create a donations URL intent.
+ val donationsUrlIntent = Intent(Intent.ACTION_VIEW)
+
+ // Add the URL to the intent.
+ donationsUrlIntent.data = Uri.parse("https://www.stoutner.com/donations/")
+
+ // Make it so.
+ startActivity(donationsUrlIntent)
+ }
+ }
+
+ // 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)
// Set the text color.
secureFromStingrayTextView.setTextColor(getColor(R.color.red_text))
+ }
- // Get the strings that correspond to the network information.
- val dataNetworkType = getNetworkType(telephonyDisplayInfo.networkType)
- val additionalNetworkInfo = getAdditionalNetworkInfo(telephonyDisplayInfo.overrideNetworkType)
+ // Get the strings that correspond to the network information.
+ val dataNetworkType = getNetworkType(telephonyDisplayInfo.networkType)
+ val additionalNetworkInfo = getAdditionalNetworkInfo(telephonyDisplayInfo.overrideNetworkType)
- // Populate the data network text views.
- dataNetworkTextView.text = getString(R.string.data_network, dataNetworkType[0])
- dataNetworkDetailsTextView.text = dataNetworkType[1]
- additionalNetworkInfoTextView.text = getString(R.string.additional_network_info, additionalNetworkInfo[0])
- additionalNetworkInfoDetailsTextView.text = additionalNetworkInfo[1]
- }
+ // Populate the data network text views.
+ dataNetworkTextView.text = getString(R.string.data_network, dataNetworkType[0])
+ dataNetworkDetailsTextView.text = dataNetworkType[1]
+ additionalNetworkInfoTextView.text = getString(R.string.additional_network_info, additionalNetworkInfo[0])
+ additionalNetworkInfoDetailsTextView.text = additionalNetworkInfo[1]
}
override fun onServiceStateChanged(serviceState: ServiceState) {