diff --git a/binder-order-failure-demo/.gitignore b/binder-order-failure-demo/.gitignore deleted file mode 100644 index 42afabfd..00000000 --- a/binder-order-failure-demo/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build \ No newline at end of file diff --git a/binder-order-failure-demo/build.gradle b/binder-order-failure-demo/build.gradle deleted file mode 100644 index 34bdb312..00000000 --- a/binder-order-failure-demo/build.gradle +++ /dev/null @@ -1,51 +0,0 @@ -plugins { - id 'com.android.application' - id 'org.jetbrains.kotlin.android' -} - -android { - compileSdkVersion 31 - - defaultConfig { - applicationId "com.bumble.binder_order_failure_demo" - minSdkVersion 15 - targetSdkVersion 31 - versionCode 1 - versionName "1.0" - - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - kotlinOptions { - jvmTarget = '1.8' - } -} - -dependencies { - - implementation deps('androidx.appcompat:appcompat') - implementation deps('com.google.android.material:material') - - implementation deps("org.jetbrains.kotlin:kotlin-stdlib-jdk7") - - implementation project(":mvicore") - implementation project(":mvicore-android") - - implementation deps('io.reactivex.rxjava2:rxjava') - implementation deps('io.reactivex.rxjava2:rxandroid') - - testImplementation deps('junit:junit') - androidTestImplementation deps("androidx.test:runner") - androidTestImplementation deps("androidx.test:rules") - androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' -} \ No newline at end of file diff --git a/binder-order-failure-demo/proguard-rules.pro b/binder-order-failure-demo/proguard-rules.pro deleted file mode 100644 index 481bb434..00000000 --- a/binder-order-failure-demo/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/binder-order-failure-demo/src/androidTest/java/com/bumble/PreBindEventActivityTest.kt b/binder-order-failure-demo/src/androidTest/java/com/bumble/PreBindEventActivityTest.kt deleted file mode 100644 index a74bd4dc..00000000 --- a/binder-order-failure-demo/src/androidTest/java/com/bumble/PreBindEventActivityTest.kt +++ /dev/null @@ -1,27 +0,0 @@ -package com.bumble - -import androidx.test.espresso.Espresso -import androidx.test.espresso.assertion.ViewAssertions -import androidx.test.espresso.matcher.ViewMatchers -import androidx.test.rule.ActivityTestRule -import androidx.test.runner.AndroidJUnit4 -import com.bumble.binder.orderfailure.R -import com.bumble.binder.orderfailure.prebindevent.PreBindEventActivity -import org.hamcrest.CoreMatchers.not -import org.junit.Rule -import org.junit.Test -import org.junit.runner.RunWith - -@RunWith(AndroidJUnit4::class) -class PreBindEventActivityTest { - - @get:Rule - val activityRule = ActivityTestRule(PreBindEventActivity::class.java) - - @Test - fun `GIVEN_the_screen_launched_THEN_the_title_should_not_be_visible`() { - Espresso.onView(ViewMatchers.withId(R.id.title)) - .check(ViewAssertions.matches(not(ViewMatchers.isDisplayed()))) - } - -} \ No newline at end of file diff --git a/binder-order-failure-demo/src/main/AndroidManifest.xml b/binder-order-failure-demo/src/main/AndroidManifest.xml deleted file mode 100644 index f748d655..00000000 --- a/binder-order-failure-demo/src/main/AndroidManifest.xml +++ /dev/null @@ -1,25 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<manifest xmlns:android="http://schemas.android.com/apk/res/android" - package="com.bumble.binder.orderfailure"> - - <application - android:allowBackup="true" - android:icon="@mipmap/ic_launcher" - android:label="@string/app_name" - android:roundIcon="@mipmap/ic_launcher_round" - android:supportsRtl="true" - android:theme="@style/Theme.MVICoreFixes" > - - <activity - android:name=".prebindevent.PreBindEventActivity" - android:exported="true"> - <intent-filter> - <action android:name="android.intent.action.MAIN" /> - - <category android:name="android.intent.category.LAUNCHER" /> - </intent-filter> - </activity> - - </application> - -</manifest> \ No newline at end of file diff --git a/binder-order-failure-demo/src/main/java/com/bumble/binder/orderfailure/RxExtensions.kt b/binder-order-failure-demo/src/main/java/com/bumble/binder/orderfailure/RxExtensions.kt deleted file mode 100644 index cb7c44d2..00000000 --- a/binder-order-failure-demo/src/main/java/com/bumble/binder/orderfailure/RxExtensions.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.bumble.binder.orderfailure - -import io.reactivex.Observable -import io.reactivex.ObservableSource -import io.reactivex.functions.BiFunction - -fun <T1, T2> combineLatest( - o1: ObservableSource<T1>, - o2: ObservableSource<T2> -): ObservableSource<Pair<T1, T2>> = - Observable.combineLatest( - o1, - o2, - BiFunction<T1, T2, Pair<T1, T2>> { t1, t2 -> - t1 to t2 - } - ) diff --git a/binder-order-failure-demo/src/main/java/com/bumble/binder/orderfailure/prebindevent/Feature1.kt b/binder-order-failure-demo/src/main/java/com/bumble/binder/orderfailure/prebindevent/Feature1.kt deleted file mode 100644 index 85377fae..00000000 --- a/binder-order-failure-demo/src/main/java/com/bumble/binder/orderfailure/prebindevent/Feature1.kt +++ /dev/null @@ -1,39 +0,0 @@ -package com.bumble.binder.orderfailure.prebindevent - -import com.badoo.mvicore.element.Bootstrapper -import com.badoo.mvicore.element.Reducer -import com.badoo.mvicore.feature.ReducerFeature -import com.bumble.binder.orderfailure.prebindevent.Feature1.State -import com.bumble.binder.orderfailure.prebindevent.Feature1.Wish -import io.reactivex.Observable - -class Feature1 : ReducerFeature<Wish, State, Nothing>( - initialState = State(), - bootstrapper = BootstrapperImpl(), - reducer = ReducerImpl() -) { - - data class State(val text: String? = "") - - sealed class Wish { - object Wish1 : Wish() - object Wish2 : Wish() - } - - class BootstrapperImpl : Bootstrapper<Wish> { - - override fun invoke(): Observable<out Wish> { - return Observable - .just(Wish.Wish1) - } - } - - class ReducerImpl : Reducer<State, Wish> { - - override fun invoke(state: State, effect: Wish): State = - when (effect) { - Wish.Wish1 -> state.copy(text = "Wish1") - Wish.Wish2 -> state.copy(text = null) - } - } -} \ No newline at end of file diff --git a/binder-order-failure-demo/src/main/java/com/bumble/binder/orderfailure/prebindevent/Feature2.kt b/binder-order-failure-demo/src/main/java/com/bumble/binder/orderfailure/prebindevent/Feature2.kt deleted file mode 100644 index 75912a46..00000000 --- a/binder-order-failure-demo/src/main/java/com/bumble/binder/orderfailure/prebindevent/Feature2.kt +++ /dev/null @@ -1,27 +0,0 @@ -package com.bumble.binder.orderfailure.prebindevent - -import com.badoo.mvicore.element.Reducer -import com.badoo.mvicore.feature.ReducerFeature -import com.bumble.binder.orderfailure.prebindevent.Feature2.State -import com.bumble.binder.orderfailure.prebindevent.Feature2.Wish - -class Feature2 : ReducerFeature<Wish, State, Nothing>( - initialState = State(), - reducer = ReducerImpl() -) { - - data class State(val actionEnabled: Boolean = true) - - sealed class Wish { - object Wish1 : Wish() - } - - class ReducerImpl : Reducer<State, Wish> { - - override fun invoke(state: State, effect: Wish): State { - return when (effect) { - Wish.Wish1 -> state.copy(actionEnabled = false) - } - } - } -} diff --git a/binder-order-failure-demo/src/main/java/com/bumble/binder/orderfailure/prebindevent/PreBindEventActivity.kt b/binder-order-failure-demo/src/main/java/com/bumble/binder/orderfailure/prebindevent/PreBindEventActivity.kt deleted file mode 100644 index 61080a22..00000000 --- a/binder-order-failure-demo/src/main/java/com/bumble/binder/orderfailure/prebindevent/PreBindEventActivity.kt +++ /dev/null @@ -1,59 +0,0 @@ -package com.bumble.binder.orderfailure.prebindevent - -import android.os.Bundle -import android.view.View -import android.widget.Button -import android.widget.TextView -import androidx.appcompat.app.AppCompatActivity -import com.bumble.binder.orderfailure.R -import io.reactivex.ObservableSource -import io.reactivex.Observer -import io.reactivex.functions.Consumer -import io.reactivex.subjects.PublishSubject - -class PreBindEventActivity : AppCompatActivity(), Consumer<ViewModel>, ObservableSource<UiEvent> { - - private val source = PublishSubject.create<UiEvent>() - private lateinit var title: TextView - private lateinit var button: Button - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_main) - title = findViewById(R.id.title) - button = findViewById(R.id.button) - MainActivityBindings(this, Feature1()).setup(this) - } - - override fun subscribe(observer: Observer<in UiEvent>) { - source.subscribe(observer) - } - - override fun accept(viewModel: ViewModel) { - if (viewModel.title != null) { - title.visibility = View.VISIBLE - title.text = viewModel.title - source.onNext(UiEvent.InitialEvent) - } else { - title.visibility = View.INVISIBLE - } - - if (viewModel.showButton) { - button.visibility = View.VISIBLE - button.setOnClickListener { source.onNext(UiEvent.SecondEvent) } - } else { - button.visibility = View.INVISIBLE - button.setOnClickListener(null) - } - } -} - -sealed class UiEvent { - object InitialEvent : UiEvent() - object SecondEvent : UiEvent() -} - -data class ViewModel( - val title: String?, - val showButton: Boolean = false -) \ No newline at end of file diff --git a/binder-order-failure-demo/src/main/java/com/bumble/binder/orderfailure/prebindevent/PreBindEventBinder.kt b/binder-order-failure-demo/src/main/java/com/bumble/binder/orderfailure/prebindevent/PreBindEventBinder.kt deleted file mode 100644 index 9976e673..00000000 --- a/binder-order-failure-demo/src/main/java/com/bumble/binder/orderfailure/prebindevent/PreBindEventBinder.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.bumble.binder.orderfailure.prebindevent - -import com.badoo.binder.using -import com.badoo.mvicore.android.AndroidBindings - -class MainActivityBindings( - view: PreBindEventActivity, - private val feature1: Feature1 -) : AndroidBindings<PreBindEventActivity>(view) { - - override fun setup(view: PreBindEventActivity) { - binder.bind(feature1 to view using object : (Feature1.State) -> ViewModel() { - override fun invoke(p1: Feature1.State): ViewModel { - return ViewModel(p1.text, true) - } - }) - binder.bind(view to feature1 using UiEventTransformer1) - } -} - -object UiEventTransformer1 : (UiEvent) -> Feature1.Wish? { - - override fun invoke(uiEvent: UiEvent): Feature1.Wish? = - when (uiEvent) { - UiEvent.InitialEvent -> Feature1.Wish.Wish2 - UiEvent.SecondEvent -> null - } -} diff --git a/binder-order-failure-demo/src/main/res/drawable-v24/ic_launcher_foreground.xml b/binder-order-failure-demo/src/main/res/drawable-v24/ic_launcher_foreground.xml deleted file mode 100644 index 2b068d11..00000000 --- a/binder-order-failure-demo/src/main/res/drawable-v24/ic_launcher_foreground.xml +++ /dev/null @@ -1,30 +0,0 @@ -<vector xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:aapt="http://schemas.android.com/aapt" - android:width="108dp" - android:height="108dp" - android:viewportWidth="108" - android:viewportHeight="108"> - <path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z"> - <aapt:attr name="android:fillColor"> - <gradient - android:endX="85.84757" - android:endY="92.4963" - android:startX="42.9492" - android:startY="49.59793" - android:type="linear"> - <item - android:color="#44000000" - android:offset="0.0" /> - <item - android:color="#00000000" - android:offset="1.0" /> - </gradient> - </aapt:attr> - </path> - <path - android:fillColor="#FFFFFF" - android:fillType="nonZero" - android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z" - android:strokeWidth="1" - android:strokeColor="#00000000" /> -</vector> \ No newline at end of file diff --git a/binder-order-failure-demo/src/main/res/drawable/ic_launcher_background.xml b/binder-order-failure-demo/src/main/res/drawable/ic_launcher_background.xml deleted file mode 100644 index 07d5da9c..00000000 --- a/binder-order-failure-demo/src/main/res/drawable/ic_launcher_background.xml +++ /dev/null @@ -1,170 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<vector xmlns:android="http://schemas.android.com/apk/res/android" - android:width="108dp" - android:height="108dp" - android:viewportWidth="108" - android:viewportHeight="108"> - <path - android:fillColor="#3DDC84" - android:pathData="M0,0h108v108h-108z" /> - <path - android:fillColor="#00000000" - android:pathData="M9,0L9,108" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> - <path - android:fillColor="#00000000" - android:pathData="M19,0L19,108" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> - <path - android:fillColor="#00000000" - android:pathData="M29,0L29,108" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> - <path - android:fillColor="#00000000" - android:pathData="M39,0L39,108" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> - <path - android:fillColor="#00000000" - android:pathData="M49,0L49,108" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> - <path - android:fillColor="#00000000" - android:pathData="M59,0L59,108" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> - <path - android:fillColor="#00000000" - android:pathData="M69,0L69,108" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> - <path - android:fillColor="#00000000" - android:pathData="M79,0L79,108" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> - <path - android:fillColor="#00000000" - android:pathData="M89,0L89,108" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> - <path - android:fillColor="#00000000" - android:pathData="M99,0L99,108" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> - <path - android:fillColor="#00000000" - android:pathData="M0,9L108,9" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> - <path - android:fillColor="#00000000" - android:pathData="M0,19L108,19" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> - <path - android:fillColor="#00000000" - android:pathData="M0,29L108,29" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> - <path - android:fillColor="#00000000" - android:pathData="M0,39L108,39" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> - <path - android:fillColor="#00000000" - android:pathData="M0,49L108,49" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> - <path - android:fillColor="#00000000" - android:pathData="M0,59L108,59" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> - <path - android:fillColor="#00000000" - android:pathData="M0,69L108,69" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> - <path - android:fillColor="#00000000" - android:pathData="M0,79L108,79" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> - <path - android:fillColor="#00000000" - android:pathData="M0,89L108,89" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> - <path - android:fillColor="#00000000" - android:pathData="M0,99L108,99" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> - <path - android:fillColor="#00000000" - android:pathData="M19,29L89,29" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> - <path - android:fillColor="#00000000" - android:pathData="M19,39L89,39" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> - <path - android:fillColor="#00000000" - android:pathData="M19,49L89,49" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> - <path - android:fillColor="#00000000" - android:pathData="M19,59L89,59" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> - <path - android:fillColor="#00000000" - android:pathData="M19,69L89,69" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> - <path - android:fillColor="#00000000" - android:pathData="M19,79L89,79" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> - <path - android:fillColor="#00000000" - android:pathData="M29,19L29,89" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> - <path - android:fillColor="#00000000" - android:pathData="M39,19L39,89" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> - <path - android:fillColor="#00000000" - android:pathData="M49,19L49,89" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> - <path - android:fillColor="#00000000" - android:pathData="M59,19L59,89" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> - <path - android:fillColor="#00000000" - android:pathData="M69,19L69,89" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> - <path - android:fillColor="#00000000" - android:pathData="M79,19L79,89" - android:strokeWidth="0.8" - android:strokeColor="#33FFFFFF" /> -</vector> diff --git a/binder-order-failure-demo/src/main/res/layout/activity_main.xml b/binder-order-failure-demo/src/main/res/layout/activity_main.xml deleted file mode 100644 index 072f7218..00000000 --- a/binder-order-failure-demo/src/main/res/layout/activity_main.xml +++ /dev/null @@ -1,25 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:tools="http://schemas.android.com/tools" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:orientation="vertical" - tools:context=".prebindevent.PreBindEventActivity"> - - <TextView - android:id="@+id/title" - android:layout_width="match_parent" - android:layout_height="wrap_content" - android:text="Hello World!" - android:visibility="invisible" - tools:visibility="visible" /> - - <Button - android:id="@+id/button" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="Hide Me" - android:visibility="invisible" - tools:visibility="visible" /> - -</LinearLayout> \ No newline at end of file diff --git a/binder-order-failure-demo/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/binder-order-failure-demo/src/main/res/mipmap-anydpi-v26/ic_launcher.xml deleted file mode 100644 index eca70cfe..00000000 --- a/binder-order-failure-demo/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +++ /dev/null @@ -1,5 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> - <background android:drawable="@drawable/ic_launcher_background" /> - <foreground android:drawable="@drawable/ic_launcher_foreground" /> -</adaptive-icon> \ No newline at end of file diff --git a/binder-order-failure-demo/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/binder-order-failure-demo/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml deleted file mode 100644 index eca70cfe..00000000 --- a/binder-order-failure-demo/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +++ /dev/null @@ -1,5 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> - <background android:drawable="@drawable/ic_launcher_background" /> - <foreground android:drawable="@drawable/ic_launcher_foreground" /> -</adaptive-icon> \ No newline at end of file diff --git a/binder-order-failure-demo/src/main/res/mipmap-hdpi/ic_launcher.webp b/binder-order-failure-demo/src/main/res/mipmap-hdpi/ic_launcher.webp deleted file mode 100644 index c209e78e..00000000 Binary files a/binder-order-failure-demo/src/main/res/mipmap-hdpi/ic_launcher.webp and /dev/null differ diff --git a/binder-order-failure-demo/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/binder-order-failure-demo/src/main/res/mipmap-hdpi/ic_launcher_round.webp deleted file mode 100644 index b2dfe3d1..00000000 Binary files a/binder-order-failure-demo/src/main/res/mipmap-hdpi/ic_launcher_round.webp and /dev/null differ diff --git a/binder-order-failure-demo/src/main/res/mipmap-mdpi/ic_launcher.webp b/binder-order-failure-demo/src/main/res/mipmap-mdpi/ic_launcher.webp deleted file mode 100644 index 4f0f1d64..00000000 Binary files a/binder-order-failure-demo/src/main/res/mipmap-mdpi/ic_launcher.webp and /dev/null differ diff --git a/binder-order-failure-demo/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/binder-order-failure-demo/src/main/res/mipmap-mdpi/ic_launcher_round.webp deleted file mode 100644 index 62b611da..00000000 Binary files a/binder-order-failure-demo/src/main/res/mipmap-mdpi/ic_launcher_round.webp and /dev/null differ diff --git a/binder-order-failure-demo/src/main/res/mipmap-xhdpi/ic_launcher.webp b/binder-order-failure-demo/src/main/res/mipmap-xhdpi/ic_launcher.webp deleted file mode 100644 index 948a3070..00000000 Binary files a/binder-order-failure-demo/src/main/res/mipmap-xhdpi/ic_launcher.webp and /dev/null differ diff --git a/binder-order-failure-demo/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/binder-order-failure-demo/src/main/res/mipmap-xhdpi/ic_launcher_round.webp deleted file mode 100644 index 1b9a6956..00000000 Binary files a/binder-order-failure-demo/src/main/res/mipmap-xhdpi/ic_launcher_round.webp and /dev/null differ diff --git a/binder-order-failure-demo/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/binder-order-failure-demo/src/main/res/mipmap-xxhdpi/ic_launcher.webp deleted file mode 100644 index 28d4b77f..00000000 Binary files a/binder-order-failure-demo/src/main/res/mipmap-xxhdpi/ic_launcher.webp and /dev/null differ diff --git a/binder-order-failure-demo/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/binder-order-failure-demo/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp deleted file mode 100644 index 9287f508..00000000 Binary files a/binder-order-failure-demo/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp and /dev/null differ diff --git a/binder-order-failure-demo/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/binder-order-failure-demo/src/main/res/mipmap-xxxhdpi/ic_launcher.webp deleted file mode 100644 index aa7d6427..00000000 Binary files a/binder-order-failure-demo/src/main/res/mipmap-xxxhdpi/ic_launcher.webp and /dev/null differ diff --git a/binder-order-failure-demo/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/binder-order-failure-demo/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp deleted file mode 100644 index 9126ae37..00000000 Binary files a/binder-order-failure-demo/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp and /dev/null differ diff --git a/binder-order-failure-demo/src/main/res/values-night/themes.xml b/binder-order-failure-demo/src/main/res/values-night/themes.xml deleted file mode 100644 index 948501b5..00000000 --- a/binder-order-failure-demo/src/main/res/values-night/themes.xml +++ /dev/null @@ -1,16 +0,0 @@ -<resources xmlns:tools="http://schemas.android.com/tools"> - <!-- Base application theme. --> - <style name="Theme.MVICoreFixes" parent="Theme.MaterialComponents.DayNight.DarkActionBar"> - <!-- Primary brand color. --> - <item name="colorPrimary">@color/purple_200</item> - <item name="colorPrimaryVariant">@color/purple_700</item> - <item name="colorOnPrimary">@color/black</item> - <!-- Secondary brand color. --> - <item name="colorSecondary">@color/teal_200</item> - <item name="colorSecondaryVariant">@color/teal_200</item> - <item name="colorOnSecondary">@color/black</item> - <!-- Status bar color. --> - <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item> - <!-- Customize your theme here. --> - </style> -</resources> \ No newline at end of file diff --git a/binder-order-failure-demo/src/main/res/values/colors.xml b/binder-order-failure-demo/src/main/res/values/colors.xml deleted file mode 100644 index f8c6127d..00000000 --- a/binder-order-failure-demo/src/main/res/values/colors.xml +++ /dev/null @@ -1,10 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<resources> - <color name="purple_200">#FFBB86FC</color> - <color name="purple_500">#FF6200EE</color> - <color name="purple_700">#FF3700B3</color> - <color name="teal_200">#FF03DAC5</color> - <color name="teal_700">#FF018786</color> - <color name="black">#FF000000</color> - <color name="white">#FFFFFFFF</color> -</resources> \ No newline at end of file diff --git a/binder-order-failure-demo/src/main/res/values/strings.xml b/binder-order-failure-demo/src/main/res/values/strings.xml deleted file mode 100644 index 86169d82..00000000 --- a/binder-order-failure-demo/src/main/res/values/strings.xml +++ /dev/null @@ -1,3 +0,0 @@ -<resources> - <string name="app_name">binder-order-failure-demo</string> -</resources> \ No newline at end of file diff --git a/binder-order-failure-demo/src/main/res/values/themes.xml b/binder-order-failure-demo/src/main/res/values/themes.xml deleted file mode 100644 index c132c7e9..00000000 --- a/binder-order-failure-demo/src/main/res/values/themes.xml +++ /dev/null @@ -1,16 +0,0 @@ -<resources xmlns:tools="http://schemas.android.com/tools"> - <!-- Base application theme. --> - <style name="Theme.MVICoreFixes" parent="Theme.MaterialComponents.DayNight.DarkActionBar"> - <!-- Primary brand color. --> - <item name="colorPrimary">@color/purple_500</item> - <item name="colorPrimaryVariant">@color/purple_700</item> - <item name="colorOnPrimary">@color/white</item> - <!-- Secondary brand color. --> - <item name="colorSecondary">@color/teal_200</item> - <item name="colorSecondaryVariant">@color/teal_700</item> - <item name="colorOnSecondary">@color/black</item> - <!-- Status bar color. --> - <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item> - <!-- Customize your theme here. --> - </style> -</resources> \ No newline at end of file diff --git a/binder/src/main/java/com/badoo/binder/Binder.kt b/binder/src/main/java/com/badoo/binder/Binder.kt index ec0dac4f..a60fbe9e 100644 --- a/binder/src/main/java/com/badoo/binder/Binder.kt +++ b/binder/src/main/java/com/badoo/binder/Binder.kt @@ -64,11 +64,13 @@ class Binder( } private fun <Out, In> subscribeWithLifecycle(binding: Binding) { - connectionDisposables += wrap(binding.source as UnicastSubject<Out>) - .subscribeWithMiddleware( - binding.connection as Connection<Out, In>, - binding.middleware as? Middleware<Out, In> - ) + (binding.source as? UnicastSubject<Out>)?.let { source -> + connectionDisposables += wrap(source) + .subscribeWithMiddleware( + binding.connection as Connection<Out, In>, + binding.middleware as? Middleware<Out, In> + ) + } } private fun <Out, In> subscribe( diff --git a/binder/src/main/java/com/badoo/binder/Binding.kt b/binder/src/main/java/com/badoo/binder/Binding.kt index 5ee43173..dd491947 100644 --- a/binder/src/main/java/com/badoo/binder/Binding.kt +++ b/binder/src/main/java/com/badoo/binder/Binding.kt @@ -12,9 +12,9 @@ internal class Binding( private set fun accumulate() { - source = connection.from?.run { + source = connection.from?.let { source -> UnicastSubject.create<Any>() - .also { this.subscribe(it) } + .also { observer -> source.subscribe(observer) } } } } \ No newline at end of file diff --git a/binder/src/test/java/com/badoo/binder/BinderMissingPreBindEventsTest.kt b/binder/src/test/java/com/badoo/binder/BinderMissingPreBindEventsTest.kt new file mode 100644 index 00000000..6cf5635c --- /dev/null +++ b/binder/src/test/java/com/badoo/binder/BinderMissingPreBindEventsTest.kt @@ -0,0 +1,85 @@ +package com.badoo.binder + +import com.badoo.binder.lifecycle.Lifecycle +import com.badoo.binder.lifecycle.ManualLifecycle +import io.reactivex.ObservableSource +import io.reactivex.functions.Consumer +import io.reactivex.subjects.BehaviorSubject +import io.reactivex.subjects.PublishSubject +import kotlin.test.assertEquals +import org.junit.Test + +class BinderMissingPreBindEventsTest { + + @Test + fun `consumer consumes the events produced before the binding`() { + val lifecycle: ManualLifecycle = Lifecycle.manual() + val scoreConsumer = ScoreConsumer() + val testObserver = scoreConsumer.state.test() + val scoreState = ScoreState() + val binder = Binder(lifecycle) + binder.bind(scoreState to scoreConsumer using { state -> ScoreConsumer.State(state) }) + binder.bind(scoreConsumer to scoreState using { event -> + when (event) { + ScoreConsumer.Event.Start -> ScoreState.Message.Start + } + }) + + lifecycle.begin() + + testObserver.onComplete() + testObserver.assertValueCount(2) + assertEquals(PENDING, testObserver.values()[0].points) + assertEquals(INITIAL, testObserver.values()[1].points) + } + + private class ScoreState( + private val events: BehaviorSubject<Int> = BehaviorSubject.create<Int>() + ) : ObservableSource<Int> by events, Consumer<ScoreState.Message> { + + var score = PENDING + private set + + init { + accept(Message.Prepare) + } + + sealed class Message { + object Prepare : Message() + object Start : Message() + } + + override fun accept(message: Message) = when (message) { + Message.Prepare -> events.onNext(score) + Message.Start -> { + score = INITIAL + events.onNext(score) + } + } + } + + private class ScoreConsumer( + private val events: PublishSubject<Event> = PublishSubject.create() + ) : ObservableSource<ScoreConsumer.Event> by events, Consumer<ScoreConsumer.State> { + + val state = PublishSubject.create<State>() + + override fun accept(state: State) { + this.state.onNext(state) + if (state.points == PENDING) { + events.onNext(Event.Start) + } + } + + sealed class Event { + object Start : Event() + } + + data class State(val points: Int) + } + + private companion object { + const val PENDING = -1 + const val INITIAL = 0 + } +} diff --git a/settings.gradle b/settings.gradle index fdd6ade0..9872e30b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -12,4 +12,3 @@ include ':mvicore-demo:mvicore-demo-feature1' include ':mvicore-demo:mvicore-demo-feature2' include ':mvicore-demo:mvicore-demo-app' -include ':binder-order-failure-demo'