pass serviceId instead of item, reduce duplication

This commit is contained in:
khimaros 2021-01-02 11:24:33 -08:00
parent 48a5107296
commit ac59382b84
6 changed files with 7 additions and 12 deletions

View File

@ -333,7 +333,6 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I>
}
}
protected void showStreamDialog(final StreamInfoItem item) {
final Context context = getContext();
final Activity activity = getActivity();
@ -360,7 +359,7 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I>
StreamDialogEntry.share
));
}
if (KoreUtil.shouldShowPlayWithKodi(context, item)) {
if (KoreUtil.shouldShowPlayWithKodi(context, item.getServiceId())) {
entries.add(StreamDialogEntry.play_with_kodi);
}
StreamDialogEntry.setEnabledEntries(entries);

View File

@ -175,7 +175,7 @@ public class PlaylistFragment extends BaseListInfoFragment<PlaylistInfo> {
StreamDialogEntry.share
));
}
if (KoreUtil.shouldShowPlayWithKodi(context, item)) {
if (KoreUtil.shouldShowPlayWithKodi(context, item.getServiceId())) {
entries.add(StreamDialogEntry.play_with_kodi);
}
StreamDialogEntry.setEnabledEntries(entries);

View File

@ -414,7 +414,7 @@ public class StatisticsPlaylistFragment
StreamDialogEntry.share
));
}
if (KoreUtil.shouldShowPlayWithKodi(context, infoItem)) {
if (KoreUtil.shouldShowPlayWithKodi(context, infoItem.getServiceId())) {
entries.add(StreamDialogEntry.play_with_kodi);
}
StreamDialogEntry.setEnabledEntries(entries);

View File

@ -782,7 +782,7 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
StreamDialogEntry.share
));
}
if (KoreUtil.shouldShowPlayWithKodi(context, infoItem)) {
if (KoreUtil.shouldShowPlayWithKodi(context, infoItem.getServiceId())) {
entries.add(StreamDialogEntry.play_with_kodi);
}
StreamDialogEntry.setEnabledEntries(entries);

View File

@ -932,9 +932,7 @@ public class VideoPlayerImpl extends VideoPlayer
service.getString(R.string.show_play_with_kodi_key), false);
// show kodi button if it supports the current service and it is enabled in settings
final boolean showKodiButton = playQueue != null && playQueue.getItem() != null
&& KoreUtil.isServiceSupportedByKore(playQueue.getItem().getServiceId())
&& PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(context.getString(R.string.show_play_with_kodi_key), false);
&& KoreUtil.shouldShowPlayWithKodi(context, playQueue.getItem().getServiceId());
playWithKodi.setVisibility(videoPlayerSelected() && kodiEnabled && showKodiButton
? View.VISIBLE : View.GONE);
}

View File

@ -1,6 +1,5 @@
package org.schabi.newpipe.util;
import android.content.Context;
import androidx.appcompat.app.AlertDialog;
@ -8,7 +7,6 @@ import androidx.preference.PreferenceManager;
import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.ServiceList;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
public final class KoreUtil {
private KoreUtil() { }
@ -18,8 +16,8 @@ public final class KoreUtil {
|| serviceId == ServiceList.SoundCloud.getServiceId());
}
public static boolean shouldShowPlayWithKodi(final Context context, final StreamInfoItem item) {
return isServiceSupportedByKore(item.getServiceId())
public static boolean shouldShowPlayWithKodi(final Context context, final int serviceId) {
return isServiceSupportedByKore(serviceId)
&& PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(context.getString(R.string.show_play_with_kodi_key), false);
}