mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 10:48:46 +00:00
Price filter debugging
This commit is contained in:
parent
e98d2a6a93
commit
c9d40d0eae
@ -31,12 +31,18 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme
|
|||||||
private int storeSelection;
|
private int storeSelection;
|
||||||
private int sortMode;
|
private int sortMode;
|
||||||
private boolean descending;
|
private boolean descending;
|
||||||
|
private double minPrice = 0;
|
||||||
|
private double maxPrice = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendSort(int storeSelection, int sortMode, boolean descending) {
|
public void sendSort(int storeSelection, int sortMode, boolean descending, double maxPrice, double minPrice) {
|
||||||
this.storeSelection = storeSelection;
|
this.storeSelection = storeSelection;
|
||||||
this.sortMode = sortMode;
|
this.sortMode = sortMode;
|
||||||
this.descending = descending;
|
this.descending = descending;
|
||||||
|
this.minPrice = minPrice;
|
||||||
|
this.maxPrice = maxPrice;
|
||||||
|
System.out.println(minPrice);
|
||||||
|
System.out.println(maxPrice);
|
||||||
sortResults();
|
sortResults();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,7 +124,27 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme
|
|||||||
return o1.compareTo(o2);
|
return o1.compareTo(o2);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
SortDialogFragment sortDialog = new SortDialogFragment(storeSelection, stores, sortMode, descending);
|
|
||||||
|
// Determine the max price for the price slider
|
||||||
|
double maxProductPrice;
|
||||||
|
if (resultsProductList.isEmpty()) {
|
||||||
|
// default to $100
|
||||||
|
maxProductPrice = 100.00;
|
||||||
|
|
||||||
|
minPrice = 0;
|
||||||
|
maxPrice = 100;
|
||||||
|
} else {
|
||||||
|
maxProductPrice = resultsProductList.get(0).getPrice().doubleValue();
|
||||||
|
for (int i = 1; i < resultsProductList.size(); i++) {
|
||||||
|
if (resultsProductList.get(i).getPrice().doubleValue() > maxProductPrice) {
|
||||||
|
maxProductPrice = resultsProductList.get(i).getPrice().doubleValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (maxPrice == 0) {
|
||||||
|
maxPrice = maxProductPrice;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SortDialogFragment sortDialog = new SortDialogFragment(storeSelection, stores, sortMode, descending, maxProductPrice, minPrice, maxPrice);
|
||||||
sortDialog.show(getSupportFragmentManager(), "Sort");
|
sortDialog.show(getSupportFragmentManager(), "Sort");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -20,29 +20,35 @@ import com.crystal.crystalrangeseekbar.interfaces.OnRangeSeekbarChangeListener;
|
|||||||
import com.crystal.crystalrangeseekbar.interfaces.OnRangeSeekbarFinalValueListener;
|
import com.crystal.crystalrangeseekbar.interfaces.OnRangeSeekbarFinalValueListener;
|
||||||
import com.crystal.crystalrangeseekbar.widgets.CrystalRangeSeekbar;
|
import com.crystal.crystalrangeseekbar.widgets.CrystalRangeSeekbar;
|
||||||
|
|
||||||
import org.w3c.dom.Text;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
|
||||||
public class SortDialogFragment extends DialogFragment {
|
public class SortDialogFragment extends DialogFragment {
|
||||||
|
|
||||||
public interface OnSortingListener {
|
public interface OnSortingListener {
|
||||||
void sendSort(int storeSelection, int sortMode, boolean descending);
|
void sendSort(int storeSelection, int sortMode, boolean descending, double minPrice, double maxPrice);
|
||||||
}
|
}
|
||||||
|
|
||||||
public OnSortingListener onSortingListener;
|
public OnSortingListener onSortingListener;
|
||||||
|
|
||||||
|
CrystalRangeSeekbar priceSeekbar;
|
||||||
|
|
||||||
private int storeSelection;
|
private int storeSelection;
|
||||||
private int sortMode;
|
private int sortMode;
|
||||||
private boolean descending;
|
private boolean descending;
|
||||||
private ArrayList<String> stores;
|
private ArrayList<String> stores;
|
||||||
|
private double maxProductPrice; // The highest price on the slider
|
||||||
|
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) {
|
public SortDialogFragment(int storeSelection, ArrayList<String> stores, int sortMode, boolean descending, double maxProductPrice, double minPrice, double maxPrice) {
|
||||||
this.storeSelection = storeSelection;
|
this.storeSelection = storeSelection;
|
||||||
this.stores = stores;
|
this.stores = stores;
|
||||||
this.sortMode = sortMode;
|
this.sortMode = sortMode;
|
||||||
this.descending = descending;
|
this.descending = descending;
|
||||||
|
this.maxProductPrice = maxProductPrice;
|
||||||
|
this.minPrice = minPrice;
|
||||||
|
this.maxPrice = maxPrice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -60,7 +66,7 @@ public class SortDialogFragment extends DialogFragment {
|
|||||||
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
onSortingListener.sendSort(storeSelection, sortMode, descending);
|
onSortingListener.sendSort(storeSelection, sortMode, descending, priceSeekbar.getSelectedMinValue().doubleValue(), priceSeekbar.getSelectedMaxValue().doubleValue());
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
|
.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
|
||||||
@ -100,7 +106,7 @@ public class SortDialogFragment extends DialogFragment {
|
|||||||
sortDirectionButton.setImageResource(R.drawable.ic_baseline_arrow_upward_50);
|
sortDirectionButton.setImageResource(R.drawable.ic_baseline_arrow_upward_50);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change array pointing direction whenever the user clicks the button
|
// Change arrow pointing direction whenever the user clicks the button
|
||||||
sortDirectionButton.setOnClickListener(new View.OnClickListener() {
|
sortDirectionButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
@ -146,11 +152,15 @@ public class SortDialogFragment extends DialogFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set up the seekbar for price
|
// Set up the seekbar for price
|
||||||
final CrystalRangeSeekbar priceSeekbar = (CrystalRangeSeekbar) root.findViewById(R.id.price_range_seekbar);
|
priceSeekbar = (CrystalRangeSeekbar) root.findViewById(R.id.price_range_seekbar);
|
||||||
final TextView tvMin = (TextView) root.findViewById(R.id.tv_min_price);
|
final TextView tvMin = (TextView) root.findViewById(R.id.tv_min_price);
|
||||||
final TextView tvMax = (TextView) root.findViewById(R.id.tv_max_price);
|
final TextView tvMax = (TextView) root.findViewById(R.id.tv_max_price);
|
||||||
|
|
||||||
priceSeekbar.setMaxValue(367);
|
priceSeekbar.setMaxValue((float) this.maxProductPrice);
|
||||||
|
System.out.println(String.format("%f : %f", this.minPrice, this.maxPrice));
|
||||||
|
priceSeekbar.setMinStartValue((float) this.minPrice);
|
||||||
|
priceSeekbar.setMaxStartValue((float) this.maxPrice);
|
||||||
|
priceSeekbar.apply();
|
||||||
|
|
||||||
// Update price display
|
// Update price display
|
||||||
priceSeekbar.setOnRangeSeekbarChangeListener(new OnRangeSeekbarChangeListener() {
|
priceSeekbar.setOnRangeSeekbarChangeListener(new OnRangeSeekbarChangeListener() {
|
||||||
@ -161,13 +171,15 @@ public class SortDialogFragment extends DialogFragment {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Save price values when user finishes moving the slider
|
// // Save price values when user finishes moving the slider
|
||||||
priceSeekbar.setOnRangeSeekbarFinalValueListener(new OnRangeSeekbarFinalValueListener() {
|
// priceSeekbar.setOnRangeSeekbarFinalValueListener(new OnRangeSeekbarFinalValueListener() {
|
||||||
@Override
|
// @Override
|
||||||
public void finalValue(Number minValue, Number maxValue) {
|
// public void finalValue(Number minValue, Number maxValue) {
|
||||||
System.out.println(String.format("Min: $%.2f, Max: $%.2f", minValue.doubleValue(), maxValue.doubleValue()));
|
// minPrice = minValue.doubleValue();
|
||||||
}
|
// maxPrice = maxValue.doubleValue();
|
||||||
});
|
//// System.out.println(String.format("Min: $%.2f, Max: $%.2f", minValue.doubleValue(), maxValue.doubleValue()));
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
|
|
||||||
return builder.create();
|
return builder.create();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user