mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-14 04:35:05 +01:00
Fix extension source toggles not showing up for preferences without custom settings
This commit is contained in:
parent
801568950f
commit
203758dddd
@ -106,9 +106,7 @@ class ExtensionDetailsController(bundle: Bundle? = null) :
|
|||||||
val langauges = preferences.enabledLanguages().get()
|
val langauges = preferences.enabledLanguages().get()
|
||||||
|
|
||||||
for (source in extension.sources.sortedByDescending { it.isLangEnabled(langauges) }) {
|
for (source in extension.sources.sortedByDescending { it.isLangEnabled(langauges) }) {
|
||||||
if (source is ConfigurableSource) {
|
addPreferencesForSource(screen, source, multiSource, isMultiLangSingleSource)
|
||||||
addPreferencesForSource(screen, source, multiSource, isMultiLangSingleSource)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
manager.setPreferences(screen)
|
manager.setPreferences(screen)
|
||||||
@ -187,47 +185,52 @@ class ExtensionDetailsController(bundle: Bundle? = null) :
|
|||||||
context.getSharedPreferences("source_${source.id}", Context.MODE_PRIVATE)
|
context.getSharedPreferences("source_${source.id}", Context.MODE_PRIVATE)
|
||||||
)
|
)
|
||||||
|
|
||||||
if (source is ConfigurableSource) {
|
val prefs = mutableListOf<Preference>()
|
||||||
val prefs = mutableListOf<Preference>()
|
val block: (@DSL SwitchPreferenceCompat).() -> Unit = {
|
||||||
val block: (@DSL SwitchPreferenceCompat).() -> Unit = {
|
key = source.getPreferenceKey()
|
||||||
key = source.getPreferenceKey()
|
title = when {
|
||||||
title = when {
|
isMultiSource && !isMultiLangSingleSource -> source.toString()
|
||||||
isMultiSource && !isMultiLangSingleSource -> source.toString()
|
else -> LocaleHelper.getSourceDisplayName(source.lang, context)
|
||||||
else -> LocaleHelper.getSourceDisplayName(source.lang, context)
|
}
|
||||||
}
|
isPersistent = false
|
||||||
isPersistent = false
|
isChecked = source.isEnabled()
|
||||||
isChecked = source.isEnabled()
|
|
||||||
|
|
||||||
onChange { newValue ->
|
onChange { newValue ->
|
||||||
if (source.isLangEnabled()) {
|
if (source.isLangEnabled()) {
|
||||||
val checked = newValue as Boolean
|
val checked = newValue as Boolean
|
||||||
toggleSource(source, checked)
|
toggleSource(source, checked)
|
||||||
prefs.forEach { it.isVisible = checked }
|
prefs.forEach { it.isVisible = checked }
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
binding.coordinator.snack(context.getString(R.string._must_be_enabled_first, title), Snackbar.LENGTH_LONG) {
|
binding.coordinator.snack(
|
||||||
setAction(R.string.enable) {
|
context.getString(
|
||||||
preferences.enabledLanguages() += source.lang
|
R.string._must_be_enabled_first,
|
||||||
isChecked = true
|
title
|
||||||
toggleSource(source, true)
|
), Snackbar.LENGTH_LONG
|
||||||
prefs.forEach { it.isVisible = true }
|
) {
|
||||||
}
|
setAction(R.string.enable) {
|
||||||
|
preferences.enabledLanguages() += source.lang
|
||||||
|
isChecked = true
|
||||||
|
toggleSource(source, true)
|
||||||
|
prefs.forEach { it.isVisible = true }
|
||||||
}
|
}
|
||||||
false
|
|
||||||
}
|
}
|
||||||
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
// React to enable/disable all changes
|
|
||||||
preferences.hiddenSources().asFlow()
|
|
||||||
.onEach {
|
|
||||||
val enabled = source.isEnabled()
|
|
||||||
isChecked = enabled
|
|
||||||
}
|
|
||||||
.launchIn(viewScope)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// React to enable/disable all changes
|
||||||
|
preferences.hiddenSources().asFlow()
|
||||||
|
.onEach {
|
||||||
|
val enabled = source.isEnabled()
|
||||||
|
isChecked = enabled
|
||||||
|
}
|
||||||
|
.launchIn(viewScope)
|
||||||
|
}
|
||||||
|
|
||||||
|
screen.switchPreference(block)
|
||||||
|
if (source is ConfigurableSource) {
|
||||||
val newScreen = screen.preferenceManager.createPreferenceScreen(context)
|
val newScreen = screen.preferenceManager.createPreferenceScreen(context)
|
||||||
screen.switchPreference(block)
|
|
||||||
source.setupPreferenceScreen(newScreen)
|
source.setupPreferenceScreen(newScreen)
|
||||||
|
|
||||||
// Reparent the preferences
|
// Reparent the preferences
|
||||||
|
Loading…
Reference in New Issue
Block a user