Revert "refactor: properly use OnBackPressedDispatcher"

Narrator: it was in fact not proper

This reverts commit 7c9e563d96.
This commit is contained in:
Harsh Shandilya 2024-05-28 14:31:28 +05:30
parent 68d735c28e
commit 68636cdcb6
2 changed files with 15 additions and 11 deletions

View file

@ -13,7 +13,6 @@ import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.MenuItem.OnActionExpandListener import android.view.MenuItem.OnActionExpandListener
import android.view.WindowManager import android.view.WindowManager
import androidx.activity.addCallback
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
@ -215,9 +214,6 @@ class PasswordStore : BaseGitActivity() {
override fun onStart() { override fun onStart() {
super.onStart() super.onStart()
refreshPasswordList() refreshPasswordList()
onBackPressedDispatcher.addCallback {
isEnabled = getPasswordFragment()?.onBackPressedInActivity() == true
}
} }
override fun onResume() { override fun onResume() {
@ -319,12 +315,20 @@ class PasswordStore : BaseGitActivity() {
} }
} }
R.id.refresh -> refreshPasswordList() R.id.refresh -> refreshPasswordList()
android.R.id.home -> onBackPressedDispatcher.onBackPressed() android.R.id.home -> {
@Suppress("DEPRECATION") onBackPressed()
}
else -> return super.onOptionsItemSelected(item) else -> return super.onOptionsItemSelected(item)
} }
return true return true
} }
@Deprecated("Deprecated in Java")
@Suppress("DEPRECATION")
override fun onBackPressed() {
if (getPasswordFragment()?.onBackPressedInActivity() != true) super.onBackPressed()
}
private fun getPasswordFragment(): PasswordFragment? { private fun getPasswordFragment(): PasswordFragment? {
return supportFragmentManager.findFragmentByTag(PASSWORD_FRAGMENT_TAG) as? PasswordFragment return supportFragmentManager.findFragmentByTag(PASSWORD_FRAGMENT_TAG) as? PasswordFragment
} }

View file

@ -7,7 +7,6 @@ package app.passwordstore.ui.settings
import android.os.Bundle import android.os.Bundle
import android.view.MenuItem import android.view.MenuItem
import androidx.activity.addCallback
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
@ -102,11 +101,6 @@ class SettingsActivity : AppCompatActivity() {
binding.preferenceRecyclerView.adapter = adapter binding.preferenceRecyclerView.adapter = adapter
} }
override fun onStart() {
super.onStart()
onBackPressedDispatcher.addCallback { isEnabled = !preferencesAdapter.goBack() }
}
override fun onSaveInstanceState(outState: Bundle) { override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState) super.onSaveInstanceState(outState)
outState.putParcelable("adapter", preferencesAdapter.getSavedState()) outState.putParcelable("adapter", preferencesAdapter.getSavedState())
@ -123,4 +117,10 @@ 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()
}
} }