From 2de409e7d68785778e839d7df9fcaed600c70085 Mon Sep 17 00:00:00 2001 From: JingMatrix Date: Sun, 24 Dec 2023 12:28:21 +0100 Subject: [PATCH] Fix preferenceFragmentCompat for Brave It requires a loop over superclasses for Brave browsers to find the correct class for preferenceFragmentCompat. Fix #142 --- .../java/org/matrix/chromext/proxy/Preference.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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)