From af59673718d11a9e1216df157b05faca32c298fd Mon Sep 17 00:00:00 2001 From: Jay Ohms Date: Tue, 11 Jun 2024 16:14:55 -0400 Subject: [PATCH] Rename HotwireCore -> Hotwire and use extension functions in the navigation module to extend the Hotwire.* configuration options --- .../core/bridge/StradaJsonConverter.kt | 6 +- .../config/{HotwireCore.kt => Hotwire.kt} | 2 +- .../dev/hotwire/core/logging/CoreLog.kt | 4 +- .../core/turbo/http/TurboHttpClient.kt | 4 +- .../http/TurboWebViewRequestInterceptor.kt | 4 +- .../dev/hotwire/core/turbo/session/Session.kt | 4 +- .../hotwire/core/turbo/views/TurboWebView.kt | 4 +- .../core/bridge/BridgeComponentTest.kt | 6 +- .../dev/hotwire/core/bridge/MessageTest.kt | 8 +-- .../dev/hotwire/core/bridge/UserAgentTest.kt | 12 ++-- .../dev/hotwire/demo/DemoApplication.kt | 6 +- .../dev/hotwire/navigation/config/Hotwire.kt | 67 ------------------- .../navigation/config/HotwireNavigation.kt | 65 ++++++++++++++++++ .../destinations/HotwireNavDestination.kt | 5 +- .../HotwireWebBottomSheetFragment.kt | 4 +- .../fragments/HotwireWebFragment.kt | 4 +- .../fragments/HotwireWebFragmentDelegate.kt | 2 +- .../navigation/logging/NavigationLog.kt | 2 +- .../hotwire/navigation/navigator/Navigator.kt | 5 +- .../navigator/NavigatorGraphBuilder.kt | 10 ++- .../navigation/navigator/NavigatorHost.kt | 5 +- .../navigation/navigator/NavigatorRule.kt | 11 ++- 22 files changed, 127 insertions(+), 113 deletions(-) rename core/src/main/kotlin/dev/hotwire/core/config/{HotwireCore.kt => Hotwire.kt} (79%) delete mode 100644 navigation-fragments/src/main/java/dev/hotwire/navigation/config/Hotwire.kt create mode 100644 navigation-fragments/src/main/java/dev/hotwire/navigation/config/HotwireNavigation.kt diff --git a/core/src/main/kotlin/dev/hotwire/core/bridge/StradaJsonConverter.kt b/core/src/main/kotlin/dev/hotwire/core/bridge/StradaJsonConverter.kt index d59cfa6..77cbec9 100644 --- a/core/src/main/kotlin/dev/hotwire/core/bridge/StradaJsonConverter.kt +++ b/core/src/main/kotlin/dev/hotwire/core/bridge/StradaJsonConverter.kt @@ -1,6 +1,6 @@ package dev.hotwire.core.bridge -import dev.hotwire.core.config.HotwireCore +import dev.hotwire.core.config.Hotwire import dev.hotwire.core.logging.logError import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json @@ -15,7 +15,7 @@ abstract class StradaJsonConverter { "or use the provided KotlinXJsonConverter." inline fun toObject(jsonData: String): T? { - val converter = requireNotNull(HotwireCore.config.jsonConverter) { NO_CONVERTER } + val converter = requireNotNull(Hotwire.config.jsonConverter) { NO_CONVERTER } return when (converter) { is KotlinXJsonConverter -> converter.toObject(jsonData) @@ -25,7 +25,7 @@ abstract class StradaJsonConverter { } inline fun toJson(data: T): String { - val converter = requireNotNull(HotwireCore.config.jsonConverter) { NO_CONVERTER } + val converter = requireNotNull(Hotwire.config.jsonConverter) { NO_CONVERTER } return when (converter) { is KotlinXJsonConverter -> converter.toJson(data) diff --git a/core/src/main/kotlin/dev/hotwire/core/config/HotwireCore.kt b/core/src/main/kotlin/dev/hotwire/core/config/Hotwire.kt similarity index 79% rename from core/src/main/kotlin/dev/hotwire/core/config/HotwireCore.kt rename to core/src/main/kotlin/dev/hotwire/core/config/Hotwire.kt index 7269e96..240ff54 100644 --- a/core/src/main/kotlin/dev/hotwire/core/config/HotwireCore.kt +++ b/core/src/main/kotlin/dev/hotwire/core/config/Hotwire.kt @@ -1,5 +1,5 @@ package dev.hotwire.core.config -object HotwireCore { +object Hotwire { val config: HotwireConfig = HotwireConfig() } diff --git a/core/src/main/kotlin/dev/hotwire/core/logging/CoreLog.kt b/core/src/main/kotlin/dev/hotwire/core/logging/CoreLog.kt index 7902c08..3533bfd 100644 --- a/core/src/main/kotlin/dev/hotwire/core/logging/CoreLog.kt +++ b/core/src/main/kotlin/dev/hotwire/core/logging/CoreLog.kt @@ -1,12 +1,12 @@ package dev.hotwire.core.logging import android.util.Log -import dev.hotwire.core.config.HotwireCore +import dev.hotwire.core.config.Hotwire internal object CoreLog { private const val DEFAULT_TAG = "Hotwire-Core" - private val debugEnabled get() = HotwireCore.config.debugLoggingEnabled + private val debugEnabled get() = Hotwire.config.debugLoggingEnabled internal fun d(msg: String) = log(Log.DEBUG, msg) diff --git a/core/src/main/kotlin/dev/hotwire/core/turbo/http/TurboHttpClient.kt b/core/src/main/kotlin/dev/hotwire/core/turbo/http/TurboHttpClient.kt index 17d999d..5e3066f 100644 --- a/core/src/main/kotlin/dev/hotwire/core/turbo/http/TurboHttpClient.kt +++ b/core/src/main/kotlin/dev/hotwire/core/turbo/http/TurboHttpClient.kt @@ -1,7 +1,7 @@ package dev.hotwire.core.turbo.http import android.content.Context -import dev.hotwire.core.config.HotwireCore +import dev.hotwire.core.config.Hotwire import dev.hotwire.core.logging.logError import okhttp3.Cache import okhttp3.OkHttpClient @@ -60,7 +60,7 @@ object TurboHttpClient { builder.cache(it) } - if (HotwireCore.config.debugLoggingEnabled) { + if (Hotwire.config.debugLoggingEnabled) { builder.addInterceptor(loggingInterceptor) } diff --git a/core/src/main/kotlin/dev/hotwire/core/turbo/http/TurboWebViewRequestInterceptor.kt b/core/src/main/kotlin/dev/hotwire/core/turbo/http/TurboWebViewRequestInterceptor.kt index e9b0adf..dde5682 100644 --- a/core/src/main/kotlin/dev/hotwire/core/turbo/http/TurboWebViewRequestInterceptor.kt +++ b/core/src/main/kotlin/dev/hotwire/core/turbo/http/TurboWebViewRequestInterceptor.kt @@ -2,13 +2,13 @@ package dev.hotwire.core.turbo.http import android.webkit.WebResourceRequest import android.webkit.WebResourceResponse -import dev.hotwire.core.config.HotwireCore +import dev.hotwire.core.config.Hotwire import dev.hotwire.core.logging.logEvent import dev.hotwire.core.turbo.session.Session import dev.hotwire.core.turbo.util.isHttpGetRequest internal class TurboWebViewRequestInterceptor(val session: Session) { - private val offlineRequestHandler get() = HotwireCore.config.offlineRequestHandler + private val offlineRequestHandler get() = Hotwire.config.offlineRequestHandler private val httpRepository get() = session.httpRepository private val currentVisit get() = session.currentVisit diff --git a/core/src/main/kotlin/dev/hotwire/core/turbo/session/Session.kt b/core/src/main/kotlin/dev/hotwire/core/turbo/session/Session.kt index 1ad98f2..e0d0d5b 100644 --- a/core/src/main/kotlin/dev/hotwire/core/turbo/session/Session.kt +++ b/core/src/main/kotlin/dev/hotwire/core/turbo/session/Session.kt @@ -13,7 +13,7 @@ import androidx.webkit.WebViewClientCompat import androidx.webkit.WebViewCompat import androidx.webkit.WebViewFeature.VISUAL_STATE_CALLBACK import androidx.webkit.WebViewFeature.isFeatureSupported -import dev.hotwire.core.config.HotwireCore +import dev.hotwire.core.config.Hotwire import dev.hotwire.core.logging.logEvent import dev.hotwire.core.turbo.delegates.TurboFileChooserDelegate import dev.hotwire.core.turbo.errors.HttpError @@ -92,7 +92,7 @@ class Session( * @param location Location to cache. */ fun preCacheLocation(location: String) { - val requestHandler = checkNotNull(HotwireCore.config.offlineRequestHandler) { + val requestHandler = checkNotNull(Hotwire.config.offlineRequestHandler) { "An offline request handler must be provided to pre-cache $location" } diff --git a/core/src/main/kotlin/dev/hotwire/core/turbo/views/TurboWebView.kt b/core/src/main/kotlin/dev/hotwire/core/turbo/views/TurboWebView.kt index 1672150..d80cea3 100644 --- a/core/src/main/kotlin/dev/hotwire/core/turbo/views/TurboWebView.kt +++ b/core/src/main/kotlin/dev/hotwire/core/turbo/views/TurboWebView.kt @@ -13,7 +13,7 @@ import androidx.webkit.WebSettingsCompat import androidx.webkit.WebViewCompat import androidx.webkit.WebViewFeature import com.google.gson.GsonBuilder -import dev.hotwire.core.config.HotwireCore +import dev.hotwire.core.config.Hotwire import dev.hotwire.core.turbo.util.contentFromAsset import dev.hotwire.core.turbo.util.runOnUiThread import dev.hotwire.core.turbo.util.toJson @@ -39,7 +39,7 @@ open class TurboWebView @JvmOverloads constructor( id = View.generateViewId() settings.javaScriptEnabled = true settings.domStorageEnabled = true - settings.userAgentString = "${HotwireCore.config.userAgent} ${settings.userAgentString}" + settings.userAgentString = "${Hotwire.config.userAgent} ${settings.userAgentString}" settings.setSupportMultipleWindows(true) layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT) initDayNightTheming() diff --git a/core/src/test/kotlin/dev/hotwire/core/bridge/BridgeComponentTest.kt b/core/src/test/kotlin/dev/hotwire/core/bridge/BridgeComponentTest.kt index 4b80a04..a9d80f4 100644 --- a/core/src/test/kotlin/dev/hotwire/core/bridge/BridgeComponentTest.kt +++ b/core/src/test/kotlin/dev/hotwire/core/bridge/BridgeComponentTest.kt @@ -1,7 +1,7 @@ package dev.hotwire.core.bridge import com.nhaarman.mockito_kotlin.* -import dev.hotwire.core.config.HotwireCore +import dev.hotwire.core.config.Hotwire import kotlinx.serialization.Serializable import org.assertj.core.api.Assertions.assertThatThrownBy import org.junit.Assert.assertEquals @@ -23,7 +23,7 @@ class BridgeComponentTest { @Before fun setup() { - HotwireCore.config.jsonConverter = KotlinXJsonConverter() + Hotwire.config.jsonConverter = KotlinXJsonConverter() component = TestData.OneBridgeComponent("one", delegate) } @@ -104,7 +104,7 @@ class BridgeComponentTest { @Test fun replyToReplacingDataWithNoConverter() { - HotwireCore.config.jsonConverter = null + Hotwire.config.jsonConverter = null component.didReceive(message) diff --git a/core/src/test/kotlin/dev/hotwire/core/bridge/MessageTest.kt b/core/src/test/kotlin/dev/hotwire/core/bridge/MessageTest.kt index 72dbb14..9c9feb5 100644 --- a/core/src/test/kotlin/dev/hotwire/core/bridge/MessageTest.kt +++ b/core/src/test/kotlin/dev/hotwire/core/bridge/MessageTest.kt @@ -1,6 +1,6 @@ package dev.hotwire.core.bridge -import dev.hotwire.core.config.HotwireCore +import dev.hotwire.core.config.Hotwire import kotlinx.serialization.Serializable import org.assertj.core.api.Assertions.assertThatThrownBy import org.junit.Assert.assertEquals @@ -12,7 +12,7 @@ class MessageTest { @Before fun setup() { - HotwireCore.config.jsonConverter = KotlinXJsonConverter() + Hotwire.config.jsonConverter = KotlinXJsonConverter() } @Test @@ -98,7 +98,7 @@ class MessageTest { @Test fun replacingDataWithNoConverter() { - HotwireCore.config.jsonConverter = null + Hotwire.config.jsonConverter = null val message = Message( id = "1", @@ -117,7 +117,7 @@ class MessageTest { @Test fun replacingDataWithInvalidConverter() { - HotwireCore.config.jsonConverter = InvalidJsonConverter() + Hotwire.config.jsonConverter = InvalidJsonConverter() val message = Message( id = "1", diff --git a/core/src/test/kotlin/dev/hotwire/core/bridge/UserAgentTest.kt b/core/src/test/kotlin/dev/hotwire/core/bridge/UserAgentTest.kt index 72e3246..7d1b97c 100644 --- a/core/src/test/kotlin/dev/hotwire/core/bridge/UserAgentTest.kt +++ b/core/src/test/kotlin/dev/hotwire/core/bridge/UserAgentTest.kt @@ -1,24 +1,24 @@ package dev.hotwire.core.bridge -import dev.hotwire.core.config.HotwireCore +import dev.hotwire.core.config.Hotwire import org.junit.Assert.assertEquals import org.junit.Test class UserAgentTest { @Test fun userAgentSubstring() { - HotwireCore.config.registeredBridgeComponentFactories = TestData.componentFactories + Hotwire.config.registeredBridgeComponentFactories = TestData.componentFactories - val userAgentSubstring = HotwireCore.config.userAgentSubstring() + val userAgentSubstring = Hotwire.config.userAgentSubstring() assertEquals(userAgentSubstring, "Turbo Native Android; bridge-components: [one two];") } @Test fun userAgent() { - HotwireCore.config.registeredBridgeComponentFactories = TestData.componentFactories - HotwireCore.config.userAgent = "Test; ${HotwireCore.config.userAgentSubstring()}" + Hotwire.config.registeredBridgeComponentFactories = TestData.componentFactories + Hotwire.config.userAgent = "Test; ${Hotwire.config.userAgentSubstring()}" - val userAgent = HotwireCore.config.userAgent + val userAgent = Hotwire.config.userAgent assertEquals(userAgent, "Test; Turbo Native Android; bridge-components: [one two];") } } diff --git a/demo/src/main/kotlin/dev/hotwire/demo/DemoApplication.kt b/demo/src/main/kotlin/dev/hotwire/demo/DemoApplication.kt index 318cf37..1f806a7 100644 --- a/demo/src/main/kotlin/dev/hotwire/demo/DemoApplication.kt +++ b/demo/src/main/kotlin/dev/hotwire/demo/DemoApplication.kt @@ -4,6 +4,7 @@ import android.app.Application import dev.hotwire.core.BuildConfig import dev.hotwire.core.bridge.BridgeComponentFactory import dev.hotwire.core.bridge.KotlinXJsonConverter +import dev.hotwire.core.config.Hotwire import dev.hotwire.core.turbo.config.PathConfiguration import dev.hotwire.demo.bridge.FormComponent import dev.hotwire.demo.bridge.MenuComponent @@ -15,7 +16,10 @@ import dev.hotwire.demo.features.web.WebBottomSheetFragment import dev.hotwire.demo.features.web.WebFragment import dev.hotwire.demo.features.web.WebHomeFragment import dev.hotwire.demo.features.web.WebModalFragment -import dev.hotwire.navigation.config.Hotwire +import dev.hotwire.navigation.config.defaultFragmentDestination +import dev.hotwire.navigation.config.registerBridgeComponents +import dev.hotwire.navigation.config.registerFragmentDestinations +import dev.hotwire.navigation.config.registerRouteDecisionHandlers import dev.hotwire.navigation.routing.AppNavigationRouteDecisionHandler import dev.hotwire.navigation.routing.BrowserTabRouteDecisionHandler diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/config/Hotwire.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/config/Hotwire.kt deleted file mode 100644 index a409cbd..0000000 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/config/Hotwire.kt +++ /dev/null @@ -1,67 +0,0 @@ -package dev.hotwire.navigation.config - -import androidx.fragment.app.Fragment -import dev.hotwire.core.bridge.BridgeComponent -import dev.hotwire.core.bridge.BridgeComponentFactory -import dev.hotwire.core.config.HotwireConfig -import dev.hotwire.core.config.HotwireCore -import dev.hotwire.navigation.destinations.HotwireNavDestination -import dev.hotwire.navigation.fragments.HotwireWebBottomSheetFragment -import dev.hotwire.navigation.fragments.HotwireWebFragment -import dev.hotwire.navigation.routing.AppNavigationRouteDecisionHandler -import dev.hotwire.navigation.routing.BrowserRouteDecisionHandler -import dev.hotwire.navigation.routing.Router -import kotlin.reflect.KClass - -object Hotwire { - val config: HotwireConfig = HotwireCore.config - - @Suppress("UNCHECKED_CAST") - internal var registeredBridgeComponentFactories: - List>> - get() = config.registeredBridgeComponentFactories as List>> - set(value) { config.registeredBridgeComponentFactories = value } - - internal var registeredFragmentDestinations: - List> = listOf( - HotwireWebFragment::class, - HotwireWebBottomSheetFragment::class - ) - private set - - internal var router = Router(listOf( - AppNavigationRouteDecisionHandler(), - BrowserRouteDecisionHandler() - )) - - /** - * Registers the [Router.RouteDecisionHandler] instances that determine whether to route location - * urls within in-app navigation or with alternative custom behaviors. - */ - fun registerRouteDecisionHandlers(decisionHandlers: List) { - router = Router(decisionHandlers) - } - - /** - * Register bridge components that the app supports. Every possible bridge - * component, wrapped in a [BridgeComponentFactory], must be provided here. - */ - fun registerBridgeComponents(factories: List>>) { - config.registeredBridgeComponentFactories = factories - } - - /** - * The default fragment destination for web requests. If you have not - * loaded a path configuration with a matching rule and a `uri` available - * for all possible paths, this destination will be used as the default. - */ - var defaultFragmentDestination: KClass = HotwireWebFragment::class - - /** - * Register fragment destinations that can be navigated to. Every possible - * destination must be provided here. - */ - fun registerFragmentDestinations(destinations: List>) { - registeredFragmentDestinations = destinations - } -} diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/config/HotwireNavigation.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/config/HotwireNavigation.kt new file mode 100644 index 0000000..4176505 --- /dev/null +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/config/HotwireNavigation.kt @@ -0,0 +1,65 @@ +package dev.hotwire.navigation.config + +import androidx.fragment.app.Fragment +import dev.hotwire.core.bridge.BridgeComponent +import dev.hotwire.core.bridge.BridgeComponentFactory +import dev.hotwire.core.config.Hotwire +import dev.hotwire.navigation.destinations.HotwireNavDestination +import dev.hotwire.navigation.fragments.HotwireWebBottomSheetFragment +import dev.hotwire.navigation.fragments.HotwireWebFragment +import dev.hotwire.navigation.routing.AppNavigationRouteDecisionHandler +import dev.hotwire.navigation.routing.BrowserRouteDecisionHandler +import dev.hotwire.navigation.routing.Router +import kotlin.reflect.KClass + +internal object HotwireNavigation { + var router = Router(listOf( + AppNavigationRouteDecisionHandler(), + BrowserRouteDecisionHandler() + )) + + var defaultFragmentDestination: KClass = HotwireWebFragment::class + + var registeredFragmentDestinations: List> = listOf( + HotwireWebFragment::class, + HotwireWebBottomSheetFragment::class + ) + + @Suppress("UNCHECKED_CAST") + var registeredBridgeComponentFactories: List>> + get() = Hotwire.config.registeredBridgeComponentFactories as List>> + set(value) { Hotwire.config.registeredBridgeComponentFactories = value } +} + +/** + * Registers the [Router.RouteDecisionHandler] instances that determine whether to route location + * urls within in-app navigation or with alternative custom behaviors. + */ +fun Hotwire.registerRouteDecisionHandlers(decisionHandlers: List) { + HotwireNavigation.router = Router(decisionHandlers) +} + +/** + * Register bridge components that the app supports. Every possible bridge + * component, wrapped in a [BridgeComponentFactory], must be provided here. + */ +fun Hotwire.registerBridgeComponents(factories: List>>) { + config.registeredBridgeComponentFactories = factories +} + +/** + * The default fragment destination for web requests. If you have not + * loaded a path configuration with a matching rule and a `uri` available + * for all possible paths, this destination will be used as the default. + */ +var Hotwire.defaultFragmentDestination: KClass + get() = HotwireNavigation.defaultFragmentDestination + set(value) { HotwireNavigation.defaultFragmentDestination = value } + +/** + * Register fragment destinations that can be navigated to. Every possible + * destination must be provided here. + */ +fun Hotwire.registerFragmentDestinations(destinations: List>) { + HotwireNavigation.registeredFragmentDestinations = destinations +} diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireNavDestination.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireNavDestination.kt index 17275d5..335e2e8 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireNavDestination.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireNavDestination.kt @@ -8,12 +8,13 @@ import androidx.fragment.app.Fragment import androidx.navigation.NavOptions import androidx.navigation.navOptions import dev.hotwire.core.bridge.BridgeDestination +import dev.hotwire.core.config.Hotwire import dev.hotwire.core.turbo.config.PathConfigurationProperties import dev.hotwire.core.turbo.config.context import dev.hotwire.core.turbo.nav.TurboNavPresentationContext import dev.hotwire.core.turbo.visit.VisitAction import dev.hotwire.navigation.R -import dev.hotwire.navigation.config.Hotwire +import dev.hotwire.navigation.config.HotwireNavigation import dev.hotwire.navigation.fragments.HotwireFragmentDelegate import dev.hotwire.navigation.fragments.HotwireFragmentViewModel import dev.hotwire.navigation.navigator.Navigator @@ -115,7 +116,7 @@ interface HotwireNavDestination : BridgeDestination { * but it's recommend to use dedicated [Router.RouteDecisionHandler] instances for routing logic. */ fun decideRoute(newLocation: String): Router.Decision { - return Hotwire.router.decideRoute( + return HotwireNavigation.router.decideRoute( location = newLocation, configuration = navigator.configuration, activity = fragment.requireActivity() as dev.hotwire.navigation.activities.HotwireActivity diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebBottomSheetFragment.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebBottomSheetFragment.kt index b066bf8..a5f60ba 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebBottomSheetFragment.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebBottomSheetFragment.kt @@ -14,7 +14,7 @@ import dev.hotwire.core.turbo.util.TURBO_REQUEST_CODE_FILES import dev.hotwire.core.turbo.views.TurboWebChromeClient import dev.hotwire.core.turbo.views.TurboWebView import dev.hotwire.navigation.R -import dev.hotwire.navigation.config.Hotwire +import dev.hotwire.navigation.config.HotwireNavigation import dev.hotwire.navigation.destinations.HotwireDestination import dev.hotwire.navigation.views.TurboView @@ -32,7 +32,7 @@ open class HotwireWebBottomSheetFragment : HotwireBottomSheetFragment(), Hotwire BridgeDelegate( location = location, destination = this, - componentFactories = Hotwire.registeredBridgeComponentFactories + componentFactories = HotwireNavigation.registeredBridgeComponentFactories ) } diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebFragment.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebFragment.kt index 06c7fdc..1f69939 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebFragment.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebFragment.kt @@ -13,7 +13,7 @@ import dev.hotwire.core.turbo.util.TURBO_REQUEST_CODE_FILES import dev.hotwire.core.turbo.views.TurboWebChromeClient import dev.hotwire.core.turbo.views.TurboWebView import dev.hotwire.navigation.R -import dev.hotwire.navigation.config.Hotwire +import dev.hotwire.navigation.config.HotwireNavigation import dev.hotwire.navigation.destinations.HotwireDestination import dev.hotwire.navigation.session.SessionModalResult import dev.hotwire.navigation.views.TurboView @@ -32,7 +32,7 @@ open class HotwireWebFragment : HotwireFragment(), HotwireWebFragmentCallback { BridgeDelegate( location = location, destination = this, - componentFactories = Hotwire.registeredBridgeComponentFactories + componentFactories = HotwireNavigation.registeredBridgeComponentFactories ) } diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebFragmentDelegate.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebFragmentDelegate.kt index 064aa67..4f93ee5 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebFragmentDelegate.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebFragmentDelegate.kt @@ -9,6 +9,7 @@ import androidx.lifecycle.Lifecycle.State.STARTED import androidx.lifecycle.findViewTreeLifecycleOwner import androidx.lifecycle.lifecycleScope import androidx.lifecycle.whenStateAtLeast +import dev.hotwire.core.config.Hotwire import dev.hotwire.core.turbo.config.pullToRefreshEnabled import dev.hotwire.core.turbo.errors.VisitError import dev.hotwire.core.turbo.session.SessionCallback @@ -17,7 +18,6 @@ import dev.hotwire.core.turbo.visit.Visit import dev.hotwire.core.turbo.visit.VisitAction import dev.hotwire.core.turbo.visit.VisitDestination import dev.hotwire.core.turbo.visit.VisitOptions -import dev.hotwire.navigation.config.Hotwire import dev.hotwire.navigation.destinations.HotwireNavDestination import dev.hotwire.navigation.session.SessionModalResult import dev.hotwire.navigation.util.dispatcherProvider diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/logging/NavigationLog.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/logging/NavigationLog.kt index 9541be5..13a4eb6 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/logging/NavigationLog.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/logging/NavigationLog.kt @@ -1,7 +1,7 @@ package dev.hotwire.navigation.logging import android.util.Log -import dev.hotwire.navigation.config.Hotwire +import dev.hotwire.core.config.Hotwire internal object NavigationLog { private const val DEFAULT_TAG = "Hotwire-Navigation" diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/navigator/Navigator.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/navigator/Navigator.kt index 884588c..59c965a 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/navigator/Navigator.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/navigator/Navigator.kt @@ -8,12 +8,13 @@ import androidx.navigation.NavController import androidx.navigation.NavOptions import androidx.navigation.fragment.FragmentNavigator import dev.hotwire.core.bridge.Bridge +import dev.hotwire.core.config.Hotwire import dev.hotwire.core.turbo.nav.TurboNavPresentation import dev.hotwire.core.turbo.nav.TurboNavPresentationContext import dev.hotwire.core.turbo.session.Session import dev.hotwire.core.turbo.visit.VisitAction import dev.hotwire.core.turbo.visit.VisitOptions -import dev.hotwire.navigation.config.Hotwire +import dev.hotwire.navigation.config.HotwireNavigation import dev.hotwire.navigation.destinations.HotwireNavDestination import dev.hotwire.navigation.destinations.HotwireNavDialogDestination import dev.hotwire.navigation.logging.logEvent @@ -58,7 +59,7 @@ class Navigator( webView = Hotwire.config.makeCustomWebView(host.requireContext()) ).also { // Initialize bridge with new WebView instance - if (Hotwire.registeredBridgeComponentFactories.isNotEmpty()) { + if (HotwireNavigation.registeredBridgeComponentFactories.isNotEmpty()) { Bridge.initialize(it.webView) } } diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/navigator/NavigatorGraphBuilder.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/navigator/NavigatorGraphBuilder.kt index 21b049c..e25d2a9 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/navigator/NavigatorGraphBuilder.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/navigator/NavigatorGraphBuilder.kt @@ -4,14 +4,18 @@ import android.net.Uri import androidx.core.net.toUri import androidx.fragment.app.DialogFragment import androidx.fragment.app.Fragment -import androidx.navigation.* +import androidx.navigation.NavController +import androidx.navigation.NavGraph +import androidx.navigation.NavGraphBuilder +import androidx.navigation.createGraph import androidx.navigation.fragment.DialogFragmentNavigator import androidx.navigation.fragment.DialogFragmentNavigatorDestinationBuilder import androidx.navigation.fragment.FragmentNavigator import androidx.navigation.fragment.FragmentNavigatorDestinationBuilder +import androidx.navigation.get import dev.hotwire.core.turbo.config.PathConfiguration import dev.hotwire.core.turbo.config.uri -import dev.hotwire.navigation.config.Hotwire +import dev.hotwire.navigation.config.HotwireNavigation import dev.hotwire.navigation.destinations.HotwireDestination import java.util.UUID import kotlin.reflect.KClass @@ -90,7 +94,7 @@ internal class NavigatorGraphBuilder( private fun List.startDestination(): FragmentDestination { val startDestinationUri = pathConfiguration.properties(startLocation).uri ?: - HotwireDestination.from(Hotwire.defaultFragmentDestination).uri.toUri() + HotwireDestination.from(HotwireNavigation.defaultFragmentDestination).uri.toUri() return requireNotNull(firstOrNull { it.uri == startDestinationUri }) { "A start Fragment destination was not found for uri: $startDestinationUri" diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/navigator/NavigatorHost.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/navigator/NavigatorHost.kt index 705c01f..b5a2273 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/navigator/NavigatorHost.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/navigator/NavigatorHost.kt @@ -3,8 +3,9 @@ package dev.hotwire.navigation.navigator import android.os.Bundle import androidx.navigation.fragment.NavHostFragment import androidx.navigation.fragment.findNavController +import dev.hotwire.core.config.Hotwire import dev.hotwire.navigation.activities.HotwireActivity -import dev.hotwire.navigation.config.Hotwire +import dev.hotwire.navigation.config.HotwireNavigation open class NavigatorHost : NavHostFragment() { internal lateinit var activity: HotwireActivity @@ -33,7 +34,7 @@ open class NavigatorHost : NavHostFragment() { pathConfiguration = Hotwire.config.pathConfiguration, navController = findNavController() ).build( - registeredFragments = Hotwire.registeredFragmentDestinations + registeredFragments = HotwireNavigation.registeredFragmentDestinations ) } } diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/navigator/NavigatorRule.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/navigator/NavigatorRule.kt index ebd7e77..5c7c8d5 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/navigator/NavigatorRule.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/navigator/NavigatorRule.kt @@ -9,13 +9,18 @@ import androidx.navigation.NavDestination import androidx.navigation.NavOptions import androidx.navigation.fragment.FragmentNavigator import androidx.navigation.navOptions -import dev.hotwire.core.turbo.config.* +import dev.hotwire.core.turbo.config.PathConfiguration +import dev.hotwire.core.turbo.config.context +import dev.hotwire.core.turbo.config.fallbackUri +import dev.hotwire.core.turbo.config.presentation +import dev.hotwire.core.turbo.config.queryStringPresentation +import dev.hotwire.core.turbo.config.uri import dev.hotwire.core.turbo.nav.TurboNavPresentation import dev.hotwire.core.turbo.nav.TurboNavPresentationContext import dev.hotwire.core.turbo.nav.TurboNavQueryStringPresentation import dev.hotwire.core.turbo.visit.VisitAction import dev.hotwire.core.turbo.visit.VisitOptions -import dev.hotwire.navigation.config.Hotwire +import dev.hotwire.navigation.config.HotwireNavigation import dev.hotwire.navigation.destinations.HotwireDestination import dev.hotwire.navigation.session.SessionModalResult import dev.hotwire.navigation.util.location @@ -30,7 +35,7 @@ internal class NavigatorRule( pathConfiguration: PathConfiguration, val controller: NavController ) { - val defaultUri = HotwireDestination.from(Hotwire.defaultFragmentDestination).uri.toUri() + val defaultUri = HotwireDestination.from(HotwireNavigation.defaultFragmentDestination).uri.toUri() // Current destination val previousLocation = controller.previousBackStackEntry.location