From 9adaf8c0135fb8e0e51bdde6c0884bc4aa68a837 Mon Sep 17 00:00:00 2001 From: Tom Date: Sun, 15 Feb 2026 14:42:07 -0300 Subject: [PATCH] feat: improve playlist chooser dialog UI (#439) * fix: lock buttons at dialog bottom The previous implementation appended the buttons to the RecyclerView programmatically this disabled the scroll and pushed the buttons outside the visible dialog area if too there were too many playlists. To fix this now the XML defines a fixed location for the buttons, enabling the scroll of the RecyclerView and preventing the buttons to become unreachable * feat: improve playlist chooser dialog UI Implement it in the XML layout and not programmatically. * fix: detached listeners from XML layout * fix: missing dialog title --- .../ui/dialog/PlaylistChooserDialog.java | 55 ++++++++----------- .../res/layout/dialog_playlist_chooser.xml | 51 +++++++++++++++++ app/src/main/res/values-ca/strings.xml | 4 +- app/src/main/res/values-de/strings.xml | 4 +- app/src/main/res/values-es-rES/strings.xml | 4 +- app/src/main/res/values-fr/strings.xml | 4 +- app/src/main/res/values-it/strings.xml | 4 +- app/src/main/res/values-ko/strings.xml | 4 +- app/src/main/res/values-pl/strings.xml | 4 +- app/src/main/res/values-pt/strings.xml | 4 +- app/src/main/res/values-ro/strings.xml | 4 +- app/src/main/res/values-ru/strings.xml | 4 +- app/src/main/res/values-tr/strings.xml | 4 +- app/src/main/res/values-zh/strings.xml | 4 +- app/src/main/res/values/strings.xml | 6 +- 15 files changed, 101 insertions(+), 59 deletions(-) diff --git a/app/src/main/java/com/cappielloantonio/tempo/ui/dialog/PlaylistChooserDialog.java b/app/src/main/java/com/cappielloantonio/tempo/ui/dialog/PlaylistChooserDialog.java index af0d2bbe..4ca1f44f 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/ui/dialog/PlaylistChooserDialog.java +++ b/app/src/main/java/com/cappielloantonio/tempo/ui/dialog/PlaylistChooserDialog.java @@ -6,7 +6,6 @@ import android.view.View; import android.widget.Toast; import androidx.annotation.NonNull; -import androidx.annotation.StringRes; import androidx.fragment.app.DialogFragment; import androidx.lifecycle.ViewModelProvider; import androidx.recyclerview.widget.LinearLayoutManager; @@ -20,41 +19,30 @@ import com.cappielloantonio.tempo.util.Constants; import com.cappielloantonio.tempo.viewmodel.PlaylistChooserViewModel; import com.google.android.material.dialog.MaterialAlertDialogBuilder; -import java.util.Objects; -import java.util.concurrent.atomic.AtomicInteger; - public class PlaylistChooserDialog extends DialogFragment implements ClickCallback { private DialogPlaylistChooserBinding bind; private PlaylistChooserViewModel playlistChooserViewModel; - private PlaylistDialogHorizontalAdapter playlistDialogHorizontalAdapter; - @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { + DialogPlaylistChooserBinding.inflate(getLayoutInflater()); bind = DialogPlaylistChooserBinding.inflate(getLayoutInflater()); playlistChooserViewModel = new ViewModelProvider(requireActivity()).get(PlaylistChooserViewModel.class); - String[] playlistVisibilityChoice = { - getString(R.string.playlist_chooser_dialog_visibility_public), - getString(R.string.playlist_chooser_dialog_visibility_private) - }; + bind.playlistDialogChooserVisibilitySwitch.setOnCheckedChangeListener( + (buttonView, + isChecked) -> playlistChooserViewModel.setIsPlaylistPublic(isChecked) + ); + bind.playlistChooserDialogCreateButton.setOnClickListener(v -> launchPlaylistEditor()); + bind.playlistChooserDialogCancelButton.setOnClickListener(v -> dismiss()); - return new MaterialAlertDialogBuilder(getActivity()) + MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(requireContext()) .setView(bind.getRoot()) - .setTitle(R.string.playlist_chooser_dialog_title) - .setSingleChoiceItems( - playlistVisibilityChoice, - 0, - (dialog, which) -> { - boolean isPublic = (which == 0); - playlistChooserViewModel.setIsPlaylistPublic(isPublic); - }) - .setNeutralButton(R.string.playlist_chooser_dialog_neutral_button, (dialog, id) -> { }) - .setNegativeButton(R.string.playlist_chooser_dialog_negative_button, (dialog, id) -> dialog.cancel()) - .create(); + .setTitle(R.string.playlist_chooser_dialog_title); + return builder.create(); } @Override @@ -69,25 +57,26 @@ public class PlaylistChooserDialog extends DialogFragment implements ClickCallba initPlaylistView(); setSongInfo(); - setButtonAction(); } private void setSongInfo() { playlistChooserViewModel.setSongsToAdd(requireArguments().getParcelableArrayList(Constants.TRACKS_OBJECT)); } - private void setButtonAction() { - androidx.appcompat.app.AlertDialog alertDialog = (androidx.appcompat.app.AlertDialog) Objects.requireNonNull(getDialog()); - alertDialog.getButton(androidx.appcompat.app.AlertDialog.BUTTON_NEUTRAL).setOnClickListener(v -> { - Bundle bundle = new Bundle(); - bundle.putParcelableArrayList(Constants.TRACKS_OBJECT, playlistChooserViewModel.getSongsToAdd()); + private void launchPlaylistEditor() { + Bundle bundle = new Bundle(); + bundle.putParcelableArrayList( + Constants.TRACKS_OBJECT, + playlistChooserViewModel.getSongsToAdd() + ); - PlaylistEditorDialog dialog = new PlaylistEditorDialog(null); - dialog.setArguments(bundle); - dialog.show(requireActivity().getSupportFragmentManager(), null); + PlaylistEditorDialog editorDialog = new PlaylistEditorDialog(null); + editorDialog.setArguments(bundle); + editorDialog.show( + requireActivity().getSupportFragmentManager(), + null); - Objects.requireNonNull(getDialog()).dismiss(); - }); + dismiss(); } private void initPlaylistView() { diff --git a/app/src/main/res/layout/dialog_playlist_chooser.xml b/app/src/main/res/layout/dialog_playlist_chooser.xml index 3be03136..1a2e8008 100644 --- a/app/src/main/res/layout/dialog_playlist_chooser.xml +++ b/app/src/main/res/layout/dialog_playlist_chooser.xml @@ -3,6 +3,26 @@ android:layout_height="wrap_content" android:orientation="vertical"> + + + + + + + +