-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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: introduce a view model in ManageNotetypes #17804
base: main
Are you sure you want to change the base?
Conversation
Encapsulates a loading dialog like we use in withProgress {} into a fragment so it can be handled in transactions and react to restores.
Improves the documentation. Removes the internal keyword, only useful if we would actually used modules/libraries. The rename was done to better integrate with the changes for transitioning to a view model in ManageNotetypes.
The implemented viewmodel follows the official recommendations by implementing UDF(unidirectional data flow): user events go to the viewmodel and the viewmodel exposes states consumed by the ui. Not all actions in ManageNotetypes are done in the style of the reactive ManageNotetypeViewModel(delete/rename + the actions in AddNewNotetype).
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.
One apparent issue with error handling, rest of the code looks great
And a few nits
private val _uiState = MutableStateFlow(NotetypesUiState()) | ||
val uiState: StateFlow<NotetypesUiState> = _uiState.asStateFlow() |
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 action needed, comment only]
I prefer exposing the mutable Flow, instead of the additional boilerplate
) | ||
} | ||
} | ||
_uiState.update { state -> |
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.
Either an error in this method, or if callers don't call this method
AnkiDroid/src/main/java/com/ichi2/anki/notetype/ManageNotetypeViewModel.kt
Show resolved
Hide resolved
} | ||
|
||
/** | ||
* Refreshes the list of notetypes, additionally filtering the list. Also calls to emit the new |
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.
'emit the new' feels like it's a truncated sentence
AnkiDroid/src/main/java/com/ichi2/anki/notetype/ManageNotetypeViewModel.kt
Show resolved
Hide resolved
I'll use a LinearProgressDialog for this comment: the padding on the dialog should be a little larger |
Purpose / Description
A bit more info in the commit message. The line count is big but it's mostly comments, copyright etc the actual code should be easy to read. Did this in one go as changing step by step into a view model would have introduced even more useless changes to review.
How the loading indicator looks:
How Has This Been Tested?
Ran the tests, manually verified the app.
Checklist