diff --git a/rxpm/src/main/kotlin/me/dmdev/rxpm/PresentationModel.kt b/rxpm/src/main/kotlin/me/dmdev/rxpm/PresentationModel.kt index aac0e44..495820b 100644 --- a/rxpm/src/main/kotlin/me/dmdev/rxpm/PresentationModel.kt +++ b/rxpm/src/main/kotlin/me/dmdev/rxpm/PresentationModel.kt @@ -26,7 +26,7 @@ abstract class PresentationModel { /** * The [lifecycle][Lifecycle] of this presentation model. */ - val lifecycleObservable = lifecycle.distinctUntilChanged() + val lifecycleObservable: Observable = lifecycle.distinctUntilChanged() internal val lifecycleConsumer = lifecycle.asConsumer() /** @@ -116,13 +116,9 @@ abstract class PresentationModel { */ fun attachToParent(parent: PresentationModel) { - if (parent == this) { - throw IllegalArgumentException("Presentation model can't be attached to itself.") - } + require(parent != this) { "Presentation model can't be attached to itself." } - if (lifecycle.hasValue()) { - throw IllegalStateException("Presentation model can't be a child more than once. It must not be reused.") - } + check(!lifecycle.hasValue()) { "Presentation model can't be a child more than once. It must not be reused." } when (parent.lifecycle.value) { diff --git a/rxpm/src/main/kotlin/me/dmdev/rxpm/State.kt b/rxpm/src/main/kotlin/me/dmdev/rxpm/State.kt index 4e4b1a0..ed170c4 100644 --- a/rxpm/src/main/kotlin/me/dmdev/rxpm/State.kt +++ b/rxpm/src/main/kotlin/me/dmdev/rxpm/State.kt @@ -132,7 +132,7 @@ infix fun State.bindTo(consumer: (T) -> Unit) { interface DiffStrategy { /** - * Сompares the old and the new values. + * Compares the old and the new values. * @return [true] if both values ​​are identical or [false] if they are different. */ fun areTheSame(new: T, old: T): Boolean diff --git a/rxpm/src/main/kotlin/me/dmdev/rxpm/delegate/PmActivityDelegate.kt b/rxpm/src/main/kotlin/me/dmdev/rxpm/delegate/PmActivityDelegate.kt index 399548a..3b950d2 100644 --- a/rxpm/src/main/kotlin/me/dmdev/rxpm/delegate/PmActivityDelegate.kt +++ b/rxpm/src/main/kotlin/me/dmdev/rxpm/delegate/PmActivityDelegate.kt @@ -91,13 +91,13 @@ class PmActivityDelegate( commonDelegate.onUnbind() when (retainMode) { - RetainMode.IS_FINISHING -> { + IS_FINISHING -> { if (pmActivity.isFinishing) { commonDelegate.onDestroy() } } - RetainMode.CONFIGURATION_CHANGES -> { + CONFIGURATION_CHANGES -> { if (!pmActivity.isChangingConfigurations) { commonDelegate.onDestroy() } diff --git a/rxpm/src/main/kotlin/me/dmdev/rxpm/delegate/PmFragmentDelegate.kt b/rxpm/src/main/kotlin/me/dmdev/rxpm/delegate/PmFragmentDelegate.kt index 10fe3ed..b0c681a 100644 --- a/rxpm/src/main/kotlin/me/dmdev/rxpm/delegate/PmFragmentDelegate.kt +++ b/rxpm/src/main/kotlin/me/dmdev/rxpm/delegate/PmFragmentDelegate.kt @@ -96,7 +96,7 @@ class PmFragmentDelegate( */ fun onDestroy() { when (retainMode) { - RetainMode.SAVED_STATE -> { + SAVED_STATE -> { if (pmFragment.activity?.isFinishing == true || (pmFragment.fragmentManager?.isStateSaved?.not() == true) ) { @@ -104,7 +104,7 @@ class PmFragmentDelegate( } } - RetainMode.CONFIGURATION_CHANGES -> { + CONFIGURATION_CHANGES -> { if (pmFragment.activity?.isChangingConfigurations?.not() == true) { commonDelegate.onDestroy() } diff --git a/rxpm/src/main/kotlin/me/dmdev/rxpm/test/PmTestHelper.kt b/rxpm/src/main/kotlin/me/dmdev/rxpm/test/PmTestHelper.kt index 9ce676d..98c8e62 100644 --- a/rxpm/src/main/kotlin/me/dmdev/rxpm/test/PmTestHelper.kt +++ b/rxpm/src/main/kotlin/me/dmdev/rxpm/test/PmTestHelper.kt @@ -12,8 +12,6 @@ class PmTestHelper(val pm: PresentationModel) { enum class LifecycleSteps { ALL, BYPASS_BINDING, BYPASS_RESUMING } - private val lifecycleStates = PresentationModel.Lifecycle.values() - /** * Sets the lifecycle of the [presentation model][pm] under test to the specified [state][lifecycleState]. * This will also create natural sequence of states before the requested one. @@ -79,14 +77,10 @@ class PmTestHelper(val pm: PresentationModel) { private fun checkStateAllowed(lifecycleState: PresentationModel.Lifecycle) { pm.currentLifecycleState?.let { currentState -> - if (lifecycleState <= currentState - && !isBindedAgain(lifecycleState) - && !isResumedAgain((lifecycleState)) - ) { - throw IllegalStateException( - "You can't set lifecycle state as $lifecycleState when it already is $pm.currentLifecycleState." - ) - } + check(!(lifecycleState <= currentState + && !isBindedAgain(lifecycleState) + && !isResumedAgain((lifecycleState))) + ) { "You can't set lifecycle state as $lifecycleState when it already is $pm.currentLifecycleState." } } } diff --git a/rxpm/src/test/kotlin/me/dmdev/rxpm/util/SchedulersRule.kt b/rxpm/src/test/kotlin/me/dmdev/rxpm/util/SchedulersRule.kt index d1baacc..b3e66b9 100644 --- a/rxpm/src/test/kotlin/me/dmdev/rxpm/util/SchedulersRule.kt +++ b/rxpm/src/test/kotlin/me/dmdev/rxpm/util/SchedulersRule.kt @@ -1,10 +1,9 @@ package me.dmdev.rxpm.util -import io.reactivex.android.plugins.RxAndroidPlugins -import io.reactivex.plugins.RxJavaPlugins -import io.reactivex.schedulers.Schedulers -import io.reactivex.schedulers.TestScheduler -import org.junit.rules.ExternalResource +import io.reactivex.android.plugins.* +import io.reactivex.plugins.* +import io.reactivex.schedulers.* +import org.junit.rules.* class SchedulersRule(private val useTestScheduler: Boolean = false) : ExternalResource() { @@ -12,7 +11,7 @@ class SchedulersRule(private val useTestScheduler: Boolean = false) : ExternalRe val testScheduler: TestScheduler get() { - if (!useTestScheduler) throw IllegalStateException("TestScheduler is switched off.") + check(useTestScheduler) { "TestScheduler is switched off." } return _testScheduler }