mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 02:38:47 +00:00
Layout for sort and filter dialog on search results page
This commit is contained in:
parent
550483a708
commit
ef2a58d23f
@ -189,9 +189,9 @@ public class SearchResults extends AppCompatActivity implements SortDialogFragme
|
||||
resultsProductListSorted.sort(new Comparator<Product>() {
|
||||
@Override
|
||||
public int compare(Product a, Product b) {
|
||||
if (a.getPrice() - b.getPrice() > 0) {
|
||||
if (b.getPrice() - a.getPrice() > 0) {
|
||||
return 1;
|
||||
} else if (a.getPrice() - b.getPrice() < 0) {
|
||||
} else if (b.getPrice() - a.getPrice() < 0) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
|
||||
@ -36,6 +36,7 @@ public class SortDialogFragment extends DialogFragment {
|
||||
this.descending = descending;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(final Bundle savedInstanceState) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
@ -65,6 +66,8 @@ public class SortDialogFragment extends DialogFragment {
|
||||
for (int i = 1; i < stores.size() + 1; i++) {
|
||||
storeChoices[i] = stores.get(i - 1);
|
||||
}
|
||||
|
||||
// Create the store selection dropdown
|
||||
ArrayAdapter<String> storeAdapter = new ArrayAdapter<>(root.getContext(), android.R.layout.simple_spinner_dropdown_item, storeChoices);
|
||||
storeDropdown.setAdapter(storeAdapter);
|
||||
storeDropdown.setSelection(this.storeSelection);
|
||||
@ -80,6 +83,29 @@ public class SortDialogFragment extends DialogFragment {
|
||||
}
|
||||
});
|
||||
|
||||
// Change the sort arrow to be pointing up or down based on ascending or descending
|
||||
final ImageButton sortDirectionButton = root.findViewById(R.id.sort_direction_button);
|
||||
if (descending) {
|
||||
sortDirectionButton.setImageResource(R.drawable.ic_baseline_arrow_downward_50);
|
||||
} else {
|
||||
sortDirectionButton.setImageResource(R.drawable.ic_baseline_arrow_upward_50);
|
||||
}
|
||||
|
||||
// Change array pointing direction whenever the user clicks the button
|
||||
sortDirectionButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (descending) {
|
||||
descending = false;
|
||||
sortDirectionButton.setImageResource(R.drawable.ic_baseline_arrow_upward_50);
|
||||
} else {
|
||||
descending = true;
|
||||
sortDirectionButton.setImageResource(R.drawable.ic_baseline_arrow_downward_50);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Create the sort mode selection dropdown
|
||||
Spinner sortDropdown = (Spinner) root.findViewById(R.id.sort_mode_dropdown);
|
||||
String[] items = new String[] {"<Default>", "Name", "Price", "Store"};
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<>(root.getContext(), android.R.layout.simple_spinner_dropdown_item, items);
|
||||
@ -89,6 +115,13 @@ public class SortDialogFragment extends DialogFragment {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
sortMode = position;
|
||||
|
||||
// Update the sort direction button
|
||||
if (position == 0) {
|
||||
sortDirectionButton.setEnabled(false);
|
||||
} else {
|
||||
sortDirectionButton.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -97,21 +130,16 @@ public class SortDialogFragment extends DialogFragment {
|
||||
}
|
||||
});
|
||||
|
||||
ImageButton sortDirectionButton = root.findViewById(R.id.sort_direction_button);
|
||||
sortDirectionButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (descending) {
|
||||
descending = false;
|
||||
} else {
|
||||
descending = true;
|
||||
// Disable the direction button if they have the default sorting mode selected
|
||||
// Ascending and Descending are mostly irrelevant in the default sort mode
|
||||
if (sortDropdown.getSelectedItemPosition() == 0) {
|
||||
sortDirectionButton.setEnabled(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
// Required to extend DialogFragment
|
||||
@Override
|
||||
public void onAttach(@NonNull Context context) {
|
||||
super.onAttach(context);
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
<vector android:height="50dp" android:tint="?attr/colorControlNormal"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="50dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M20,12l-1.41,-1.41L13,16.17V4h-2v12.17l-5.58,-5.59L4,12l8,8 8,-8z"/>
|
||||
</vector>
|
||||
@ -0,0 +1,5 @@
|
||||
<vector android:height="50dp" android:tint="?attr/colorControlNormal"
|
||||
android:viewportHeight="24" android:viewportWidth="24"
|
||||
android:width="50dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="@android:color/white" android:pathData="M4,12l1.41,1.41L11,7.83V20h2V7.83l5.58,5.59L20,12l-8,-8 -8,8z"/>
|
||||
</vector>
|
||||
@ -2,60 +2,52 @@
|
||||
android:orientation="vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
<!-- <ImageView-->
|
||||
<!-- android:src="@drawable/ic_baseline_filter_list_28"-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="64dp"-->
|
||||
<!-- android:scaleType="center"-->
|
||||
<!-- android:background="#FFFFBB33"-->
|
||||
<!-- android:contentDescription="@string/app_name" />-->
|
||||
<!-- <EditText-->
|
||||
<!-- android:id="@+id/username"-->
|
||||
<!-- android:inputType="textEmailAddress"-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:layout_marginTop="16dp"-->
|
||||
<!-- android:layout_marginLeft="4dp"-->
|
||||
<!-- android:layout_marginRight="4dp"-->
|
||||
<!-- android:layout_marginBottom="4dp"-->
|
||||
<!-- android:hint="Username" />-->
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_store_selection"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginTop="15dp"
|
||||
android:layout_marginStart="15dp"
|
||||
android:text="@string/store_selection" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/sort_store_dropdown"
|
||||
android:layout_width="260dp"
|
||||
android:layout_width="265dp"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@android:drawable/spinner_dropdown_background"
|
||||
android:spinnerMode="dropdown"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_sort_by"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginStart="15dp"
|
||||
android:text="Sort by" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="150dp"
|
||||
android:padding="15dp">
|
||||
android:layout_height="100dp"
|
||||
android:paddingStart="15dp">
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/sort_mode_dropdown"
|
||||
android:layout_width="260dp"
|
||||
android:layout_width="265dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@android:drawable/spinner_dropdown_background"
|
||||
android:spinnerMode="dropdown"/>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/sort_direction_button"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:src="@drawable/ic_baseline_sort_28"/>
|
||||
android:layout_marginTop="-6dp"
|
||||
android:layout_width="57dp"
|
||||
android:layout_height="70dp"
|
||||
android:background="@null"
|
||||
android:src="@drawable/ic_baseline_arrow_upward_50"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<!-- <EditText-->
|
||||
<!-- android:id="@+id/password"-->
|
||||
<!-- android:inputType="textPassword"-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:layout_marginTop="4dp"-->
|
||||
<!-- android:layout_marginLeft="4dp"-->
|
||||
<!-- android:layout_marginRight="4dp"-->
|
||||
<!-- android:layout_marginBottom="16dp"-->
|
||||
<!-- android:fontFamily="sans-serif"-->
|
||||
<!-- android:hint="Password"/>-->
|
||||
</LinearLayout>
|
||||
@ -28,4 +28,5 @@
|
||||
<string name="hello_second_fragment">Hello second fragment. Arg: %1$s</string>
|
||||
<string name="search_button_desc">Search Button</string>
|
||||
<string name="title_activity_search_results">SearchResults</string>
|
||||
<string name="store_selection">Store selection</string>
|
||||
</resources>
|
||||
Loading…
Reference in New Issue
Block a user