-
Notifications
You must be signed in to change notification settings - Fork 554
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
Fix part of #1633: Removed view dependency from ProfileEditViewModel #1925
Fix part of #1633: Removed view dependency from ProfileEditViewModel #1925
Conversation
- Used MutableLiveData to store the value of ProfileEditActivity Title and then expose it using a livedata variable in profleEditViewModel class - Observe the livedata variable to set ProfileEditActivity Title in ProfileEditActivityPresenter class
@alokbharti you must ask for a review from any of the code maintainers else your PR will be noticed late. Like |
@Arjupta I already know this but I was waiting for the checks to be finished. |
@rt4914 PTAL |
@@ -27,6 +25,9 @@ class ProfileEditViewModel @Inject constructor( | |||
|
|||
lateinit var profileName: String | |||
|
|||
private val _activityTitle = MutableLiveData<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.
As per I understand from the issue and this committed file, we have to work on Switch
.
@miaboloix Could you please correct me here?
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.
@anandwana001 you might need to approach @miaboloix directly w.r.t. this.
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.
@anandwana001 is correct, though there are actually two issues with this view model:
- It relies on a view directly (the
Switch
--view models should not depend on views) - It relies on Activity, but its lifecycle is managed by AndroidX's ViewModelProvider which means it will leak references to the previous activity during configuration changes
#1633 is meant to fix (1), but if possible we should also fix (2) while here. The way we've been fixing (2) everywhere else is just by injecting the view model directly into the presenter rather than using ViewModelProvider.
@alokbharti you'll need to figure out a way to make (1) work--we don't want to depend on Switch
which may require introducing a callback interface or a live data from this view model.
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.
Hi @BenHenning , thanks for the suggestions. I'll fix those issues one by one for this viewmodel. For now, as suggested I'm doing the changes for the switch part.
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.
Thanks. While here, can you also do (2)? All that's needed is to switch the presenter from using ModelViewProvider to injecting the view model directly. There aren't straightforward tests that we can add for this, so we'll rely on existing tests to pass.
Also, I have assigned this PR to @BenHenning too as I am not completely sure about this solution yet. |
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.
Thanks @alokbharti! Left some thoughts.
@@ -27,6 +25,9 @@ class ProfileEditViewModel @Inject constructor( | |||
|
|||
lateinit var profileName: String | |||
|
|||
private val _activityTitle = MutableLiveData<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.
@anandwana001 is correct, though there are actually two issues with this view model:
- It relies on a view directly (the
Switch
--view models should not depend on views) - It relies on Activity, but its lifecycle is managed by AndroidX's ViewModelProvider which means it will leak references to the previous activity during configuration changes
#1633 is meant to fix (1), but if possible we should also fix (2) while here. The way we've been fixing (2) everywhere else is just by injecting the view model directly into the presenter rather than using ViewModelProvider.
@alokbharti you'll need to figure out a way to make (1) work--we don't want to depend on Switch
which may require introducing a callback interface or a live data from this view model.
- Added a livedata variable to expose the checked state of switch in ProfileViewModel through which ProfileEditActivityPresenter can observe and update the UI accordingly - Removed switch variable initialization from viewmodel - Added activity dependeny as it was before
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.
Thanks @alokbharti! Left two comments. I noticed that your PR description is out-of-date--could you update that to reflect the changes in this PR?
Also to confirm, have you manually tested the app with these changes to make sure that the profile switch still works correctly?
Further, can you please also verify or add tests to make sure the switch functionality is working correctly after the changes from this PR?
private lateinit var switch: Switch | ||
|
||
private val _isAllowedDownloadAccess = MutableLiveData<Boolean>() | ||
val isAllowedDownloadAccess: LiveData<Boolean> = _isAllowedDownloadAccess |
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.
Public members of a class should have documentation. See https://developer.android.com/kotlin/style-guide#usage and https://developer.android.com/kotlin/style-guide#documentation.
@@ -27,6 +25,9 @@ class ProfileEditViewModel @Inject constructor( | |||
|
|||
lateinit var profileName: String | |||
|
|||
private val _activityTitle = MutableLiveData<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.
Thanks. While here, can you also do (2)? All that's needed is to switch the presenter from using ModelViewProvider to injecting the view model directly. There aren't straightforward tests that we can add for this, so we'll rely on existing tests to pass.
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.
Apologies, I meant to select 'request changes' in the last review.
Thanks @BenHenning , I've tested the app manually & using talkback and It's working correctly. I'll add the second part too in the next commit i.e. changes for activity title and will update the PR. |
- Removed activity variable from ProfileViewModel, as we can simply use existing profile livedata variable to update the title of the ProfileEditActivity in the ProfileEditActivityPresenter - Instead of using viewModelProvider in ProfileEditActivityPresenter to get viewmodel, now it is directly injected - Since viewmodel can survive configuration changes, there is no need to create an extra variable to store profile name to use it in onRestoreInstanceState - Added comments for public variable in ProfileEditViewModel
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.
nit change.
app/src/sharedTest/java/org/oppia/android/app/settings/profile/ProfileEditActivityTest.kt
Outdated
Show resolved
Hide resolved
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.
LGTM, Thanks @alokbharti
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.
LGTM, thanks.
@anandwana001 Please resolve your comment threads. Also if you find any comment which I have not resolved feel free to add me again. @alokbharti We will have to wait for @BenHenning review on this as the merging is blocked. Mostly by End of this month. |
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.
Thanks @alokbharti! Really nice improvements to the tests.
Left a couple of comments, but the PR overall LGTM.
@alokbharti If you are looking for another approval from Ben. Please assign him this PR. Thanks. |
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.
Thanks @alokbharti, LGTM!
@Sarthak2601 I'm not seeing your comments for some reason, so going ahead and merging this. Please follow-up with an issue if you have any additional requests for this implementation. |
Explanation
This PR fixes part of #1633
Fixes part of #1870
This PR contains following changes:
Following tests are done to ensure that everything is working as it was before
Update
Roboelectric

Espresso

Checklist