channel groups reworking

This commit is contained in:
Yuriy Liskov
2024-12-22 03:11:54 +02:00
parent 699f85c295
commit ea78c3d1ce
11 changed files with 134 additions and 339 deletions

View File

@@ -5,6 +5,8 @@ import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.liskovsoft.mediaserviceinterfaces.yt.data.ChannelGroup;
import com.liskovsoft.mediaserviceinterfaces.yt.data.ChapterItem;
import com.liskovsoft.mediaserviceinterfaces.yt.data.DislikeData;
import com.liskovsoft.mediaserviceinterfaces.yt.data.MediaGroup;
@@ -17,8 +19,6 @@ import com.liskovsoft.sharedutils.helpers.DateHelper;
import com.liskovsoft.sharedutils.helpers.Helpers;
import com.liskovsoft.sharedutils.helpers.MessageHelpers;
import com.liskovsoft.smartyoutubetv2.common.app.models.playback.service.VideoStateService;
import com.liskovsoft.smartyoutubetv2.common.app.presenters.dialogs.menu.providers.channelgroup.ChannelGroup;
import com.liskovsoft.smartyoutubetv2.common.app.presenters.dialogs.menu.providers.channelgroup.ChannelGroup.Channel;
import com.liskovsoft.smartyoutubetv2.common.prefs.PlayerTweaksData;
import com.liskovsoft.youtubeapi.common.helpers.ServiceHelper;
@@ -210,20 +210,19 @@ public final class Video {
public static Video from(ChannelGroup group) {
Video video = new Video();
video.title = group.title;
video.cardImageUrl = group.iconUrl;
video.channelGroupId = group.id;
video.title = group.getTitle();
video.cardImageUrl = group.getIconUrl();
video.channelGroupId = group.getId();
return video;
}
public static Video from(Channel channel) {
public static Video from(ChannelGroup.Channel channel) {
Video video = new Video();
video.title = channel.title;
video.cardImageUrl = channel.iconUrl;
video.channelId = channel.channelId;
video.title = channel.getTitle();
video.cardImageUrl = channel.getIconUrl();
video.channelId = channel.getChannelId();
return video;
}
///**
// * Don't change the logic from equality by reference!<br/>
// * Or adapters won't work properly (same video may appear twice).

View File

@@ -28,7 +28,7 @@ import com.liskovsoft.smartyoutubetv2.common.app.presenters.ChannelPresenter;
import com.liskovsoft.smartyoutubetv2.common.app.presenters.SearchPresenter;
import com.liskovsoft.smartyoutubetv2.common.app.presenters.dialogs.menu.VideoMenuPresenter;
import com.liskovsoft.smartyoutubetv2.common.app.presenters.dialogs.menu.VideoMenuPresenter.VideoMenuCallback;
import com.liskovsoft.smartyoutubetv2.common.app.presenters.dialogs.menu.providers.channelgroup.ChannelGroupService;
import com.liskovsoft.smartyoutubetv2.common.app.presenters.dialogs.menu.providers.channelgroup.ChannelGroupServiceWrapper;
import com.liskovsoft.smartyoutubetv2.common.app.presenters.settings.AutoFrameRateSettingsPresenter;
import com.liskovsoft.smartyoutubetv2.common.exoplayer.selector.FormatItem;
import com.liskovsoft.smartyoutubetv2.common.exoplayer.selector.track.SubtitleTrack;
@@ -56,7 +56,6 @@ public class PlayerUIController extends BasePlayerController {
private SuggestionsController mSuggestionsController;
private PlayerData mPlayerData;
private PlayerTweaksData mPlayerTweaksData;
private ChannelGroupService mChannelGroupService;
private List<PlaylistInfo> mPlaylistInfos;
private FormatItem mAudioFormat = FormatItem.AUDIO_HQ_MP4A;
private boolean mEngineReady;
@@ -89,7 +88,6 @@ public class PlayerUIController extends BasePlayerController {
mSuggestionsController = getController(SuggestionsController.class);
mPlayerData = PlayerData.instance(getContext());
mPlayerTweaksData = PlayerTweaksData.instance(getContext());
mChannelGroupService = ChannelGroupService.instance(getContext());
// Could be set once per activity creation (view layout stuff)
getPlayer().setVideoZoomMode(mPlayerData.getVideoZoomMode());
@@ -334,7 +332,7 @@ public class PlayerUIController extends BasePlayerController {
setPlaylistAddButtonStateCached();
setSubtitleButtonState();
getPlayer().setButtonState(R.id.action_rotate, mPlayerData.getVideoRotation() == 0 ? PlayerUI.BUTTON_OFF : PlayerUI.BUTTON_ON);
getPlayer().setButtonState(R.id.action_subscribe, (metadata.isSubscribed() || mChannelGroupService.isSubscribed(metadata.getChannelId())) ? PlayerUI.BUTTON_ON : PlayerUI.BUTTON_OFF);
getPlayer().setButtonState(R.id.action_subscribe, metadata.isSubscribed() ? PlayerUI.BUTTON_ON : PlayerUI.BUTTON_OFF);
getPlayer().setButtonState(R.id.action_afr, mPlayerData.isAfrEnabled() ? PlayerUI.BUTTON_ON : PlayerUI.BUTTON_OFF);
}
@@ -829,16 +827,6 @@ public class PlayerUIController extends BasePlayerController {
return;
}
if (!YouTubeSignInService.instance().isSigned()) {
//MessageHelpers.showMessage(getContext(), R.string.msg_signed_users_only);
mChannelGroupService.subscribe(getPlayer().getVideo(), buttonState == PlayerUI.BUTTON_OFF);
getPlayer().getVideo().isSubscribed = buttonState == PlayerUI.BUTTON_OFF;
getPlayer().setButtonState(R.id.action_subscribe, buttonState == PlayerUI.BUTTON_OFF ? PlayerUI.BUTTON_ON : PlayerUI.BUTTON_OFF);
return;
}
if (buttonState == PlayerUI.BUTTON_OFF) {
callMediaItemObservable(mMediaItemService::subscribeObserve);
} else {

View File

@@ -10,6 +10,7 @@ import com.liskovsoft.mediaserviceinterfaces.yt.NotificationsService;
import com.liskovsoft.mediaserviceinterfaces.yt.ServiceManager;
import com.liskovsoft.mediaserviceinterfaces.yt.SignInService;
import com.liskovsoft.mediaserviceinterfaces.yt.data.Account;
import com.liskovsoft.mediaserviceinterfaces.yt.data.ChannelGroup;
import com.liskovsoft.mediaserviceinterfaces.yt.data.MediaGroup;
import com.liskovsoft.sharedutils.helpers.Helpers;
import com.liskovsoft.sharedutils.helpers.ScreenHelper;
@@ -34,9 +35,7 @@ import com.liskovsoft.smartyoutubetv2.common.app.presenters.dialogs.menu.Channel
import com.liskovsoft.smartyoutubetv2.common.app.presenters.dialogs.menu.SectionMenuPresenter;
import com.liskovsoft.smartyoutubetv2.common.app.presenters.dialogs.menu.VideoMenuPresenter;
import com.liskovsoft.smartyoutubetv2.common.app.presenters.dialogs.menu.VideoMenuPresenter.VideoMenuCallback;
import com.liskovsoft.smartyoutubetv2.common.app.presenters.dialogs.menu.providers.channelgroup.ChannelGroup;
import com.liskovsoft.smartyoutubetv2.common.app.presenters.dialogs.menu.providers.channelgroup.ChannelGroup.Channel;
import com.liskovsoft.smartyoutubetv2.common.app.presenters.dialogs.menu.providers.channelgroup.ChannelGroupService;
import com.liskovsoft.smartyoutubetv2.common.app.presenters.dialogs.menu.providers.channelgroup.ChannelGroupServiceWrapper;
import com.liskovsoft.smartyoutubetv2.common.app.presenters.interfaces.SectionPresenter;
import com.liskovsoft.smartyoutubetv2.common.app.presenters.interfaces.VideoGroupPresenter;
import com.liskovsoft.smartyoutubetv2.common.app.presenters.service.SidebarService;
@@ -823,9 +822,9 @@ public class BrowsePresenter extends BasePresenter<BrowseView> implements Sectio
videoGroup.setType(MediaGroup.TYPE_HISTORY);
appendLocalHistory(videoGroup);
getView().updateSection(videoGroup);
} else if (isSubscriptionsSection() && !ChannelGroupService.instance(getContext()).isEmpty()) {
} else if (isSubscriptionsSection() && !ChannelGroupServiceWrapper.instance(getContext()).isEmpty()) {
appendLocalSubscriptions();
} else if (isMultiGridChannelUploadsSection() && !ChannelGroupService.instance(getContext()).isEmpty()) {
} else if (isMultiGridChannelUploadsSection() && !ChannelGroupServiceWrapper.instance(getContext()).isEmpty()) {
getView().showProgressBar(false);
appendLocalChannels();
} else if (getView().isProgressBarShowing()) {
@@ -985,7 +984,7 @@ public class BrowsePresenter extends BasePresenter<BrowseView> implements Sectio
private Observable<MediaGroup> createPinnedGridAction(Video item) {
if (item.channelGroupId != -1) {
return mContentService.getSubscriptionsObserve(ChannelGroupService.instance(getContext()).getChannelGroupIds(item.channelGroupId));
return mContentService.getSubscriptionsObserve(ChannelGroupServiceWrapper.instance(getContext()).getChannelGroupIds(item.channelGroupId));
}
return ChannelUploadsPresenter.instance(getContext()).obtainUploadsObservable(item);
@@ -1145,14 +1144,14 @@ public class BrowsePresenter extends BasePresenter<BrowseView> implements Sectio
private void appendLocalSubscriptions() {
updateVideoGrid(getCurrentSection(),
mContentService.getSubscriptionsObserve(
ChannelGroupService.instance(getContext()).getChannelGroupIds(ChannelGroupService.SUBSCRIPTION_GROUP_ID)), -1);
ChannelGroupServiceWrapper.instance(getContext()).getChannelGroupIds(ChannelGroupServiceWrapper.SUBSCRIPTION_GROUP_ID)), -1);
}
private void appendLocalChannels() {
ChannelGroup subscriptions = ChannelGroupService.instance(getContext()).findChannelGroup(ChannelGroupService.SUBSCRIPTION_GROUP_ID);
ChannelGroup subscriptions = ChannelGroupServiceWrapper.instance(getContext()).findChannelGroup(ChannelGroupServiceWrapper.SUBSCRIPTION_GROUP_ID);
if (subscriptions != null) {
List<Video> channels = new ArrayList<>();
for (Channel channel : subscriptions.channels) {
for (ChannelGroup.Channel channel : subscriptions.getChannels()) {
channels.add(Video.from(channel));
}
VideoGroup group = VideoGroup.from(channels, 0);

View File

@@ -23,7 +23,6 @@ import com.liskovsoft.smartyoutubetv2.common.app.presenters.ChannelUploadsPresen
import com.liskovsoft.smartyoutubetv2.common.app.presenters.PlaybackPresenter;
import com.liskovsoft.smartyoutubetv2.common.app.presenters.dialogs.menu.providers.ContextMenuManager;
import com.liskovsoft.smartyoutubetv2.common.app.presenters.dialogs.menu.providers.ContextMenuProvider;
import com.liskovsoft.smartyoutubetv2.common.app.presenters.dialogs.menu.providers.channelgroup.ChannelGroupService;
import com.liskovsoft.smartyoutubetv2.common.app.views.ChannelUploadsView;
import com.liskovsoft.smartyoutubetv2.common.app.views.PlaybackView;
import com.liskovsoft.smartyoutubetv2.common.app.views.ViewManager;
@@ -663,11 +662,7 @@ public class VideoMenuPresenter extends BaseMenuPresenter {
return;
}
if (!mServiceManager.isSigned() && mVideo.channelId != null) {
mVideo.isSubscribed = ChannelGroupService.instance(getContext()).isSubscribed(mVideo.channelId);
} else {
mVideo.isSubscribed = mVideo.isSubscribed || mVideo.belongsToSubscriptions() || mVideo.belongsToChannelUploads();
}
mVideo.isSubscribed = mVideo.isSubscribed || mVideo.belongsToSubscriptions() || mVideo.belongsToChannelUploads();
mDialogPresenter.appendSingleButton(
UiOptionItem.from(getContext().getString(
@@ -886,14 +881,10 @@ public class VideoMenuPresenter extends BaseMenuPresenter {
RxHelper.disposeActions(mSubscribeAction);
if (mServiceManager.isSigned()) {
Observable<Void> observable = video.isSubscribed ?
mMediaItemService.unsubscribeObserve(video.channelId) : mMediaItemService.subscribeObserve(video.channelId);
Observable<Void> observable = video.isSubscribed ?
mMediaItemService.unsubscribeObserve(video.channelId) : mMediaItemService.subscribeObserve(video.channelId);
mSubscribeAction = RxHelper.execute(observable);
} else {
ChannelGroupService.instance(getContext()).subscribe(video, !video.isSubscribed);
}
mSubscribeAction = RxHelper.execute(observable);
video.isSubscribed = !video.isSubscribed;

View File

@@ -1,110 +0,0 @@
package com.liskovsoft.smartyoutubetv2.common.app.presenters.dialogs.menu.providers.channelgroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.liskovsoft.sharedutils.helpers.Helpers;
import java.util.ArrayList;
import java.util.List;
public class ChannelGroup {
public final int id;
public String title;
public String iconUrl;
public final List<Channel> channels;
private static final String ITEM_DELIM = "&sgi;";
private static final String LIST_DELIM = "&sga;";
public static class Channel {
public final String title;
public final String iconUrl;
public final String channelId;
private static final String ITEM_DELIM = "&ci;";
public Channel(String title, String iconUrl, String channelId) {
this.title = title;
this.iconUrl = iconUrl;
this.channelId = channelId;
}
public static Channel fromString(String spec) {
String[] split = Helpers.split(ITEM_DELIM, spec);
String title = Helpers.parseStr(split, 0);
String groupIconUrl = Helpers.parseStr(split, 1);
String channelId = Helpers.parseStr(split, 2);
return new Channel(title, groupIconUrl, channelId);
}
@Override
public boolean equals(@Nullable Object obj) {
return obj instanceof Channel && Helpers.equals(((Channel) obj).channelId, channelId);
}
@NonNull
@Override
public String toString() {
return Helpers.merge(ITEM_DELIM, title, iconUrl, channelId);
}
}
public ChannelGroup(String title, String iconUrl, Channel channel) {
this(title, iconUrl, createChannels(channel));
}
public ChannelGroup(String title, String iconUrl, List<Channel> channels) {
this(Helpers.getRandomNumber(ChannelGroupService.SUBSCRIPTION_GROUP_ID + 100, Integer.MAX_VALUE), title, iconUrl, channels);
}
public ChannelGroup(int id, String title, String iconUrl, List<Channel> channels) {
this.id = id;
this.title = title;
this.iconUrl = iconUrl;
this.channels = channels;
}
private static @NonNull List<Channel> createChannels(Channel channel) {
List<Channel> channels = new ArrayList<>();
channels.add(channel);
return channels;
}
public boolean contains(String channelId) {
return Helpers.containsIf(channels, value -> Helpers.equals(value.channelId, channelId));
}
public boolean isEmpty() {
return channels == null || channels.isEmpty();
}
public void add(Channel channel) {
if (channels != null && !channels.contains(channel)) {
channels.add(0, channel);
}
}
public void remove(String channelId) {
if (channels != null) {
Helpers.removeIf(channels, channel -> Helpers.equals(channel.channelId, channelId));
}
}
public static ChannelGroup fromString(String spec) {
String[] split = Helpers.split(ITEM_DELIM, spec);
int id = Helpers.parseInt(split, 0);
String title = Helpers.parseStr(split, 1);
String groupIconUrl = Helpers.parseStr(split, 2);
List<Channel> channels = Helpers.parseList(split, 3, LIST_DELIM, Channel::fromString);
return new ChannelGroup(id, title, groupIconUrl, channels);
}
@NonNull
@Override
public String toString() {
return Helpers.merge(ITEM_DELIM, id, title, iconUrl, Helpers.mergeList(LIST_DELIM, channels));
}
}

View File

@@ -4,6 +4,7 @@ import android.content.Context;
import androidx.annotation.NonNull;
import com.liskovsoft.mediaserviceinterfaces.yt.data.ChannelGroup;
import com.liskovsoft.sharedutils.helpers.MessageHelpers;
import com.liskovsoft.smartyoutubetv2.common.R;
import com.liskovsoft.smartyoutubetv2.common.app.models.data.Video;
@@ -13,21 +14,21 @@ import com.liskovsoft.smartyoutubetv2.common.app.presenters.AppDialogPresenter;
import com.liskovsoft.smartyoutubetv2.common.app.presenters.BrowsePresenter;
import com.liskovsoft.smartyoutubetv2.common.app.presenters.dialogs.menu.VideoMenuPresenter.VideoMenuCallback;
import com.liskovsoft.smartyoutubetv2.common.app.presenters.dialogs.menu.providers.ContextMenuProvider;
import com.liskovsoft.smartyoutubetv2.common.app.presenters.dialogs.menu.providers.channelgroup.ChannelGroup.Channel;
import com.liskovsoft.smartyoutubetv2.common.misc.MediaServiceManager;
import com.liskovsoft.smartyoutubetv2.common.utils.SimpleEditDialog;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class ChannelGroupMenuProvider extends ContextMenuProvider {
private final Context mContext;
private final ChannelGroupService mService;
private final ChannelGroupServiceWrapper mService;
public ChannelGroupMenuProvider(@NonNull Context context, int idx) {
super(idx);
mContext = context;
mService = ChannelGroupService.instance(context);
mService = ChannelGroupServiceWrapper.instance(context);
}
@Override
@@ -80,7 +81,9 @@ public class ChannelGroupMenuProvider extends ContextMenuProvider {
return false;
}
ChannelGroup group = new ChannelGroup(newValue, null, new Channel(item.getAuthor(), item.cardImageUrl, item.channelId));
//ChannelGroup group = new ChannelGroup(newValue, null, new Channel(item.getAuthor(), item.cardImageUrl, item.channelId));
ChannelGroup group = mService.createChannelGroup(newValue, null,
Collections.singletonList(mService.createChannel(item.getAuthor(), item.cardImageUrl, item.channelId)));
mService.addChannelGroup(group);
BrowsePresenter.instance(mContext).pinItem(Video.from(group));
MessageHelpers.showMessage(mContext, mContext.getString(R.string.pinned_to_sidebar));
@@ -89,15 +92,15 @@ public class ChannelGroupMenuProvider extends ContextMenuProvider {
}, false));
for (ChannelGroup group : groups) {
options.add(UiOptionItem.from(group.title, optionItem -> {
options.add(UiOptionItem.from(group.getTitle(), optionItem -> {
BrowsePresenter presenter = BrowsePresenter.instance(mContext);
if (optionItem.isSelected()) {
group.add(new Channel(item.getAuthor(), item.cardImageUrl, item.channelId));
group.add(mService.createChannel(item.getAuthor(), item.cardImageUrl, item.channelId));
} else {
group.remove(item.channelId);
Object data = presenter.getCurrentSection() != null ? presenter.getCurrentSection().getData() : null;
if (callback != null && (data instanceof Video) && ((Video) data).channelGroupId == group.id) {
if (callback != null && (data instanceof Video) && ((Video) data).channelGroupId == group.getId()) {
callback.onItemAction(item, VideoMenuCallback.ACTION_REMOVE_AUTHOR);
}
}

View File

@@ -1,169 +0,0 @@
package com.liskovsoft.smartyoutubetv2.common.app.presenters.dialogs.menu.providers.channelgroup;
import android.annotation.SuppressLint;
import android.content.Context;
import com.liskovsoft.sharedutils.helpers.Helpers;
import com.liskovsoft.smartyoutubetv2.common.R;
import com.liskovsoft.smartyoutubetv2.common.app.models.data.Video;
import com.liskovsoft.smartyoutubetv2.common.app.presenters.dialogs.menu.providers.channelgroup.ChannelGroup.Channel;
import com.liskovsoft.smartyoutubetv2.common.app.presenters.service.SidebarService;
import com.liskovsoft.smartyoutubetv2.common.prefs.AppPrefs;
import com.liskovsoft.smartyoutubetv2.common.prefs.AppPrefs.ProfileChangeListener;
import com.liskovsoft.smartyoutubetv2.common.prefs.GeneralData;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class ChannelGroupService implements ProfileChangeListener {
public static final int SUBSCRIPTION_GROUP_ID = 1_000;
@SuppressLint("StaticFieldLeak")
private static ChannelGroupService sInstance;
private final Context mContext;
private List<ChannelGroup> mChannelGroups;
private final AppPrefs mPrefs;
private ChannelGroupService(Context context) {
mContext = context.getApplicationContext();
mPrefs = AppPrefs.instance(context);
mPrefs.addListener(this);
restoreState();
}
public static ChannelGroupService instance(Context context) {
if (sInstance == null && context != null) {
sInstance = new ChannelGroupService(context.getApplicationContext());
}
return sInstance;
}
public List<ChannelGroup> getChannelGroups() {
return mChannelGroups;
}
public void addChannelGroup(ChannelGroup group) {
// Move to the top
mChannelGroups.remove(group);
mChannelGroups.add(0, group);
persistState();
}
public void removeChannelGroup(ChannelGroup group) {
if (mChannelGroups.contains(group)) {
mChannelGroups.remove(group);
persistState();
}
}
public String[] getChannelGroupIds(int channelGroupId) {
if (channelGroupId == -1) {
return null;
}
List<String> result = new ArrayList<>();
ChannelGroup channelGroup = null;
for (ChannelGroup group : getChannelGroups()) {
if (group.id == channelGroupId) {
channelGroup = group;
break;
}
}
if (channelGroup != null) {
for (Channel channel : channelGroup.channels) {
result.add(channel.channelId);
}
}
return result.toArray(new String[]{});
}
public ChannelGroup findChannelGroup(int channelGroupId) {
if (channelGroupId == -1) {
return null;
}
for (ChannelGroup group : getChannelGroups()) {
if (group.id == channelGroupId) {
return group;
}
}
return null;
}
public ChannelGroup findChannelGroup(String title) {
if (title == null) {
return null;
}
for (ChannelGroup group : getChannelGroups()) {
if (Helpers.equals(group.title, title)) {
return group;
}
}
return null;
}
public void subscribe(Video item, boolean subscribe) {
ChannelGroup group = findChannelGroup(SUBSCRIPTION_GROUP_ID);
if (group == null) {
group = new ChannelGroup(SUBSCRIPTION_GROUP_ID, mContext.getString(R.string.header_subscriptions), null, new ArrayList<>());
}
if (subscribe) {
group.add(new Channel(item.getAuthor(), item.cardImageUrl, item.channelId));
} else {
group.remove(item.channelId);
}
if (!group.isEmpty()) {
addChannelGroup(group);
} else {
removeChannelGroup(group);
}
}
public boolean isSubscribed(String channelId) {
ChannelGroup group = findChannelGroup(SUBSCRIPTION_GROUP_ID);
return group != null && group.contains(channelId);
}
public boolean isEmpty() {
return mChannelGroups == null || mChannelGroups.isEmpty();
}
private void restoreState() {
String data = mPrefs.getChannelGroupData();
String[] split = Helpers.splitData(data);
mChannelGroups = Helpers.parseList(split, 0, ChannelGroup::fromString);
cleanupChannelGroups();
}
public void persistState() {
mPrefs.setChannelGroupData(Helpers.mergeData(mChannelGroups));
}
@Override
public void onProfileChanged() {
restoreState();
}
private void cleanupChannelGroups() {
Collection<Video> pinnedItems = SidebarService.instance(mContext).getPinnedItems();
Helpers.removeIf(mChannelGroups, value -> {
return value.id != SUBSCRIPTION_GROUP_ID && !pinnedItems.contains(Video.from(value));
});
}
}

View File

@@ -0,0 +1,92 @@
package com.liskovsoft.smartyoutubetv2.common.app.presenters.dialogs.menu.providers.channelgroup;
import android.annotation.SuppressLint;
import android.content.Context;
import com.liskovsoft.mediaserviceinterfaces.yt.ChannelGroupService;
import com.liskovsoft.mediaserviceinterfaces.yt.data.ChannelGroup;
import com.liskovsoft.mediaserviceinterfaces.yt.data.ChannelGroup.Channel;
import com.liskovsoft.smartyoutubetv2.common.app.models.data.Video;
import com.liskovsoft.smartyoutubetv2.common.prefs.AppPrefs;
import com.liskovsoft.smartyoutubetv2.common.prefs.AppPrefs.ProfileChangeListener;
import com.liskovsoft.youtubeapi.service.YouTubeServiceManager;
import java.util.List;
public class ChannelGroupServiceWrapper implements ProfileChangeListener {
public static final int SUBSCRIPTION_GROUP_ID = 1_000;
@SuppressLint("StaticFieldLeak")
private static ChannelGroupServiceWrapper sInstance;
private final Context mContext;
private final ChannelGroupService mService;
private final AppPrefs mPrefs;
private ChannelGroupServiceWrapper(Context context) {
mContext = context.getApplicationContext();
mPrefs = AppPrefs.instance(context);
mPrefs.addListener(this);
mService = YouTubeServiceManager.instance().getChannelGroupService();
restoreState();
}
public static ChannelGroupServiceWrapper instance(Context context) {
if (sInstance == null && context != null) {
sInstance = new ChannelGroupServiceWrapper(context.getApplicationContext());
}
return sInstance;
}
public List<ChannelGroup> getChannelGroups() {
return mService.getChannelGroups();
}
public void addChannelGroup(ChannelGroup group) {
mService.addChannelGroup(group);
}
public void removeChannelGroup(ChannelGroup group) {
mService.removeChannelGroup(group);
}
public String[] getChannelGroupIds(int channelGroupId) {
return mService.getChannelGroupIds(channelGroupId);
}
public ChannelGroup findChannelGroup(int channelGroupId) {
return mService.findChannelGroup(channelGroupId);
}
public ChannelGroup findChannelGroup(String title) {
return mService.findChannelGroup(title);
}
public ChannelGroup createChannelGroup(String title, String iconUrl, List<Channel> channels) {
return mService.createChannelGroup(title, iconUrl, channels);
}
public Channel createChannel(String title, String iconUrl, String channelId) {
return mService.createChannel(title, iconUrl, channelId);
}
public void renameChannelGroup(ChannelGroup channelGroup, String title) {
mService.renameChannelGroup(channelGroup, title);
}
public boolean isEmpty() {
return mService.isEmpty();
}
private void restoreState() {
String data = mPrefs.getChannelGroupData();
if (data != null) {
mPrefs.setChannelGroupData(null);
mService.exportData(data);
}
}
@Override
public void onProfileChanged() {
restoreState();
}
}

View File

@@ -14,12 +14,12 @@ import com.liskovsoft.smartyoutubetv2.common.utils.AppDialogUtil;
public class RemoveGroupMenuProvider extends ContextMenuProvider {
private final Context mContext;
private final ChannelGroupService mService;
private final ChannelGroupServiceWrapper mService;
public RemoveGroupMenuProvider(@NonNull Context context, int idx) {
super(idx);
mContext = context;
mService = ChannelGroupService.instance(context);
mService = ChannelGroupServiceWrapper.instance(context);
}
@Override

View File

@@ -4,6 +4,7 @@ import android.content.Context;
import androidx.annotation.NonNull;
import com.liskovsoft.mediaserviceinterfaces.yt.data.ChannelGroup;
import com.liskovsoft.smartyoutubetv2.common.R;
import com.liskovsoft.smartyoutubetv2.common.app.models.data.Video;
import com.liskovsoft.smartyoutubetv2.common.app.presenters.AppDialogPresenter;
@@ -14,12 +15,12 @@ import com.liskovsoft.smartyoutubetv2.common.utils.SimpleEditDialog;
public class RenameGroupMenuProvider extends ContextMenuProvider {
private final Context mContext;
private final ChannelGroupService mService;
private final ChannelGroupServiceWrapper mService;
public RenameGroupMenuProvider(@NonNull Context context, int idx) {
super(idx);
mContext = context;
mService = ChannelGroupService.instance(context);
mService = ChannelGroupServiceWrapper.instance(context);
}
@Override
@@ -41,8 +42,9 @@ public class RenameGroupMenuProvider extends ContextMenuProvider {
ChannelGroup channelGroup = mService.findChannelGroup(item.channelGroupId);
if (channelGroup != null) {
channelGroup.title = newValue;
mService.addChannelGroup(channelGroup);
//channelGroup.title = newValue;
//mService.addChannelGroup(channelGroup);
mService.renameChannelGroup(channelGroup, newValue);
}
return true;