-
Notifications
You must be signed in to change notification settings - Fork 604
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: Update identifiers list on adding or removing items #743
Conversation
e83f15f
to
11639a7
Compare
|
||
void onClientIdentifierCreationSuccess(); | ||
|
||
void onClientIdentifierCreationFailure(); |
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.
Amazing 😀 That you care about failures and not just success.
@@ -52,6 +52,8 @@ | |||
@Inject | |||
IdentifierDialogPresenter mIdentifierDialogPresenter; | |||
|
|||
ClientIdentifierCreationListener clientIdentifierCreationListener; |
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.
Can this be private
and also @Nullable
since I see you are doing a null check below.
@@ -52,6 +52,8 @@ | |||
@Inject | |||
IdentifierDialogPresenter mIdentifierDialogPresenter; | |||
|
|||
ClientIdentifierCreationListener clientIdentifierCreationListener; | |||
|
|||
View rootView; |
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.
View should be private
even if this is not your change, please do it since we've spotted the problem in this review.
@@ -130,16 +132,34 @@ public void showUserInterface() { | |||
public void showClientIdentifiers(List<Identifier> identifiers) { | |||
this.identifiers = identifiers; | |||
identifierListAdapter.setIdentifiers(identifiers); | |||
identifierListAdapter.notifyDataSetChanged(); |
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 a bad way of handling changes on a recycler view. I'd recommend reading Google's Documentation about RecyclerView.
Hint : You should almost never call notifyDataSetChanged()
method on a RecyclerView's Adapter. There are other methods available for addition, modification, removal etc.
Also read about DiffUtils
and try to use that here.
I am aware we use this bad approach all across the app but this is the time you learn and do it and set a precedence for the future devs so we can just point them to your code and they can learn from it.
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 read about DiffUtils
and if I understood it well, it's a good option to juxtapose two lists. In our case, however, we are sure of either 'adding' or 'removing' a single identifier. How about we have a method in the adapter to add (or remove the identifier) and then update the adapter accordingly? Or is DiffUtils
a better option?
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 agree with you ! DiffUtils
is not relevant for our case. However I just wanted to you to know about it :) It is optimized for large operations in our case we won't have very large lists to play with. You can even copy new lists to old ones :P
However since we know about additions and deletions we can use more precise methods than just notifyDataSetChanged()
Makes sense ?
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.
Yes. Used notifyItemInserted(position)
and notifyItemRemoved(position)
methods now and saved some bandwidth. :P
|
||
@Override | ||
public void onClientIdentifierCreationFailure() { | ||
|
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 Nasty !! 😡 An Empty Stub Method pushed sent in a PR that does nothing. WHY is it not implemented ?
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.
Sorry! It was handled in the dialogfragment too. Nevertheless, I edited and implemented in a better way now.
ll_error.setVisibility(View.VISIBLE); | ||
mNoIdentifierText.setText(getResources().getString(R.string.no_identifier_to_show)); | ||
mNoIdentifierIcon.setImageResource(R.drawable.ic_assignment_turned_in_black_24dp); | ||
} | ||
|
||
@Override | ||
public void onClientIdentifierCreationSuccess() { | ||
loadIdentifiers(); |
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.
Why do you want to retrieve all the identifiers again, when you create a new Identifier ? You have most of the data already that you POST
, you'll get some stuff from the server in the response like ID or whatever that the server is responsible for generating. Why don't you just push that stuff into your list ?
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! I never noticed this tbh. Implemented it this way.
@@ -187,4 +195,8 @@ public void onItemSelected(AdapterView<?> parent, View view, int position, long | |||
public void onNothingSelected(AdapterView<?> parent) { | |||
|
|||
} | |||
|
|||
public void setOnClientIdentifierCreationListener(ClientIdentifierCreationListener listener) { |
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.
@Nullable
annotation missing.
50455a2
to
877b44c
Compare
*/ | ||
public Observable<GenericResponse> createClientIdentifier(int clientId, | ||
IdentifierPayload identifierPayload) { | ||
public Observable<IdentifierCreationResponse> createClientIdentifier( |
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.
@tarun0 don't need to create new Model, It's generic response that's why @droidchef made it. It is making more sense.
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.
@therajanmaurya We are not fetching the identifiers list again. We are retrieving the created identifier's id from the response based on the discussion with @droidchef That's why I changed it.
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.
@droidchef Will it be a better approach to check if the GenericResponse
got resourceId
and similar values that we want to check and then proceed accordingly? You once told about the naming and readability. I created the new model following those lines.
*/ | ||
@POST(APIEndPoint.CLIENTS + "/{clientId}/identifiers") | ||
Observable<GenericResponse> createClientIdentifier(@Path("clientId") int clientId, | ||
@Body IdentifierPayload identifierPayload); | ||
Observable<IdentifierCreationResponse> createClientIdentifier( |
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.
same as above
@tarun0 Please fix the conflicts. |
Fix #658
Apply the
MifosStyle.xml
style template to your code in Android Studio.Run the unit tests with
./gradlew check
to make sure you didn't break anythingIf you have multiple commits please combine them into one commit by squashing them.