Group SC debug prefs

Change-Id: I96ffa490c11f64da1648afe3ef545a911a350389
This commit is contained in:
SpiritCroc 2023-01-27 09:00:58 +01:00
parent 04c1811e50
commit e02a3adcdf
3 changed files with 29 additions and 8 deletions

View File

@ -158,6 +158,8 @@
<!-- SC debugging -->
<string name="settings_sc_debugging">Schildi-debugging</string>
<string name="settings_sc_debugging_summary">Enable additional logs or debugging features</string>
<string name="settings_sc_debugging_category_logs">Additional logs</string>
<string name="settings_sc_debugging_category_visuals">Visual debugging info</string>
<string name="settings_sc_dbg_read_marker">Read marker debugging</string>
<string name="settings_sc_dbg_timeline_chunks">Timeline consistency debugging</string>
<string name="settings_sc_dbg_show_display_index">Show displayIndex in timeline</string>

View File

@ -2,6 +2,7 @@ package im.vector.app.features.settings
import androidx.annotation.StringRes
import androidx.preference.Preference
import androidx.preference.PreferenceGroup
import de.spiritcroc.matrixsdk.util.DbgUtil
import im.vector.app.R
import im.vector.app.core.preference.VectorSwitchPreference
@ -14,31 +15,44 @@ class VectorSettingsScDebuggingFragment @Inject constructor(
override var titleRes = R.string.settings_sc_debugging
override val preferenceXmlRes = R.xml.vector_settings_sc_debugging
companion object {
const val SC_DEBUGGING_CATEGORY_LOGS = "SC_DEBUGGING_CATEGORY_LOGS"
const val SC_DEBUGGING_CATEGORY_VISUALS = "SC_DEBUGGING_CATEGORY_VISUALS"
}
data class DbgPref(val key: String, @StringRes val stringRes: Int)
val dbgPrefs = arrayOf(
private val dbgLoggingPrefs = arrayOf(
DbgPref(DbgUtil.DBG_TIMELINE_CHUNKS, R.string.settings_sc_dbg_timeline_chunks),
DbgPref(DbgUtil.DBG_SHOW_DISPLAY_INDEX, R.string.settings_sc_dbg_show_display_index),
DbgPref(DbgUtil.DBG_READ_MARKER, R.string.settings_sc_dbg_read_marker),
DbgPref(DbgUtil.DBG_SHOW_READ_TRACKING, R.string.settings_sc_dbg_show_read_tracking),
DbgPref(DbgUtil.DBG_READ_RECEIPTS, R.string.settings_sc_dbg_read_receipts),
DbgPref(DbgUtil.DBG_VIEW_PAGER, R.string.settings_sc_dbg_view_pager),
)
private val dbgVisualsPrefs = arrayOf(
DbgPref(DbgUtil.DBG_SHOW_DISPLAY_INDEX, R.string.settings_sc_dbg_show_display_index),
DbgPref(DbgUtil.DBG_SHOW_READ_TRACKING, R.string.settings_sc_dbg_show_read_tracking),
DbgPref(DbgUtil.DBG_VIEW_PAGER_VISUALS, R.string.settings_sc_dbg_view_pager_visuals),
)
val dbgPrefs = dbgLoggingPrefs + dbgVisualsPrefs
override fun bindPref() {
dbgPrefs.forEach { dbgPref ->
private fun addScDbgPrefs(prefs: Array<DbgPref>, group: PreferenceGroup) {
prefs.forEach { dbgPref ->
var pref: VectorSwitchPreference? = findPreference(dbgPref.key)
if (pref == null) {
pref = VectorSwitchPreference(requireContext())
pref.key = dbgPref.key
pref.title = getString(dbgPref.stringRes)
preferenceScreen.addPreference(pref)
group.addPreference(pref)
}
pref.isChecked = DbgUtil.isDbgEnabled(pref.key)
pref.onPreferenceChangeListener = preferenceChangeListener
}
}
override fun bindPref() {
findPreference<PreferenceGroup>(SC_DEBUGGING_CATEGORY_LOGS)?.let { addScDbgPrefs(dbgLoggingPrefs, it) }
findPreference<PreferenceGroup>(SC_DEBUGGING_CATEGORY_VISUALS)?.let { addScDbgPrefs(dbgVisualsPrefs, it) }
}
private val preferenceChangeListener = Preference.OnPreferenceChangeListener { preference, newValue ->
if (newValue is Boolean && dbgPrefs.any { preference.key == it.key }) {
DbgUtil.onPreferenceChanged(requireContext(), preference.key as String, newValue)

View File

@ -3,7 +3,12 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<im.vector.app.core.preference.VectorPreference
android:summary="@string/settings_sc_debugging_summary" />
<im.vector.app.core.preference.VectorPreferenceCategory
android:key="SC_DEBUGGING_CATEGORY_LOGS"
android:title="@string/settings_sc_debugging_category_logs" />
<im.vector.app.core.preference.VectorPreferenceCategory
android:key="SC_DEBUGGING_CATEGORY_VISUALS"
android:title="@string/settings_sc_debugging_category_visuals" />
</androidx.preference.PreferenceScreen>