From 990a35422933de64a9cab2e252bb332cdeaccc90 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Mon, 11 Sep 2023 21:09:03 +0200 Subject: [PATCH] Remove deprecated function and prevent errors in case of a null fragment name --- .../android/settings/SettingsActivity.kt | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/settings/SettingsActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/settings/SettingsActivity.kt index 0de8c99..8dd817b 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/settings/SettingsActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/settings/SettingsActivity.kt @@ -71,23 +71,25 @@ class SettingsActivity : AppCompatActivity(), } override fun onPreferenceStartFragment( - caller: PreferenceFragmentCompat, - pref: Preference + caller: PreferenceFragmentCompat, + pref: Preference ): Boolean { + val fragmentClassName = pref.fragment ?: return false + // Instantiate the new Fragment val args = pref.extras val fragment = supportFragmentManager.fragmentFactory.instantiate( - classLoader, - pref.fragment + classLoader, + fragmentClassName ).apply { arguments = args - setTargetFragment(caller, 0) } + // Replace the existing Fragment with the new Fragment supportFragmentManager.beginTransaction() - .replace(R.id.settings, fragment) - .addToBackStack(null) - .commit() + .replace(R.id.settings, fragment) + .addToBackStack(null) + .commit() title = pref.title supportActionBar?.title = title return true