Skip to content

Commit

Permalink
fix preferences in single line
Browse files Browse the repository at this point in the history
  • Loading branch information
RobozinhoD authored and lukstbit committed Aug 8, 2023
1 parent 6861e68 commit d8b3a55
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import androidx.annotation.VisibleForTesting
import androidx.appcompat.app.AlertDialog
import androidx.core.content.edit
import androidx.preference.Preference
import androidx.preference.PreferenceCategory
import com.ichi2.anki.R
import com.ichi2.utils.*

Expand Down Expand Up @@ -72,18 +71,7 @@ class CustomButtonsSettingsFragment : SettingsFragment() {

@VisibleForTesting(otherwise = VisibleForTesting.NONE)
fun allKeys(): HashSet<String> {
val allKeys = HashSet<String>()
for (i in 0 until preferenceScreen.preferenceCount) {
val pref = preferenceScreen.getPreference(i)
if (pref is PreferenceCategory) {
for (j in 0 until pref.preferenceCount) {
allKeys.add(pref.getPreference(j).key)
}
} else {
allKeys.add(pref.key)
}
}
return allKeys
return allPreferences().mapTo(hashSetOf()) { it.key }
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.annotation.VisibleForTesting
import androidx.annotation.XmlRes
import androidx.core.os.bundleOf
import androidx.preference.Preference
import androidx.preference.PreferenceCategory
import androidx.preference.PreferenceFragmentCompat
import androidx.preference.PreferenceManager
import androidx.preference.PreferenceManager.OnPreferenceTreeClickListener
Expand Down Expand Up @@ -78,6 +79,7 @@ abstract class SettingsFragment :
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
UsageAnalytics.sendAnalyticsScreenView(analyticsScreenNameConstant)
addPreferencesFromResource(preferenceResource)
allPreferences().forEach { it.isSingleLineTitle = false }
initSubscreen()
}

Expand Down Expand Up @@ -110,6 +112,21 @@ abstract class SettingsFragment :
.unregisterOnSharedPreferenceChangeListener(this)
}

protected fun allPreferences(): List<Preference> {
val allPreferences = mutableListOf<Preference>()
for (i in 0 until preferenceScreen.preferenceCount) {
val pref = preferenceScreen.getPreference(i)
if (pref is PreferenceCategory) {
for (j in 0 until pref.preferenceCount) {
allPreferences.add(pref.getPreference(j))
}
} else {
allPreferences.add(pref)
}
}
return allPreferences
}

companion object {
@JvmStatic // Using protected members which are not @JvmStatic in the superclass companion is unsupported yet
protected fun getSubscreenIntent(context: Context, fragmentClass: KClass<out SettingsFragment>): Intent {
Expand Down

0 comments on commit d8b3a55

Please sign in to comment.