From abf165a665bdd761c54568b9fb6e30ca50a3c34b Mon Sep 17 00:00:00 2001 From: zhxnlai Date: Thu, 17 Jan 2019 14:04:35 -0800 Subject: [PATCH] Do not terminate default lifecycle --- .../websocket/echo/view/EchoBotFragment.kt | 2 + .../android/ApplicationResumedLifecycle.kt | 43 ------------------- .../gson/GsonMessageAdapterTest.kt | 3 -- .../scarlet/lifecycle/DefaultLifecycle.kt | 12 ++++-- .../scarlet/lifecycle/DefaultLifecycleTest.kt | 10 +++++ 5 files changed, 20 insertions(+), 50 deletions(-) delete mode 100644 scarlet-lifecycle-android/src/main/java/com/tinder/scarlet/lifecycle/android/ApplicationResumedLifecycle.kt diff --git a/demo/src/main/java/com/tinder/app/websocket/echo/view/EchoBotFragment.kt b/demo/src/main/java/com/tinder/app/websocket/echo/view/EchoBotFragment.kt index 9a4dac58..62b67ad6 100755 --- a/demo/src/main/java/com/tinder/app/websocket/echo/view/EchoBotFragment.kt +++ b/demo/src/main/java/com/tinder/app/websocket/echo/view/EchoBotFragment.kt @@ -75,6 +75,8 @@ class EchoBotFragment : Fragment() { val numberOfMessages = chatView.getMessageView().messageList.size if (numberOfMessages == 0) { setMessages(chatMessages) + } else if (chatMessages.isEmpty()) { + chatView.getMessageView().removeAll() } else { for (i in numberOfMessages until chatMessages.size) { addMessage(chatMessages[i]) diff --git a/scarlet-lifecycle-android/src/main/java/com/tinder/scarlet/lifecycle/android/ApplicationResumedLifecycle.kt b/scarlet-lifecycle-android/src/main/java/com/tinder/scarlet/lifecycle/android/ApplicationResumedLifecycle.kt deleted file mode 100644 index cc5f288d..00000000 --- a/scarlet-lifecycle-android/src/main/java/com/tinder/scarlet/lifecycle/android/ApplicationResumedLifecycle.kt +++ /dev/null @@ -1,43 +0,0 @@ -/* - * © 2018 Match Group, LLC. - */ - -package com.tinder.scarlet.lifecycle.android - -import android.app.Activity -import android.app.Application -import android.os.Bundle -import com.tinder.scarlet.Lifecycle -import com.tinder.scarlet.LifecycleState -import com.tinder.scarlet.lifecycle.LifecycleRegistry - -internal class ApplicationResumedLifecycle( - application: Application, - private val lifecycleRegistry: LifecycleRegistry -) : Lifecycle by lifecycleRegistry { - - init { - lifecycleRegistry.onNext(LifecycleState.Started) - application.registerActivityLifecycleCallbacks(ActivityLifecycleCallbacks()) - } - - private inner class ActivityLifecycleCallbacks : Application.ActivityLifecycleCallbacks { - override fun onActivityPaused(activity: Activity?) { - lifecycleRegistry.onNext(LifecycleState.Stopped) - } - - override fun onActivityResumed(activity: Activity?) { - lifecycleRegistry.onNext(LifecycleState.Started) - } - - override fun onActivityStarted(activity: Activity?) {} - - override fun onActivityDestroyed(activity: Activity?) {} - - override fun onActivitySaveInstanceState(activity: Activity?, outState: Bundle?) {} - - override fun onActivityStopped(activity: Activity?) {} - - override fun onActivityCreated(activity: Activity?, savedInstanceState: Bundle?) {} - } -} diff --git a/scarlet-message-adapter-gson/src/test/java/com/tinder/scarlet/messageadapter/gson/GsonMessageAdapterTest.kt b/scarlet-message-adapter-gson/src/test/java/com/tinder/scarlet/messageadapter/gson/GsonMessageAdapterTest.kt index 5ff51609..a062d4b1 100644 --- a/scarlet-message-adapter-gson/src/test/java/com/tinder/scarlet/messageadapter/gson/GsonMessageAdapterTest.kt +++ b/scarlet-message-adapter-gson/src/test/java/com/tinder/scarlet/messageadapter/gson/GsonMessageAdapterTest.kt @@ -184,9 +184,6 @@ internal class GsonMessageAdapterTest { @Receive fun observeEvents(): Stream - @Receive - fun observeStateTransition(): Stream - @Send fun sendString(message: String): Boolean diff --git a/scarlet/src/main/java/com/tinder/scarlet/lifecycle/DefaultLifecycle.kt b/scarlet/src/main/java/com/tinder/scarlet/lifecycle/DefaultLifecycle.kt index 16105cb7..fc1d23aa 100644 --- a/scarlet/src/main/java/com/tinder/scarlet/lifecycle/DefaultLifecycle.kt +++ b/scarlet/src/main/java/com/tinder/scarlet/lifecycle/DefaultLifecycle.kt @@ -6,8 +6,12 @@ package com.tinder.scarlet.lifecycle import com.tinder.scarlet.Lifecycle import com.tinder.scarlet.LifecycleState -import io.reactivex.Flowable -internal class DefaultLifecycle() : Lifecycle by FlowableLifecycle( - Flowable.just(LifecycleState.Started) -) +internal class DefaultLifecycle( + private val lifecycleRegistry: LifecycleRegistry = LifecycleRegistry() +) : Lifecycle by lifecycleRegistry { + init { + lifecycleRegistry.onNext(LifecycleState.Started) + } +} + diff --git a/scarlet/src/test/java/com/tinder/scarlet/lifecycle/DefaultLifecycleTest.kt b/scarlet/src/test/java/com/tinder/scarlet/lifecycle/DefaultLifecycleTest.kt index 253b6586..640c4b49 100644 --- a/scarlet/src/test/java/com/tinder/scarlet/lifecycle/DefaultLifecycleTest.kt +++ b/scarlet/src/test/java/com/tinder/scarlet/lifecycle/DefaultLifecycleTest.kt @@ -20,4 +20,14 @@ internal class DefaultLifecycleTest { // Then testSubscriber.assertValues(LifecycleState.Started) } + + @Test + fun observeState_shouldNotTerminate() { + // When + val testSubscriber = Flowable.fromPublisher(defaultLifecycle).test() + + // Then + testSubscriber.assertNotTerminated() + } + }