From 6513a45ec821b99ce36bc553784cbb9c81c84d74 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 22 Aug 2023 11:49:44 +0000 Subject: [PATCH 1/2] Update dependency org.jmailen.kotlinter to v3.16.0 --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 94031d40..d7128ef8 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -25,7 +25,7 @@ testCore = "1.5.0" lint = "31.1.1" detekt = "1.18.0" -kotlinter = "3.12.0" +kotlinter = "3.16.0" [plugins] kotest = { id = "io.kotest.multiplatform", version.ref = "kotest" } From de23833cbd8a028a93fbd74ac584b54801786630 Mon Sep 17 00:00:00 2001 From: Ryan Moelter Date: Wed, 23 Aug 2023 02:06:47 +0200 Subject: [PATCH 2/2] Apply lint --- .../ActivityLifecycleComposeAdapter.kt | 4 ++-- .../magellanx/compose/ComposeExtensions.kt | 2 +- .../magellanx/compose/SimpleComposeStep.kt | 2 +- .../compose/navigation/ComposeNavigator.kt | 20 +++++++++---------- .../magellanx/compose/navigation/Direction.kt | 2 +- .../transitions/BuiltInTransitionSpecs.kt | 13 ++++++------ .../magellanx/core/debug/StatePrinter.kt | 8 ++++---- .../magellanx/core/init/Magellan.kt | 2 +- ...AttachFieldToLifecycleWhenShownDelegate.kt | 6 +++--- .../core/lifecycle/LifecycleAwareComponent.kt | 12 +++++------ .../core/lifecycle/LifecycleExtensions.kt | 14 ++++++------- .../core/lifecycle/LifecycleOwner.kt | 4 ++-- .../core/lifecycle/LifecycleRegistry.kt | 14 ++++++------- .../core/lifecycle/LifecycleState.kt | 4 ++-- .../LifecycleTransitionExtensions.kt | 8 ++++---- .../core/lifecycle/LifecycleRegistryTest.kt | 18 ++++++++--------- .../EnforceLifecycleAwareAttachment.kt | 4 ++-- .../com/ryanmoelter/magellanx/LintRegistry.kt | 2 +- .../EnforceLifecycleAwareAttachmentTest.kt | 16 +++++++-------- .../magellanx/test/FakeComposeNavigator.kt | 2 +- .../magellanx/test/TestNavigable.kt | 3 ++- .../magellanx/test/FakeLinearNavigatorTest.kt | 8 ++++---- 22 files changed, 84 insertions(+), 84 deletions(-) diff --git a/magellanx-compose/src/main/java/com/ryanmoelter/magellanx/compose/ActivityLifecycleComposeAdapter.kt b/magellanx-compose/src/main/java/com/ryanmoelter/magellanx/compose/ActivityLifecycleComposeAdapter.kt index 02edee20..f1931816 100644 --- a/magellanx-compose/src/main/java/com/ryanmoelter/magellanx/compose/ActivityLifecycleComposeAdapter.kt +++ b/magellanx-compose/src/main/java/com/ryanmoelter/magellanx/compose/ActivityLifecycleComposeAdapter.kt @@ -19,7 +19,7 @@ private var adapterMap = emptyMap Unit>, AdapterLife public class ActivityLifecycleComposeAdapter( private val navigable: Navigable<@Composable () -> Unit>, - private val context: Activity + private val context: Activity, ) : DefaultLifecycleObserver { override fun onStart(owner: ActivityLifecycleOwner) { @@ -59,7 +59,7 @@ public fun ComponentActivity.setContentNavigable(navigable: Navigable<@Composabl private fun Navigable<@Composable () -> Unit>.attachAndAddToStaticMap( lifecycleAdapter: ActivityLifecycleComposeAdapter, - lifecycle: ActivityLifecycle + lifecycle: ActivityLifecycle, ) { lifecycle.addObserver(lifecycleAdapter) adapterMap = adapterMap + (this to (lifecycleAdapter to lifecycle)) diff --git a/magellanx-compose/src/main/java/com/ryanmoelter/magellanx/compose/ComposeExtensions.kt b/magellanx-compose/src/main/java/com/ryanmoelter/magellanx/compose/ComposeExtensions.kt index 0970aeb3..756d0888 100644 --- a/magellanx-compose/src/main/java/com/ryanmoelter/magellanx/compose/ComposeExtensions.kt +++ b/magellanx-compose/src/main/java/com/ryanmoelter/magellanx/compose/ComposeExtensions.kt @@ -24,7 +24,7 @@ public fun Displayable<@Composable () -> Unit>.Content(modifier: Modifier = Modi @Composable public fun Displayable( displayable: Displayable<@Composable () -> Unit>, - modifier: Modifier = Modifier + modifier: Modifier = Modifier, ): Unit = displayable.Content(modifier) @Composable diff --git a/magellanx-compose/src/main/java/com/ryanmoelter/magellanx/compose/SimpleComposeStep.kt b/magellanx-compose/src/main/java/com/ryanmoelter/magellanx/compose/SimpleComposeStep.kt index b0306022..9a7664cb 100644 --- a/magellanx-compose/src/main/java/com/ryanmoelter/magellanx/compose/SimpleComposeStep.kt +++ b/magellanx-compose/src/main/java/com/ryanmoelter/magellanx/compose/SimpleComposeStep.kt @@ -3,7 +3,7 @@ package com.ryanmoelter.magellanx.compose import androidx.compose.runtime.Composable public open class SimpleComposeStep( - private val SimpleContent: @Composable SimpleComposeStep.() -> Unit + private val SimpleContent: @Composable SimpleComposeStep.() -> Unit, ) : ComposeStep() { @Composable diff --git a/magellanx-compose/src/main/java/com/ryanmoelter/magellanx/compose/navigation/ComposeNavigator.kt b/magellanx-compose/src/main/java/com/ryanmoelter/magellanx/compose/navigation/ComposeNavigator.kt index 4e76b877..14db5c49 100644 --- a/magellanx-compose/src/main/java/com/ryanmoelter/magellanx/compose/navigation/ComposeNavigator.kt +++ b/magellanx-compose/src/main/java/com/ryanmoelter/magellanx/compose/navigation/ComposeNavigator.kt @@ -68,7 +68,7 @@ public open class ComposeNavigator : AnimatedContent( targetState = currentNavigable, - transitionSpec = currentTransitionSpec.getTransitionForDirection(currentDirection) + transitionSpec = currentTransitionSpec.getTransitionForDirection(currentDirection), ) { navigable -> DisposableEffect( key1 = navigable, @@ -87,7 +87,7 @@ public open class ComposeNavigator : } else { onDispose { } } - } + }, ) Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { navigable?.Content() @@ -104,24 +104,24 @@ public open class ComposeNavigator : public open fun goTo( navigable: Navigable<@Composable () -> Unit>, - overrideTransitionSpec: MagellanComposeTransition? = null + overrideTransitionSpec: MagellanComposeTransition? = null, ) { navigate(FORWARD) { backStack -> backStack + ComposeNavigationEvent( navigable = navigable, - transitionSpec = overrideTransitionSpec ?: defaultTransition + transitionSpec = overrideTransitionSpec ?: defaultTransition, ) } } public open fun replace( navigable: Navigable<@Composable () -> Unit>, - overrideTransitionSpec: MagellanComposeTransition? = null + overrideTransitionSpec: MagellanComposeTransition? = null, ) { navigate(FORWARD) { backStack -> backStack - backStack.last() + ComposeNavigationEvent( navigable = navigable, - transitionSpec = overrideTransitionSpec ?: defaultTransition + transitionSpec = overrideTransitionSpec ?: defaultTransition, ) } } @@ -155,7 +155,7 @@ public open class ComposeNavigator : public open fun navigate( direction: Direction, - backStackOperation: (backStack: List) -> List + backStackOperation: (backStack: List) -> List, ) { // TODO: Intercept touch events, if necessary NavigationPropagator._beforeNavigation.tryEmit(Unit) @@ -171,7 +171,7 @@ public open class ComposeNavigator : findBackstackChangesAndUpdateStates( oldBackStack = oldBackStack.map { it.navigable }, newBackStack = newBackStack.map { it.navigable }, - from = fromNavigable + from = fromNavigable, ) /* Optimistically update toNavigable's limit to smooth out transitions. This will also get set * by the DisposedEffect in #Content(), but redundancy is fine. fromNavigable's limit will be @@ -186,7 +186,7 @@ public open class ComposeNavigator : private fun findBackstackChangesAndUpdateStates( oldBackStack: List>, newBackStack: List>, - from: Navigable<*>? + from: Navigable<*>?, ) { val oldNavigables = oldBackStack.toSet() // Don't remove the last Navigable (from) until it's removed from composition in DisposedEffect @@ -208,5 +208,5 @@ public open class ComposeNavigator : public data class ComposeNavigationEvent( val navigable: Navigable<@Composable () -> Unit>, - val transitionSpec: MagellanComposeTransition + val transitionSpec: MagellanComposeTransition, ) diff --git a/magellanx-compose/src/main/java/com/ryanmoelter/magellanx/compose/navigation/Direction.kt b/magellanx-compose/src/main/java/com/ryanmoelter/magellanx/compose/navigation/Direction.kt index dba748f9..4cb0c01d 100644 --- a/magellanx-compose/src/main/java/com/ryanmoelter/magellanx/compose/navigation/Direction.kt +++ b/magellanx-compose/src/main/java/com/ryanmoelter/magellanx/compose/navigation/Direction.kt @@ -4,5 +4,5 @@ package com.ryanmoelter.magellanx.compose.navigation * Represent the direction in which we are navigating, either forward or backward. */ public enum class Direction { - FORWARD, BACKWARD; + FORWARD, BACKWARD } diff --git a/magellanx-compose/src/main/java/com/ryanmoelter/magellanx/compose/transitions/BuiltInTransitionSpecs.kt b/magellanx-compose/src/main/java/com/ryanmoelter/magellanx/compose/transitions/BuiltInTransitionSpecs.kt index b55db73b..b480f034 100644 --- a/magellanx-compose/src/main/java/com/ryanmoelter/magellanx/compose/transitions/BuiltInTransitionSpecs.kt +++ b/magellanx-compose/src/main/java/com/ryanmoelter/magellanx/compose/transitions/BuiltInTransitionSpecs.kt @@ -19,21 +19,20 @@ import kotlin.math.roundToInt public interface MagellanComposeTransition { @Composable - public fun getTransitionForDirection( - direction: Direction + direction: Direction, ): AnimatedContentTransitionScope Unit>?>.() -> ContentTransform } public class SimpleComposeTransition( public val transitionSpec: AnimatedContentTransitionScope Unit>?>.( - Direction - ) -> ContentTransform + Direction, + ) -> ContentTransform, ) : MagellanComposeTransition { @Composable public override fun getTransitionForDirection( - direction: Direction + direction: Direction, ): AnimatedContentTransitionScope Unit>?>.() -> ContentTransform { return { transitionSpec(direction) } } @@ -63,7 +62,7 @@ public val showTransition: MagellanComposeTransition = SimpleComposeTransition { Direction.FORWARD -> { fadeIn() + slideInVertically( - initialOffsetY = { fullHeight -> (fullHeight * HEIGHT_OFFSET_FACTOR).roundToInt() } + initialOffsetY = { fullHeight -> (fullHeight * HEIGHT_OFFSET_FACTOR).roundToInt() }, ) togetherWith fadeOut() + scaleOut(targetScale = SCALE_UP_FACTOR) } @@ -71,7 +70,7 @@ public val showTransition: MagellanComposeTransition = SimpleComposeTransition { Direction.BACKWARD -> { fadeIn() + scaleIn(initialScale = SCALE_UP_FACTOR) togetherWith fadeOut() + slideOutVertically( - targetOffsetY = { fullHeight -> (fullHeight * HEIGHT_OFFSET_FACTOR).roundToInt() } + targetOffsetY = { fullHeight -> (fullHeight * HEIGHT_OFFSET_FACTOR).roundToInt() }, ) } } diff --git a/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/debug/StatePrinter.kt b/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/debug/StatePrinter.kt index 17eac2d0..e39a9a0a 100644 --- a/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/debug/StatePrinter.kt +++ b/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/debug/StatePrinter.kt @@ -17,7 +17,7 @@ public fun LifecycleOwner.getLifecycleStateSnapshot(): String { lifecycleAware.getLifecycleStateSnapshotRecursive( "", index == children.lastIndex, - currentState + currentState, ) } .forEach { stringBuilder.append(it) } @@ -28,7 +28,7 @@ public fun LifecycleOwner.getLifecycleStateSnapshot(): String { private fun LifecycleAware.getLifecycleStateSnapshotRecursive( indent: String, isLastChild: Boolean, - parentLifecycleState: LifecycleState + parentLifecycleState: LifecycleState, ): String { val stringBuilder = StringBuilder() val lineChar = if (isLastChild) CONNECTOR_L else VERTICAL_T @@ -44,7 +44,7 @@ private fun LifecycleAware.getLifecycleStateSnapshotRecursive( lifecycleAware.getLifecycleStateSnapshotRecursive( childIndent, index == children.lastIndex, - currentState + currentState, ) } .forEach { stringBuilder.append(it) } @@ -60,6 +60,6 @@ private fun LifecycleOwner.describeSelf(indent: String): String = private fun LifecycleAware.describeSelf( indent: String, - parentLifecycleState: LifecycleState + parentLifecycleState: LifecycleState, ): String = "$indent${this::class.java.simpleName} (${parentLifecycleState.name}?)\n" diff --git a/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/init/Magellan.kt b/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/init/Magellan.kt index ced458dd..e21e6e51 100644 --- a/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/init/Magellan.kt +++ b/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/init/Magellan.kt @@ -12,7 +12,7 @@ public object Magellan { @JvmOverloads public fun init( disableAnimations: Boolean = false, - logDebugInfo: Boolean = false + logDebugInfo: Boolean = false, ) { this.logDebugInfo = logDebugInfo this.disableAnimations = disableAnimations diff --git a/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/lifecycle/CreateAndAttachFieldToLifecycleWhenShownDelegate.kt b/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/lifecycle/CreateAndAttachFieldToLifecycleWhenShownDelegate.kt index dfdbbcdb..d65aa3c0 100644 --- a/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/lifecycle/CreateAndAttachFieldToLifecycleWhenShownDelegate.kt +++ b/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/lifecycle/CreateAndAttachFieldToLifecycleWhenShownDelegate.kt @@ -1,7 +1,7 @@ package com.ryanmoelter.magellanx.core.lifecycle public class CreateAndAttachFieldToLifecycleWhenShownDelegate( - public val fieldSupplier: () -> Field + public val fieldSupplier: () -> Field, ) : LifecycleAware { public var field: Field? = null @@ -17,9 +17,9 @@ public class CreateAndAttachFieldToLifecycleWhenShownDelegate( } public fun LifecycleOwner.createAndAttachFieldToLifecycleWhenShown( - fieldSupplier: () -> Field + fieldSupplier: () -> Field, ): AttachFieldToLifecycleDelegate, Field?> = attachFieldToLifecycle( CreateAndAttachFieldToLifecycleWhenShownDelegate(fieldSupplier), - { it.field } + { it.field }, ) diff --git a/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/lifecycle/LifecycleAwareComponent.kt b/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/lifecycle/LifecycleAwareComponent.kt index ee526ec7..e4c48fde 100644 --- a/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/lifecycle/LifecycleAwareComponent.kt +++ b/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/lifecycle/LifecycleAwareComponent.kt @@ -16,7 +16,7 @@ public abstract class LifecycleAwareComponent : LifecycleAware, LifecycleOwner { if (currentState != LifecycleState.Destroyed) { throw IllegalStateException( "Cannot create() from a state that is not Destroyed: " + - "${this::class.java.simpleName} is ${currentState::class.java.simpleName}" + "${this::class.java.simpleName} is ${currentState::class.java.simpleName}", ) } lifecycleRegistry.create() @@ -27,7 +27,7 @@ public abstract class LifecycleAwareComponent : LifecycleAware, LifecycleOwner { if (currentState != LifecycleState.Created) { throw IllegalStateException( "Cannot show() from a state that is not Created: " + - "${this::class.java.simpleName} is ${currentState::class.java.simpleName}" + "${this::class.java.simpleName} is ${currentState::class.java.simpleName}", ) } lifecycleRegistry.show() @@ -38,7 +38,7 @@ public abstract class LifecycleAwareComponent : LifecycleAware, LifecycleOwner { if (currentState != LifecycleState.Shown) { throw IllegalStateException( "Cannot resume() from a state that is not Shown: " + - "${this::class.java.simpleName} is ${currentState::class.java.simpleName}" + "${this::class.java.simpleName} is ${currentState::class.java.simpleName}", ) } lifecycleRegistry.resume() @@ -49,7 +49,7 @@ public abstract class LifecycleAwareComponent : LifecycleAware, LifecycleOwner { if (currentState != LifecycleState.Resumed) { throw IllegalStateException( "Cannot pause() from a state that is not Resumed: " + - "${this::class.java.simpleName} is ${currentState::class.java.simpleName}" + "${this::class.java.simpleName} is ${currentState::class.java.simpleName}", ) } onPause() @@ -60,7 +60,7 @@ public abstract class LifecycleAwareComponent : LifecycleAware, LifecycleOwner { if (currentState != LifecycleState.Shown) { throw IllegalStateException( "Cannot hide() from a state that is not Shown: " + - "${this::class.java.simpleName} is ${currentState::class.java.simpleName}" + "${this::class.java.simpleName} is ${currentState::class.java.simpleName}", ) } onHide() @@ -71,7 +71,7 @@ public abstract class LifecycleAwareComponent : LifecycleAware, LifecycleOwner { if (currentState != LifecycleState.Created) { throw IllegalStateException( "Cannot destroy() from a state that is not Created: " + - "${this::class.java.simpleName} is ${currentState::class.java.simpleName}" + "${this::class.java.simpleName} is ${currentState::class.java.simpleName}", ) } onDestroy() diff --git a/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/lifecycle/LifecycleExtensions.kt b/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/lifecycle/LifecycleExtensions.kt index 4872b67c..6f1903c6 100644 --- a/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/lifecycle/LifecycleExtensions.kt +++ b/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/lifecycle/LifecycleExtensions.kt @@ -4,29 +4,29 @@ import kotlin.reflect.KProperty public fun LifecycleOwner.attachFieldToLifecycle( lifecycleAware: ChildType, - getPropertyType: (ChildType) -> PropertyType + getPropertyType: (ChildType) -> PropertyType, ): AttachFieldToLifecycleDelegate { return AttachFieldToLifecycleDelegate( parent = this, lifecycleAware = lifecycleAware, - getPropertyType = getPropertyType + getPropertyType = getPropertyType, ) } public fun LifecycleOwner.attachFieldToLifecycle( - lifecycleAware: ChildType + lifecycleAware: ChildType, ): AttachFieldToLifecycleDelegate { return AttachFieldToLifecycleDelegate( parent = this, lifecycleAware = lifecycleAware, - getPropertyType = { lifecycleAware } + getPropertyType = { lifecycleAware }, ) } public class AttachFieldToLifecycleDelegate( private val parent: LifecycleOwner, private val lifecycleAware: ChildType, - private val getPropertyType: (ChildType) -> PropertyType + private val getPropertyType: (ChildType) -> PropertyType, ) { private var hasOverrideValue = false @@ -68,14 +68,14 @@ public fun LifecycleOwner.attachLateinitFieldToLife } public class AttachLateinitFieldToLifecycleDelegate( - private val parent: LifecycleOwner + private val parent: LifecycleOwner, ) { private var lifecycleAware: ChildType? = null public operator fun getValue(thisRef: Any?, property: KProperty<*>): ChildType { return lifecycleAware ?: error( - "This lateinit LifecycleAware has not been set yet. (Has your dependency injection run yet?)" + "This lateinit LifecycleAware has not been set yet. (Has your dependency injection run yet?)", ) } diff --git a/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/lifecycle/LifecycleOwner.kt b/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/lifecycle/LifecycleOwner.kt index 5a7723b0..5f1eac6e 100644 --- a/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/lifecycle/LifecycleOwner.kt +++ b/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/lifecycle/LifecycleOwner.kt @@ -13,11 +13,11 @@ public interface LifecycleOwner { public fun attachToLifecycle( lifecycleAware: LifecycleAware, - detachedState: LifecycleState = LifecycleState.Destroyed + detachedState: LifecycleState = LifecycleState.Destroyed, ) public fun removeFromLifecycle( lifecycleAware: LifecycleAware, - detachedState: LifecycleState = LifecycleState.Destroyed + detachedState: LifecycleState = LifecycleState.Destroyed, ) } diff --git a/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/lifecycle/LifecycleRegistry.kt b/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/lifecycle/LifecycleRegistry.kt index fdedf285..bd703c07 100644 --- a/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/lifecycle/LifecycleRegistry.kt +++ b/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/lifecycle/LifecycleRegistry.kt @@ -29,7 +29,7 @@ public class LifecycleRegistry : LifecycleAware, LifecycleOwner { if (oldState.limitBy(maxState).order != newState.limitBy(maxState).order) { lifecycleAware.transition( oldState.limitBy(maxState), - newState.limitBy(maxState) + newState.limitBy(maxState), ) } } @@ -43,12 +43,12 @@ public class LifecycleRegistry : LifecycleAware, LifecycleOwner { public fun attachToLifecycleWithMaxState( lifecycleAware: LifecycleAware, maxState: LifecycleLimit = NO_LIMIT, - detachedState: LifecycleState = LifecycleState.Destroyed + detachedState: LifecycleState = LifecycleState.Destroyed, ) { if (listenersToMaxStates.containsKey(lifecycleAware)) { throw IllegalStateException( "Cannot attach a lifecycleAware that is already a child: " + - lifecycleAware::class.java.simpleName + lifecycleAware::class.java.simpleName, ) } lifecycleAware.transition(detachedState, currentState.limitBy(maxState)) @@ -57,12 +57,12 @@ public class LifecycleRegistry : LifecycleAware, LifecycleOwner { override fun removeFromLifecycle( lifecycleAware: LifecycleAware, - detachedState: LifecycleState + detachedState: LifecycleState, ) { if (!listenersToMaxStates.containsKey(lifecycleAware)) { throw IllegalStateException( "Cannot remove a lifecycleAware that is not a child: " + - lifecycleAware::class.java.simpleName + lifecycleAware::class.java.simpleName, ) } val maxState = listenersToMaxStates[lifecycleAware]!! @@ -74,7 +74,7 @@ public class LifecycleRegistry : LifecycleAware, LifecycleOwner { if (!listenersToMaxStates.containsKey(lifecycleAware)) { throw IllegalArgumentException( "Cannot update the state of a lifecycleAware that is not a child: " + - lifecycleAware::class.java.simpleName + lifecycleAware::class.java.simpleName, ) } val oldMaxState = listenersToMaxStates[lifecycleAware]!! @@ -83,7 +83,7 @@ public class LifecycleRegistry : LifecycleAware, LifecycleOwner { if (needsToTransition) { lifecycleAware.transition( currentState.limitBy(oldMaxState), - currentState.limitBy(maxState) + currentState.limitBy(maxState), ) } listenersToMaxStates = listenersToMaxStates + (lifecycleAware to maxState) diff --git a/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/lifecycle/LifecycleState.kt b/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/lifecycle/LifecycleState.kt index 2809c367..31b0600f 100644 --- a/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/lifecycle/LifecycleState.kt +++ b/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/lifecycle/LifecycleState.kt @@ -13,11 +13,11 @@ public enum class LifecycleState(internal val order: Int) { order == other.order -> NO_MOVEMENT order < other.order -> FORWARD else -> throw IllegalStateException( - "Unhandled order comparison: this is $order and other is ${other.order}" + "Unhandled order comparison: this is $order and other is ${other.order}", ) } } public enum class LifecycleStateDirection { - FORWARD, BACKWARDS, NO_MOVEMENT; + FORWARD, BACKWARDS, NO_MOVEMENT } diff --git a/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/lifecycle/LifecycleTransitionExtensions.kt b/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/lifecycle/LifecycleTransitionExtensions.kt index 4f24b1b0..49cee4bf 100644 --- a/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/lifecycle/LifecycleTransitionExtensions.kt +++ b/magellanx-core/src/main/java/com/ryanmoelter/magellanx/core/lifecycle/LifecycleTransitionExtensions.kt @@ -9,7 +9,7 @@ import com.ryanmoelter.magellanx.core.lifecycle.LifecycleStateDirection.FORWARD import com.ryanmoelter.magellanx.core.lifecycle.LifecycleStateDirection.NO_MOVEMENT public fun T.transitionToState( - newState: LifecycleState + newState: LifecycleState, ) where T : LifecycleAware, T : LifecycleOwner { transition(this.currentState, newState) } @@ -25,7 +25,7 @@ public fun Iterable.transition(oldState: LifecycleState, newStat FORWARD -> next(this, currentState) BACKWARDS -> previous(this, currentState) NO_MOVEMENT -> throw IllegalStateException( - "Attempting to transition from $currentState to $newState" + "Attempting to transition from $currentState to $newState", ) } } @@ -33,7 +33,7 @@ public fun Iterable.transition(oldState: LifecycleState, newStat private fun next( subjects: Iterable, - currentState: LifecycleState + currentState: LifecycleState, ): LifecycleState { return when (currentState) { Destroyed -> { @@ -56,7 +56,7 @@ private fun next( private fun previous( subjects: Iterable, - currentState: LifecycleState + currentState: LifecycleState, ): LifecycleState { return when (currentState) { Destroyed -> { diff --git a/magellanx-core/src/test/java/com/ryanmoelter/magellanx/core/lifecycle/LifecycleRegistryTest.kt b/magellanx-core/src/test/java/com/ryanmoelter/magellanx/core/lifecycle/LifecycleRegistryTest.kt index 155d59ae..a4ba4497 100644 --- a/magellanx-core/src/test/java/com/ryanmoelter/magellanx/core/lifecycle/LifecycleRegistryTest.kt +++ b/magellanx-core/src/test/java/com/ryanmoelter/magellanx/core/lifecycle/LifecycleRegistryTest.kt @@ -64,7 +64,7 @@ internal class LifecycleRegistryTest { lifecycleAware2, lifecycleAware3, lifecycleAware5, - lifecycleAware4 + lifecycleAware4, ) } @@ -77,7 +77,7 @@ internal class LifecycleRegistryTest { lifecycleRegistry.attachToLifecycle(dummyLifecycleComponent1) lifecycleRegistry.attachToLifecycleWithMaxState( dummyLifecycleComponent2, - LifecycleLimit.CREATED + LifecycleLimit.CREATED, ) dummyLifecycleComponent1.currentState shouldBe Resumed @@ -101,7 +101,7 @@ internal class LifecycleRegistryTest { lifecycleRegistry.attachToLifecycleWithMaxState( dummyLifecycleComponent1, - LifecycleLimit.CREATED + LifecycleLimit.CREATED, ) dummyLifecycleComponent1.currentState shouldBe Created @@ -124,7 +124,7 @@ internal class LifecycleRegistryTest { lifecycleRegistry.attachToLifecycleWithMaxState( dummyLifecycleComponent1, - LifecycleLimit.CREATED + LifecycleLimit.CREATED, ) dummyLifecycleComponent1.currentState shouldBe Created @@ -152,14 +152,14 @@ internal class LifecycleRegistryTest { unwantedBackPressed = true true }, - LifecycleLimit.CREATED + LifecycleLimit.CREATED, ) lifecycleRegistry.attachToLifecycleWithMaxState( DummyLifecycleComponent { wantedBackPressed = true true }, - LifecycleLimit.NO_LIMIT + LifecycleLimit.NO_LIMIT, ) val backPressedHandled = lifecycleRegistry.backPressed() @@ -183,14 +183,14 @@ internal class LifecycleRegistryTest { wantedBackPressed = true true }, - LifecycleLimit.NO_LIMIT + LifecycleLimit.NO_LIMIT, ) lifecycleRegistry.attachToLifecycleWithMaxState( DummyLifecycleComponent { unwantedBackPressed = true true }, - LifecycleLimit.NO_LIMIT + LifecycleLimit.NO_LIMIT, ) val backPressedHandled = lifecycleRegistry.backPressed() @@ -202,7 +202,7 @@ internal class LifecycleRegistryTest { } private class DummyLifecycleComponent( - val backPressedAction: () -> Boolean = { true } + val backPressedAction: () -> Boolean = { true }, ) : LifecycleAwareComponent() { override fun onBackPressed(): Boolean = backPressedAction() diff --git a/magellanx-lint/src/main/java/com/ryanmoelter/magellanx/EnforceLifecycleAwareAttachment.kt b/magellanx-lint/src/main/java/com/ryanmoelter/magellanx/EnforceLifecycleAwareAttachment.kt index 55368c18..bbfc4cb8 100644 --- a/magellanx-lint/src/main/java/com/ryanmoelter/magellanx/EnforceLifecycleAwareAttachment.kt +++ b/magellanx-lint/src/main/java/com/ryanmoelter/magellanx/EnforceLifecycleAwareAttachment.kt @@ -20,7 +20,7 @@ internal val ENFORCE_LIFECYCLE_AWARE_ATTACHMENT = Issue.create( category = Category.CORRECTNESS, priority = PRIORITY_HIGH, severity = ERROR, - implementation = Implementation(EnforceLifecycleAwareAttachment::class.java, JAVA_FILE_SCOPE) + implementation = Implementation(EnforceLifecycleAwareAttachment::class.java, JAVA_FILE_SCOPE), ) internal class EnforceLifecycleAwareAttachment : Detector(), Detector.UastScanner { @@ -40,7 +40,7 @@ internal class EnforceLifecycleAwareAttachment : Detector(), Detector.UastScanne "In order to make this lifecycle aware work as expected, " + "please attach it to the lifecycle owner with a lifecycle delegate. " + "Eg. `val someObject by lifecycle(SomeObject())` or " + - "`lateinit var someObject: SomeObject by lateinitLifecycle()`" + "`lateinit var someObject: SomeObject by lateinitLifecycle()`", ) } } diff --git a/magellanx-lint/src/main/java/com/ryanmoelter/magellanx/LintRegistry.kt b/magellanx-lint/src/main/java/com/ryanmoelter/magellanx/LintRegistry.kt index 7e16c038..7f8ea344 100644 --- a/magellanx-lint/src/main/java/com/ryanmoelter/magellanx/LintRegistry.kt +++ b/magellanx-lint/src/main/java/com/ryanmoelter/magellanx/LintRegistry.kt @@ -12,7 +12,7 @@ class LintRegistry : IssueRegistry() { override val issues: List get() = listOf( - ENFORCE_LIFECYCLE_AWARE_ATTACHMENT + ENFORCE_LIFECYCLE_AWARE_ATTACHMENT, ) override val api: Int diff --git a/magellanx-lint/src/test/java/com/ryanmoelter/magellanx/EnforceLifecycleAwareAttachmentTest.kt b/magellanx-lint/src/test/java/com/ryanmoelter/magellanx/EnforceLifecycleAwareAttachmentTest.kt index 4cb6b52d..c5be9f1d 100644 --- a/magellanx-lint/src/test/java/com/ryanmoelter/magellanx/EnforceLifecycleAwareAttachmentTest.kt +++ b/magellanx-lint/src/test/java/com/ryanmoelter/magellanx/EnforceLifecycleAwareAttachmentTest.kt @@ -16,7 +16,7 @@ class EnforceLifecycleAwareAttachmentTest { fun create() {} } - """ + """, ).indented() private val LINEAR_NAVIGATOR = kt( @@ -29,7 +29,7 @@ class EnforceLifecycleAwareAttachmentTest { val backStack: List = listOf() } - """ + """, ).indented() private val LIFECYCLE_OWNER = kt( @@ -43,7 +43,7 @@ class EnforceLifecycleAwareAttachmentTest { fun removeFromLifecycle(lifecycleAware: LifecycleAware, detachedState: LifecycleState = LifecycleState.Destroyed) } - """ + """, ).indented() private val LIFECYCLE_FILES = arrayOf(LIFECYCLE_AWARE, LIFECYCLE_OWNER, LINEAR_NAVIGATOR) @@ -66,8 +66,8 @@ class EnforceLifecycleAwareAttachmentTest { val navigator = LinearNavigator() } - """ - ).indented() + """, + ).indented(), ) .issues(ENFORCE_LIFECYCLE_AWARE_ATTACHMENT) .run() @@ -79,7 +79,7 @@ class EnforceLifecycleAwareAttachmentTest { "by lateinitLifecycle() [EnforceLifecycleAwareAttachment]\n" + " val navigator = LinearNavigator()\n" + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + - "1 errors, 0 warnings" + "1 errors, 0 warnings", ) .expectFixDiffs("") } @@ -101,8 +101,8 @@ class EnforceLifecycleAwareAttachmentTest { val navigator by lifecycle(LinearNavigator()) } - """ - ).indented() + """, + ).indented(), ) .issues(ENFORCE_LIFECYCLE_AWARE_ATTACHMENT) .run() diff --git a/magellanx-test/src/main/java/com/ryanmoelter/magellanx/test/FakeComposeNavigator.kt b/magellanx-test/src/main/java/com/ryanmoelter/magellanx/test/FakeComposeNavigator.kt index 69a832ea..4f037c8a 100644 --- a/magellanx-test/src/main/java/com/ryanmoelter/magellanx/test/FakeComposeNavigator.kt +++ b/magellanx-test/src/main/java/com/ryanmoelter/magellanx/test/FakeComposeNavigator.kt @@ -32,7 +32,7 @@ public class FakeComposeNavigator : ComposeNavigator() { public override fun navigate( direction: Direction, - backStackOperation: (List) -> List + backStackOperation: (List) -> List, ) { backStack = backStackOperation(backStack) } diff --git a/magellanx-test/src/main/java/com/ryanmoelter/magellanx/test/TestNavigable.kt b/magellanx-test/src/main/java/com/ryanmoelter/magellanx/test/TestNavigable.kt index d29342f4..b2c882ec 100644 --- a/magellanx-test/src/main/java/com/ryanmoelter/magellanx/test/TestNavigable.kt +++ b/magellanx-test/src/main/java/com/ryanmoelter/magellanx/test/TestNavigable.kt @@ -11,6 +11,7 @@ import com.ryanmoelter.magellanx.core.lifecycle.createAndAttachFieldToLifecycleW public class TestNavigable : Navigable<@Composable () -> Unit>, LifecycleAwareComponent() { public override val view: (@Composable () -> Unit)? by createAndAttachFieldToLifecycleWhenShown { - { } + { + } } } diff --git a/magellanx-test/src/test/java/com/ryanmoelter/magellanx/test/FakeLinearNavigatorTest.kt b/magellanx-test/src/test/java/com/ryanmoelter/magellanx/test/FakeLinearNavigatorTest.kt index 2d98b711..39082048 100644 --- a/magellanx-test/src/test/java/com/ryanmoelter/magellanx/test/FakeLinearNavigatorTest.kt +++ b/magellanx-test/src/test/java/com/ryanmoelter/magellanx/test/FakeLinearNavigatorTest.kt @@ -63,20 +63,20 @@ public class FakeLinearNavigatorTest { val newTopNavigable = TestNavigable() navigator.backStack = listOf( ComposeNavigationEvent(originalBottomNavigable, defaultTransition), - ComposeNavigationEvent(TestNavigable(), defaultTransition) + ComposeNavigationEvent(TestNavigable(), defaultTransition), ) navigator.navigate(Direction.FORWARD) { listOf( ComposeNavigationEvent(newBottomNavigable, defaultTransition), ComposeNavigationEvent(originalBottomNavigable, defaultTransition), - ComposeNavigationEvent(newTopNavigable, defaultTransition) + ComposeNavigationEvent(newTopNavigable, defaultTransition), ) } navigator.backStack.map { it.navigable } shouldContainExactly listOf( newBottomNavigable, originalBottomNavigable, - newTopNavigable + newTopNavigable, ) navigator.currentNavigable shouldBeSameInstanceAs newTopNavigable } @@ -94,7 +94,7 @@ public class FakeLinearNavigatorTest { val bottomNavigable = TestNavigable() navigator.backStack = listOf( ComposeNavigationEvent(bottomNavigable, defaultTransition), - ComposeNavigationEvent(TestNavigable(), defaultTransition) + ComposeNavigationEvent(TestNavigable(), defaultTransition), ) navigator.goBack().shouldBeTrue() navigator.backStack shouldHaveSize 1