mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2025-12-16 18:48:48 +00:00
New sort dialog layout
This commit is contained in:
parent
e7c1ab85ea
commit
20b86c573a
@ -1,20 +1,15 @@
|
|||||||
package com.example.listify;
|
package com.example.listify;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.AdapterView;
|
import android.widget.TextView;
|
||||||
import android.widget.ArrayAdapter;
|
|
||||||
import android.widget.ImageButton;
|
|
||||||
import android.widget.Spinner;
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.fragment.app.DialogFragment;
|
import androidx.fragment.app.DialogFragment;
|
||||||
|
|
||||||
|
|
||||||
public class SortDialogFragment extends DialogFragment {
|
public class SortDialogFragment extends DialogFragment {
|
||||||
|
|
||||||
public interface OnSortListener {
|
public interface OnSortListener {
|
||||||
@ -41,70 +36,40 @@ public class SortDialogFragment extends DialogFragment {
|
|||||||
// Inflate and set the layout for the dialog
|
// Inflate and set the layout for the dialog
|
||||||
// Pass null as the parent view because its going in the dialog layout
|
// 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_sort, null);
|
||||||
builder.setView(root)
|
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();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Change the sort arrow to be pointing up or down based on ascending or descending
|
TextView tvSortNone = root.findViewById(R.id.sort_none);
|
||||||
final ImageButton sortDirectionButton = root.findViewById(R.id.sort_direction_button);
|
TextView tvSortName = root.findViewById(R.id.sort_name);
|
||||||
if (descending) {
|
TextView tvSortPrice = root.findViewById(R.id.sort_price);
|
||||||
sortDirectionButton.setImageResource(R.drawable.ic_baseline_arrow_downward_50);
|
TextView tvSortStore = root.findViewById(R.id.sort_store);
|
||||||
} else {
|
|
||||||
sortDirectionButton.setImageResource(R.drawable.ic_baseline_arrow_upward_50);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Change arrow pointing direction whenever the user clicks the button
|
tvSortNone.setOnClickListener(new View.OnClickListener() {
|
||||||
sortDirectionButton.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
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
|
tvSortName.setOnClickListener(new View.OnClickListener() {
|
||||||
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() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
public void onClick(View v) {
|
||||||
sortMode = position;
|
|
||||||
|
|
||||||
// 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
|
tvSortPrice.setOnClickListener(new View.OnClickListener() {
|
||||||
// Ascending and Descending are mostly irrelevant in the default sort mode
|
@Override
|
||||||
if (sortDropdown.getSelectedItemPosition() == 0) {
|
public void onClick(View v) {
|
||||||
sortDirectionButton.setEnabled(false);
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
tvSortStore.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return builder.create();
|
return builder.create();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,10 +23,12 @@
|
|||||||
android:id="@+id/backToHomeButton"
|
android:id="@+id/backToHomeButton"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:translationX="-10dp"
|
||||||
|
android:padding="10dp"
|
||||||
app:srcCompat="@drawable/abc_vector_test"
|
app:srcCompat="@drawable/abc_vector_test"
|
||||||
android:background="@null"
|
android:background="@null"
|
||||||
android:contentDescription="@string/backButton"/>
|
android:contentDescription="@string/backButton"
|
||||||
|
android:foreground="?android:attr/selectableItemBackgroundBorderless"/>
|
||||||
|
|
||||||
<SearchView
|
<SearchView
|
||||||
android:id="@+id/searchBar"
|
android:id="@+id/searchBar"
|
||||||
@ -36,14 +38,6 @@
|
|||||||
>
|
>
|
||||||
</SearchView>
|
</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>
|
</androidx.appcompat.widget.Toolbar>
|
||||||
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|||||||
@ -19,13 +19,15 @@
|
|||||||
app:popupTheme="@style/AppTheme.PopupOverlay" >
|
app:popupTheme="@style/AppTheme.PopupOverlay" >
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/searchButton"
|
android:id="@+id/searchButton"
|
||||||
android:layout_width="30dp"
|
android:layout_width="wrap_content"
|
||||||
android:layout_gravity="end"
|
android:layout_gravity="end"
|
||||||
android:layout_marginEnd="5dp"
|
android:layout_marginEnd="5dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="10dp"
|
||||||
app:srcCompat="@drawable/ic_baseline_search_28"
|
app:srcCompat="@drawable/ic_baseline_search_28"
|
||||||
android:contentDescription="@string/search_button_desc"
|
android:contentDescription="@string/search_button_desc"
|
||||||
android:background="@null"/>
|
android:background="@null"
|
||||||
|
android:foreground="?android:attr/selectableItemBackgroundBorderless"/>
|
||||||
</androidx.appcompat.widget.Toolbar>
|
</androidx.appcompat.widget.Toolbar>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,41 +1,99 @@
|
|||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="30dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tv_sort_by"
|
android:id="@+id/sort_none"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="50dp"
|
||||||
android:layout_weight="1"
|
android:text="None"
|
||||||
android:layout_marginTop="20dp"
|
android:textSize="16sp"
|
||||||
android:layout_marginStart="15dp"
|
android:textColor="@android:color/black"
|
||||||
android:text="Sort by" />
|
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
|
<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:layout_height="wrap_content"
|
||||||
android:paddingStart="15dp">
|
android:text="Descending"
|
||||||
|
android:textSize="16sp"
|
||||||
<Spinner
|
android:textColor="@android:color/black"
|
||||||
android:id="@+id/sort_mode_dropdown"
|
android:paddingStart="16dp"/>
|
||||||
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"/>
|
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.SwitchCompat
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<ListView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
Loading…
Reference in New Issue
Block a user