mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 10:48:46 +00:00
Add menu to search and rename SortDialogFragment to FilterDialogFragment
This commit is contained in:
parent
367ff12f58
commit
d8bf4e02f8
@ -22,13 +22,13 @@ import com.crystal.crystalrangeseekbar.widgets.CrystalRangeSeekbar;
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
public class SortDialogFragment extends DialogFragment {
|
||||
public class FilterDialogFragment extends DialogFragment {
|
||||
|
||||
public interface OnSortingListener {
|
||||
public interface OnFilterListener {
|
||||
void sendSort(int storeSelection, int sortMode, boolean descending, double minPrice, double maxPrice);
|
||||
}
|
||||
|
||||
public OnSortingListener onSortingListener;
|
||||
public OnFilterListener onFilterListener;
|
||||
|
||||
CrystalRangeSeekbar priceSeekbar;
|
||||
|
||||
@ -40,7 +40,7 @@ public class SortDialogFragment extends DialogFragment {
|
||||
private double minPrice; // The selected min price
|
||||
private double maxPrice; // The selected max price
|
||||
|
||||
public SortDialogFragment(int storeSelection, ArrayList<String> stores, int sortMode, boolean descending, double maxProductPrice, double minPrice, double maxPrice) {
|
||||
public FilterDialogFragment(int storeSelection, ArrayList<String> stores, int sortMode, boolean descending, double maxProductPrice, double minPrice, double maxPrice) {
|
||||
this.storeSelection = storeSelection;
|
||||
this.stores = stores;
|
||||
this.sortMode = sortMode;
|
||||
@ -59,18 +59,18 @@ public class SortDialogFragment extends DialogFragment {
|
||||
|
||||
// Inflate and set the layout for the dialog
|
||||
// Pass null as the parent view because its going in the dialog layout
|
||||
View root = inflater.inflate(R.layout.dialog_sort, null);
|
||||
View root = inflater.inflate(R.layout.dialog_filter, null);
|
||||
builder.setView(root)
|
||||
// Add action buttons
|
||||
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
onSortingListener.sendSort(storeSelection, sortMode, descending, priceSeekbar.getSelectedMinValue().doubleValue(), priceSeekbar.getSelectedMaxValue().doubleValue());
|
||||
onFilterListener.sendSort(storeSelection, sortMode, descending, priceSeekbar.getSelectedMinValue().doubleValue(), priceSeekbar.getSelectedMaxValue().doubleValue());
|
||||
}
|
||||
})
|
||||
.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
SortDialogFragment.this.getDialog().cancel();
|
||||
FilterDialogFragment.this.getDialog().cancel();
|
||||
}
|
||||
});
|
||||
|
||||
@ -175,9 +175,9 @@ public class SortDialogFragment extends DialogFragment {
|
||||
public void onAttach(@NonNull Context context) {
|
||||
super.onAttach(context);
|
||||
try {
|
||||
onSortingListener = (OnSortingListener) getActivity();
|
||||
onFilterListener = (OnFilterListener) getActivity();
|
||||
} catch (ClassCastException e) {
|
||||
Log.e("SortDialogFragment", "onAttach: ClassCastException: " + e.getMessage());
|
||||
Log.e("FilterDialogFragment", "onAttach: ClassCastException: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3,6 +3,9 @@ import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.EditText;
|
||||
@ -22,7 +25,7 @@ import java.util.Properties;
|
||||
|
||||
import static com.example.listify.MainActivity.am;
|
||||
|
||||
public class SearchResults extends AppCompatActivity implements SortDialogFragment.OnSortingListener {
|
||||
public class SearchResults extends AppCompatActivity implements FilterDialogFragment.OnFilterListener {
|
||||
private ListView listView;
|
||||
private SearchResultsListAdapter searchResultsListAdapter;
|
||||
private List<Product> resultsProductList = new ArrayList<>();
|
||||
@ -108,14 +111,26 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: Change this to a menu in which sort and filter are two different options
|
||||
// TODO: Sort should be disabled until a search is made
|
||||
// Create a dialog for filtering and sorting search results
|
||||
ImageButton sortButton = (ImageButton) findViewById(R.id.results_sort_button);
|
||||
sortButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
//Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.search, menu);
|
||||
MenuItem sortItem = menu.findItem(R.id.action_sort);
|
||||
sortItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
// TODO: Create a sort dialog
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// TODO: filter should be disabled until a search is made
|
||||
MenuItem filterItem = menu.findItem(R.id.action_filter);
|
||||
filterItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
// Sort the store list
|
||||
stores.sort(new Comparator<String>() {
|
||||
@Override
|
||||
@ -147,11 +162,12 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme
|
||||
// Round up to nearest whole number for display on price seekbar
|
||||
maxProductPrice = Math.ceil(maxProductPrice);
|
||||
|
||||
SortDialogFragment sortDialog = new SortDialogFragment(storeSelection, stores, sortMode, descending, maxProductPrice, minPrice, maxPrice);
|
||||
FilterDialogFragment sortDialog = new FilterDialogFragment(storeSelection, stores, sortMode, descending, maxProductPrice, minPrice, maxPrice);
|
||||
sortDialog.show(getSupportFragmentManager(), "Sort");
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -36,13 +36,13 @@
|
||||
>
|
||||
</SearchView>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/results_sort_button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/sort_button_desc"
|
||||
android:background="@null"
|
||||
app:srcCompat="@drawable/ic_baseline_sort_28" />
|
||||
<!-- <ImageButton-->
|
||||
<!-- android:id="@+id/results_sort_button"-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:contentDescription="@string/sort_button_desc"-->
|
||||
<!-- android:background="@null"-->
|
||||
<!-- app:srcCompat="@drawable/ic_baseline_sort_28" />-->
|
||||
|
||||
</androidx.appcompat.widget.Toolbar>
|
||||
|
||||
|
||||
14
Listify/app/src/main/res/menu/search.xml
Normal file
14
Listify/app/src/main/res/menu/search.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/action_sort"
|
||||
android:orderInCategory="101"
|
||||
android:title="Sort"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/action_filter"
|
||||
android:orderInCategory="101"
|
||||
android:title="Filter"
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
||||
Loading…
Reference in New Issue
Block a user