-
Notifications
You must be signed in to change notification settings - Fork 551
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
refractor: Replace all hard-coded string messages #1272
refractor: Replace all hard-coded string messages #1272
Conversation
Please resolve conflicts |
@iamareebjamal I have resolved merge conflicts, please take a look |
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.
No Android class should be used in ViewModel, including context
@iamareebjamal please take a look, I have updated another solution on extracting resource in ViewModel |
@@ -24,7 +26,7 @@ class AboutEventViewModel(private val eventService: EventService) : ViewModel() | |||
|
|||
fun loadEvent(id: Long) { | |||
if (id.equals(-1)) { | |||
mutableError.value = "Error fetching event" | |||
mutableError.value = OpenEventGeneral.appResource.getString(R.string.error_fetching_event_message) |
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 is still using resources in viewmodel
Easy way to check if you are using resources in ViewModel - Instantiate the ViewModel in a test and run all methods
If the test crashes, you are using Android class in ViewModel
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 understand that now and referencing string resource inside ViewModel is not safe, so I don't find a way to extract those strings inside ViewModel.
And I have read the Android documentation, and it said "if the ViewModel needs the Application context, it can extend the AndroidViewModel class and have a constructor that receives the Application in the constructor". Should I use this technique to extract the hard-coded strings inside the view model into res/values/strings file or I should leave them unextracted?
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.
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.
Use dependency injection
No need to create an object for using each time
month.add(Resource().getString(R.string.september) ?: "September") | ||
month.add(Resource().getString(R.string.october) ?: "October") | ||
month.add(Resource().getString(R.string.november) ?: "November") | ||
month.add(Resource().getString(R.string.december) ?: "December") |
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.
Redundant
<string name="postal_code">Needs translation</string> | ||
<string name="payment_info">Needs translation</string> | ||
<string name="removed_from_liked">Needs translation</string> | ||
<string name="undo">Needs translation</string> |
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.
Remove all of these
Details: - Resolve merge conflicts - Strings are extracted using Resource class Fixes: #1256
All approved PRs beyond this point will be merged after release |
Details:
Fixes #1256