Skip to content

Commit

Permalink
release livedata-transformer 2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
microtears committed Oct 11, 2019
1 parent a15fc72 commit fd0fc9f
Show file tree
Hide file tree
Showing 85 changed files with 383 additions and 89,676 deletions.
2 changes: 1 addition & 1 deletion livedata_transformer/publish.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
artifact = 'livedata_transformer'
libraryName = 'livedata_transformer'
libraryVersion = '2.0.0'
libraryVersion = '2.1.0'
libraryDescription = 'orange livedata transformer library'
bintrayName = 'orange-' + artifact
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,147 +1,89 @@
package com.microtears.orange.livedata.transformer

import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer
import com.microtears.orange.livedata.transformer.observers.*
import java.util.concurrent.TimeUnit

class Transform {
companion object {

@JvmStatic
fun <S> from(collection: Collection<S>): LiveData<S> {
val result = MutableLiveData<S>()
collection.forEach(result::setValue)
return result
}
fun <S> from(collection: Collection<S>): LiveData<S> = MutableLiveData<S>().from(collection)

@JvmStatic
fun <S, T> map(source: LiveData<S>, mapFunction: (S) -> T): LiveData<T> {
return TransformerBase(MapObserver(mapFunction)).transform(source)
}
fun <S, T> map(source: LiveData<S>, mapFunction: (S) -> T): LiveData<T> = source.map(mapFunction)

@JvmStatic
fun <S, T> mapIndex(source: LiveData<S>, mapIndexFunction: (Int, S) -> T): LiveData<T> {
return TransformerBase(MapIndexObserver(mapIndexFunction)).transform(source)
}
fun <S, T> mapIndex(source: LiveData<S>, mapIndexFunction: (Int, S) -> T): LiveData<T> = source.mapIndex(mapIndexFunction)

@JvmStatic
fun <S, T> switchMap(
source: LiveData<S>,
switchMapFunction: (S) -> LiveData<T>
): LiveData<T> {
return TransformerBase(SwitchMapObserver(switchMapFunction)).transform(source)
}
fun <S, T> switchMap(source: LiveData<S>, switchMapFunction: (S) -> LiveData<T>): LiveData<T> = source.switchMap(switchMapFunction)

@JvmStatic
fun <S> distinctUntilChanged(source: LiveData<S>): LiveData<S> {
return TransformerBase<S, S>(DistinctUntilChangedObserver()).transform(source)
}
fun <S> distinctUntilChanged(source: LiveData<S>): LiveData<S> = source.distinctUntilChanged()

@JvmStatic
fun <S, T> flatMap(source: LiveData<S>, flatMapFunction: (S) -> LiveData<T>): LiveData<T> {
return TransformerBase(FlatMapObserver(flatMapFunction)).transform(source)
}
fun <S, T> flatMap(source: LiveData<S>, flatMapFunction: (S) -> LiveData<T>): LiveData<T> = source.flatMap(flatMapFunction)

@JvmStatic
fun <S> where(source: LiveData<S>, testFunction: (S) -> Boolean): LiveData<S> {
return TransformerBase(WhereObservable(testFunction)).transform(source)
}
fun <S> where(source: LiveData<S>, testFunction: (S) -> Boolean): LiveData<S> = source.where(testFunction)

@JvmStatic
fun <S> distinct(source: LiveData<S>): LiveData<S> {
return TransformerBase(DistinctObserver<S, S> { it }).transform(source)
}
fun <S> distinct(source: LiveData<S>): LiveData<S> = source.distinct()

@JvmStatic
fun <S, K> distinct(source: LiveData<S>, keys: (S) -> K): LiveData<S> {
return TransformerBase(DistinctObserver(keys)).transform(source)
}
fun <S, K> distinct(source: LiveData<S>, keys: (S) -> K): LiveData<S> = source.distinct(keys)

@JvmStatic
fun <S> throttleFirst(
source: LiveData<S>,
timeValue: Long,
timeUnit: TimeUnit
): LiveData<S> {
return TransformerBase<S, S>(ThrottleFirstObservable(timeValue, timeUnit)).transform(
source
)
}
fun <S> throttleFirst(source: LiveData<S>, timeValue: Long, timeUnit: TimeUnit): LiveData<S> = source.throttleFirst(timeValue, timeUnit)

@JvmStatic
fun <S> collect(source: LiveData<S>): LiveData<Collection<S>> {
return collect(source, mutableListOf())
}
fun <S> collect(source: LiveData<S>): LiveData<Collection<S>> = source.collect()

@JvmStatic
fun <S> collect(
source: LiveData<S>,
mutableCollection: MutableCollection<S> = mutableListOf(),
collectFunction: (collection: MutableCollection<S>, S) -> Unit = { collection, it ->
collection.add(it)
}
): LiveData<Collection<S>> {
return TransformerBase(CollectObservable(mutableCollection, collectFunction)).transform(
source
)
}
source: LiveData<S>,
mutableCollection: MutableCollection<S> = mutableListOf(),
collectFunction: (collection: MutableCollection<S>, S) -> Unit = { collection, it ->
collection.add(it)
}
): LiveData<Collection<S>> = source.collect(mutableCollection, collectFunction)

@JvmStatic
fun <S, T> reduce(
source: LiveData<S>,
initValue: T,
reduceFunction: (T, S) -> T
): LiveData<T> {
return TransformerBase(ReduceObservable(initValue, reduceFunction)).transform(source)
}
source: LiveData<S>,
initValue: T,
reduceFunction: (T, S) -> T
): LiveData<T> = source.reduce(initValue, reduceFunction)

@JvmStatic
fun <S> count(source: LiveData<S>): LiveData<Int> {
return TransformerBase<S, Int>(CountObservable()).transform(source)
}
fun <S> count(source: LiveData<S>): LiveData<Int> = source.count()

@JvmStatic
fun <S, T> cast(source: LiveData<S>): LiveData<T> {
return TransformerBase(CastObservable<S, T>()).transform(source)
}
fun <S, T> cast(source: LiveData<S>): LiveData<T> = source.cast()

@JvmStatic
fun <S> timestamp(source: LiveData<S>): LiveData<Pair<S, Long>> {
return TransformerBase(TimestampObservable<S>()).transform(source)
}
fun <S> timestamp(source: LiveData<S>): LiveData<Pair<S, Long>> = source.timestamp()

@JvmStatic
fun <S> take(source: LiveData<S>, size: Int): LiveData<S> {
return TransformerBase(TakeObservable<S>(size)).transform(source)
}
fun <S> take(source: LiveData<S>, size: Int): LiveData<S> = source.take(size)

@JvmStatic
fun <S> takeWhile(source: LiveData<S>, testFunction: (S) -> Boolean): LiveData<S> {
return TransformerBase(TakeWhileObservable(testFunction)).transform(source)
}
fun <S> takeWhile(source: LiveData<S>, testFunction: (S) -> Boolean): LiveData<S> = source.takeWhile(testFunction)

@JvmStatic
fun <S> takeUntil(source: LiveData<S>, testFunction: (S) -> Boolean): LiveData<S> {
return TransformerBase(TakeUntilObservable(testFunction)).transform(source)
}

fun <S> takeUntil(source: LiveData<S>, testFunction: (S) -> Boolean): LiveData<S> = source.takeUntil(testFunction)

@JvmStatic
fun <S> skip(source: LiveData<S>, size: Int): LiveData<S> {
return TransformerBase(SkipObservable<S>(size)).transform(source)
}
fun <S> skip(source: LiveData<S>, size: Int): LiveData<S> = source.skip(size)

@JvmStatic
fun <S> at(source: LiveData<S>, index: Int): LiveData<S> {
return TransformerBase(AtObservable<S>(index)).transform(source)
}
fun <S> at(source: LiveData<S>, index: Int): LiveData<S> = source.at(index)

@JvmStatic
fun <S, T> type(source: LiveData<S>, clazz: Class<T>): LiveData<T> {
return TransformerBase<S, T>(TypeObservable(clazz)).transform(source)
}
fun <S, T> type(source: LiveData<S>, clazz: Class<T>): LiveData<T> = source.type(clazz)

fun <S> skipNull(source: LiveData<S>): LiveData<S> = source.skipNull()
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit fd0fc9f

Please sign in to comment.