From 62398099649e379a2c44e242fc9f8deb3f96d9c1 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Tue, 28 May 2024 15:03:12 +0530 Subject: fix: convert SettingsActivity to `onBackPressedDispatcher` --- .../app/passwordstore/ui/settings/SettingsActivity.kt | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'app') 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() - } } -- cgit v1.2.3