Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shuffle button for music video collection #3861

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import org.jellyfin.androidtv.util.ImageHelper;
import org.jellyfin.androidtv.util.InfoLayoutHelper;
import org.jellyfin.androidtv.util.KeyProcessor;
import org.jellyfin.androidtv.util.PlaybackHelper;
import org.jellyfin.androidtv.util.Utils;
import org.jellyfin.androidtv.util.apiclient.EmptyLifecycleAwareResponse;
import org.jellyfin.sdk.api.client.ApiClient;
Expand Down Expand Up @@ -123,6 +124,7 @@ public class BrowseGridFragment extends Fragment implements View.OnKeyListener {
private final Lazy<ItemLauncher> itemLauncher = inject(ItemLauncher.class);
private final Lazy<KeyProcessor> keyProcessor = inject(KeyProcessor.class);
private final Lazy<ApiClient> api = inject(ApiClient.class);
private final Lazy<PlaybackHelper> playbackHelper = inject(PlaybackHelper.class);

private int mCardsScreenEst = 0;
private int mCardsScreenStride = 0;
Expand Down Expand Up @@ -699,6 +701,7 @@ public void loadGrid() {
mAdapter.Retrieve();
}

private ImageButton mShuffleButton;
private ImageButton mSortButton;
private ImageButton mSettingsButton;
private ImageButton mUnwatchedButton;
Expand All @@ -719,6 +722,23 @@ private void addTools() {
//Add tools
int size = Utils.convertDpToPixel(requireContext(), 26);

if (mFolder.getCollectionType() == CollectionType.MUSICVIDEOS)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about other collection types like music (when browsing albums/artists etc.)?

{
mShuffleButton = new ImageButton(requireContext(), null, 0, R.style.Button_Icon);
mShuffleButton.setImageResource(R.drawable.ic_shuffle);
mShuffleButton.setMaxHeight(size);
mShuffleButton.setAdjustViewBounds(true);
mShuffleButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
playbackHelper.getValue().retrieveAndPlay(mFolder.getId(), true, requireContext());
}
});
mShuffleButton.setContentDescription(getString(R.string.lbl_shuffle_all));

binding.toolBar.addView(mShuffleButton);
}

mSortButton = new ImageButton(requireContext(), null, 0, R.style.Button_Icon);
mSortButton.setImageResource(R.drawable.ic_sort);
mSortButton.setMaxHeight(size);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,18 @@ class SdkPlaybackHelper(
}
}

BaseItemKind.COLLECTION_FOLDER -> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding COLLECTION_FOLDER to the BaseItemKind.SERIES, BaseItemKind.SEASON, BaseItemKind.BOX_SET, BaseItemKind.FOLDER line makes more sense. That results in (mostly) the same request.

val response by api.itemsApi.getItems(
parentId = mainItem.id,
isMissing = false,
sortBy = if (shuffle) listOf(ItemSortBy.RANDOM) else null,
recursive = true,
limit = ITEM_QUERY_LIMIT
)

response.items.orEmpty()
}

else -> {
val parts = getParts(mainItem)
val addIntros = allowIntros && userPreferences[UserPreferences.cinemaModeEnabled]
Expand Down
Loading