mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 02:38:47 +00:00
Filtering search results is disabled until there are results to filter
This commit is contained in:
parent
e392820404
commit
33c3d8c56e
@ -27,6 +27,7 @@ import static com.example.listify.MainActivity.am;
|
||||
|
||||
public class SearchResults extends AppCompatActivity implements FilterDialogFragment.OnFilterListener, SortDialogFragment.OnSortListener {
|
||||
private ListView listView;
|
||||
private MenuItem filterItem;
|
||||
private SearchResultsListAdapter searchResultsListAdapter;
|
||||
private List<Product> resultsProductList = new ArrayList<>();
|
||||
private List<Product> resultsProductListSorted = new ArrayList<>();
|
||||
@ -133,7 +134,7 @@ public class SearchResults extends AppCompatActivity implements FilterDialogFrag
|
||||
});
|
||||
|
||||
// TODO: price filter should be disabled until a search is made
|
||||
MenuItem filterItem = menu.findItem(R.id.action_filter);
|
||||
filterItem = menu.findItem(R.id.action_filter);
|
||||
filterItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
@ -173,6 +174,12 @@ public class SearchResults extends AppCompatActivity implements FilterDialogFrag
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// Disable filtering by default until a search is made
|
||||
if (resultsProductList.isEmpty()) {
|
||||
filterItem.setEnabled(false);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -223,6 +230,13 @@ public class SearchResults extends AppCompatActivity implements FilterDialogFrag
|
||||
// Add all results to the sorted list
|
||||
resultsProductListSorted.addAll(resultsProductList);
|
||||
|
||||
// Filtering should only be allowed if there are items in the results
|
||||
if (resultsProductList.isEmpty()) {
|
||||
filterItem.setEnabled(false);
|
||||
} else {
|
||||
filterItem.setEnabled(true);
|
||||
}
|
||||
|
||||
// Apply selected sorting to the list
|
||||
sortResults();
|
||||
}
|
||||
|
||||
@ -35,6 +35,7 @@ public class SortDialogFragment extends DialogFragment {
|
||||
}
|
||||
|
||||
|
||||
// TODO: Sorting should scroll the user back to the top of the page
|
||||
@Override
|
||||
public Dialog onCreateDialog(final Bundle savedInstanceState) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user