From f9c8af737a7ce8550f6ee5651f48fe1e33282fd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Matej=C4=8D=C3=ADk?= Date: Fri, 11 May 2018 16:30:32 +0200 Subject: [PATCH] Set one name for livedata combine functions --- .../mvvmsample/ui/form/FormViewState.kt | 4 ++-- .../mvvm/livedata/LiveDataUtils.kt | 12 +++++----- .../mvvm/livedata/MediatorLiveDataUtils.kt | 12 +++++----- .../mvvm/livedata/LiveDataUtilsTest.kt | 24 +++++++++---------- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/com/thefuntasty/mvvmsample/ui/form/FormViewState.kt b/app/src/main/java/com/thefuntasty/mvvmsample/ui/form/FormViewState.kt index 67af942c..85632329 100644 --- a/app/src/main/java/com/thefuntasty/mvvmsample/ui/form/FormViewState.kt +++ b/app/src/main/java/com/thefuntasty/mvvmsample/ui/form/FormViewState.kt @@ -2,13 +2,13 @@ package com.thefuntasty.mvvmsample.ui.form import com.thefuntasty.mvvm.ViewState import com.thefuntasty.mvvm.livedata.DefaultValueLiveData -import com.thefuntasty.mvvm.livedata.liveDataCombineTwo +import com.thefuntasty.mvvm.livedata.combineLiveData class FormViewState(login: String, password: String) : ViewState { val login = DefaultValueLiveData(login) val password = DefaultValueLiveData(password) - val submitEnabled = liveDataCombineTwo(this.login, this.password) { login, password -> + val submitEnabled = combineLiveData(this.login, this.password) { login, password -> login.isNotEmpty() && password.isNotEmpty() } } diff --git a/mvvm/src/main/java/com/thefuntasty/mvvm/livedata/LiveDataUtils.kt b/mvvm/src/main/java/com/thefuntasty/mvvm/livedata/LiveDataUtils.kt index 38a40061..f0446770 100644 --- a/mvvm/src/main/java/com/thefuntasty/mvvm/livedata/LiveDataUtils.kt +++ b/mvvm/src/main/java/com/thefuntasty/mvvm/livedata/LiveDataUtils.kt @@ -4,7 +4,7 @@ import android.arch.lifecycle.LiveData import android.arch.lifecycle.MediatorLiveData import android.arch.lifecycle.Transformations -fun liveDataCombineTwo(t1: LiveData, +fun combineLiveData(t1: LiveData, t2: LiveData, callback: (T1, T2) -> RESULT): LiveData { val mediatorLiveData = MediatorLiveData>().apply { @@ -24,7 +24,7 @@ fun liveDataCombineTwo(t1: LiveData, return Transformations.map(mediatorLiveData) { callback(it.first, it.second) } } -fun liveDataCombineThree(t1: LiveData, +fun combineLiveData(t1: LiveData, t2: LiveData, t3: LiveData, callback: (T1, T2, T3) -> RESULT): LiveData { @@ -49,7 +49,7 @@ fun liveDataCombineThree(t1: LiveData, return Transformations.map(mediatorLiveData) { callback(it.first, it.second, it.third) } } -fun liveDataCombineFour(t1: LiveData, +fun combineLiveData(t1: LiveData, t2: LiveData, t3: LiveData, t4: LiveData, @@ -80,7 +80,7 @@ fun liveDataCombineFour(t1: LiveData, return Transformations.map(mediatorLiveData) { callback(it.first, it.second, it.third, it.fourth) } } -fun liveDataCombineFive(t1: LiveData, +fun combineLiveData(t1: LiveData, t2: LiveData, t3: LiveData, t4: LiveData, @@ -115,7 +115,7 @@ fun liveDataCombineFive(t1: LiveData, return Transformations.map(mediatorLiveData) { callback(it.first, it.second, it.third, it.fourth, it.fifth) } } -fun liveDataCombineSix(t1: LiveData, +fun combineLiveData(t1: LiveData, t2: LiveData, t3: LiveData, t4: LiveData, @@ -155,7 +155,7 @@ fun liveDataCombineSix(t1: LiveData, return Transformations.map(mediatorLiveData) { callback(it.first, it.second, it.third, it.fourth, it.fifth, it.sixth) } } -fun liveDataCombineSeven(t1: LiveData, +fun combineLiveData(t1: LiveData, t2: LiveData, t3: LiveData, t4: LiveData, diff --git a/mvvm/src/main/java/com/thefuntasty/mvvm/livedata/MediatorLiveDataUtils.kt b/mvvm/src/main/java/com/thefuntasty/mvvm/livedata/MediatorLiveDataUtils.kt index 57385d8a..a6e53302 100644 --- a/mvvm/src/main/java/com/thefuntasty/mvvm/livedata/MediatorLiveDataUtils.kt +++ b/mvvm/src/main/java/com/thefuntasty/mvvm/livedata/MediatorLiveDataUtils.kt @@ -7,7 +7,7 @@ fun combineLiveData( t1: LiveData, t2: LiveData, callback: (T1, T2) -> RESULT -): DefaultValueMediatorLiveData = liveDataCombineTwo(t1, t2, callback) +): DefaultValueMediatorLiveData = combineLiveData(t1, t2, callback) .nonNull(defaultValue) fun combineLiveData( @@ -16,7 +16,7 @@ fun combineLiveData( t2: LiveData, t3: LiveData, callback: (T1, T2, T3) -> RESULT -): DefaultValueMediatorLiveData = liveDataCombineThree(t1, t2, t3, callback) +): DefaultValueMediatorLiveData = combineLiveData(t1, t2, t3, callback) .nonNull(defaultValue) fun combineLiveData( @@ -26,7 +26,7 @@ fun combineLiveData( t3: LiveData, t4: LiveData, callback: (T1, T2, T3, T4) -> RESULT -): DefaultValueMediatorLiveData = liveDataCombineFour(t1, t2, t3, t4, callback) +): DefaultValueMediatorLiveData = combineLiveData(t1, t2, t3, t4, callback) .nonNull(defaultValue) fun combineLiveData( @@ -37,7 +37,7 @@ fun combineLiveData( t4: LiveData, t5: LiveData, callback: (T1, T2, T3, T4, T5) -> RESULT -): DefaultValueMediatorLiveData = liveDataCombineFive(t1, t2, t3, t4, t5, callback) +): DefaultValueMediatorLiveData = combineLiveData(t1, t2, t3, t4, t5, callback) .nonNull(defaultValue) fun combineLiveData( @@ -49,7 +49,7 @@ fun combineLiveData( t5: LiveData, t6: LiveData, callback: (T1, T2, T3, T4, T5, T6) -> RESULT -): DefaultValueMediatorLiveData = liveDataCombineSix(t1, t2, t3, t4, t5, t6, callback) +): DefaultValueMediatorLiveData = combineLiveData(t1, t2, t3, t4, t5, t6, callback) .nonNull(defaultValue) fun combineLiveData( @@ -62,5 +62,5 @@ fun combineLiveData( t6: LiveData, t7: LiveData, callback: (T1, T2, T3, T4, T5, T6, T7) -> RESULT -): DefaultValueMediatorLiveData = liveDataCombineSeven(t1, t2, t3, t4, t5, t6, t7, callback) +): DefaultValueMediatorLiveData = combineLiveData(t1, t2, t3, t4, t5, t6, t7, callback) .nonNull(defaultValue) diff --git a/mvvm/src/test/java/com/thefuntasty/mvvm/livedata/LiveDataUtilsTest.kt b/mvvm/src/test/java/com/thefuntasty/mvvm/livedata/LiveDataUtilsTest.kt index b2b02ed5..81330dd6 100644 --- a/mvvm/src/test/java/com/thefuntasty/mvvm/livedata/LiveDataUtilsTest.kt +++ b/mvvm/src/test/java/com/thefuntasty/mvvm/livedata/LiveDataUtilsTest.kt @@ -19,7 +19,7 @@ class LiveDataUtilsTest { fun testLiveDataCombineTwoNotEmpty() { val liveData1 = DefaultValueLiveData("") val liveData2 = DefaultValueLiveData("") - val resultLiveData = liveDataCombineTwo(liveData1, liveData2) { first, second -> + val resultLiveData = combineLiveData(liveData1, liveData2) { first, second -> first.isNotEmpty() && second.isNotEmpty() } resultLiveData.observeForever(observer) @@ -34,7 +34,7 @@ class LiveDataUtilsTest { fun testLiveDataCombineTwoEmpty() { val liveData1 = DefaultValueLiveData("") val liveData2 = DefaultValueLiveData("") - val resultLiveData = liveDataCombineTwo(liveData1, liveData2) { first, second -> + val resultLiveData = combineLiveData(liveData1, liveData2) { first, second -> first.isNotEmpty() && second.isNotEmpty() } resultLiveData.observeForever(observer) @@ -49,7 +49,7 @@ class LiveDataUtilsTest { val liveData1 = DefaultValueLiveData("") val liveData2 = DefaultValueLiveData("") val liveData3 = DefaultValueLiveData("") - val resultLiveData = liveDataCombineThree(liveData1, liveData2, liveData3) { first, second, third -> + val resultLiveData = combineLiveData(liveData1, liveData2, liveData3) { first, second, third -> first.isNotEmpty() && second.isNotEmpty() && third.isNotEmpty() } resultLiveData.observeForever(observer) @@ -66,7 +66,7 @@ class LiveDataUtilsTest { val liveData1 = DefaultValueLiveData("") val liveData2 = DefaultValueLiveData("") val liveData3 = DefaultValueLiveData("") - val resultLiveData = liveDataCombineThree(liveData1, liveData2, liveData3) { first, second, third -> + val resultLiveData = combineLiveData(liveData1, liveData2, liveData3) { first, second, third -> first.isNotEmpty() && second.isNotEmpty() && third.isNotEmpty() } resultLiveData.observeForever(observer) @@ -82,7 +82,7 @@ class LiveDataUtilsTest { val liveData2 = DefaultValueLiveData("") val liveData3 = DefaultValueLiveData("") val liveData4 = DefaultValueLiveData("") - val resultLiveData = liveDataCombineFour(liveData1, liveData2, liveData3, liveData4) { first, second, third, fourth -> + val resultLiveData = combineLiveData(liveData1, liveData2, liveData3, liveData4) { first, second, third, fourth -> first.isNotEmpty() && second.isNotEmpty() && third.isNotEmpty() && fourth.isNotEmpty() } resultLiveData.observeForever(observer) @@ -101,7 +101,7 @@ class LiveDataUtilsTest { val liveData2 = DefaultValueLiveData("") val liveData3 = DefaultValueLiveData("") val liveData4 = DefaultValueLiveData("") - val resultLiveData = liveDataCombineFour(liveData1, liveData2, liveData3, liveData4) { first, second, third, fourth -> + val resultLiveData = combineLiveData(liveData1, liveData2, liveData3, liveData4) { first, second, third, fourth -> first.isNotEmpty() && second.isNotEmpty() && third.isNotEmpty() && fourth.isNotEmpty() } resultLiveData.observeForever(observer) @@ -119,7 +119,7 @@ class LiveDataUtilsTest { val liveData3 = DefaultValueLiveData("") val liveData4 = DefaultValueLiveData("") val liveData5 = DefaultValueLiveData("") - val resultLiveData = liveDataCombineFive( + val resultLiveData = combineLiveData( liveData1, liveData2, liveData3, liveData4, liveData5) { first, second, third, fourth, fifth -> first.isNotEmpty() && second.isNotEmpty() && third.isNotEmpty() && fourth.isNotEmpty() && fifth.isNotEmpty() } @@ -141,7 +141,7 @@ class LiveDataUtilsTest { val liveData3 = DefaultValueLiveData("") val liveData4 = DefaultValueLiveData("") val liveData5 = DefaultValueLiveData("") - val resultLiveData = liveDataCombineFive( + val resultLiveData = combineLiveData( liveData1, liveData2, liveData3, liveData4, liveData5) { first, second, third, fourth, fifth -> first.isNotEmpty() && second.isNotEmpty() && third.isNotEmpty() && fourth.isNotEmpty() && fifth.isNotEmpty() } @@ -162,7 +162,7 @@ class LiveDataUtilsTest { val liveData4 = DefaultValueLiveData("") val liveData5 = DefaultValueLiveData("") val liveData6 = DefaultValueLiveData("") - val resultLiveData = liveDataCombineSix( + val resultLiveData = combineLiveData( liveData1, liveData2, liveData3, liveData4, liveData5, liveData6) { first, second, third, fourth, fifth, sixth -> first.isNotEmpty() && second.isNotEmpty() && third.isNotEmpty() && fourth.isNotEmpty() && fifth.isNotEmpty() && sixth.isNotEmpty() } @@ -186,7 +186,7 @@ class LiveDataUtilsTest { val liveData4 = DefaultValueLiveData("") val liveData5 = DefaultValueLiveData("") val liveData6 = DefaultValueLiveData("") - val resultLiveData = liveDataCombineSix( + val resultLiveData = combineLiveData( liveData1, liveData2, liveData3, liveData4, liveData5, liveData6) { first, second, third, fourth, fifth, sixth -> first.isNotEmpty() && second.isNotEmpty() && third.isNotEmpty() && fourth.isNotEmpty() && fifth.isNotEmpty() && sixth.isNotEmpty() } @@ -209,7 +209,7 @@ class LiveDataUtilsTest { val liveData5 = DefaultValueLiveData("") val liveData6 = DefaultValueLiveData("") val liveData7 = DefaultValueLiveData("") - val resultLiveData = liveDataCombineSeven( + val resultLiveData = combineLiveData( liveData1, liveData2, liveData3, liveData4, liveData5, liveData6, liveData7) { first, second, third, fourth, fifth, sixth, seventh -> first.isNotEmpty() && second.isNotEmpty() && third.isNotEmpty() && fourth.isNotEmpty() && fifth.isNotEmpty() && sixth.isNotEmpty() && seventh.isNotEmpty() } @@ -235,7 +235,7 @@ class LiveDataUtilsTest { val liveData5 = DefaultValueLiveData("") val liveData6 = DefaultValueLiveData("") val liveData7 = DefaultValueLiveData("") - val resultLiveData = liveDataCombineSeven( + val resultLiveData = combineLiveData( liveData1, liveData2, liveData3, liveData4, liveData5, liveData6, liveData7) { first, second, third, fourth, fifth, sixth, seventh -> first.isNotEmpty() && second.isNotEmpty() && third.isNotEmpty() && fourth.isNotEmpty() && fifth.isNotEmpty() && sixth.isNotEmpty() && seventh.isNotEmpty() }