Merge "Clean up DynamicFeatures LiveData observer" into androidx-main am: 0de86fad88
Original change: https://android-review.googlesource.com/c/platform/frameworks/support/+/2139841
Change-Id: I13d860bcf6e1a4c113a98fa9277fb3781d85f3b3
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/navigation/navigation-dynamic-features-fragment/src/androidTest/java/androidx/navigation/dynamicfeatures/fragment/ui/DefaultProgressFragmentTest.kt b/navigation/navigation-dynamic-features-fragment/src/androidTest/java/androidx/navigation/dynamicfeatures/fragment/ui/DefaultProgressFragmentTest.kt
index 39dcd18..57d781b 100644
--- a/navigation/navigation-dynamic-features-fragment/src/androidTest/java/androidx/navigation/dynamicfeatures/fragment/ui/DefaultProgressFragmentTest.kt
+++ b/navigation/navigation-dynamic-features-fragment/src/androidTest/java/androidx/navigation/dynamicfeatures/fragment/ui/DefaultProgressFragmentTest.kt
@@ -19,6 +19,7 @@
import androidx.navigation.dynamicfeatures.fragment.R as mainR
import androidx.navigation.dynamicfeatures.fragment.test.R as testR
import android.widget.TextView
+import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.navigation.dynamicfeatures.fragment.DynamicNavHostFragment
import androidx.navigation.dynamicfeatures.fragment.NavigationActivity
@@ -27,6 +28,7 @@
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.MediumTest
import androidx.testutils.withActivity
+import com.google.android.play.core.splitinstall.SplitInstallSessionState
import com.google.android.play.core.splitinstall.model.SplitInstallSessionStatus
import com.google.common.truth.Truth.assertThat
import java.util.concurrent.CountDownLatch
@@ -68,11 +70,16 @@
// the test to wait for the failure signal from the splitInstall session. To do that
// we observe the livedata of the DefaultProgressFragment's viewModel, and wait for
// it to fail before we check for test failure.
- viewModel.installMonitor!!.status.observe(defaultProgressFragment) {
- if (it.status() == SplitInstallSessionStatus.FAILED) {
- failureCountdownLatch.countDown()
+ val liveData = viewModel.installMonitor!!.status
+ val observer = object : Observer<SplitInstallSessionState> {
+ override fun onChanged(state: SplitInstallSessionState) {
+ if (state.status() == SplitInstallSessionStatus.FAILED) {
+ liveData.removeObserver(this)
+ failureCountdownLatch.countDown()
+ }
}
}
+ liveData.observe(defaultProgressFragment, observer)
}
assertThat(failureCountdownLatch.await(1000, TimeUnit.MILLISECONDS)).isTrue()