From 20b86c573abe2721a2217663dcaff41ef8db7165 Mon Sep 17 00:00:00 2001 From: Clayton Wilson Date: Mon, 26 Oct 2020 03:49:43 -0400 Subject: [PATCH] New sort dialog layout --- .../example/listify/SortDialogFragment.java | 81 ++++--------- .../res/layout/activity_search_results.xml | 14 +-- .../app/src/main/res/layout/app_bar_home.xml | 6 +- .../app/src/main/res/layout/dialog_sort.xml | 114 +++++++++++++----- 4 files changed, 117 insertions(+), 98 deletions(-) diff --git a/Listify/app/src/main/java/com/example/listify/SortDialogFragment.java b/Listify/app/src/main/java/com/example/listify/SortDialogFragment.java index ab46236..a97cd1f 100644 --- a/Listify/app/src/main/java/com/example/listify/SortDialogFragment.java +++ b/Listify/app/src/main/java/com/example/listify/SortDialogFragment.java @@ -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[] {"", "Name", "Price", "Store"}; - ArrayAdapter 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(); } diff --git a/Listify/app/src/main/res/layout/activity_search_results.xml b/Listify/app/src/main/res/layout/activity_search_results.xml index 2017735..3850f4d 100644 --- a/Listify/app/src/main/res/layout/activity_search_results.xml +++ b/Listify/app/src/main/res/layout/activity_search_results.xml @@ -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"/> - - - - - - - - diff --git a/Listify/app/src/main/res/layout/app_bar_home.xml b/Listify/app/src/main/res/layout/app_bar_home.xml index 285fb12..d124049 100644 --- a/Listify/app/src/main/res/layout/app_bar_home.xml +++ b/Listify/app/src/main/res/layout/app_bar_home.xml @@ -19,13 +19,15 @@ app:popupTheme="@style/AppTheme.PopupOverlay" > + android:background="@null" + android:foreground="?android:attr/selectableItemBackgroundBorderless"/> diff --git a/Listify/app/src/main/res/layout/dialog_sort.xml b/Listify/app/src/main/res/layout/dialog_sort.xml index 01f3251..09f4f03 100644 --- a/Listify/app/src/main/res/layout/dialog_sort.xml +++ b/Listify/app/src/main/res/layout/dialog_sort.xml @@ -1,41 +1,99 @@ + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginHorizontal="30dp"> + 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"/> + + + + + + + + + + + + + + + android:layout_width="match_parent" + android:layout_height="50dp" + android:gravity="center_vertical"> - - - + android:text="Descending" + android:textSize="16sp" + android:textColor="@android:color/black" + android:paddingStart="16dp"/> + - \ No newline at end of file