SettingsActivity: remove from parent instead of fixed screen

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2020-03-22 01:23:23 -06:00
parent 38c360cb74
commit 7dae94976d

View File

@ -77,8 +77,10 @@ class SettingsActivity : ThemeChangeAwareActivity() {
class SettingsFragment : PreferenceFragmentCompat() { class SettingsFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, key: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, key: String?) {
addPreferencesFromResource(R.xml.preferences) addPreferencesFromResource(R.xml.preferences)
val screen = preferenceScreen if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) screen.removePreference(preferenceManager.findPreference("dark_theme")) val darkTheme = preferenceManager.findPreference<Preference>("dark_theme")
darkTheme?.parent?.removePreference(darkTheme)
}
val wgQuickOnlyPrefs = arrayOf( val wgQuickOnlyPrefs = arrayOf(
preferenceManager.findPreference("tools_installer"), preferenceManager.findPreference("tools_installer"),
preferenceManager.findPreference("restore_on_boot"), preferenceManager.findPreference("restore_on_boot"),
@ -89,21 +91,21 @@ class SettingsActivity : ThemeChangeAwareActivity() {
if (backend is WgQuickBackend) { if (backend is WgQuickBackend) {
wgQuickOnlyPrefs.forEach { it.isVisible = true } wgQuickOnlyPrefs.forEach { it.isVisible = true }
} else { } else {
wgQuickOnlyPrefs.forEach { screen.removePreference(it) } wgQuickOnlyPrefs.forEach { it.parent?.removePreference(it) }
} }
} }
val moduleInstaller = preferenceManager.findPreference<Preference>("module_downloader") val moduleInstaller = preferenceManager.findPreference<Preference>("module_downloader")
val kernelModuleDisabler = preferenceManager.findPreference<Preference>("kernel_module_disabler") val kernelModuleDisabler = preferenceManager.findPreference<Preference>("kernel_module_disabler")
moduleInstaller?.isVisible = false moduleInstaller?.isVisible = false
if (ModuleLoader.isModuleLoaded()) { if (ModuleLoader.isModuleLoaded()) {
screen.removePreference(moduleInstaller) moduleInstaller?.parent?.removePreference(moduleInstaller)
} else { } else {
screen.removePreference(kernelModuleDisabler) kernelModuleDisabler?.parent?.removePreference(kernelModuleDisabler)
Application.getAsyncWorker().runAsync(Application.getRootShell()::start).whenComplete { _, e -> Application.getAsyncWorker().runAsync(Application.getRootShell()::start).whenComplete { _, e ->
if (e == null) if (e == null)
moduleInstaller?.isVisible = true moduleInstaller?.isVisible = true
else else
screen.removePreference(moduleInstaller) moduleInstaller?.parent?.removePreference(moduleInstaller)
} }
} }
} }