-
Notifications
You must be signed in to change notification settings - Fork 29
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
Conversation
I feel this is ready for review now :) |
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? |
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. |
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: There is an example in another app that I wrote here: 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? |
That makes sense, especially because you need to manually focus the search bar anyway. I'll take a look at that. |
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? |
I looked into how to test this a little. In the test, retrieving the menu item SearchView is straight forward:
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? |
Sounds like a plan, I'll try my best. Quite new to Android so may take me some time |
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 :( |
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:
then pass the listener along:
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. |
Oh, there were a few small comments about the implementation. Could you resolve those? Then I'll accept the branch. |
0a9611e
to
5a898b4
Compare
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. |
Thanks for contributing this feature! |
Fixes #278