mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 10:48:46 +00:00
New sort dialog layout
This commit is contained in:
parent
e7c1ab85ea
commit
20b86c573a
@ -1,20 +1,15 @@
|
||||
package com.example.listify;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
|
||||
|
||||
public class SortDialogFragment extends DialogFragment {
|
||||
|
||||
public interface OnSortListener {
|
||||
@ -41,70 +36,40 @@ 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);
|
||||
builder.setView(root)
|
||||
// Add action buttons
|
||||
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
onSortListener.sendSort(sortMode, descending);
|
||||
}
|
||||
})
|
||||
.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
SortDialogFragment.this.getDialog().cancel();
|
||||
}
|
||||
});
|
||||
builder.setView(root);
|
||||
|
||||
// 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);
|
||||
}
|
||||
TextView tvSortNone = root.findViewById(R.id.sort_none);
|
||||
TextView tvSortName = root.findViewById(R.id.sort_name);
|
||||
TextView tvSortPrice = root.findViewById(R.id.sort_price);
|
||||
TextView tvSortStore = root.findViewById(R.id.sort_store);
|
||||
|
||||
// Change arrow pointing direction whenever the user clicks the button
|
||||
sortDirectionButton.setOnClickListener(new View.OnClickListener() {
|
||||
tvSortNone.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);
|
||||
sortDropdown.setAdapter(adapter);
|
||||
sortDropdown.setSelection(this.sortMode);
|
||||
sortDropdown.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
tvSortName.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
sortMode = position;
|
||||
public void onClick(View v) {
|
||||
|
||||
// Update the sort direction button
|
||||
if (position == 0) {
|
||||
sortDirectionButton.setEnabled(false);
|
||||
} else {
|
||||
sortDirectionButton.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {}
|
||||
});
|
||||
|
||||
// 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);
|
||||
tvSortPrice.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
tvSortStore.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
@ -23,10 +23,12 @@
|
||||
android:id="@+id/backToHomeButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:translationX="-10dp"
|
||||
android:padding="10dp"
|
||||
app:srcCompat="@drawable/abc_vector_test"
|
||||
android:background="@null"
|
||||
android:contentDescription="@string/backButton"/>
|
||||
android:contentDescription="@string/backButton"
|
||||
android:foreground="?android:attr/selectableItemBackgroundBorderless"/>
|
||||
|
||||
<SearchView
|
||||
android:id="@+id/searchBar"
|
||||
@ -36,14 +38,6 @@
|
||||
>
|
||||
</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" />-->
|
||||
|
||||
</androidx.appcompat.widget.Toolbar>
|
||||
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
@ -19,13 +19,15 @@
|
||||
app:popupTheme="@style/AppTheme.PopupOverlay" >
|
||||
<ImageButton
|
||||
android:id="@+id/searchButton"
|
||||
android:layout_width="30dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_gravity="end"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="10dp"
|
||||
app:srcCompat="@drawable/ic_baseline_search_28"
|
||||
android:contentDescription="@string/search_button_desc"
|
||||
android:background="@null"/>
|
||||
android:background="@null"
|
||||
android:foreground="?android:attr/selectableItemBackgroundBorderless"/>
|
||||
</androidx.appcompat.widget.Toolbar>
|
||||
|
||||
|
||||
|
||||
@ -1,41 +1,99 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginHorizontal="30dp">
|
||||
|
||||
<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" />
|
||||
android:id="@+id/sort_none"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:text="None"
|
||||
android:textSize="16sp"
|
||||
android:textColor="@android:color/black"
|
||||
android:paddingStart="16dp"
|
||||
android:gravity="center_vertical"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:foreground="?attr/selectableItemBackgroundBorderless"
|
||||
android:soundEffectsEnabled="true"/>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@color/list_divider" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sort_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:text="Name"
|
||||
android:textSize="16sp"
|
||||
android:textColor="@android:color/black"
|
||||
android:paddingStart="16dp"
|
||||
android:gravity="center_vertical"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:foreground="?attr/selectableItemBackgroundBorderless"/>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@color/list_divider" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sort_price"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:text="Price"
|
||||
android:textSize="16sp"
|
||||
android:textColor="@android:color/black"
|
||||
android:paddingStart="16dp"
|
||||
android:gravity="center_vertical"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:foreground="?attr/selectableItemBackgroundBorderless"/>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@color/list_divider" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sort_store"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:text="Store"
|
||||
android:textSize="16sp"
|
||||
android:textColor="@android:color/black"
|
||||
android:paddingStart="16dp"
|
||||
android:gravity="center_vertical"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:foreground="?attr/selectableItemBackgroundBorderless"/>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@color/list_divider" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="265dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="50dp"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="15dp">
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/sort_mode_dropdown"
|
||||
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_marginTop="-6dp"
|
||||
android:layout_width="57dp"
|
||||
android:layout_height="70dp"
|
||||
android:background="@null"
|
||||
android:src="@drawable/ic_baseline_arrow_upward_50"/>
|
||||
android:text="Descending"
|
||||
android:textSize="16sp"
|
||||
android:textColor="@android:color/black"
|
||||
android:paddingStart="16dp"/>
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
</LinearLayout>
|
||||
|
||||
<ListView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
</LinearLayout>
|
||||
Loading…
Reference in New Issue
Block a user