Milestone5#3
Conversation
| .setTitle("Choose the filtering options:") | ||
| .setView(com.example.assignment.R.layout.view_sort_dialog) | ||
| .setPositiveButton( | ||
| "Apply" |
There was a problem hiding this comment.
Don't use hardcoded strings, use string resources instead.
There was a problem hiding this comment.
This is not addressed yet.
There was a problem hiding this comment.
In commit resolve milestone5 comments
It has been changed to R.string.main_dialogue_title but back to "Choose the filtering options:" in milestone 6 in the latest commit "repository with internal storage for data persistence". Will check all comments in miletone1-milestone5 in milestone6's code.
|
|
||
| if (radioAscendingButton.isChecked) { | ||
| when (compareText) { | ||
| "Mass" -> sortList = viewModel.meteors.value?.sortedBy { it.mass }?.toList() ?: emptyList() |
There was a problem hiding this comment.
Part of his logic belongs in the ViewModel. This function should be responsible for handling the click event (by looking at the ID of the selected item), and then calling the ViewModel to inform it that a sorting has happened. You can consider introducing a sort type enum: this function would call the ViewModel with something like sortingSelected(SortType.MASS), and the sortingSelected()function in the ViewModel then updates the list throughsortedBy`, and pass the new list back to the Activity (through LiveData).
| val meteors: LiveData<List<MeteorData>> = _meteors | ||
|
|
||
| init { | ||
| getMeteorsInfo() |
There was a problem hiding this comment.
We discussed this before - this call shouldn't happen on ViewModel class initialisation, but on some kind of Activity life cycle event (e.g. onResume).
| try { | ||
| _meteors.value = MeteorsApi.retrofitService.getMeteorsInfo() | ||
| } catch (e: Exception) { | ||
| _meteors.value = listOf() |
There was a problem hiding this comment.
Consider adding an error state so that the user knows what's going on.
There was a problem hiding this comment.
Did that in milestone 6
|
|
||
| override fun onResume() { | ||
| super.onResume() | ||
| viewModel.refresh() |
There was a problem hiding this comment.
Don't do this, but do https://betterprogramming.pub/empowered-lifecycle-aware-viewmodel-for-android-f495de9a8170 instead (more automatic, and less manual work :))
| meteorDataList.removeAt(pos) | ||
| notifyItemRemoved(pos) | ||
| } | ||
| fun update(data: List<MeteorData>) { |
There was a problem hiding this comment.
Where does this get called?
There was a problem hiding this comment.
Where does this get called?
Milestone1 use MutableList without databinding. Milestone5 uses List so they never get called and removed here.
e5285d3 to
c3b534a
Compare
| val radioAscendingButton = dialog.findViewById<View>(com.example.assignment.R.id.radioAscending) as RadioButton | ||
| val compareText = fieldSpinner.getSelectedItem().toString() | ||
|
|
||
| Hawk.init(this.context).build() |
There was a problem hiding this comment.
A simple key-value storage for android https://github.com/orhanobut/hawk
remove databinding