diff --git a/app/src/main/java/com/cappielloantonio/tempo/ui/adapter/DownloadHorizontalAdapter.java b/app/src/main/java/com/cappielloantonio/tempo/ui/adapter/DownloadHorizontalAdapter.java index 1dedeeff..52bcadb1 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/ui/adapter/DownloadHorizontalAdapter.java +++ b/app/src/main/java/com/cappielloantonio/tempo/ui/adapter/DownloadHorizontalAdapter.java @@ -285,37 +285,35 @@ public class DownloadHorizontalAdapter extends RecyclerView.Adapter filteredSongs = new ArrayList<>(); + Bundle bundle = new Bundle(); - if (view.equals(Constants.DOWNLOAD_TYPE_TRACK)) { - bundle.putParcelable(Constants.TRACK_OBJECT, grouped.get(getBindingAdapterPosition())); - click.onMediaLongClick(bundle); - return true; - } - - List filteredSongs = null; switch (view) { + case Constants.DOWNLOAD_TYPE_TRACK: + filteredSongs.add(grouped.get(getBindingAdapterPosition())); + break; case Constants.DOWNLOAD_TYPE_ALBUM: - filteredSongs = filterSong(Constants.DOWNLOAD_TYPE_ALBUM, grouped.get(getBindingAdapterPosition()).getAlbumId(), songs); + filteredSongs.addAll(filterSong(Constants.DOWNLOAD_TYPE_ALBUM, grouped.get(getBindingAdapterPosition()).getAlbumId(), songs)); break; case Constants.DOWNLOAD_TYPE_ARTIST: - filteredSongs = filterSong(Constants.DOWNLOAD_TYPE_ARTIST, grouped.get(getBindingAdapterPosition()).getArtistId(), songs); + filteredSongs.addAll(filterSong(Constants.DOWNLOAD_TYPE_ARTIST, grouped.get(getBindingAdapterPosition()).getArtistId(), songs)); break; case Constants.DOWNLOAD_TYPE_GENRE: - filteredSongs = filterSong(Constants.DOWNLOAD_TYPE_GENRE, grouped.get(getBindingAdapterPosition()).getGenre(), songs); + filteredSongs.addAll(filterSong(Constants.DOWNLOAD_TYPE_GENRE, grouped.get(getBindingAdapterPosition()).getGenre(), songs)); break; case Constants.DOWNLOAD_TYPE_YEAR: - filteredSongs = filterSong(Constants.DOWNLOAD_TYPE_YEAR, grouped.get(getBindingAdapterPosition()).getYear().toString(), songs); + filteredSongs.addAll(filterSong(Constants.DOWNLOAD_TYPE_YEAR, grouped.get(getBindingAdapterPosition()).getYear().toString(), songs)); break; } - if (filteredSongs == null) { - return false; - } + if (filteredSongs.isEmpty()) return false; - bundle.putParcelableArrayList(Constants.DOWNLOAD_TYPE_GROUP, new ArrayList<>(filteredSongs)); - bundle.putString(Constants.DOWNLOAD_TYPE_GROUP_NAME, item.downloadedItemTitleTextView.getText().toString()); + bundle.putParcelableArrayList(Constants.DOWNLOAD_GROUP, new ArrayList<>(filteredSongs)); + bundle.putString(Constants.DOWNLOAD_GROUP_TITLE, item.downloadedItemTitleTextView.getText().toString()); + bundle.putString(Constants.DOWNLOAD_GROUP_SUBTITLE, item.downloadedItemSubtitleTextView.getText().toString()); click.onDownloadGroupLongClick(bundle); + return true; } } diff --git a/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/bottomsheetdialog/DownloadedBottomSheetDialog.java b/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/bottomsheetdialog/DownloadedBottomSheetDialog.java index a98bdfdd..6e9229f3 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/bottomsheetdialog/DownloadedBottomSheetDialog.java +++ b/app/src/main/java/com/cappielloantonio/tempo/ui/fragment/bottomsheetdialog/DownloadedBottomSheetDialog.java @@ -30,13 +30,14 @@ import com.google.common.util.concurrent.ListenableFuture; import java.util.Collections; import java.util.List; +import java.util.Random; import java.util.stream.Collectors; @UnstableApi public class DownloadedBottomSheetDialog extends BottomSheetDialogFragment implements View.OnClickListener { private List songs; - - private String groupName; + private String groupTitle; + private String groupSubtitle; private ListenableFuture mediaBrowserListenableFuture; @@ -45,9 +46,11 @@ public class DownloadedBottomSheetDialog extends BottomSheetDialogFragment imple public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.bottom_sheet_downloaded_dialog, container, false); - songs = this.requireArguments().getParcelableArrayList(Constants.DOWNLOAD_TYPE_GROUP); - groupName = this.requireArguments().getString(Constants.DOWNLOAD_TYPE_GROUP_NAME); + songs = this.requireArguments().getParcelableArrayList(Constants.DOWNLOAD_GROUP); + groupTitle = this.requireArguments().getString(Constants.DOWNLOAD_GROUP_TITLE); + groupSubtitle = this.requireArguments().getString(Constants.DOWNLOAD_GROUP_SUBTITLE); + initUI(view); init(view); return view; @@ -66,16 +69,25 @@ public class DownloadedBottomSheetDialog extends BottomSheetDialogFragment imple super.onStop(); } - private void init(View view) { - ImageView coverAlbum = view.findViewById(R.id.album_cover_image_view); - CustomGlideRequest.Builder - .from(requireContext(), songs.get(0).getCoverArtId()) - .build() - .into(coverAlbum); + private void initUI(View view) { + TextView playRandom = view.findViewById(R.id.play_random_text_view); + playRandom.setVisibility(songs.size() > 1 ? View.VISIBLE : View.GONE); - TextView groupNameView = view.findViewById(R.id.group_name_text_view); - groupNameView.setText(MusicUtil.getReadableString(this.groupName)); - groupNameView.setSelected(true); + TextView remove = view.findViewById(R.id.remove_all_text_view); + remove.setText(songs.size() > 1 ? getText(R.string.downloaded_bottom_sheet_remove_all) : getText(R.string.downloaded_bottom_sheet_remove)); + } + + private void init(View view) { + ImageView coverAlbum = view.findViewById(R.id.group_cover_image_view); + CustomGlideRequest.Builder.from(requireContext(), songs.get(new Random().nextInt(songs.size())).getCoverArtId()).build().into(coverAlbum); + + TextView groupTitleView = view.findViewById(R.id.group_title_text_view); + groupTitleView.setText(MusicUtil.getReadableString(this.groupTitle)); + groupTitleView.setSelected(true); + + TextView groupSubtitleView = view.findViewById(R.id.group_subtitle_text_view); + groupSubtitleView.setText(MusicUtil.getReadableString(this.groupSubtitle)); + groupSubtitleView.setSelected(true); TextView playRandom = view.findViewById(R.id.play_random_text_view); playRandom.setOnClickListener(v -> { @@ -93,8 +105,7 @@ public class DownloadedBottomSheetDialog extends BottomSheetDialogFragment imple ((MainActivity) requireActivity()).setBottomSheetInPeek(true); dismissBottomSheet(); - } - ); + }); TextView addToQueue = view.findViewById(R.id.add_to_queue_text_view); addToQueue.setOnClickListener(v -> { @@ -105,11 +116,12 @@ public class DownloadedBottomSheetDialog extends BottomSheetDialogFragment imple }); TextView removeAll = view.findViewById(R.id.remove_all_text_view); - removeAll.setOnClickListener(v -> { List mediaItems = MappingUtil.mapDownloads(songs); List downloads = songs.stream().map(Download::new).collect(Collectors.toList()); + DownloadUtil.getDownloadTracker(requireContext()).remove(mediaItems, downloads); + dismissBottomSheet(); }); } diff --git a/app/src/main/java/com/cappielloantonio/tempo/util/Constants.kt b/app/src/main/java/com/cappielloantonio/tempo/util/Constants.kt index 7d35740f..37a2039f 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/util/Constants.kt +++ b/app/src/main/java/com/cappielloantonio/tempo/util/Constants.kt @@ -79,11 +79,13 @@ object Constants { const val DOWNLOAD_TYPE_TRACK = "download_type_track" const val DOWNLOAD_TYPE_ALBUM = "download_type_album" const val DOWNLOAD_TYPE_ARTIST = "download_type_artist" - const val DOWNLOAD_TYPE_GROUP = "download_type_group" - const val DOWNLOAD_TYPE_GROUP_NAME = "download_type_group_name" const val DOWNLOAD_TYPE_GENRE = "download_type_genre" const val DOWNLOAD_TYPE_YEAR = "download_type_year" + const val DOWNLOAD_GROUP = "download_group" + const val DOWNLOAD_GROUP_TITLE = "download_group_title" + const val DOWNLOAD_GROUP_SUBTITLE = "download_group_subtitle" + const val PLAYABLE_MEDIA_LIMIT = 100 const val PRE_PLAYABLE_MEDIA = 15 } \ No newline at end of file diff --git a/app/src/main/res/layout/bottom_sheet_downloaded_dialog.xml b/app/src/main/res/layout/bottom_sheet_downloaded_dialog.xml index d36831bf..d5659cd2 100644 --- a/app/src/main/res/layout/bottom_sheet_downloaded_dialog.xml +++ b/app/src/main/res/layout/bottom_sheet_downloaded_dialog.xml @@ -14,7 +14,7 @@ + app:layout_constraintStart_toEndOf="@+id/group_cover_image_view" + app:layout_constraintTop_toTopOf="@+id/group_cover_image_view" /> + + diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index e8e99f18..b175a573 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -300,5 +300,6 @@ Mischen Nächsten Titel spielen Zur Warteschlange hinzufügen + Entfernen Alle entfernen \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 084ef31b..70629b0d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -303,6 +303,7 @@ Shuffle Play next Add to queue + Remove Remove all OK Track info