Skip to content

Commit

Permalink
pass serviceId instead of item, reduce duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
khimaros committed Jan 2, 2021
1 parent 48a5107 commit ac59382
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ protected void onScrollToBottom() {
}
}


protected void showStreamDialog(final StreamInfoItem item) {
final Context context = getContext();
final Activity activity = getActivity();
Expand All @@ -360,7 +359,7 @@ protected void showStreamDialog(final StreamInfoItem item) {
StreamDialogEntry.share
));
}
if (KoreUtil.shouldShowPlayWithKodi(context, item)) {
if (KoreUtil.shouldShowPlayWithKodi(context, item.getServiceId())) {
entries.add(StreamDialogEntry.play_with_kodi);
}
StreamDialogEntry.setEnabledEntries(entries);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ protected void showStreamDialog(final StreamInfoItem item) {
StreamDialogEntry.share
));
}
if (KoreUtil.shouldShowPlayWithKodi(context, item)) {
if (KoreUtil.shouldShowPlayWithKodi(context, item.getServiceId())) {
entries.add(StreamDialogEntry.play_with_kodi);
}
StreamDialogEntry.setEnabledEntries(entries);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ private void showStreamDialog(final StreamStatisticsEntry item) {
StreamDialogEntry.share
));
}
if (KoreUtil.shouldShowPlayWithKodi(context, infoItem)) {
if (KoreUtil.shouldShowPlayWithKodi(context, infoItem.getServiceId())) {
entries.add(StreamDialogEntry.play_with_kodi);
}
StreamDialogEntry.setEnabledEntries(entries);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ protected void showStreamItemDialog(final PlaylistStreamEntry item) {
StreamDialogEntry.share
));
}
if (KoreUtil.shouldShowPlayWithKodi(context, infoItem)) {
if (KoreUtil.shouldShowPlayWithKodi(context, infoItem.getServiceId())) {
entries.add(StreamDialogEntry.play_with_kodi);
}
StreamDialogEntry.setEnabledEntries(entries);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -932,9 +932,7 @@ private void showHideKodiButton() {
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);
}
Expand Down
6 changes: 2 additions & 4 deletions app/src/main/java/org/schabi/newpipe/util/KoreUtil.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package org.schabi.newpipe.util;


import android.content.Context;

import androidx.appcompat.app.AlertDialog;
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() { }
Expand All @@ -18,8 +16,8 @@ public static boolean isServiceSupportedByKore(final int serviceId) {
|| 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);
}
Expand Down

0 comments on commit ac59382

Please sign in to comment.