Skip to content
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

Love it! But a couple of questions #3

Open
DaveOddy opened this issue Oct 12, 2022 · 1 comment
Open

Love it! But a couple of questions #3

DaveOddy opened this issue Oct 12, 2022 · 1 comment

Comments

@DaveOddy
Copy link

Three questions:

  • Is it possible to add any kind of validation to EditTextPref to make sure invalid data doesn't make its way into the data store? For example, I want to make sure only positive integers are added. I also want to validate one value against another (one must always be greater than the other).

  • What's the best way to show the current value of an EditTextPref? I want to make sure the current value is visible without having to click into the edit dialog.

  • Is it possible to separate the DataStore connection so that the library can provide UI only and allow for a custom ViewModel?

Thanks - great work on this!!

@JamalMulla
Copy link
Owner

JamalMulla commented Oct 13, 2022

Hello,

  • I don't think it would be too difficult to add validation. There is a callback called onValueChange which fires every time the value changes. You could possibly do some validation based on that? Not 100% sure though. I'd have to look into it a bit more.
  • Something like this would probably work although I haven't tested it:
var current by remember { mutableStateOf("") }
...
EditTextPref(
    key = "et1",
    title = "EditText example",
    summary = current,
    onValueChange = {newVal -> current= newVal}
)
  • Yes it would be possible but probably a fair bit of work. I urge you to give it a try though. I'm very open to PRs.

As it's probably quite clear I am not actively working on ComposePrefs anymore. The library works for what it was meant for and I don't have the time to actively maintain it. I would be glad to see more external contributions though.

Jamal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants