mirror of
https://github.com/CappielloAntonio/tempo.git
synced 2026-01-31 06:42:06 +00:00
Queue elements are now clickable and customized
This commit is contained in:
@@ -8,14 +8,19 @@ import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.media3.common.MediaItem;
|
||||
import androidx.media3.session.MediaBrowser;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
|
||||
import com.cappielloantonio.play.R;
|
||||
import com.cappielloantonio.play.glide.CustomGlideRequest;
|
||||
import com.cappielloantonio.play.interfaces.MediaIndexCallback;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.service.MediaManager;
|
||||
import com.cappielloantonio.play.ui.fragment.PlayerBottomSheetFragment;
|
||||
import com.cappielloantonio.play.util.MusicUtil;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -27,6 +32,7 @@ public class PlayerSongQueueAdapter extends RecyclerView.Adapter<PlayerSongQueue
|
||||
private final PlayerBottomSheetFragment playerBottomSheetFragment;
|
||||
private final Context context;
|
||||
|
||||
private ListenableFuture<MediaBrowser> mediaBrowserListenableFuture;
|
||||
private List<Song> songs;
|
||||
|
||||
public PlayerSongQueueAdapter(Context context, PlayerBottomSheetFragment playerBottomSheetFragment) {
|
||||
@@ -56,10 +62,12 @@ public class PlayerSongQueueAdapter extends RecyclerView.Adapter<PlayerSongQueue
|
||||
.transform(new RoundedCorners(CustomGlideRequest.CORNER_RADIUS))
|
||||
.into(holder.cover);
|
||||
|
||||
/* if (position < MusicPlayerRemote.getPosition()) {
|
||||
holder.songTitle.setTextColor(context.getResources().getColor(R.color.songToPlayTextColor, null));
|
||||
holder.songSubtitle.setTextColor(context.getResources().getColor(R.color.songToPlayTextColor, null));
|
||||
} */
|
||||
MediaManager.getCurrentIndex(mediaBrowserListenableFuture, index -> {
|
||||
if (position < index) {
|
||||
holder.songTitle.setTextColor(context.getResources().getColor(R.color.songToPlayTextColor, null));
|
||||
holder.songSubtitle.setTextColor(context.getResources().getColor(R.color.songToPlayTextColor, null));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -76,6 +84,10 @@ public class PlayerSongQueueAdapter extends RecyclerView.Adapter<PlayerSongQueue
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setMediaBrowserListenableFuture(ListenableFuture<MediaBrowser> mediaBrowserListenableFuture) {
|
||||
this.mediaBrowserListenableFuture = mediaBrowserListenableFuture;
|
||||
}
|
||||
|
||||
public Song getItem(int id) {
|
||||
return songs.get(id);
|
||||
}
|
||||
@@ -100,8 +112,7 @@ public class PlayerSongQueueAdapter extends RecyclerView.Adapter<PlayerSongQueue
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
// playerBottomSheetFragment.setSongInfo(songs.get(getBindingAdapterPosition()));
|
||||
// MusicPlayerRemote.openQueue(songs, getBindingAdapterPosition(), true);
|
||||
MediaManager.startQueue(mediaBrowserListenableFuture, context, songs, getBindingAdapterPosition());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.cappielloantonio.play.interfaces;
|
||||
|
||||
public interface MediaIndexCallback {
|
||||
void onRecovery(int index);
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import androidx.media3.common.MediaItem;
|
||||
import androidx.media3.session.MediaBrowser;
|
||||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.interfaces.MediaIndexCallback;
|
||||
import com.cappielloantonio.play.model.Song;
|
||||
import com.cappielloantonio.play.repository.QueueRepository;
|
||||
import com.cappielloantonio.play.util.MappingUtil;
|
||||
@@ -240,6 +241,20 @@ public class MediaManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static void getCurrentIndex(ListenableFuture<MediaBrowser> mediaBrowserListenableFuture, MediaIndexCallback callback) {
|
||||
if (mediaBrowserListenableFuture != null) {
|
||||
mediaBrowserListenableFuture.addListener(() -> {
|
||||
try {
|
||||
if (mediaBrowserListenableFuture.isDone()) {
|
||||
callback.onRecovery(mediaBrowserListenableFuture.get().getCurrentMediaItemIndex());
|
||||
}
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
Log.e(TAG, e.getMessage());
|
||||
}
|
||||
}, MoreExecutors.directExecutor());
|
||||
}
|
||||
}
|
||||
|
||||
public static void timestamp(MediaItem mediaItem) {
|
||||
if (mediaItem != null) getQueueRepository().setTimestamp(mediaItem.mediaId);
|
||||
}
|
||||
|
||||
@@ -99,6 +99,12 @@ public class PlayerBottomSheetFragment extends Fragment {
|
||||
bindMediaController();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
setMediaBrowserListenableFuture();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
releaseMediaBrowser();
|
||||
@@ -135,6 +141,9 @@ public class PlayerBottomSheetFragment extends Fragment {
|
||||
MediaController.releaseFuture(mediaBrowserListenableFuture);
|
||||
}
|
||||
|
||||
private void setMediaBrowserListenableFuture() {
|
||||
playerSongQueueAdapter.setMediaBrowserListenableFuture(mediaBrowserListenableFuture);
|
||||
}
|
||||
|
||||
@SuppressLint("UnsafeOptInUsageError")
|
||||
private void bindMediaController() {
|
||||
|
||||
Reference in New Issue
Block a user