Skip to content

Instantly share code, notes, and snippets.

@HanCheng
Last active August 29, 2015 14:09
Show Gist options
  • Save HanCheng/d2663c085a473e6a0f61 to your computer and use it in GitHub Desktop.
Save HanCheng/d2663c085a473e6a0f61 to your computer and use it in GitHub Desktop.
changing the filter to remain active if do same search
1. In FlightSearchFormActivity, line FilterActivity.resetFilter() replaced with:
if (mFlightSearch == null || !isSameFlightSearch(mFlightSearch, mFile)) {
FiltersActivity.resetFilters();
}
2. isSameFlightSearch(FlightSearch flightSearch, File file) is defined in Utils file. I was trying to make this method
do less calculation in UI thread, so another way is create an AsyncTask, as we did in SaveFlightSearchTask.java
http://stackoverflow.com/questions/12575068/how-to-get-the-result-of-onpostexecute-to-main-activity-because-asynctask-is-a
public static boolean isSameFlightSearch(FlightSearch flightSearch, File file) {
if (flightSearch.isValid() && file != null) {
return flightSearch.equals(flightSearchFromFile(file.getPath()));
}
return false;
}
3. In FlightSearchFormActivity changed the local variable file into private member variable, named mFile.
4. Added unit test in Utils
testIsSameFlightSearchReturnsTrueIfSameFlightSearchIsPerformed()
testIsSameFlightSearchReturnsFalseIfNewFlightSearchIsPerformed()
testIsSameFlightSearchReturnsFalseIfFlightSearchIsNotValid()
testIsSameFlightSearchReturnsFalseIfDifferentFilePath()
5. Added integration test in FlightSearchFormActivityTest
testToVerifyPerformingSameSearchWillKeepAllSelectedFilters()
testToVerifyPerformingNewSearchWillResetAllFilters()
@ksarmalkar
Copy link

You don't need to read from file and add any async task. Just have old flight search object in memory and compare it with new flight search. No need to add extra util method. Just oldFlightSearch.equals(newFlightSearch) should do it.

@HanCheng
Copy link
Author

Yeah! That's much better! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment