Skip to content

Commit

Permalink
SettingsActivity: remove from parent instead of fixed screen
Browse files Browse the repository at this point in the history
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
  • Loading branch information
zx2c4 committed Mar 22, 2020
1 parent 38c360c commit 7dae949
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ class SettingsActivity : ThemeChangeAwareActivity() {
class SettingsFragment : PreferenceFragmentCompat() {
override fun onCreatePreferences(savedInstanceState: Bundle?, key: String?) {
addPreferencesFromResource(R.xml.preferences)
val screen = preferenceScreen
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) screen.removePreference(preferenceManager.findPreference("dark_theme"))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
val darkTheme = preferenceManager.findPreference<Preference>("dark_theme")
darkTheme?.parent?.removePreference(darkTheme)
}
val wgQuickOnlyPrefs = arrayOf(
preferenceManager.findPreference("tools_installer"),
preferenceManager.findPreference("restore_on_boot"),
Expand All @@ -89,21 +91,21 @@ class SettingsActivity : ThemeChangeAwareActivity() {
if (backend is WgQuickBackend) {
wgQuickOnlyPrefs.forEach { it.isVisible = true }
} else {
wgQuickOnlyPrefs.forEach { screen.removePreference(it) }
wgQuickOnlyPrefs.forEach { it.parent?.removePreference(it) }
}
}
val moduleInstaller = preferenceManager.findPreference<Preference>("module_downloader")
val kernelModuleDisabler = preferenceManager.findPreference<Preference>("kernel_module_disabler")
moduleInstaller?.isVisible = false
if (ModuleLoader.isModuleLoaded()) {
screen.removePreference(moduleInstaller)
moduleInstaller?.parent?.removePreference(moduleInstaller)
} else {
screen.removePreference(kernelModuleDisabler)
kernelModuleDisabler?.parent?.removePreference(kernelModuleDisabler)
Application.getAsyncWorker().runAsync(Application.getRootShell()::start).whenComplete { _, e ->
if (e == null)
moduleInstaller?.isVisible = true
else
screen.removePreference(moduleInstaller)
moduleInstaller?.parent?.removePreference(moduleInstaller)
}
}
}
Expand Down

0 comments on commit 7dae949

Please sign in to comment.