2021-08-25 01:30:40 +00:00
|
|
|
package org.schabi.newpipe;
|
|
|
|
|
|
|
|
import static org.schabi.newpipe.util.external_communication.ShareUtils.shareText;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.view.ContextThemeWrapper;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.PopupMenu;
|
|
|
|
|
|
|
|
import androidx.fragment.app.FragmentManager;
|
|
|
|
|
2021-10-09 16:46:20 +00:00
|
|
|
import org.schabi.newpipe.database.stream.model.StreamEntity;
|
|
|
|
import org.schabi.newpipe.local.dialog.PlaylistDialog;
|
2021-08-25 01:30:40 +00:00
|
|
|
import org.schabi.newpipe.player.playqueue.PlayQueue;
|
|
|
|
import org.schabi.newpipe.player.playqueue.PlayQueueItem;
|
|
|
|
import org.schabi.newpipe.util.NavigationHelper;
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
|
|
|
public final class QueueItemMenuUtil {
|
2021-10-15 18:18:52 +00:00
|
|
|
private QueueItemMenuUtil() {
|
|
|
|
}
|
|
|
|
|
2021-08-25 01:30:40 +00:00
|
|
|
public static void openPopupMenu(final PlayQueue playQueue,
|
|
|
|
final PlayQueueItem item,
|
|
|
|
final View view,
|
|
|
|
final boolean hideDetails,
|
|
|
|
final FragmentManager fragmentManager,
|
2021-08-25 09:04:15 +00:00
|
|
|
final Context context) {
|
2021-08-25 01:30:40 +00:00
|
|
|
final ContextThemeWrapper themeWrapper =
|
|
|
|
new ContextThemeWrapper(context, R.style.DarkPopupMenu);
|
|
|
|
|
|
|
|
final PopupMenu popupMenu = new PopupMenu(themeWrapper, view);
|
|
|
|
popupMenu.inflate(R.menu.menu_play_queue_item);
|
|
|
|
|
|
|
|
if (hideDetails) {
|
|
|
|
popupMenu.getMenu().findItem(R.id.menu_item_details).setVisible(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
popupMenu.setOnMenuItemClickListener(menuItem -> {
|
|
|
|
switch (menuItem.getItemId()) {
|
|
|
|
case R.id.menu_item_remove:
|
|
|
|
final int index = playQueue.indexOf(item);
|
|
|
|
playQueue.remove(index);
|
|
|
|
return true;
|
|
|
|
case R.id.menu_item_details:
|
|
|
|
// playQueue is null since we don't want any queue change
|
|
|
|
NavigationHelper.openVideoDetail(context, item.getServiceId(),
|
|
|
|
item.getUrl(), item.getTitle(), null,
|
|
|
|
false);
|
|
|
|
return true;
|
|
|
|
case R.id.menu_item_append_playlist:
|
2021-10-09 16:46:20 +00:00
|
|
|
PlaylistDialog.createCorrespondingDialog(
|
|
|
|
context,
|
|
|
|
Collections.singletonList(new StreamEntity(item)),
|
|
|
|
dialog -> dialog.show(
|
|
|
|
fragmentManager,
|
|
|
|
"QueueItemMenuUtil@append_playlist"
|
|
|
|
)
|
2021-08-25 01:30:40 +00:00
|
|
|
);
|
2021-10-09 16:46:20 +00:00
|
|
|
|
2021-08-25 01:30:40 +00:00
|
|
|
return true;
|
2021-10-11 06:46:29 +00:00
|
|
|
case R.id.menu_item_channel_details:
|
2021-10-15 18:16:34 +00:00
|
|
|
// An intent must be used here.
|
|
|
|
// Opening with FragmentManager transactions is not working,
|
|
|
|
// as PlayQueueActivity doesn't use fragments.
|
2021-10-11 06:46:29 +00:00
|
|
|
NavigationHelper.openChannelFragmentUsingIntent(context, item.getServiceId(),
|
|
|
|
item.getUploaderUrl(), item.getUploader());
|
|
|
|
return true;
|
2021-08-25 01:30:40 +00:00
|
|
|
case R.id.menu_item_share:
|
|
|
|
shareText(context, item.getTitle(), item.getUrl(),
|
|
|
|
item.getThumbnailUrl());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
|
|
|
popupMenu.show();
|
|
|
|
}
|
|
|
|
}
|