Remove deprecated function and prevent errors in case of a null fragment name

This commit is contained in:
davidoskky 2023-09-11 21:09:03 +02:00
parent bd6b96d09d
commit 990a354229

View File

@ -74,15 +74,17 @@ class SettingsActivity : AppCompatActivity(),
caller: PreferenceFragmentCompat, caller: PreferenceFragmentCompat,
pref: Preference pref: Preference
): Boolean { ): Boolean {
val fragmentClassName = pref.fragment ?: return false
// Instantiate the new Fragment // Instantiate the new Fragment
val args = pref.extras val args = pref.extras
val fragment = supportFragmentManager.fragmentFactory.instantiate( val fragment = supportFragmentManager.fragmentFactory.instantiate(
classLoader, classLoader,
pref.fragment fragmentClassName
).apply { ).apply {
arguments = args arguments = args
setTargetFragment(caller, 0)
} }
// Replace the existing Fragment with the new Fragment // Replace the existing Fragment with the new Fragment
supportFragmentManager.beginTransaction() supportFragmentManager.beginTransaction()
.replace(R.id.settings, fragment) .replace(R.id.settings, fragment)