mirror of
https://github.com/yuliskov/SmartTube.git
synced 2026-02-13 18:20:24 -06:00
grid update errors fix 3
This commit is contained in:
@@ -8,7 +8,6 @@ import androidx.leanback.widget.PresenterSelector;
|
||||
import com.liskovsoft.sharedutils.helpers.Helpers;
|
||||
import com.liskovsoft.smartyoutubetv2.common.app.models.data.Video;
|
||||
import com.liskovsoft.smartyoutubetv2.common.app.models.data.VideoGroup;
|
||||
import com.liskovsoft.smartyoutubetv2.common.utils.Utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@@ -167,16 +166,12 @@ public class VideoGroupObjectAdapter extends ObjectAdapter {
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
Utils.postDelayed(this::clearInt, 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear takes some time. Do not call it immediately before the add or you'll get an exception!
|
||||
* IndexOutOfBoundsException: Invalid item position... GridLayoutManager.getViewForPosition
|
||||
*/
|
||||
private void clearInt() {
|
||||
public void clear() {
|
||||
int itemCount = mVideoItems.size();
|
||||
mVideoItems.clear();
|
||||
mVideoGroups.clear();
|
||||
@@ -210,14 +205,6 @@ public class VideoGroupObjectAdapter extends ObjectAdapter {
|
||||
}
|
||||
|
||||
public void sync(VideoGroup group) {
|
||||
Utils.postDelayed(() -> syncInt(group), 100);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync takes some time. Do not call it immediately before the add or you'll get an exception!
|
||||
* IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling
|
||||
*/
|
||||
private void syncInt(VideoGroup group) {
|
||||
for (Video video : group.getVideos()) {
|
||||
// Search for multiple occurrences (e.g. History section)
|
||||
for (int i = 0; i < mVideoItems.size(); i++) {
|
||||
|
||||
@@ -19,7 +19,6 @@ import com.liskovsoft.sharedutils.mylogger.Log;
|
||||
import com.liskovsoft.smartyoutubetv2.common.app.models.data.Video;
|
||||
import com.liskovsoft.smartyoutubetv2.common.app.models.data.VideoGroup;
|
||||
import com.liskovsoft.smartyoutubetv2.common.app.presenters.interfaces.VideoGroupPresenter;
|
||||
import com.liskovsoft.smartyoutubetv2.common.utils.Utils;
|
||||
import com.liskovsoft.smartyoutubetv2.tv.adapter.VideoGroupObjectAdapter;
|
||||
import com.liskovsoft.smartyoutubetv2.tv.presenter.ChannelHeaderPresenter;
|
||||
import com.liskovsoft.smartyoutubetv2.tv.presenter.ChannelHeaderPresenter.ChannelHeaderCallback;
|
||||
@@ -177,6 +176,14 @@ public abstract class MultipleRowsFragment extends RowsSupportFragment implement
|
||||
|
||||
@Override
|
||||
public void update(VideoGroup group) {
|
||||
freeze(true);
|
||||
|
||||
updateInt(group);
|
||||
|
||||
freeze(false);
|
||||
}
|
||||
|
||||
private void updateInt(VideoGroup group) {
|
||||
if (mVideoGroupAdapters == null) {
|
||||
mPendingUpdates.add(group);
|
||||
return;
|
||||
@@ -233,11 +240,7 @@ public abstract class MultipleRowsFragment extends RowsSupportFragment implement
|
||||
} else {
|
||||
Log.d(TAG, "Continue row %s %s", group.getTitle(), System.currentTimeMillis());
|
||||
|
||||
freeze(true);
|
||||
|
||||
existingAdapter.add(group); // continue
|
||||
|
||||
freeze(false);
|
||||
}
|
||||
|
||||
restorePosition();
|
||||
|
||||
@@ -15,7 +15,6 @@ import com.liskovsoft.smartyoutubetv2.common.app.presenters.interfaces.VideoGrou
|
||||
import com.liskovsoft.smartyoutubetv2.common.misc.TickleManager;
|
||||
import com.liskovsoft.smartyoutubetv2.common.prefs.MainUIData;
|
||||
import com.liskovsoft.smartyoutubetv2.common.utils.LoadingManager;
|
||||
import com.liskovsoft.smartyoutubetv2.common.utils.Utils;
|
||||
import com.liskovsoft.smartyoutubetv2.tv.R;
|
||||
import com.liskovsoft.smartyoutubetv2.tv.adapter.VideoGroupObjectAdapter;
|
||||
import com.liskovsoft.smartyoutubetv2.tv.presenter.CustomVerticalGridPresenter;
|
||||
@@ -137,6 +136,14 @@ public class VideoGridFragment extends GridFragment implements VideoSection {
|
||||
|
||||
@Override
|
||||
public void update(VideoGroup group) {
|
||||
freeze(true);
|
||||
|
||||
updateInt(group);
|
||||
|
||||
freeze(false);
|
||||
}
|
||||
|
||||
private void updateInt(VideoGroup group) {
|
||||
if (mGridAdapter == null) {
|
||||
mPendingUpdates.add(group);
|
||||
return;
|
||||
@@ -161,12 +168,8 @@ public class VideoGridFragment extends GridFragment implements VideoSection {
|
||||
return;
|
||||
}
|
||||
|
||||
freeze(true);
|
||||
|
||||
mGridAdapter.add(group);
|
||||
|
||||
freeze(false);
|
||||
|
||||
restorePosition();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user