Skip to content

Instantly share code, notes, and snippets.

@HanCheng
Last active August 29, 2015 14:09
Show Gist options
  • Select an option

  • Save HanCheng/d2663c085a473e6a0f61 to your computer and use it in GitHub Desktop.

Select an option

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