fix: convert SettingsActivity to onBackPressedDispatcher
This commit is contained in:
parent
7ab2d4c6cc
commit
6239809964
1 changed files with 9 additions and 6 deletions
|
@ -7,6 +7,7 @@ package app.passwordstore.ui.settings
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
|
import androidx.activity.OnBackPressedCallback
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.os.BundleCompat
|
import androidx.core.os.BundleCompat
|
||||||
import app.passwordstore.R
|
import app.passwordstore.R
|
||||||
|
@ -80,9 +81,17 @@ class SettingsActivity : AppCompatActivity() {
|
||||||
pgpSettings.provideSettings(this)
|
pgpSettings.provideSettings(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
val backPressedCallback =
|
||||||
|
object : OnBackPressedCallback(true) {
|
||||||
|
override fun handleOnBackPressed() {
|
||||||
|
preferencesAdapter.goBack()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onBackPressedDispatcher.addCallback(backPressedCallback)
|
||||||
val adapter = PreferencesAdapter(screen)
|
val adapter = PreferencesAdapter(screen)
|
||||||
adapter.onScreenChangeListener =
|
adapter.onScreenChangeListener =
|
||||||
PreferencesAdapter.OnScreenChangeListener { subScreen, entering ->
|
PreferencesAdapter.OnScreenChangeListener { subScreen, entering ->
|
||||||
|
backPressedCallback.isEnabled = entering
|
||||||
supportActionBar?.title =
|
supportActionBar?.title =
|
||||||
if (!entering) {
|
if (!entering) {
|
||||||
getString(R.string.action_settings)
|
getString(R.string.action_settings)
|
||||||
|
@ -117,10 +126,4 @@ class SettingsActivity : AppCompatActivity() {
|
||||||
else -> super.onOptionsItemSelected(item)
|
else -> super.onOptionsItemSelected(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated("Deprecated in Java")
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
override fun onBackPressed() {
|
|
||||||
if (!preferencesAdapter.goBack()) super.onBackPressed()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue