Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 68636cd

Browse files
committed
Revert "refactor: properly use OnBackPressedDispatcher"
Narrator: it was in fact not proper This reverts commit 7c9e563.
1 parent 68d735c commit 68636cd

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

app/src/main/java/app/passwordstore/ui/passwords/PasswordStore.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import android.view.Menu
1313
import android.view.MenuItem
1414
import android.view.MenuItem.OnActionExpandListener
1515
import android.view.WindowManager
16-
import androidx.activity.addCallback
1716
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult
1817
import androidx.activity.viewModels
1918
import androidx.appcompat.widget.SearchView
@@ -215,9 +214,6 @@ class PasswordStore : BaseGitActivity() {
215214
override fun onStart() {
216215
super.onStart()
217216
refreshPasswordList()
218-
onBackPressedDispatcher.addCallback {
219-
isEnabled = getPasswordFragment()?.onBackPressedInActivity() == true
220-
}
221217
}
222218

223219
override fun onResume() {
@@ -319,12 +315,20 @@ class PasswordStore : BaseGitActivity() {
319315
}
320316
}
321317
R.id.refresh -> refreshPasswordList()
322-
android.R.id.home -> onBackPressedDispatcher.onBackPressed()
318+
android.R.id.home -> {
319+
@Suppress("DEPRECATION") onBackPressed()
320+
}
323321
else -> return super.onOptionsItemSelected(item)
324322
}
325323
return true
326324
}
327325

326+
@Deprecated("Deprecated in Java")
327+
@Suppress("DEPRECATION")
328+
override fun onBackPressed() {
329+
if (getPasswordFragment()?.onBackPressedInActivity() != true) super.onBackPressed()
330+
}
331+
328332
private fun getPasswordFragment(): PasswordFragment? {
329333
return supportFragmentManager.findFragmentByTag(PASSWORD_FRAGMENT_TAG) as? PasswordFragment
330334
}

app/src/main/java/app/passwordstore/ui/settings/SettingsActivity.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package app.passwordstore.ui.settings
77

88
import android.os.Bundle
99
import android.view.MenuItem
10-
import androidx.activity.addCallback
1110
import androidx.appcompat.app.AppCompatActivity
1211
import androidx.core.os.BundleCompat
1312
import app.passwordstore.R
@@ -102,11 +101,6 @@ class SettingsActivity : AppCompatActivity() {
102101
binding.preferenceRecyclerView.adapter = adapter
103102
}
104103

105-
override fun onStart() {
106-
super.onStart()
107-
onBackPressedDispatcher.addCallback { isEnabled = !preferencesAdapter.goBack() }
108-
}
109-
110104
override fun onSaveInstanceState(outState: Bundle) {
111105
super.onSaveInstanceState(outState)
112106
outState.putParcelable("adapter", preferencesAdapter.getSavedState())
@@ -123,4 +117,10 @@ class SettingsActivity : AppCompatActivity() {
123117
else -> super.onOptionsItemSelected(item)
124118
}
125119
}
120+
121+
@Deprecated("Deprecated in Java")
122+
@Suppress("DEPRECATION")
123+
override fun onBackPressed() {
124+
if (!preferencesAdapter.goBack()) super.onBackPressed()
125+
}
126126
}

0 commit comments

Comments
 (0)