diff options
author | Harsh Shandilya <me@msfjarvis.dev> | 2024-05-28 15:03:12 +0530 |
---|---|---|
committer | Harsh Shandilya <me@msfjarvis.dev> | 2024-05-28 15:03:12 +0530 |
commit | 62398099649e379a2c44e242fc9f8deb3f96d9c1 (patch) | |
tree | 540f47ff734d7f25554d053cad4500810876fa64 /app | |
parent | 7ab2d4c6cc32420aa72ee7474aa3b89cb1c68101 (diff) |
fix: convert SettingsActivity to `onBackPressedDispatcher`
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/app/passwordstore/ui/settings/SettingsActivity.kt | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/app/src/main/java/app/passwordstore/ui/settings/SettingsActivity.kt b/app/src/main/java/app/passwordstore/ui/settings/SettingsActivity.kt index 508120ce..7c9d8e8b 100644 --- a/app/src/main/java/app/passwordstore/ui/settings/SettingsActivity.kt +++ b/app/src/main/java/app/passwordstore/ui/settings/SettingsActivity.kt @@ -7,6 +7,7 @@ package app.passwordstore.ui.settings import android.os.Bundle import android.view.MenuItem +import androidx.activity.OnBackPressedCallback import androidx.appcompat.app.AppCompatActivity import androidx.core.os.BundleCompat import app.passwordstore.R @@ -80,9 +81,17 @@ class SettingsActivity : AppCompatActivity() { pgpSettings.provideSettings(this) } } + val backPressedCallback = + object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + preferencesAdapter.goBack() + } + } + onBackPressedDispatcher.addCallback(backPressedCallback) val adapter = PreferencesAdapter(screen) adapter.onScreenChangeListener = PreferencesAdapter.OnScreenChangeListener { subScreen, entering -> + backPressedCallback.isEnabled = entering supportActionBar?.title = if (!entering) { getString(R.string.action_settings) @@ -117,10 +126,4 @@ class SettingsActivity : AppCompatActivity() { else -> super.onOptionsItemSelected(item) } } - - @Deprecated("Deprecated in Java") - @Suppress("DEPRECATION") - override fun onBackPressed() { - if (!preferencesAdapter.goBack()) super.onBackPressed() - } } |