From 3bc96ffe12e80c7efbb12c7d982fef1d01ff0bc7 Mon Sep 17 00:00:00 2001 From: Yuriy Liskov Date: Wed, 30 Sep 2020 19:23:52 +0300 Subject: [PATCH] add channel scroll --- SharedModules | 2 +- .../app/presenters/ChannelPresenter.java | 42 ++++++++++++++++--- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/SharedModules b/SharedModules index 6e8d887c5..4ee1960a7 160000 --- a/SharedModules +++ b/SharedModules @@ -1 +1 @@ -Subproject commit 6e8d887c564855e3a14ec490722858be1d6a6b52 +Subproject commit 4ee1960a7464e876ac495d16b581b5761936ea5c diff --git a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/presenters/ChannelPresenter.java b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/presenters/ChannelPresenter.java index 66876ca42..4fc8d5793 100644 --- a/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/presenters/ChannelPresenter.java +++ b/common/src/main/java/com/liskovsoft/smartyoutubetv2/common/app/presenters/ChannelPresenter.java @@ -2,6 +2,7 @@ package com.liskovsoft.smartyoutubetv2.common.app.presenters; import android.annotation.SuppressLint; import android.content.Context; +import com.liskovsoft.mediaserviceinterfaces.MediaGroupManager; import com.liskovsoft.mediaserviceinterfaces.MediaService; import com.liskovsoft.mediaserviceinterfaces.data.MediaGroup; import com.liskovsoft.sharedutils.helpers.MessageHelpers; @@ -28,8 +29,9 @@ public class ChannelPresenter implements VideoGroupPresenter { private final MediaService mMediaService; private final PlaybackPresenter mPlaybackPresenter; private ChannelView mView; - private Disposable mUpdateAction; private String mChannelId; + private Disposable mUpdateAction; + private Disposable mScrollAction; public ChannelPresenter(Context context) { mContext = context; @@ -65,7 +67,13 @@ public class ChannelPresenter implements VideoGroupPresenter { @Override public void onScrollEnd(VideoGroup group) { + Log.d(TAG, "onScrollEnd: Group title: " + group.getTitle()); + boolean scrollInProgress = mScrollAction != null && !mScrollAction.isDisposed(); + + if (!scrollInProgress) { + continueGroup(group); + } } @Override @@ -76,6 +84,8 @@ public class ChannelPresenter implements VideoGroupPresenter { @Override public void unregister(ChannelView view) { mView = null; + + disposeActions(); } public void openChannel(String channelId) { @@ -83,7 +93,7 @@ public class ChannelPresenter implements VideoGroupPresenter { return; } - disposeUpdateAction(); + disposeActions(); ViewManager.instance(mContext).startView(ChannelView.class); if (mView != null) { @@ -94,12 +104,14 @@ public class ChannelPresenter implements VideoGroupPresenter { } } - private void disposeUpdateAction() { - boolean updateInProgress = mUpdateAction != null && !mUpdateAction.isDisposed(); - - if (updateInProgress) { + private void disposeActions() { + if (mUpdateAction != null && !mUpdateAction.isDisposed()) { mUpdateAction.dispose(); } + + if (mScrollAction != null && !mScrollAction.isDisposed()) { + mScrollAction.dispose(); + } } private void updateRows(String channelId) { @@ -131,4 +143,22 @@ public class ChannelPresenter implements VideoGroupPresenter { mView.update(VideoGroup.from(mediaGroup)); } } + + private void continueGroup(VideoGroup group) { + Log.d(TAG, "continueGroup: start continue group: " + group.getTitle()); + + mView.showProgressBar(true); + + MediaGroup mediaGroup = group.getMediaGroup(); + + MediaGroupManager mediaGroupManager = mMediaService.getMediaGroupManager(); + + mScrollAction = mediaGroupManager.continueGroupObserve(mediaGroup) + .subscribeOn(Schedulers.newThread()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe(continueMediaGroup -> { + mView.update(VideoGroup.from(continueMediaGroup)); + }, error -> Log.e(TAG, "continueGroup error: " + error), + () -> mView.showProgressBar(false)); + } }