Skip to content
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

Merged
merged 1 commit into from
Mar 7, 2018

Conversation

tarun0
Copy link
Member

@tarun0 tarun0 commented Aug 7, 2017

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 anything

  • If you have multiple commits please combine them into one commit by squashing them.

@tarun0
Copy link
Member Author

tarun0 commented Aug 7, 2017

658

@tarun0 tarun0 force-pushed the fix658 branch 3 times, most recently from e83f15f to 11639a7 Compare August 7, 2017 10:45
@tarun0 tarun0 changed the title fix: Update identifiers list on removing the only item fix: Update identifiers list on adding or removing items Aug 7, 2017

void onClientIdentifierCreationSuccess();

void onClientIdentifierCreationFailure();
Copy link
Member

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;
Copy link
Member

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;
Copy link
Member

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();
Copy link
Member

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.

Copy link
Member Author

@tarun0 tarun0 Aug 8, 2017

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?

Copy link
Member

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 ?

Copy link
Member Author

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() {

Copy link
Member

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 ?

Copy link
Member Author

@tarun0 tarun0 Aug 8, 2017

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();
Copy link
Member

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 ?

Copy link
Member Author

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nullable annotation missing.

@tarun0 tarun0 force-pushed the fix658 branch 3 times, most recently from 50455a2 to 877b44c Compare August 8, 2017 08:51
*/
public Observable<GenericResponse> createClientIdentifier(int clientId,
IdentifierPayload identifierPayload) {
public Observable<IdentifierCreationResponse> createClientIdentifier(
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

@therajanmaurya
Copy link
Member

@tarun0 Please fix the conflicts.

@therajanmaurya therajanmaurya merged commit 1cee4f4 into openMF:master Mar 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants