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

feat: start settings page #37

Merged
merged 14 commits into from
Aug 20, 2024
Merged

feat: start settings page #37

merged 14 commits into from
Aug 20, 2024

Conversation

aanorbel
Copy link
Member

@aanorbel aanorbel commented Aug 6, 2024

Closes #26

Proposed changes.

  • Add Settings repository and tests.
  • Implement template for settings page

Sample UI

. . .
Screenshot_20240806_101248 Screenshot_20240806_101304 Screenshot_20240806_101317

@aanorbel aanorbel requested a review from sdsantos August 6, 2024 09:35
@aanorbel aanorbel marked this pull request as ready for review August 16, 2024 14:05
@aanorbel aanorbel requested a review from sdsantos August 19, 2024 11:12
Copy link
Collaborator

@sdsantos sdsantos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only blocking comments are regarding the shared preference names, which should match the previous app (I know our applicationIds are still different, but we'll need to match them as well in the future).

The bigger architecture suggestions could be made in the future, but I think it's an important discussion to have.

return "${prefix?.let { "${it}_" } ?: ""}$name${if (autoRun) "_autorun" else ""}"
}

fun allSettings(keys: List<Preferences.Key<*>>): Flow<Map<String, Any?>> =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This abstraction seems a bit off, but I want to get your feedback on it. We have an enum with all the keys: SettingsKey. But we're not using it in all these methods. We could be doing a allSettings(keys: List<SettingsKey>) for example.

On the other side, it's the responsibility of the users of this class to call the datastore methods like booleanPreferencesKey to actually create the key. Should this class be hiding that? Or maybe a domain class in between to abstract it? In theory we want repositories, or at least the domain layer, to hide implementation details such as DataStore.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see your point.

import platform.Foundation.NSURL
import platform.Foundation.NSUserDomainMask

@OptIn(kotlinx.cinterop.ExperimentalForeignApi::class)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably not needed anymore.

Comment on lines 46 to 50
_state.update { state ->
state.copy(
preference = state.preference?.plus(it.key to it.value),
)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't need to do this. The state should update automatically since you subscribed above to the flow from the preferencesManager.allSettings.

(() -> Unit)? = null,
)

data class SettingsItem(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel this classes should be in separate files, especially because they are not just related with this screen.

return "${prefix?.let { "${it}_" } ?: ""}$name${if (autoRun) "_autorun" else ""}"
}

fun preferenceKeyFromSettingsKey(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If getValueByKey and setValueByKey would use SettingsKey as well, this method could be private.

@aanorbel aanorbel merged commit 99217a5 into main Aug 20, 2024
7 checks passed
@sdsantos sdsantos deleted the issues/26 branch August 20, 2024 13:52
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

Successfully merging this pull request may close these issues.

Multi-platform: Setup preferences in database
2 participants