Skip to content

Commit

Permalink
Fix preferenceFragmentCompat for Brave
Browse files Browse the repository at this point in the history
It requires a loop over superclasses for Brave browsers to find the
correct class for preferenceFragmentCompat.

Fix #142
  • Loading branch information
JingMatrix committed Dec 24, 2023
1 parent b895d16 commit 2de409e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions app/src/main/java/org/matrix/chromext/proxy/Preference.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand All @@ -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<String, Any>) {
val ctx = Chrome.getContext()
val sharedPref = ctx.getSharedPreferences("ChromeXt", Context.MODE_PRIVATE)
Expand Down

0 comments on commit 2de409e

Please sign in to comment.