This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface Lifecycle : ObservableSource<Lifecycle.Event> { | |
enum class Event { | |
BEGIN, | |
END | |
} | |
// Remainder omitted | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val output: PublishSubject<String> = PublishSubject.create() | |
val input: Consumer<String> = Consumer { System.out.println(it) } | |
val lifecycle = ManualLifecycle() | |
val binder = Binder(lifecycle) | |
binder.bind(output to input) | |
output.onNext("1") | |
lifecycle.begin() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun createBinderForActivity(activity: AppCompatActivity) = Binder( | |
CreateDestroyBinderLifecycle(activity.lifecycle) | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun Observable<T>.toBinderLifecycle() = Lifecycle.wrap(this | |
.first() | |
.map { END } | |
.startWith(BEGIN) | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun Completable.toBinderLifecycle() = Lifecycle.wrap( | |
Observable.concat( | |
Observable.just(BEGIN), | |
this.andThen(Observable.just(END)) | |
) | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with(binder) { | |
bind(feature to view using stateToViewModelTransformer) | |
bind(view to feature using uiEventToWishTransformer) | |
bind(view to analyticsTracker) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed class Lce<out T> { | |
open val content: T? = null | |
open val error: Throwable? = null | |
open val isLoading: Boolean = false | |
object Loading : Lce<Nothing>() { override val isLoading: Boolean = true } | |
data class Content<out T>(override val content: T) : Lce<T>() | |
data class Error(override val error: Throwable) : Lce<Nothing>() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.nio.ByteBuffer; | |
import java.util.UUID; | |
public class UuidAdapter { | |
public static byte[] getBytesFromUUID(UUID uuid) { | |
ByteBuffer bb = ByteBuffer.wrap(new byte[16]); | |
bb.putLong(uuid.getMostSignificantBits()); | |
bb.putLong(uuid.getLeastSignificantBits()); | |
return bb.array(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface FooView : Consumer<ViewModel>, ObservableSource<Event> { | |
data class ViewModel( | |
val title: String, | |
val bgColor: Int | |
) | |
sealed class Event { | |
object ButtonClicked : Event() | |
data class TextFocusChanged(val hasFocus: Boolean) : Event() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FooViewImpl @JvmOverloads constructor( | |
context: Context, | |
attrs: AttributeSet? = null, | |
defStyle: Int = 0, | |
private val events: PublishRelay<Event> = PublishRelay.create<Event>() | |
) : LinearLayout(context, attrs, defStyle), | |
FooView, | |
// delegate implementing ObservableSource to our Relay | |
ObservableSource<Event> by events { | |