Compare commits

...

9 Commits
mvvm ... master

Author SHA1 Message Date
Denis Karmyshakov fb79dc971a Gradle update (#52) 2017-11-20 19:20:18 +03:00
Arseniy Borisov eef6932a4a Update by payload fixed (#51) 2017-11-13 12:10:06 +03:00
Denis Karmyshakov 10fcb22358 Merge pull request #48 from TouchInstinct/versions_in_constants
Versions in constants
2017-10-04 13:12:32 +03:00
Denis Karmyshakov f20db0317e Versions in constants 2017-10-04 13:10:49 +03:00
Denis Karmyshakov deff9f7cdd Versions in constants 2017-10-04 13:05:39 +03:00
Ilia Kurtov 9dcf3fb6b2 Merge pull request #43 from TouchInstinct/lib_version
rxjava version
2017-09-15 16:19:22 +03:00
gorodeckii 00b13c3acb rxjava version 2017-09-15 15:18:05 +03:00
Gavriil 74e70be245 RxJava version update (#42) 2017-09-11 18:51:05 +03:00
Arseniy Borisov c7edf3c84d idea formatter (#41) 2017-09-04 17:36:48 +03:00
6 changed files with 56 additions and 41 deletions

View File

@ -1,9 +1,7 @@
apply plugin: 'com.android.library'
apply plugin: 'me.tatarka.retrolambda'
android {
compileSdkVersion 25
buildToolsVersion '25.0.3'
compileSdkVersion compileSdk
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
@ -16,7 +14,7 @@ android {
}
dependencies {
provided 'com.android.support:support-annotations:25.4.0'
provided 'io.reactivex:rxandroid:1.2.1'
provided 'io.reactivex:rxjava:1.3.0'
compileOnly "com.android.support:support-annotations:$supportLibraryVersion"
compileOnly "io.reactivex:rxandroid:$rxAndroidVersion"
compileOnly "io.reactivex:rxjava:$rxJavaVersion"
}

View File

@ -50,13 +50,13 @@ import java.util.List;
* and the cost of your comparison methods. Below are some average run times for reference:
* (The areSame list is composed of random UUID Strings and the tests are run on Nexus 5X with M)
* <ul>
* <li>100 items and 10 modifications: avg: 0.39 ms, median: 0.35 ms
* <li>100 items and 100 modifications: 3.82 ms, median: 3.75 ms
* <li>100 items and 100 modifications without moves: 2.09 ms, median: 2.06 ms
* <li>1000 items and 50 modifications: avg: 4.67 ms, median: 4.59 ms
* <li>1000 items and 50 modifications without moves: avg: 3.59 ms, median: 3.50 ms
* <li>1000 items and 200 modifications: 27.07 ms, median: 26.92 ms
* <li>1000 items and 200 modifications without moves: 13.54 ms, median: 13.36 ms
* <li>100 items and 10 modifications: avg: 0.39 ms, median: 0.35 ms
* <li>100 items and 100 modifications: 3.82 ms, median: 3.75 ms
* <li>100 items and 100 modifications without moves: 2.09 ms, median: 2.06 ms
* <li>1000 items and 50 modifications: avg: 4.67 ms, median: 4.59 ms
* <li>1000 items and 50 modifications without moves: avg: 3.59 ms, median: 3.50 ms
* <li>1000 items and 200 modifications: 27.07 ms, median: 26.92 ms
* <li>1000 items and 200 modifications without moves: 13.54 ms, median: 13.36 ms
* </ul>
*
* <p>Due to implementation constraints, the max size of the list can be 2^26.
@ -83,7 +83,6 @@ public class DiffUtil {
* 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
*
* @return A DiffResult that contains the information about the edit sequence to convert the
* old list into the new list.
*/
@ -98,9 +97,8 @@ public class DiffUtil {
* positions), you can disable move detection which takes <code>O(N^2)</code> time where
* N is the number of added, moved, removed items.
*
* @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.
*
* @return A DiffResult that contains the information about the edit sequence to convert the
* old list into the new list.
*/
@ -185,7 +183,7 @@ public class DiffUtil {
}
private static Snake diffPartial(Callback cb, int startOld, int endOld,
int startNew, int endNew, int[] forward, int[] backward, int kOffset) {
int startNew, int endNew, int[] forward, int[] backward, int kOffset) {
final int oldSize = endOld - startOld;
final int newSize = endNew - startNew;
@ -329,7 +327,6 @@ public class DiffUtil {
*
* @param oldItemPosition The position of the item in the old list
* @param newItemPosition The position of the item in the new list
*
* @return A payload object that represents the change between the two items.
*/
@Nullable
@ -453,14 +450,14 @@ public class DiffUtil {
private final boolean mDetectMoves;
/**
* @param callback The callback that was used to calculate the diff
* @param snakes The list of Myers' snakes
* @param callback The callback that was used to calculate the diff
* @param snakes The list of Myers' snakes
* @param oldItemStatuses An int[] that can be re-purposed to keep metadata
* @param newItemStatuses An int[] that can be re-purposed to keep metadata
* @param detectMoves True if this DiffResult will try to detect moved items
* @param detectMoves True if this DiffResult will try to detect moved items
*/
DiffResult(Callback callback, List<Snake> snakes, int[] oldItemStatuses,
int[] newItemStatuses, boolean detectMoves) {
int[] newItemStatuses, boolean detectMoves) {
mSnakes = snakes;
mOldItemStatuses = oldItemStatuses;
mNewItemStatuses = newItemStatuses;
@ -556,15 +553,14 @@ public class DiffUtil {
* Finds a matching item that is before the given coordinates in the matrix
* (before : left and above).
*
* @param x The x position in the matrix (position in the old list)
* @param y The y position in the matrix (position in the new list)
* @param x The x position in the matrix (position in the old list)
* @param y The y position in the matrix (position in the new list)
* @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.
*/
private boolean findMatchingItem(final int x, final int y, final int snakeIndex,
final boolean removal) {
final boolean removal) {
final int myItemPos;
int curX;
int curY;
@ -664,7 +660,7 @@ public class DiffUtil {
}
private static PostponedUpdate removePostponedUpdate(List<PostponedUpdate> updates,
int pos, boolean removal) {
int pos, boolean removal) {
for (int i = updates.size() - 1; i >= 0; i--) {
final PostponedUpdate update = updates.get(i);
if (update.posInOwnerList == pos && update.removal == removal) {
@ -680,7 +676,7 @@ public class DiffUtil {
}
private void dispatchAdditions(List<PostponedUpdate> postponedUpdates,
ListUpdateCallback updateCallback, int start, int count, int globalIndex) {
ListUpdateCallback updateCallback, int start, int count, int globalIndex) {
if (!mDetectMoves) {
updateCallback.onInserted(start, count);
return;
@ -720,7 +716,7 @@ public class DiffUtil {
}
private void dispatchRemovals(List<PostponedUpdate> postponedUpdates,
ListUpdateCallback updateCallback, int start, int count, int globalIndex) {
ListUpdateCallback updateCallback, int start, int count, int globalIndex) {
if (!mDetectMoves) {
updateCallback.onRemoved(start, count);
return;

View File

@ -98,8 +98,8 @@ public abstract class ObservableCollection<TItem> {
* Method to notify that collection have changed.
*
* @param insertedItems Collection of inserted items;
* @param removedItems Collection of removed items;
* @param changes Changes of collection.
* @param removedItems Collection of removed items;
* @param changes Changes of collection.
*/
protected void notifyAboutChanges(@NonNull final List<TItem> insertedItems,
@NonNull final List<TItem> removedItems,

View File

@ -58,6 +58,8 @@ public class ObservableList<TItem> extends ObservableCollection<TItem> implement
private SameItemsPredicate<TItem> sameItemsPredicate;
@Nullable
private ChangePayloadProducer<TItem> changePayloadProducer;
@Nullable
private ObservableList<TItem> diffUtilsSource;
public ObservableList() {
super();
@ -227,9 +229,19 @@ public class ObservableList<TItem> extends ObservableCollection<TItem> implement
synchronized (this) {
final List<TItem> oldList = new ArrayList<>(items);
final List<TItem> newList = new ArrayList<>(newItems);
final CollectionsChangesCalculator<TItem> calculator = sameItemsPredicate != null
? new DiffCollectionsChangesCalculator<>(oldList, newList, detectMoves, sameItemsPredicate, changePayloadProducer)
: new DefaultCollectionsChangesCalculator<>(oldList, newList, false);
final CollectionsChangesCalculator<TItem> calculator;
if (diffUtilsSource != null) {
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.addAll(newItems);
notifyAboutChanges(calculator.calculateInsertedItems(), calculator.calculateRemovedItems(), calculator.calculateChanges());
@ -246,8 +258,8 @@ public class ObservableList<TItem> extends ObservableCollection<TItem> implement
/**
* Enable diff utils algorithm in collection changes.
*
* @param detectMoves The flag that determines whether the {@link Change.Moved} changes will be generated or not;
* @param sameItemsPredicate Predicate for the determination of the same elements;
* @param detectMoves The flag that determines whether the {@link Change.Moved} changes will be generated or not;
* @param sameItemsPredicate Predicate for the determination of the same elements;
* @param changePayloadProducer Function that calculate change payload when items the same but contents are different.
*/
public void enableDiffUtils(final boolean detectMoves,
@ -271,7 +283,16 @@ public class ObservableList<TItem> extends ObservableCollection<TItem> implement
* @return true if diff utils is enabled.
*/
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;
}
/**

View File

@ -38,7 +38,7 @@ public interface Converter<TObject, TStoreObject> {
*
* @param objectType Type of object;
* @param storeObjectType Type of store object allowed to store;
* @param object Object to be converted to store object;
* @param object Object to be converted to store object;
* @return Object that is allowed to store into specific {@link Store};
* @throws ConversionException Exception during conversion. Usually it indicates illegal state.
*/
@ -51,7 +51,7 @@ public interface Converter<TObject, TStoreObject> {
*
* @param objectType Type of object;
* @param storeObjectType Type of store object allowed to store;
* @param storeObject Object from specific {@link Store};
* @param storeObject Object from specific {@link Store};
* @return Object converted from store object;
* @throws ConversionException Exception during conversion. Usually it indicates illegal state.
*/

View File

@ -32,7 +32,7 @@ import ru.touchin.roboswag.core.utils.ObjectUtils;
* Both arguments are not null.
* Note that if you want to save this pair in state, you need make TFirst and TSecond Serializable too.
*
* @param <TFirst> type of the first nonnull argument.
* @param <TFirst> type of the first nonnull argument.
* @param <TSecond> type of the second nonnull argument.
*/
public class NonNullPair<TFirst, TSecond> implements Serializable {