-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add mechanism to listen for general settings changes #8763
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is solving the callaback issue, but ties the implementation to GeneralSettingsManager
exclusively. I think it would make sense to extract the notification logic and make that available for use in feature configurations too. So it plays nicely with #8735
|
||
override fun addListener(listener: GeneralSettingsChangeListener) { | ||
listeners.add(listener) | ||
} | ||
|
||
override fun removeListener(listener: GeneralSettingsChangeListener) { | ||
listeners.remove(listener) | ||
} | ||
|
||
private fun notifyListeners() { | ||
for (listener in listeners) { | ||
listener.onGeneralSettingsChanged() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would make sense to extract this into it's own class to allow reuse in feature configurations to avoid the need to always depend on GeneralSettingsManager
when interested in change notifications.
@@ -0,0 +1,5 @@ | |||
package app.k9mail.legacy.preferences | |||
|
|||
fun interface GeneralSettingsChangeListener { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be more generic like SettingsChangeListener
and onSettingsChanged()
|
||
fun addListener(listener: GeneralSettingsChangeListener) | ||
fun removeListener(listener: GeneralSettingsChangeListener) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See above, could be part of a specialized class to handle listener registration.
This is meant to be a small improvement to the current situation, not a proper solution to the settings problem. Right now there's no way for feature modules to retrieve general settings without depending on either For a proper solution I think we will want to have a low-level settings store that feature modules can use to store and retrieve their settings (both general and account settings). Once we have that, I think it makes sense for this settings store to also contain the listener mechanism and not have it be separate. I don't see a situation where some code wants to be notified about settings changes, but not also retrieve the new settings. interface SettingsStore {
fun getInt(key: String): Int
fun setInt(key: String, value: Int)
fun getString(key: String): String
fun setString(key: String, value: String)
// …
fun addListener(listener: SettingsChangeListener)
fun removeListener(listener: SettingsChangeListener)
// Probably also a mechanism to change more than one setting at once
} However, that's a much more complex change that requires deeper architectural changes. I think this PR fixes an immediate problem and only introduces code that should be fairly straight-forward to adapt to a proper solution in the future. Note: I added the listening mechanism to |
I thought about implementing a Publish-Subscribe (Pub/Sub) pattern to decouple the producer and consumer of settings change events, enabling individual registration of feature configurations. I'll create a pull-request for this. Yes, it should be part of the |
Use that mechanism to update the drawer when any of the
DrawerConfig
settings are changed.