From 41fb6f54642c04ff450a91a051f852efeeaf947a Mon Sep 17 00:00:00 2001 From: Vasiliy Date: Sat, 27 Apr 2019 18:01:18 +0300 Subject: [PATCH] Update states in lists --- .../stream/model/StreamStateEntity.java | 9 +++++++ .../fragments/list/BaseListFragment.java | 2 ++ .../newpipe/info_list/InfoListAdapter.java | 24 +++++++++++++++++++ .../newpipe/local/BaseLocalListFragment.java | 1 + .../newpipe/local/LocalItemListAdapter.java | 22 +++++++++++++++++ 5 files changed, 58 insertions(+) diff --git a/app/src/main/java/org/schabi/newpipe/database/stream/model/StreamStateEntity.java b/app/src/main/java/org/schabi/newpipe/database/stream/model/StreamStateEntity.java index 946ee1182..d46d5cd74 100644 --- a/app/src/main/java/org/schabi/newpipe/database/stream/model/StreamStateEntity.java +++ b/app/src/main/java/org/schabi/newpipe/database/stream/model/StreamStateEntity.java @@ -4,6 +4,7 @@ package org.schabi.newpipe.database.stream.model; import android.arch.persistence.room.ColumnInfo; import android.arch.persistence.room.Entity; import android.arch.persistence.room.ForeignKey; +import android.support.annotation.Nullable; import java.util.concurrent.TimeUnit; @@ -62,4 +63,12 @@ public class StreamStateEntity { return seconds > PLAYBACK_SAVE_THRESHOLD_START_SECONDS && seconds < durationInSeconds - PLAYBACK_SAVE_THRESHOLD_END_SECONDS; } + + @Override + public boolean equals(@Nullable Object obj) { + if (obj instanceof StreamStateEntity) { + return ((StreamStateEntity) obj).streamUid == streamUid + && ((StreamStateEntity) obj).progressTime == progressTime; + } else return false; + } } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java index 5a49cce28..53d549a46 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/BaseListFragment.java @@ -100,6 +100,8 @@ public abstract class BaseListFragment extends BaseStateFragment implem } updateFlags = 0; } + + infoListAdapter.updateStates(); } /*////////////////////////////////////////////////////////////////////////// diff --git a/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java b/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java index df207abb5..8a30c998a 100644 --- a/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java +++ b/app/src/main/java/org/schabi/newpipe/info_list/InfoListAdapter.java @@ -31,6 +31,7 @@ import org.schabi.newpipe.util.OnClickGesture; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; @@ -195,6 +196,29 @@ public class InfoListAdapter extends RecyclerView.Adapter { + if (streamStateEntities.size() == states.size()) { + for (int i = 0; i < states.size(); i++) { + final StreamStateEntity newState = streamStateEntities.get(i); + if (!Objects.equals(states.get(i), newState)) { + states.set(i, newState); + notifyItemChanged(header == null ? i : i + 1); + } + } + } else { + //oops, something is wrong + } + }) + ); + } + public void clearStreamItemList() { if (infoItemList.isEmpty()) { return; diff --git a/app/src/main/java/org/schabi/newpipe/local/BaseLocalListFragment.java b/app/src/main/java/org/schabi/newpipe/local/BaseLocalListFragment.java index 20676c6db..75d49e466 100644 --- a/app/src/main/java/org/schabi/newpipe/local/BaseLocalListFragment.java +++ b/app/src/main/java/org/schabi/newpipe/local/BaseLocalListFragment.java @@ -76,6 +76,7 @@ public abstract class BaseLocalListFragment extends BaseStateFragment } updateFlags = 0; } + itemListAdapter.updateStates(); } /*////////////////////////////////////////////////////////////////////////// diff --git a/app/src/main/java/org/schabi/newpipe/local/LocalItemListAdapter.java b/app/src/main/java/org/schabi/newpipe/local/LocalItemListAdapter.java index 372392d7b..80d008231 100644 --- a/app/src/main/java/org/schabi/newpipe/local/LocalItemListAdapter.java +++ b/app/src/main/java/org/schabi/newpipe/local/LocalItemListAdapter.java @@ -26,6 +26,7 @@ import org.schabi.newpipe.util.OnClickGesture; import java.text.DateFormat; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.CompositeDisposable; @@ -136,6 +137,27 @@ public class LocalItemListAdapter extends RecyclerView.Adapter { + if (streamStateEntities.size() == states.size()) { + for (int i = 0; i < states.size(); i++) { + final StreamStateEntity newState = streamStateEntities.get(i); + if (!Objects.equals(states.get(i), newState)) { + states.set(i, newState); + notifyItemChanged(header == null ? i : i + 1); + } + } + } else { + //oops, something is wrong + } + }) + ); + } + public void removeItem(final LocalItem data) { final int index = localItems.indexOf(data);