Update by payload fixed (#51)
This commit is contained in:
parent
10fcb22358
commit
eef6932a4a
|
|
@ -58,6 +58,8 @@ public class ObservableList<TItem> extends ObservableCollection<TItem> implement
|
||||||
private SameItemsPredicate<TItem> sameItemsPredicate;
|
private SameItemsPredicate<TItem> sameItemsPredicate;
|
||||||
@Nullable
|
@Nullable
|
||||||
private ChangePayloadProducer<TItem> changePayloadProducer;
|
private ChangePayloadProducer<TItem> changePayloadProducer;
|
||||||
|
@Nullable
|
||||||
|
private ObservableList<TItem> diffUtilsSource;
|
||||||
|
|
||||||
public ObservableList() {
|
public ObservableList() {
|
||||||
super();
|
super();
|
||||||
|
|
@ -227,9 +229,19 @@ public class ObservableList<TItem> extends ObservableCollection<TItem> implement
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
final List<TItem> oldList = new ArrayList<>(items);
|
final List<TItem> oldList = new ArrayList<>(items);
|
||||||
final List<TItem> newList = new ArrayList<>(newItems);
|
final List<TItem> newList = new ArrayList<>(newItems);
|
||||||
final CollectionsChangesCalculator<TItem> calculator = sameItemsPredicate != null
|
final CollectionsChangesCalculator<TItem> calculator;
|
||||||
? new DiffCollectionsChangesCalculator<>(oldList, newList, detectMoves, sameItemsPredicate, changePayloadProducer)
|
if (diffUtilsSource != null) {
|
||||||
: new DefaultCollectionsChangesCalculator<>(oldList, newList, false);
|
if (diffUtilsSource.sameItemsPredicate != null) {
|
||||||
|
calculator = new DiffCollectionsChangesCalculator<>(oldList, newList,
|
||||||
|
diffUtilsSource.detectMoves, diffUtilsSource.sameItemsPredicate, diffUtilsSource.changePayloadProducer);
|
||||||
|
} else {
|
||||||
|
calculator = new DefaultCollectionsChangesCalculator<>(oldList, newList, false);
|
||||||
|
}
|
||||||
|
} else if (sameItemsPredicate != null) {
|
||||||
|
calculator = new DiffCollectionsChangesCalculator<>(oldList, newList, detectMoves, sameItemsPredicate, changePayloadProducer);
|
||||||
|
} else {
|
||||||
|
calculator = new DefaultCollectionsChangesCalculator<>(oldList, newList, false);
|
||||||
|
}
|
||||||
items.clear();
|
items.clear();
|
||||||
items.addAll(newItems);
|
items.addAll(newItems);
|
||||||
notifyAboutChanges(calculator.calculateInsertedItems(), calculator.calculateRemovedItems(), calculator.calculateChanges());
|
notifyAboutChanges(calculator.calculateInsertedItems(), calculator.calculateRemovedItems(), calculator.calculateChanges());
|
||||||
|
|
@ -271,7 +283,16 @@ public class ObservableList<TItem> extends ObservableCollection<TItem> implement
|
||||||
* @return true if diff utils is enabled.
|
* @return true if diff utils is enabled.
|
||||||
*/
|
*/
|
||||||
public boolean diffUtilsIsEnabled() {
|
public boolean diffUtilsIsEnabled() {
|
||||||
return sameItemsPredicate != null;
|
return diffUtilsSource != null ? diffUtilsSource.diffUtilsIsEnabled() : sameItemsPredicate != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets observableCollection as a source of diff utils parameters;
|
||||||
|
*
|
||||||
|
* @param diffUtilsSource Source of diff utils parameters.
|
||||||
|
*/
|
||||||
|
public void setDiffUtilsSource(@Nullable final ObservableList<TItem> diffUtilsSource) {
|
||||||
|
this.diffUtilsSource = diffUtilsSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue