Skip to content
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 @@ -12,6 +12,7 @@
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -40,8 +41,10 @@
import org.schabi.newpipe.views.SuperScrollLayoutManager;

import javax.annotation.Nonnull;
import java.util.HashSet;
import java.util.List;
import java.util.Queue;
import java.util.Set;
import java.util.function.Supplier;

public abstract class BaseListFragment<I, N> extends BaseStateFragment<I>
Expand Down Expand Up @@ -278,6 +281,12 @@ public void held(final StreamInfoItem selectedItem) {
@Override
public void selected(final ChannelInfoItem selectedItem) {
try {
if (isChannelBlocked(selectedItem.getName())) {
Toast.makeText(requireContext(),
R.string.channel_is_blocked,
Toast.LENGTH_SHORT).show();
return;
}
onItemSelected(selectedItem);
NavigationHelper.openChannelFragment(getFM(),
selectedItem.getServiceId(),
Expand All @@ -294,6 +303,12 @@ public void selected(final ChannelInfoItem selectedItem) {
@Override
public void selected(final PlaylistInfoItem selectedItem) {
try {
if (isChannelBlocked(selectedItem.getUploaderName())) {
Toast.makeText(requireContext(),
R.string.channel_is_blocked,
Toast.LENGTH_SHORT).show();
return;
}
onItemSelected(selectedItem);
NavigationHelper.openPlaylistFragment(getFM(),
selectedItem.getServiceId(),
Expand Down Expand Up @@ -542,4 +557,21 @@ public void onSharedPreferenceChanged(final SharedPreferences sharedPreferences,
protected ItemViewMode getItemViewMode() {
return ThemeHelper.getItemViewMode(requireContext());
}

/**
* Check if a channel name is in the user's block list.
* @param channelName the channel name to check
* @return true if the channel is blocked
*/
protected boolean isChannelBlocked(@Nullable final String channelName) {
if (channelName == null || channelName.isEmpty()) {
return false;
}
final SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(requireContext());
final Set<String> blockedChannels = prefs.getStringSet(
getString(R.string.filter_by_channel_key) + "_set",
new HashSet<>());
return blockedChannels.contains(channelName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -39,8 +40,10 @@
import org.schabi.newpipe.util.StateSaver;
import org.schabi.newpipe.util.external_communication.ShareUtils;

import java.util.HashSet;
import java.util.List;
import java.util.Queue;
import java.util.Set;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.core.Observable;
Expand Down Expand Up @@ -396,6 +399,26 @@ private void runWorker(final boolean forceLoad) {
@Override
public void handleResult(@NonNull final ChannelInfo result) {
super.handleResult(result);

// Safety net: if the channel is in the block list, prevent access
final String channelName = result.getName();
if (channelName != null && !channelName.isEmpty()) {
final SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(requireContext());
final Set<String> blockedChannels = prefs.getStringSet(
getString(R.string.filter_by_channel_key) + "_set",
new HashSet<>());
if (blockedChannels.contains(channelName)) {
Toast.makeText(requireContext(),
R.string.channel_is_blocked,
Toast.LENGTH_SHORT).show();
if (getParentFragmentManager().getBackStackEntryCount() > 0) {
getParentFragmentManager().popBackStack();
}
return;
}
}

currentInfo = result;
setInitialData(result.getServiceId(), result.getOriginalUrl(), result.getName());

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,7 @@
<string name="search_result">Search results</string>
<string name="filter_field_summary">Apply Filter To</string>
<string name="channel_videos">Channel videos</string>
<string name="channel_is_blocked">This channel is in your block list</string>
<string name="success">Success</string>
<string name="settings_category_proxy_title">Proxy (Supporters)</string>
<string name="proxy_token_title">Token</string>
Expand Down