-
Notifications
You must be signed in to change notification settings - Fork 2
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
Inject view model on activity #23
Conversation
tvSortByName.setOnClickListener { | ||
// viewModel.sortByName() | ||
private fun initializeAdapter() { | ||
if (filesAdapter == null) { |
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 could be an early return. That would help reduce the indentation levels
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 think in this particular case, an early return will not reduce indentation levels. It would be something like:
if(filesAdapter != null) {
return
} else {
filesAdapter = FileGridAdapter(this)
with(binding.filesRecyclerView) {
layoutManager = GridLayoutManager(this@FileViewerActivity, 2)
adapter = filesAdapter
}
}
which basically is the same
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.
Not really, that's not an early return. It would look something like this:
if (filesAdapter != null) {
return
}
filesAdapter = FileGridAdapter(this)
with(binding.filesRecyclerView) {
layoutManager = GridLayoutManager(this@FileViewerActivity, 2)
adapter = filesAdapter
}
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 think in general use inverse logic in a conditional makes code less readable than just do a straight comparison.
Anyway, i applied the suggested change 😃
done ✅
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 disagree. Early returns serve as precondition checks that show you what would stope the code from running in the first place. If you would have multiple validations, they would all go first and show you all the failure cases for the function.
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.
yeah, i'm ok with early returns. I mean about use inverse logic. I think is more readable use if(boolean)
instead if(!boolean)
.../src/main/java/com/omh/android/storage/sample/presentation/file_viewer/FileViewerActivity.kt
Show resolved
Hide resolved
storage-sample/src/main/java/com/omh/android/storage/sample/presentation/BaseViewModel.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
Added code for perform injection of the view model into the FileViewerActivity
In this PR you will find:
Evidence: