summaryrefslogtreecommitdiff
path: root/app/src/main/java/de/danoeh/antennapod/dialog
diff options
context:
space:
mode:
authorByteHamster <ByteHamster@users.noreply.github.com>2023-12-03 16:36:28 +0100
committerGitHub <noreply@github.com>2023-12-03 16:36:28 +0100
commit2e76dc8d0c950090acd95d1e8c9d6c7be314d9a6 (patch)
treeecd57518bae3916aba6ef9fca99998ca751e0944 /app/src/main/java/de/danoeh/antennapod/dialog
parentc1712fe2f55374d276d166ce02c9882a2300264a (diff)
downloadAntennaPod-2e76dc8d0c950090acd95d1e8c9d6c7be314d9a6.zip
New sort dialog (#6789)
Diffstat (limited to 'app/src/main/java/de/danoeh/antennapod/dialog')
-rw-r--r--app/src/main/java/de/danoeh/antennapod/dialog/IntraFeedSortDialog.java68
-rw-r--r--app/src/main/java/de/danoeh/antennapod/dialog/ItemSortDialog.java102
2 files changed, 102 insertions, 68 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/IntraFeedSortDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/IntraFeedSortDialog.java
deleted file mode 100644
index dc8cf65ba..000000000
--- a/app/src/main/java/de/danoeh/antennapod/dialog/IntraFeedSortDialog.java
+++ /dev/null
@@ -1,68 +0,0 @@
-package de.danoeh.antennapod.dialog;
-
-import android.content.Context;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import com.google.android.material.dialog.MaterialAlertDialogBuilder;
-
-import de.danoeh.antennapod.R;
-import de.danoeh.antennapod.model.feed.SortOrder;
-
-public abstract class IntraFeedSortDialog {
-
- @Nullable
- protected SortOrder currentSortOrder;
- @NonNull
- protected Context context;
-
- private final String[] sortItems;
- private final SortOrder[] sortValues;
-
- public IntraFeedSortDialog(@NonNull Context context, @Nullable SortOrder sortOrder, @NonNull boolean isLocalFeed) {
- this.context = context;
- this.currentSortOrder = sortOrder;
-
- if (isLocalFeed) {
- sortItems = context.getResources().getStringArray(R.array.local_feed_episodes_sort_options);
- final String[] localSortStringValues =
- context.getResources().getStringArray(R.array.local_feed_episodes_sort_values);
- sortValues = SortOrder.valuesOf(localSortStringValues);
- } else {
- sortItems = context.getResources().getStringArray(R.array.feed_episodes_sort_options);
- final String[] commonSortStringValues =
- context.getResources().getStringArray(R.array.feed_episodes_sort_values);
- sortValues = SortOrder.valuesOf(commonSortStringValues);
- }
- }
-
- public void openDialog() {
- int idxCurrentSort = getCurrentSortOrderIndex();
-
- MaterialAlertDialogBuilder builder =
- new MaterialAlertDialogBuilder(context)
- .setTitle(R.string.sort)
- .setSingleChoiceItems(sortItems, idxCurrentSort, (dialog, idxNewSort) -> {
- updateSort(sortValues[idxNewSort]);
- dialog.dismiss();
- })
- .setNegativeButton(R.string.cancel_label, null);
- builder.create().show();
- }
-
- /**
- * Retrieves index of currentSortOrder index in values array.
- * @return if currentSortOrder is found in array - returns index of that element,
- * otherwise returns 0, the default sort option;
- */
- private int getCurrentSortOrderIndex() {
- for (int i = 0; i < sortValues.length; i++) {
- if (currentSortOrder == sortValues[i]) {
- return i;
- }
- }
- return 0;
- }
-
- protected abstract void updateSort(@NonNull SortOrder sortOrder);
-}
diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/ItemSortDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/ItemSortDialog.java
new file mode 100644
index 000000000..3090dd6a5
--- /dev/null
+++ b/app/src/main/java/de/danoeh/antennapod/dialog/ItemSortDialog.java
@@ -0,0 +1,102 @@
+package de.danoeh.antennapod.dialog;
+
+import android.app.Dialog;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.FrameLayout;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import com.google.android.material.bottomsheet.BottomSheetBehavior;
+import com.google.android.material.bottomsheet.BottomSheetDialog;
+import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
+import de.danoeh.antennapod.R;
+import de.danoeh.antennapod.databinding.SortDialogBinding;
+import de.danoeh.antennapod.databinding.SortDialogItemActiveBinding;
+import de.danoeh.antennapod.databinding.SortDialogItemBinding;
+import de.danoeh.antennapod.model.feed.SortOrder;
+
+public class ItemSortDialog extends BottomSheetDialogFragment {
+ protected SortOrder sortOrder;
+ protected SortDialogBinding viewBinding;
+
+ @Nullable
+ @Override
+ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
+ @Nullable Bundle savedInstanceState) {
+ viewBinding = SortDialogBinding.inflate(inflater);
+ populateList();
+ return viewBinding.getRoot();
+ }
+
+ private void populateList() {
+ viewBinding.gridLayout.removeAllViews();
+ onAddItem(R.string.episode_title, SortOrder.EPISODE_TITLE_A_Z, SortOrder.EPISODE_TITLE_Z_A, true);
+ onAddItem(R.string.feed_title, SortOrder.FEED_TITLE_A_Z, SortOrder.FEED_TITLE_Z_A, true);
+ onAddItem(R.string.duration, SortOrder.DURATION_SHORT_LONG, SortOrder.DURATION_LONG_SHORT, true);
+ onAddItem(R.string.date, SortOrder.DATE_OLD_NEW, SortOrder.DATE_NEW_OLD, false);
+ onAddItem(R.string.size, SortOrder.SIZE_SMALL_LARGE, SortOrder.SIZE_LARGE_SMALL, false);
+ onAddItem(R.string.filename, SortOrder.EPISODE_FILENAME_A_Z, SortOrder.EPISODE_FILENAME_Z_A, true);
+ onAddItem(R.string.random, SortOrder.RANDOM, SortOrder.RANDOM, true);
+ onAddItem(R.string.smart_shuffle, SortOrder.SMART_SHUFFLE_OLD_NEW, SortOrder.SMART_SHUFFLE_NEW_OLD, false);
+ }
+
+ protected void onAddItem(int title, SortOrder ascending, SortOrder descending, boolean ascendingIsDefault) {
+ if (sortOrder == ascending || sortOrder == descending) {
+ SortDialogItemActiveBinding item = SortDialogItemActiveBinding.inflate(
+ getLayoutInflater(), viewBinding.gridLayout, false);
+ SortOrder other;
+ if (ascending == descending) {
+ item.button.setText(title);
+ other = ascending;
+ } else if (sortOrder == ascending) {
+ item.button.setText(getString(title) + "\u00A0▲");
+ other = descending;
+ } else {
+ item.button.setText(getString(title) + "\u00A0▼");
+ other = ascending;
+ }
+ item.button.setOnClickListener(v -> {
+ sortOrder = other;
+ populateList();
+ onSelectionChanged();
+ });
+ viewBinding.gridLayout.addView(item.getRoot());
+ } else {
+ SortDialogItemBinding item = SortDialogItemBinding.inflate(
+ getLayoutInflater(), viewBinding.gridLayout, false);
+ item.button.setText(title);
+ item.button.setOnClickListener(v -> {
+ sortOrder = ascendingIsDefault ? ascending : descending;
+ populateList();
+ onSelectionChanged();
+ });
+ viewBinding.gridLayout.addView(item.getRoot());
+ }
+ }
+
+ protected void onSelectionChanged() {
+ }
+
+ @NonNull
+ @Override
+ public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
+ Dialog dialog = super.onCreateDialog(savedInstanceState);
+ dialog.setOnShowListener(dialogInterface -> {
+ BottomSheetDialog bottomSheetDialog = (BottomSheetDialog) dialogInterface;
+ setupFullHeight(bottomSheetDialog);
+ });
+ return dialog;
+ }
+
+ private void setupFullHeight(BottomSheetDialog bottomSheetDialog) {
+ FrameLayout bottomSheet = bottomSheetDialog.findViewById(R.id.design_bottom_sheet);
+ if (bottomSheet != null) {
+ BottomSheetBehavior<FrameLayout> behavior = BottomSheetBehavior.from(bottomSheet);
+ ViewGroup.LayoutParams layoutParams = bottomSheet.getLayoutParams();
+ bottomSheet.setLayoutParams(layoutParams);
+ behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
+ }
+ }
+}