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

Add loyalty card filter #320

Merged
merged 13 commits into from
Nov 29, 2019
Merged

Conversation

TheLastProject
Copy link
Contributor

@TheLastProject TheLastProject commented Nov 22, 2019

Fixes #278

Screenshot_1574440421
Screenshot_1574440423
Screenshot_1574452072

@TheLastProject TheLastProject changed the title WIP: Add loyalty card filter Add loyalty card filter Nov 22, 2019
@TheLastProject
Copy link
Contributor Author

I feel this is ready for review now :)

@brarcher
Copy link
Owner

Thanks for proposing some changes for this feature!

To help me in keeping this feature alive (and preventing breakage), are there new Robolectric tests which you could add to test the feature?

@TheLastProject
Copy link
Contributor Author

I've added a filtering test and addressed your other comments. I believe I have hereby addressed all your concerns. Please tell me if there's anything else you feel needs changing.

@brarcher
Copy link
Owner

Tests look good, I appreciate it.

I loaded this onto a device to try it out. I've question about the search bar and when it is viewable. One pattern I've seen in other application is to have a menu item for search, that when clicked opens the search box. An example is in this tutorial:

https://youtu.be/9OWmnYPX1uc?t=57

I do not think that the search interface needs to be as complex that as that example. Maybe only hide the search bar until the search icon is clicked, then let it fill the app bar:

Screen Shot 2019-11-23 at 9 23 43 AM

Screen Shot 2019-11-23 at 9 23 54 AM

There is an example in another app that I wrote here:

https://github.com/brarcher/budget-watch/blob/master/app/src/main/java/protect/budgetwatch/TransactionActivity.java#L109

The relevant part of that example is setting up the search view in onCreateOptionsMenu(). The way your search filters the list on each character should be fine.

What do you think?

@TheLastProject
Copy link
Contributor Author

That makes sense, especially because you need to manually focus the search bar anyway. I'll take a look at that.

@TheLastProject
Copy link
Contributor Author

I've switched to using a SearchView, which indeed looks much better. Sadly, I can't figure out how to make the tests work at all. Got any pointers on how to send something to the search input?

@brarcher
Copy link
Owner

I looked into how to test this a little. In the test, retrieving the menu item SearchView is straight forward:

final Menu menu = shadowOf(mainActivity).getOptionsMenu();
MenuItem searchItem = menu.findItem(R.id.action_search);
searchItem.expandActionView();
SearchView searchView = (SearchView) searchItem.getActionView();

The tricky part is getting the query text listener. There is no getOnQueryTextListener() method on SearchView. If one had the listener, one could call its methods directly and simulate text input and check that it causes the correct response, namely that the card list is properly filtered.

To get at the listener, one approach is to make a Shadow.

http://robolectric.org/extending/

There is no Shadow of SearchView. One could create a simple one that only intercepted the setOnQueryTextListener() call and saved the result, then provided the result in the test.

How do you feel about creating a small Shadow for SearchView and adding it in a separate file along with the tests?

@TheLastProject
Copy link
Contributor Author

Sounds like a plan, I'll try my best. Quite new to Android so may take me some time

@TheLastProject
Copy link
Contributor Author

I made an attempt in 691497e but no matter how much I try I can't get it to work. It does seem to use the shadow class, but I just get a NullPointerException now during onCreateOptionsMenu :(

@brarcher
Copy link
Owner

I gave it an attempt as well, starting from your efforts. I find that when the SearchView shadow is being used the menu item no longer has its action view. This is the reason for the NullPointerException. Tinkering with it and looking online I could not figure out why this is the case.

Although it does not fix this issue, I think your shadow was close. In order to send the listener to the real object, one would need a reference to the real object:

@RealObject private SearchView realSearchView;

then pass the listener along:

@Implementation
    protected void setOnQueryTextListener(SearchView.OnQueryTextListener listener) {
        onQueryTextListener = listener;
        realSearchView.setOnQueryTextListener(listener);
    }

You gave it a shot, and I appreciate that. Go ahead and remove the last few test commits, and I'll accept the pull request.

@brarcher
Copy link
Owner

Oh, there were a few small comments about the implementation. Could you resolve those? Then I'll accept the branch.

@TheLastProject
Copy link
Contributor Author

I addressed your comments and I added a "filter" variable to persist the filter through resuming and so we can have some tests anyway. I have also tested manually to make sure that change didn't cause any regressions.

@brarcher brarcher merged commit ed4adad into brarcher:master Nov 29, 2019
@brarcher
Copy link
Owner

Thanks for contributing this feature!

@TheLastProject TheLastProject deleted the feature/card_filter branch October 24, 2020 12:03
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.

Add search feature
2 participants