diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/preferences/AboutFragment.kt b/AnkiDroid/src/main/java/com/ichi2/anki/preferences/AboutFragment.kt index 002ab7daae52..655764c3c764 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/preferences/AboutFragment.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/preferences/AboutFragment.kt @@ -47,7 +47,9 @@ import java.util.Date import java.util.Locale import net.ankiweb.rsdroid.BuildConfig as BackendBuildConfig -class AboutFragment : Fragment(R.layout.about_layout) { +class AboutFragment : Fragment(R.layout.about_layout), TitleProvider { + override val title: CharSequence + get() = getString(R.string.pref_cat_about_title) override fun onViewCreated(view: View, savedInstanceState: Bundle?) { // Version date @@ -113,11 +115,6 @@ class AboutFragment : Fragment(R.layout.about_layout) { } } - override fun onStart() { - super.onStart() - requireActivity().setTitle(R.string.pref_cat_about_title) - } - /** * Copies debug info (from [DebugInfoService.getDebugInfo]) to the clipboard */ diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/preferences/HeaderFragment.kt b/AnkiDroid/src/main/java/com/ichi2/anki/preferences/HeaderFragment.kt index f3685c52f94a..58c89a8db1d1 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/preferences/HeaderFragment.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/preferences/HeaderFragment.kt @@ -33,9 +33,13 @@ import com.ichi2.compat.CompatHelper import com.ichi2.preferences.HeaderPreference import com.ichi2.utils.AdaptionUtil -class HeaderFragment : PreferenceFragmentCompat() { +class HeaderFragment : PreferenceFragmentCompat(), TitleProvider { private var selectedHeaderPreference: HeaderPreference? = null private var selectedHeaderPreferenceKey: String = DEFAULT_SELECTED_HEADER + + override val title: CharSequence + get() = getString(R.string.settings) + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { setPreferencesFromResource(R.xml.preference_headers, rootKey) @@ -88,11 +92,6 @@ class HeaderFragment : PreferenceFragmentCompat() { highlightHeaderPreference(requirePreference(selectedHeaderPreferenceKey)) } - override fun onStart() { - super.onStart() - requireActivity().setTitle(R.string.settings) - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) // use the same fragment container to search in case there is a navigation container diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/preferences/Preferences.kt b/AnkiDroid/src/main/java/com/ichi2/anki/preferences/Preferences.kt index 32f60ea10a5f..fcc98fb2c877 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/preferences/Preferences.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/preferences/Preferences.kt @@ -43,12 +43,6 @@ class Preferences : PreferenceFragmentCompat.OnPreferenceStartFragmentCallback, SearchPreferenceResultListener { - override fun onTitleChanged(title: CharSequence?, color: Int) { - super.onTitleChanged(title, color) - findViewById(R.id.collapsingToolbarLayout)?.title = title - supportActionBar?.title = title - } - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.preferences) @@ -69,6 +63,10 @@ class Preferences : val isAtTop = viewHolder != null && viewHolder.itemView.top >= 0 findViewById(R.id.appbar).setExpanded(isAtTop, false) } + + val title = if (fragment is TitleProvider) fragment.title else "" + findViewById(R.id.collapsingToolbarLayout)?.title = title + supportActionBar?.title = title } } @@ -150,6 +148,10 @@ class Preferences : } } +interface TitleProvider { + val title: CharSequence +} + /* Only enable AnkiDroid notifications unrelated to due reminders */ const val PENDING_NOTIFICATIONS_ONLY = 1000000 diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/preferences/SettingsFragment.kt b/AnkiDroid/src/main/java/com/ichi2/anki/preferences/SettingsFragment.kt index a21ee9edb8c6..a517e639dcaf 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/preferences/SettingsFragment.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/preferences/SettingsFragment.kt @@ -37,12 +37,16 @@ import kotlin.reflect.jvm.jvmName abstract class SettingsFragment : PreferenceFragmentCompat(), OnPreferenceTreeClickListener, - SharedPreferences.OnSharedPreferenceChangeListener { + SharedPreferences.OnSharedPreferenceChangeListener, + TitleProvider { /** @return The XML file which defines the preferences displayed by this PreferenceFragment */ @get:XmlRes abstract val preferenceResource: Int + override val title: CharSequence + get() = preferenceManager?.preferenceScreen?.title ?: "" + /** * Refreshes all values on the screen * Call if a large number of values are changed from one preference. @@ -102,7 +106,6 @@ abstract class SettingsFragment : override fun onStart() { super.onStart() - requireActivity().title = preferenceScreen.title PreferenceManager.getDefaultSharedPreferences(requireContext()) .registerOnSharedPreferenceChangeListener(this) }