Skip to content

Commit

Permalink
Moved a bunch of things into the "android" package
Browse files Browse the repository at this point in the history
  • Loading branch information
isaac-udy committed Sep 19, 2023
1 parent 8403beb commit a023420
Show file tree
Hide file tree
Showing 45 changed files with 130 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.enro.destination.activity
package dev.enro.android

import android.content.Context
import android.content.Intent
Expand All @@ -13,7 +13,6 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import dev.enro.android.activity
import dev.enro.core.*
import dev.enro.destination.compose.OverrideNavigationAnimations
import dev.enro.destination.compose.navigationHandle
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package dev.enro.core.controller
package dev.enro.android

import dev.enro.core.controller.NavigationController

public interface NavigationApplication {
public val navigationController: NavigationController
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.enro.hilt
package dev.enro.android.hilt

import dagger.hilt.internal.GeneratedComponentManager
import dagger.hilt.internal.GeneratedComponentManagerHolder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.enro.viewmodel
package dev.enro.android.viewmodel

import androidx.activity.ComponentActivity
import androidx.annotation.MainThread
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.enro.viewmodel
package dev.enro.android.viewmodel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.enro.viewmodel
package dev.enro.android.viewmodel

import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.enro.viewmodel
package dev.enro.android.viewmodel

import androidx.annotation.Keep
import dev.enro.core.EnroException
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.enro.core.controller.usecase
package dev.enro.animation.internal

import android.provider.Settings
import dev.enro.animation.ClosingTransition
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.enro.core.controller.repository
package dev.enro.animation.internal

import dev.enro.animation.ClosingTransition
import dev.enro.animation.NavigationAnimationOverride
Expand Down
4 changes: 2 additions & 2 deletions enro-core/src/main/java/dev/enro/core/NavigationExecutor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class NavigationExecutorBuilder<FromContext : Any, OpensContext : Any, Ke
public fun defaultOpened(args: ExecutorArgs<out FromContext, out OpensContext, out KeyType>) {
when (args.binding) {
is ActivityNavigationBinding ->
DefaultContainerExecutor::open as ((ExecutorArgs<out Any, out OpensContext, out NavigationKey>) -> Unit)
DefaultContainerExecutor::open

is FragmentNavigationBinding ->
DefaultContainerExecutor::open
Expand All @@ -83,7 +83,7 @@ public class NavigationExecutorBuilder<FromContext : Any, OpensContext : Any, Ke
@Suppress("UNCHECKED_CAST")
public fun defaultClosed(context: NavigationContext<out OpensContext>) {
when (context.contextReference) {
is Activity -> DefaultContainerExecutor::close as (NavigationContext<out OpensContext>) -> Unit
is Activity -> DefaultContainerExecutor::close
is Fragment -> DefaultContainerExecutor::close
is ComposableDestination -> DefaultContainerExecutor::close
else -> throw IllegalArgumentException("No default close executor found for context ${context.contextReference::class.java.simpleName}")
Expand Down
8 changes: 5 additions & 3 deletions enro-core/src/main/java/dev/enro/core/NavigationHandle.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ public interface NavigationHandle : LifecycleOwner {
public val instruction: NavigationInstruction.Open<*>
public val dependencyScope: EnroDependencyScope
public fun executeInstruction(navigationInstruction: NavigationInstruction)
}

public interface TypedNavigationHandle<T : NavigationKey> : NavigationHandle {
override val key: T
public interface Typed<T : NavigationKey> : NavigationHandle {
override val key: T
}
}

public typealias TypedNavigationHandle<T> = NavigationHandle.Typed<T>

@PublishedApi
internal class TypedNavigationHandleImpl<T : NavigationKey>(
internal val navigationHandle: NavigationHandle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ import dev.enro.compatability.Compatibility
import dev.enro.core.controller.get
import dev.enro.core.controller.interceptor.builder.NavigationInterceptorBuilder
import dev.enro.core.controller.usecase.CanInstructionBeHostedAs
import dev.enro.core.controller.usecase.GetNavigationAnimations
import dev.enro.animation.internal.GetNavigationAnimations
import dev.enro.core.getNavigationHandle
import dev.enro.core.parentContainer
import dev.enro.destination.fragment.parentContainer
import dev.enro.extensions.getParcelableListCompat
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import dev.enro.core.controller.EnroDependencyContainer
import dev.enro.core.controller.EnroDependencyScope
import dev.enro.core.controller.get
import dev.enro.core.controller.register
import dev.enro.core.controller.usecase.GetNavigationAnimations
import dev.enro.animation.internal.GetNavigationAnimations
import dev.enro.core.parentContainer
import dev.enro.destination.fragment.parentContainer

internal class NavigationContainerScope(
owner: NavigationContainer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package dev.enro.core.controller

import android.app.Application
import androidx.annotation.Keep
import androidx.fragment.app.FragmentManager.FragmentLifecycleCallbacks
import dev.enro.android.NavigationApplication
import dev.enro.core.EnroException
import dev.enro.core.NavigationBinding
import dev.enro.core.NavigationExecutor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.enro.core.controller

import android.app.Application
import androidx.fragment.app.FragmentManager
import dev.enro.animation.internal.GetNavigationAnimations
import dev.enro.animation.internal.NavigationAnimationRepository
import dev.enro.destination.activity.internal.ActivityLifecycleCallbacksForEnro
import dev.enro.destination.fragment.internal.FragmentLifecycleCallbacksForEnro
import dev.enro.core.controller.repository.*
Expand Down Expand Up @@ -48,8 +48,8 @@ internal class NavigationControllerScope(
register { GetNavigationAnimations(get(), get<NavigationAnimationRepository>().controllerOverrides) }

// Other
register<ActivityLifecycleCallbacksForEnro> { ActivityLifecycleCallbacksForEnro(get(), get()) }
register<FragmentLifecycleCallbacksForEnro> { FragmentLifecycleCallbacksForEnro(get(), get()) }
register { ActivityLifecycleCallbacksForEnro(get(), get()) }
register { FragmentLifecycleCallbacksForEnro(get(), get()) }
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dev.enro.core.controller

import android.app.Application
import androidx.annotation.Keep
import dev.enro.android.NavigationApplication

/**
* Create a NavigationController from the NavigationControllerDefinition/DSL, and immediately attach it
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dev.enro.core.controller

import dev.enro.destination.activity.ActivityResultBridge
import dev.enro.destination.activity.ActivityResultDestination
import dev.enro.android.ActivityResultBridge
import dev.enro.android.ActivityResultDestination
import dev.enro.destination.compose.composableDestination
import dev.enro.core.controller.interceptor.HiltInstructionInterceptor
import dev.enro.core.controller.interceptor.InstructionOpenedByInterceptor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dev.enro.core.controller

import dev.enro.android.NavigationApplication


@Suppress("UNCHECKED_CAST")
internal fun NavigationApplication.loadGeneratedNavigationModule(): NavigationModule {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package dev.enro.core.controller.usecase

import dev.enro.animation.internal.NavigationAnimationRepository
import dev.enro.core.controller.NavigationModule
import dev.enro.core.controller.repository.*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import dev.enro.destination.activity.ActivityNavigationBinding
import dev.enro.destination.compose.ComposableNavigationBinding
import dev.enro.core.container.asPresentInstruction
import dev.enro.destination.fragment.FragmentNavigationBinding
import dev.enro.hilt.isHiltApplication
import dev.enro.hilt.isHiltContext
import dev.enro.android.hilt.isHiltApplication
import dev.enro.android.hilt.isHiltContext

internal class ActivityHost : NavigationHostFactory<Activity>(Activity::class.java) {
override fun supports(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import androidx.recyclerview.widget.RecyclerView
import dev.enro.core.*
import dev.enro.core.controller.usecase.createResultChannel
import dev.enro.core.result.internal.LazyResultChannelProperty
import dev.enro.viewmodel.getNavigationHandle
import dev.enro.android.viewmodel.getNavigationHandle
import kotlin.properties.ReadOnlyProperty
import kotlin.reflect.KClass
import dev.enro.core.closeWithResult as nonDeprecatedCloseWithResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import dev.enro.core.result.NavigationResultChannel
import dev.enro.core.result.internal.ResultChannelImpl
import dev.enro.core.result.registerForNavigationResultWithKey
import dev.enro.extensions.getParcelableListCompat
import dev.enro.viewmodel.getNavigationHandle
import dev.enro.android.viewmodel.getNavigationHandle
import kotlin.properties.PropertyDelegateProvider
import kotlin.properties.ReadOnlyProperty

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import androidx.lifecycle.ViewModelStore
import androidx.lifecycle.ViewModelStoreOwner
import androidx.lifecycle.viewmodel.CreationExtras
import androidx.lifecycle.viewmodel.compose.LocalViewModelStoreOwner
import dev.enro.viewmodel.withNavigationHandle
import dev.enro.android.viewmodel.withNavigationHandle

@Composable
public fun ProvideViewModelFactory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import androidx.savedstate.SavedStateRegistry
import androidx.savedstate.SavedStateRegistryOwner
import dev.enro.animation.NavigationAnimation
import dev.enro.core.*
import dev.enro.destination.compose.ComposableDestination
import dev.enro.destination.compose.LocalNavigationHandle
import dev.enro.destination.compose.dialog.*
import dev.enro.core.container.NavigationContainer
import dev.enro.core.container.getAnimationsForEntering
Expand All @@ -31,6 +29,8 @@ import dev.enro.core.controller.usecase.ComposeEnvironment
import dev.enro.core.controller.usecase.OnNavigationContextCreated
import dev.enro.core.controller.usecase.OnNavigationContextSaved
import dev.enro.android.activity
import dev.enro.destination.compose.ComposableDestination
import dev.enro.destination.compose.LocalNavigationHandle
import dev.enro.extensions.rememberLifecycleState

internal class ComposableDestinationOwner(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import dagger.hilt.internal.GeneratedComponentManagerHolder
import dev.enro.core.addOpenInstruction
import dev.enro.core.controller.application
import dev.enro.core.getNavigationHandle
import dev.enro.viewmodel.withNavigationHandle
import dev.enro.android.viewmodel.withNavigationHandle

internal class ComposableDestinationViewModelStoreOwner(
private val owner: ComposableDestinationOwner,
Expand Down
22 changes: 18 additions & 4 deletions enro-core/src/test/java/dev/enro/ProjectArchitecture.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,26 @@ internal class ProjectArchitecture {
val allowedDependencies = listOf(
"" to "dev.enro.core",
"" to "dev.enro.annotation",
"" to "dev.enro.extensions",

"dev.enro.compatability" to "",
"" to "dev.enro.compatability",

"dev.enro.destination" to "dev.enro.animation",

// Should be removed
"dev.enro.core.hosts" to "",

"dev.enro.core.container" to "dev.enro.animation",

// Destinations are allowed to access Android specific functionality,
// and the Android specific functionality is allowed to access the destinations
"dev.enro.destination" to "dev.enro.android",
"dev.enro.android" to "dev.enro.destination",
)
ArchRuleDefinition.classes()
.that()
.resideInAPackage("dev.enro.destination.activity")
.resideInAPackage("dev.enro..")
.should(NotDependOnOtherPackageGroups(allowedDependencies))
.check(classes)
}
Expand All @@ -69,7 +80,7 @@ internal object NotDependOnInternalClasses : ArchCondition<JavaClass>("not depen

internal class NotDependOnOtherPackageGroups(
private val allowedDependencies: List<Pair<String, String>>
) : ArchCondition<JavaClass>("not depend on internal classes") {
) : ArchCondition<JavaClass>("not depend on other package groups") {
override fun check(item: JavaClass, events: ConditionEvents) {
item.directDependenciesFromSelf
.forEach { dependency ->
Expand All @@ -80,9 +91,12 @@ internal class NotDependOnOtherPackageGroups(
val targetPackage = dependency.targetClass.packageName
if (!targetPackage.startsWith("dev.enro")) return@forEach

if (originPackage.startsWith(targetPackage)) return@forEach
val commonPrefix = originPackage.commonPrefixWith(targetPackage)
if (commonPrefix.count { it == '.' } >= 3) return@forEach

val isAllowed = allowedDependencies.any {
originPackage.startsWith(it.first) &&
targetPackage.startsWith(it.second)
(originPackage.startsWith(it.first) && targetPackage.startsWith(it.second))
}
if (isAllowed) return@forEach

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ sealed class DestinationReference {
.any { it.declaration.qualifiedName?.asString() == "androidx.fragment.app.Fragment" }

val isSyntheticClass = declaration is KSClassDeclaration && declaration.getAllSuperTypes()
.any { it.declaration.qualifiedName?.asString() == "dev.enro.core.synthetic.SyntheticDestination" }
.any { it.declaration.qualifiedName?.asString() == "dev.enro.destination.synthetic.SyntheticDestination" }

val isSyntheticProvider = declaration is KSPropertyDeclaration &&
declaration.type.resolve().declaration.qualifiedName?.asString() == "dev.enro.core.synthetic.SyntheticDestinationProvider"
declaration.type.resolve().declaration.qualifiedName?.asString() == "dev.enro.destination.synthetic.SyntheticDestinationProvider"

val isComposable = declaration is KSFunctionDeclaration && declaration.annotations
.any { it.shortName.asString() == "Composable" }
Expand Down Expand Up @@ -76,7 +76,7 @@ sealed class DestinationReference {
.firstOrNull { actualName == it.simpleName.toString() && it != element }

val syntheticProviderMirror = processingEnv.elementUtils
.getTypeElement("dev.enro.core.synthetic.SyntheticDestinationProvider")
.getTypeElement("dev.enro.destination.synthetic.SyntheticDestinationProvider")
.asType()
val erasedSyntheticProvider = processingEnv.typeUtils.erasure(syntheticProviderMirror)
val erasedReturnType = processingEnv.typeUtils.erasure(syntheticElement!!.returnType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,19 +306,19 @@ fun JavaFile.Builder.addImportsForBinding(): JavaFile.Builder {
fun FileSpec.Builder.addImportsForBinding(): FileSpec.Builder {
return this
.addImport(
"dev.enro.core.activity",
"dev.enro.destination.activity",
"activityDestination"
)
.addImport(
"dev.enro.core.fragment",
"dev.enro.destination.fragment",
"fragmentDestination"
)
.addImport(
"dev.enro.core.synthetic",
"dev.enro.destination.synthetic",
"syntheticDestination"
)
.addImport(
"dev.enro.core.compose",
"dev.enro.destination.compose",
"composableDestination"
)
}
4 changes: 2 additions & 2 deletions enro-test/src/main/java/dev/enro/test/EnroTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ package dev.enro.test
import android.app.Application
import androidx.test.core.app.ApplicationProvider
import androidx.test.platform.app.InstrumentationRegistry
import dev.enro.core.controller.NavigationApplication
import dev.enro.android.NavigationApplication
import dev.enro.core.controller.NavigationController
import dev.enro.core.controller.createUnattachedNavigationController
import dev.enro.viewmodel.EnroViewModelNavigationHandleProvider
import dev.enro.android.viewmodel.EnroViewModelNavigationHandleProvider

object EnroTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package dev.enro

import android.app.Application
import dev.enro.annotations.NavigationComponent
import dev.enro.core.controller.NavigationApplication
import dev.enro.android.NavigationApplication
import dev.enro.core.controller.createNavigationController
import dev.enro.core.plugins.EnroLogger

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import dev.enro.core.*
import dev.enro.destination.compose.EnroContainer
import dev.enro.destination.fragment.containerManager
import dev.enro.expectContext
import dev.enro.viewmodel.enroViewModels
import dev.enro.viewmodel.navigationHandle
import dev.enro.android.viewmodel.enroViewModels
import dev.enro.android.viewmodel.navigationHandle
import dev.enro.waitOnMain
import junit.framework.TestCase.assertTrue
import kotlinx.parcelize.Parcelize
Expand Down
2 changes: 1 addition & 1 deletion enro/src/androidTest/java/dev/enro/TestApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dev.enro
import android.app.Application
import dev.enro.annotations.NavigationComponent
import dev.enro.destination.compose.composableDestination
import dev.enro.core.controller.NavigationApplication
import dev.enro.android.NavigationApplication
import dev.enro.core.controller.createNavigationController
import dev.enro.core.destinations.ComposableDestinations
import dev.enro.core.destinations.ManuallyBoundComposableScreen
Expand Down
Loading

0 comments on commit a023420

Please sign in to comment.