Compare commits
9 Commits
master-kot
...
master
| Author | SHA1 | Date |
|---|---|---|
|
|
fb79dc971a | |
|
|
eef6932a4a | |
|
|
10fcb22358 | |
|
|
f20db0317e | |
|
|
deff9f7cdd | |
|
|
9dcf3fb6b2 | |
|
|
00b13c3acb | |
|
|
74e70be245 | |
|
|
c7edf3c84d |
10
build.gradle
10
build.gradle
|
|
@ -1,9 +1,7 @@
|
||||||
apply plugin: 'com.android.library'
|
apply plugin: 'com.android.library'
|
||||||
apply plugin: 'me.tatarka.retrolambda'
|
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 25
|
compileSdkVersion compileSdk
|
||||||
buildToolsVersion '25.0.3'
|
|
||||||
|
|
||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility JavaVersion.VERSION_1_8
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
|
|
@ -16,7 +14,7 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
provided 'com.android.support:support-annotations:25.4.0'
|
compileOnly "com.android.support:support-annotations:$supportLibraryVersion"
|
||||||
provided 'io.reactivex:rxandroid:1.2.1'
|
compileOnly "io.reactivex:rxandroid:$rxAndroidVersion"
|
||||||
provided 'io.reactivex:rxjava:1.3.0'
|
compileOnly "io.reactivex:rxjava:$rxJavaVersion"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -83,7 +83,6 @@ public class DiffUtil {
|
||||||
* Calculates the list of update operations that can covert one list into the other one.
|
* Calculates the list of update operations that can covert one list into the other one.
|
||||||
*
|
*
|
||||||
* @param cb The callback that acts as a gateway to the backing list data
|
* @param cb The callback that acts as a gateway to the backing list data
|
||||||
*
|
|
||||||
* @return A DiffResult that contains the information about the edit sequence to convert the
|
* @return A DiffResult that contains the information about the edit sequence to convert the
|
||||||
* old list into the new list.
|
* old list into the new list.
|
||||||
*/
|
*/
|
||||||
|
|
@ -100,7 +99,6 @@ public class DiffUtil {
|
||||||
*
|
*
|
||||||
* @param cb The callback that acts as a gateway to the backing list data
|
* @param cb The callback that acts as a gateway to the backing list data
|
||||||
* @param detectMoves True if DiffUtil should try to detect moved items, false otherwise.
|
* @param detectMoves True if DiffUtil should try to detect moved items, false otherwise.
|
||||||
*
|
|
||||||
* @return A DiffResult that contains the information about the edit sequence to convert the
|
* @return A DiffResult that contains the information about the edit sequence to convert the
|
||||||
* old list into the new list.
|
* old list into the new list.
|
||||||
*/
|
*/
|
||||||
|
|
@ -329,7 +327,6 @@ public class DiffUtil {
|
||||||
*
|
*
|
||||||
* @param oldItemPosition The position of the item in the old list
|
* @param oldItemPosition The position of the item in the old list
|
||||||
* @param newItemPosition The position of the item in the new list
|
* @param newItemPosition The position of the item in the new list
|
||||||
*
|
|
||||||
* @return A payload object that represents the change between the two items.
|
* @return A payload object that represents the change between the two items.
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|
@ -560,7 +557,6 @@ public class DiffUtil {
|
||||||
* @param y The y position in the matrix (position in the new list)
|
* @param y The y position in the matrix (position in the new list)
|
||||||
* @param snakeIndex The current snake index
|
* @param snakeIndex The current snake index
|
||||||
* @param removal True if we are looking for a removal, false otherwise
|
* @param removal True if we are looking for a removal, false otherwise
|
||||||
*
|
|
||||||
* @return True if such item is found.
|
* @return True if such item is found.
|
||||||
*/
|
*/
|
||||||
private boolean findMatchingItem(final int x, final int y, final int snakeIndex,
|
private boolean findMatchingItem(final int x, final int y, final int snakeIndex,
|
||||||
|
|
|
||||||
|
|
@ -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