diff --git a/app/src/main/java/org/matrix/chromext/proxy/Preference.kt b/app/src/main/java/org/matrix/chromext/proxy/Preference.kt index 3ff9013..140a020 100644 --- a/app/src/main/java/org/matrix/chromext/proxy/Preference.kt +++ b/app/src/main/java/org/matrix/chromext/proxy/Preference.kt @@ -46,8 +46,9 @@ object PreferenceProxy { } private val preferenceFragmentCompat = - if (Chrome.isBrave) developerSettings.superclass.superclass - else developerSettings.superclass as Class<*> + loopOverSuperClass(developerSettings.superclass) { + !Chrome.isBrave || it.superclass.name.startsWith("androidx.fragment") + } val findPreference = findMethod(preferenceFragmentCompat) { parameterTypes contentDeepEquals arrayOf(CharSequence::class.java) && @@ -62,6 +63,14 @@ object PreferenceProxy { } .first() + private fun loopOverSuperClass(base: Class<*>, condition: (Class<*>) -> Boolean): Class<*> { + if (condition(base)) { + return base + } else { + return loopOverSuperClass(base.superclass, condition) + } + } + fun setClickListener(preferences: Map) { val ctx = Chrome.getContext() val sharedPref = ctx.getSharedPreferences("ChromeXt", Context.MODE_PRIVATE)