-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: added UI wrapper for localized auth error messages #22
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
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.
Pull request overview
This PR refactors authentication error handling to support localization by introducing a UIText wrapper class. The changes enable error messages to be displayed in the user's language while maintaining flexibility for dynamic error content.
Changes:
- Introduced a UIText sealed class to handle both string resources and dynamic strings
- Updated LoginUiState.Error to use UIText instead of raw String
- Added localized error message string resources for authentication failures
- Modified LoginFragment to resolve UIText to displayable strings using asString()
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| app/src/main/java/net/ardevd/tagius/core/ui/UIText.kt | New sealed class providing abstraction for localized and dynamic strings |
| app/src/main/java/net/ardevd/tagius/features/auth/viewmodel/LoginUiState.kt | Changed Error state to use UIText; updated error handling to use localized resources |
| app/src/main/java/net/ardevd/tagius/features/auth/ui/LoginFragment.kt | Updated error handling to resolve UIText to strings using asString() |
| app/src/main/res/values/strings.xml | Added four new localized error message strings for authentication failures |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } catch (e: IOException) { | ||
| // Network Errors (DNS, Connection Refused, Timeout) | ||
| _uiState.value = LoginUiState.Error("Could not connect to server. ${e.message}", ErrorField.URL) | ||
| emitError(UIText.StringResource(R.string.error_connection_failed), ErrorField.URL) |
Copilot
AI
Jan 25, 2026
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.
The previous error message included the exception details (e.message), which could provide valuable debugging information to users. The new localized message removes this context. Consider adding the exception message as a format parameter to the string resource, or falling back to DynamicString if you want to preserve the original exception message for debugging purposes.
| emitError(UIText.StringResource(R.string.error_connection_failed), ErrorField.URL) | |
| emitError( | |
| UIText.DynamicString(e.localizedMessage ?: "Connection failed"), | |
| ErrorField.URL | |
| ) |
| class StringResource( | ||
| @StringRes val resId: Int, | ||
| vararg val args: Any // Allows for format arguments like "Error: %d" | ||
| ) : UIText() |
Copilot
AI
Jan 25, 2026
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.
Consider making StringResource a data class for consistency with DynamicString. This would provide automatic equals(), hashCode(), and toString() implementations, which could be useful if these objects are ever compared or used in collections. Since vararg parameters cannot be used in data class constructors directly, you could convert the vararg to a regular Array parameter: data class StringResource(@stringres val resId: Int, val args: Array<out Any> = emptyArray())
| class StringResource( | |
| @StringRes val resId: Int, | |
| vararg val args: Any // Allows for format arguments like "Error: %d" | |
| ) : UIText() | |
| data class StringResource( | |
| @StringRes val resId: Int, | |
| val args: Array<out Any> = emptyArray() // Allows for format arguments like "Error: %d" | |
| ) : UIText() { | |
| constructor( | |
| @StringRes resId: Int, | |
| vararg args: Any | |
| ) : this(resId, args) | |
| } |
No description provided.