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
Binary file added BrowsePresenter_from_master.java
Binary file not shown.
Binary file added VideoMenuPresenter_from_master.java
Binary file not shown.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.liskovsoft.sharedutils.mylogger.Log;
import com.liskovsoft.smartyoutubetv2.common.app.models.playback.service.VideoStateService;
import com.liskovsoft.smartyoutubetv2.common.app.models.playback.service.VideoStateService.State;
import com.liskovsoft.smartyoutubetv2.common.prefs.BlacklistData;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -100,10 +101,11 @@ public static VideoGroup from(MediaGroup mediaGroup, BrowseSection section, int
videoGroup.mPosition = groupPosition;
videoGroup.mVideos = new ArrayList<>();
videoGroup.mMediaGroup = mediaGroup;
videoGroup.mTitle = mediaGroup != null && mediaGroup.getTitle() != null ?
mediaGroup.getTitle() : section != null ? section.getTitle() : null;
videoGroup.mTitle = mediaGroup != null && mediaGroup.getTitle() != null ? mediaGroup.getTitle()
: section != null ? section.getTitle() : null;
// Fix duplicated rows e.g. Shorts
//videoGroup.mId = !TextUtils.isEmpty(videoGroup.mTitle) ? videoGroup.mTitle.hashCode() : videoGroup.hashCode();
// videoGroup.mId = !TextUtils.isEmpty(videoGroup.mTitle) ?
// videoGroup.mTitle.hashCode() : videoGroup.hashCode();
videoGroup.mId = videoGroup.hashCode();

if (mediaGroup == null) {
Expand Down Expand Up @@ -198,9 +200,9 @@ public String getTitle() {
public void setTitle(String title) {
mTitle = title;

//if (!TextUtils.isEmpty(title) && (mId == 0 || mId == hashCode())) {
// mId = title.hashCode();
//}
// if (!TextUtils.isEmpty(title) && (mId == 0 || mId == hashCode())) {
// mId = title.hashCode();
// }
}

public int getId() {
Expand All @@ -225,8 +227,8 @@ public boolean isShorts() {
}

for (int i = 0; i < Math.min(8, mVideos.size()); i++) {
if (!mVideos.get(i).isShorts)
return false;
if (!mVideos.get(i).isShorts)
return false;
}

return true;
Expand Down Expand Up @@ -257,7 +259,8 @@ public void setAction(int action) {
}

public int getType() {
return mType != -1 ? mType : getMediaGroup() != null ? getMediaGroup().getType() : mSection != null ? mSection.getId() : -1;
return mType != -1 ? mType
: getMediaGroup() != null ? getMediaGroup().getType() : mSection != null ? mSection.getId() : -1;
}

public void setType(int type) {
Expand Down Expand Up @@ -452,6 +455,20 @@ public void add(int idx, Video video) {
return;
}

// Filter out videos from blacklisted channels
String channelId = video.getChannelIdForBlacklist();
if (channelId != null) {
try {
BlacklistData blacklistData = BlacklistData.instance(null);
if (blacklistData != null && blacklistData.isChannelBlacklisted(channelId)) {
return; // Skip this video - it's from a blacklisted channel
}
} catch (Exception e) {
// If BlacklistData isn't initialized yet, allow the video through
// This can happen during early app startup
}
}

if (mVideos == null) {
mVideos = new ArrayList<>();
}
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ public void enableSection(int sectionId, boolean enabled) {
mIsSettingsSectionEnabled = true; // prevent Settings lock
}

//Video item = new Video();
//item.sectionId = sectionId;
// Video item = new Video();
// item.sectionId = sectionId;
//
//if (mPinnedItems.contains(item)) { // don't reorder if item already exists
// return;
//}
// if (mPinnedItems.contains(item)) { // don't reorder if item already exists
// return;
// }

Video section = Helpers.findFirst(mPinnedItems, item -> item != null && item.sectionId == sectionId);

Expand Down Expand Up @@ -162,7 +162,7 @@ private boolean canShiftSection(int sectionId, int shift) {
int index = findPinnedItemIndex(sectionId);

if (index != -1) {
return index + shift >= 0 && index + shift < mPinnedItems.size();
return index + shift >= 0 && index + shift < mPinnedItems.size();
}

return false;
Expand Down Expand Up @@ -240,6 +240,7 @@ private void initSections() {
mDefaultSections.put(R.string.header_channels, MediaGroup.TYPE_CHANNEL_UPLOADS);
mDefaultSections.put(R.string.header_subscriptions, MediaGroup.TYPE_SUBSCRIPTIONS);
mDefaultSections.put(R.string.header_history, MediaGroup.TYPE_HISTORY);
mDefaultSections.put(R.string.header_blacklisted_channels, MediaGroup.TYPE_BLACKLISTED_CHANNELS);
mDefaultSections.put(R.string.header_playlists, MediaGroup.TYPE_USER_PLAYLISTS);
mDefaultSections.put(R.string.my_videos, MediaGroup.TYPE_MY_VIDEOS);
mDefaultSections.put(R.string.playback_queue_category_title, MediaGroup.TYPE_PLAYBACK_QUEUE);
Expand All @@ -249,7 +250,8 @@ private void initSections() {
private void initPinnedItems() {
for (int sectionId : mDefaultSections.values()) {
// Broken sections
enableSection(sectionId, !Helpers.equalsAny(sectionId, new int[]{MediaGroup.TYPE_NOTIFICATIONS, MediaGroup.TYPE_PLAYBACK_QUEUE, MediaGroup.TYPE_TRENDING}));
enableSection(sectionId, !Helpers.equalsAny(sectionId, new int[] { MediaGroup.TYPE_NOTIFICATIONS,
MediaGroup.TYPE_PLAYBACK_QUEUE, MediaGroup.TYPE_TRENDING }));
}
}

Expand All @@ -268,7 +270,8 @@ private void cleanupPinnedItems() {
return true;
}

return !item.hasPlaylist() && item.channelId == null && item.sectionId == -1 && item.channelGroupId == null && !item.hasReloadPageKey();
return !item.hasPlaylist() && item.channelId == null && item.sectionId == -1 && item.channelGroupId == null
&& !item.hasReloadPageKey();
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
package com.liskovsoft.smartyoutubetv2.common.prefs;

import android.annotation.SuppressLint;
import android.content.Context;

import com.liskovsoft.sharedutils.helpers.Helpers;
import com.liskovsoft.smartyoutubetv2.common.prefs.AppPrefs.ProfileChangeListener;
import com.liskovsoft.smartyoutubetv2.common.utils.Utils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class BlacklistData implements ProfileChangeListener {
private static final String BLACKLIST_DATA = "blacklist_data";
@SuppressLint("StaticFieldLeak")
private static BlacklistData sInstance;
private final Context mContext;
private final AppPrefs mPrefs;
private Set<String> mBlacklistedChannelIds;
private Map<String, String> mBlacklistedChannelNames; // channelId -> channel name
private final Runnable mPersistStateInt = this::persistStateInt;
private final List<BlacklistChangeListener> mListeners = new ArrayList<>();

public interface BlacklistChangeListener {
void onBlacklistChanged();
}

private BlacklistData(Context context) {
mContext = context;
mPrefs = AppPrefs.instance(context);
mPrefs.addListener(this);
restoreState();
}

public static BlacklistData instance(Context context) {
if (sInstance == null) {
sInstance = new BlacklistData(context.getApplicationContext());
}

return sInstance;
}

/**
* Add a channel to the blacklist
*
* @param channelId The channel ID to blacklist
* @param channelName The channel name (optional, for display purposes)
*/
public void addBlacklistedChannel(String channelId, String channelName) {
if (channelId == null || channelId.isEmpty()) {
return;
}

mBlacklistedChannelIds.add(channelId);
if (channelName != null && !channelName.isEmpty()) {
mBlacklistedChannelNames.put(channelId, channelName);
}
persistState();
notifyListeners();
}

/**
* Remove a channel from the blacklist
*
* @param channelId The channel ID to remove
*/
public void removeBlacklistedChannel(String channelId) {
if (channelId == null || channelId.isEmpty()) {
return;
}

mBlacklistedChannelIds.remove(channelId);
mBlacklistedChannelNames.remove(channelId);
persistState();
notifyListeners();
}

/**
* Check if a channel is blacklisted
*
* @param channelId The channel ID to check
* @return true if the channel is blacklisted
*/
public boolean isChannelBlacklisted(String channelId) {
if (channelId == null || channelId.isEmpty()) {
return false;
}

return mBlacklistedChannelIds.contains(channelId);
}

/**
* Get all blacklisted channel IDs
*
* @return Unmodifiable set of blacklisted channel IDs
*/
public Set<String> getBlacklistedChannels() {
return Collections.unmodifiableSet(mBlacklistedChannelIds);
}

/**
* Get the name of a blacklisted channel
*
* @param channelId The channel ID
* @return The channel name, or null if not available
*/
public String getBlacklistedChannelName(String channelId) {
return mBlacklistedChannelNames.get(channelId);
}

/**
* Get all blacklisted channels with their names
*
* @return Unmodifiable map of channelId -> channel name
*/
public Map<String, String> getBlacklistedChannelsWithNames() {
return Collections.unmodifiableMap(mBlacklistedChannelNames);
}

/**
* Get the count of blacklisted channels
*
* @return Number of blacklisted channels
*/
public int getBlacklistedChannelCount() {
return mBlacklistedChannelIds.size();
}

/**
* Clear all blacklisted channels
*/
public void clearBlacklist() {
mBlacklistedChannelIds.clear();
mBlacklistedChannelNames.clear();
persistState();
}

private synchronized void restoreState() {
String data = mPrefs.getProfileData(BLACKLIST_DATA);

String[] split = Helpers.splitData(data);

List<String> channelIdList = Helpers.parseStrList(split, 0);
mBlacklistedChannelNames = Helpers.parseMap(split, 1, Helpers::parseStr, Helpers::parseStr);

if (channelIdList == null) {
mBlacklistedChannelIds = new HashSet<>();
} else {
mBlacklistedChannelIds = new HashSet<>(channelIdList);
}

if (mBlacklistedChannelNames == null) {
mBlacklistedChannelNames = new HashMap<>();
}
}

public void persistNow() {
Utils.post(mPersistStateInt);
}

private void persistState() {
Utils.postDelayed(mPersistStateInt, 10_000);
}

private void persistStateInt() {
// Convert Set to List for persistence
List<String> channelIdList = new ArrayList<>(mBlacklistedChannelIds);
mPrefs.setProfileData(BLACKLIST_DATA, Helpers.mergeData(
channelIdList,
mBlacklistedChannelNames));
}

public void addListener(BlacklistChangeListener listener) {
if (!mListeners.contains(listener)) {
mListeners.add(listener);
}
}

public void removeListener(BlacklistChangeListener listener) {
mListeners.remove(listener);
}

private void notifyListeners() {
for (BlacklistChangeListener listener : mListeners) {
listener.onBlacklistChanged();
}
}

@Override
public void onProfileChanged() {
restoreState();
}
}
Loading