From c2d2787b2137f943555bd0e2b8f7b7a5153838af Mon Sep 17 00:00:00 2001 From: Mario Danic Date: Wed, 18 Dec 2019 03:34:30 +0100 Subject: [PATCH] Remove useless transformation --- .../newarch/utils/LiveDataTransformations.kt | 62 ------------------- 1 file changed, 62 deletions(-) delete mode 100644 app/src/main/java/com/nextcloud/talk/newarch/utils/LiveDataTransformations.kt diff --git a/app/src/main/java/com/nextcloud/talk/newarch/utils/LiveDataTransformations.kt b/app/src/main/java/com/nextcloud/talk/newarch/utils/LiveDataTransformations.kt deleted file mode 100644 index 0f1bcb0b2..000000000 --- a/app/src/main/java/com/nextcloud/talk/newarch/utils/LiveDataTransformations.kt +++ /dev/null @@ -1,62 +0,0 @@ -package com.nextcloud.talk.newarch.utils - -import android.util.Log -import androidx.annotation.MainThread -import androidx.lifecycle.LiveData -import androidx.lifecycle.MediatorLiveData -import androidx.lifecycle.Observer -import java.util.* -import kotlin.collections.ArrayList - -class LiveDataTransformations { - - /** - * Creates a new [LiveData] object that does not emit a value until the source LiveData - * value has been changed. The value is considered changed if `equals()` yields - * `false`. - * - * @param source the input [LiveData] - * @param the generic type parameter of `source` - * @return a new [LiveData] of type `X` - */ - @MainThread - fun distinctUntilChangedForArray(source: LiveData): LiveData { - val outputLiveData = MediatorLiveData() - outputLiveData.addSource(source, object : Observer { - - var mFirstTime = true - - override fun onChanged(currentValue: X?) { - val previousValue = outputLiveData.value - if (mFirstTime && currentValue != null - || (previousValue == null && currentValue != null)) { - mFirstTime = false - outputLiveData.value = currentValue - } else if (previousValue != null) { - if (currentValue == null) { - outputLiveData.value = currentValue - } else { - val previousArray: Array = (previousValue as ArrayList).toArray() as Array - val currentArray: Array = (currentValue as ArrayList).toArray() as Array - - if (previousArray.size != currentArray.size) { - outputLiveData.value = currentValue - } else { - var counter = 0 - for(element in previousArray) { - if (!element!!.equals(currentArray[counter])) { - outputLiveData.value = currentValue - return - } - - counter++ - } - } - } - } - } - }) - - return outputLiveData - } -}