Maxr1998 / ModernAndroidPreferences

Android Preferences defined through Kotlin DSL, shown in a RecyclerView

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to specify a summary that contains the current value of the preference

sztanpet opened this issue · comments

Hi, great library!
I am trying to specify a summary for preferences that always have the current value of the preference formatted by a custom formatter. My usecase for this is a preference that opens a dialog window with a NumberPicker. I want to be nice and show the currently set value. For consistency, I would also like to do that for everything else too, like for seekbars which would mean hiding the built-in value display.
Is it possible somehow?
Thanks!

Generally, if you get a new value for a preference, you can just set it to its summary and requestRebind() on it.
For SeekBarPreferences however, there is actually a optional formatter field where you can specify an (Int) -> String function that formats your current value.
If you want to hide the default output for the seekbar, you can just set the formatter to always return an empty string. I hope that's what you were asking, if not, just let me know.

Setting the formatter for the seekbar worked perfectly, but how do I get the new values for the preferences? Do I have to do that outside of the DSL?

That's a valid concern, I should've added a listener like I did for the other preference types.. I'll open a separate issue for that.

This was implemented a while ago already and can thus be closed.