Update states in lists
This commit is contained in:
parent
36a34bd477
commit
0b8277fe44
5 changed files with 58 additions and 0 deletions
|
|
@ -76,6 +76,7 @@ public abstract class BaseLocalListFragment<I, N> extends BaseStateFragment<I>
|
|||
}
|
||||
updateFlags = 0;
|
||||
}
|
||||
itemListAdapter.updateStates();
|
||||
}
|
||||
|
||||
/*//////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -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<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) {
|
||||
final int index = localItems.indexOf(data);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue