mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-24 09:00:31 +00:00
Update states in lists
This commit is contained in:
parent
03b1a8bd41
commit
41fb6f5464
@ -4,6 +4,7 @@ package org.schabi.newpipe.database.stream.model;
|
|||||||
import android.arch.persistence.room.ColumnInfo;
|
import android.arch.persistence.room.ColumnInfo;
|
||||||
import android.arch.persistence.room.Entity;
|
import android.arch.persistence.room.Entity;
|
||||||
import android.arch.persistence.room.ForeignKey;
|
import android.arch.persistence.room.ForeignKey;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@ -62,4 +63,12 @@ public class StreamStateEntity {
|
|||||||
return seconds > PLAYBACK_SAVE_THRESHOLD_START_SECONDS
|
return seconds > PLAYBACK_SAVE_THRESHOLD_START_SECONDS
|
||||||
&& seconds < durationInSeconds - PLAYBACK_SAVE_THRESHOLD_END_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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,6 +100,8 @@ public abstract class BaseListFragment<I, N> extends BaseStateFragment<I> implem
|
|||||||
}
|
}
|
||||||
updateFlags = 0;
|
updateFlags = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
infoListAdapter.updateStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -31,6 +31,7 @@ import org.schabi.newpipe.util.OnClickGesture;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.disposables.CompositeDisposable;
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
@ -195,6 +196,29 @@ public class InfoListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateStates() {
|
||||||
|
if (infoItemList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
stateLoaders.add(
|
||||||
|
historyRecordManager.loadStreamStateBatch(infoItemList)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe((streamStateEntities) -> {
|
||||||
|
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() {
|
public void clearStreamItemList() {
|
||||||
if (infoItemList.isEmpty()) {
|
if (infoItemList.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
|
@ -76,6 +76,7 @@ public abstract class BaseLocalListFragment<I, N> extends BaseStateFragment<I>
|
|||||||
}
|
}
|
||||||
updateFlags = 0;
|
updateFlags = 0;
|
||||||
}
|
}
|
||||||
|
itemListAdapter.updateStates();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*//////////////////////////////////////////////////////////////////////////
|
/*//////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -26,6 +26,7 @@ import org.schabi.newpipe.util.OnClickGesture;
|
|||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||||
import io.reactivex.disposables.CompositeDisposable;
|
import io.reactivex.disposables.CompositeDisposable;
|
||||||
@ -136,6 +137,27 @@ public class LocalItemListAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateStates() {
|
||||||
|
if (localItems.isEmpty()) return;
|
||||||
|
stateLoaders.add(
|
||||||
|
historyRecordManager.loadLocalStreamStateBatch(localItems)
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe((streamStateEntities) -> {
|
||||||
|
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) {
|
public void removeItem(final LocalItem data) {
|
||||||
final int index = localItems.indexOf(data);
|
final int index = localItems.indexOf(data);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user