From fd84192483d65e5d9a5685cc90bfce8715ff5116 Mon Sep 17 00:00:00 2001 From: Jay Ohms Date: Thu, 13 Jun 2024 10:10:03 -0400 Subject: [PATCH] Rename HotwireNavDestination -> HotwireDestination --- .../dev/hotwire/demo/bridge/FormComponent.kt | 6 +++--- .../dev/hotwire/demo/bridge/MenuComponent.kt | 6 +++--- .../hotwire/demo/bridge/OverflowMenuComponent.kt | 6 +++--- .../navigation/config/HotwireNavigation.kt | 8 ++++---- ...reNavDestination.kt => HotwireDestination.kt} | 2 +- ...estination.kt => HotwireDialogDestination.kt} | 2 +- .../fragments/HotwireBottomSheetFragment.kt | 8 ++++---- .../navigation/fragments/HotwireFragment.kt | 6 +++--- .../fragments/HotwireFragmentDelegate.kt | 4 ++-- .../fragments/HotwireWebFragmentDelegate.kt | 7 +++---- .../hotwire/navigation/navigator/Navigator.kt | 16 ++++++++-------- .../observers/HotwireWindowThemeObserver.kt | 4 ++-- 12 files changed, 37 insertions(+), 38 deletions(-) rename navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/{HotwireNavDestination.kt => HotwireDestination.kt} (99%) rename navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/{HotwireNavDialogDestination.kt => HotwireDialogDestination.kt} (84%) diff --git a/demo/src/main/kotlin/dev/hotwire/demo/bridge/FormComponent.kt b/demo/src/main/kotlin/dev/hotwire/demo/bridge/FormComponent.kt index 162f642..260c01a 100644 --- a/demo/src/main/kotlin/dev/hotwire/demo/bridge/FormComponent.kt +++ b/demo/src/main/kotlin/dev/hotwire/demo/bridge/FormComponent.kt @@ -11,7 +11,7 @@ import dev.hotwire.core.bridge.BridgeDelegate import dev.hotwire.core.bridge.Message import dev.hotwire.demo.R import dev.hotwire.demo.databinding.FormComponentSubmitBinding -import dev.hotwire.navigation.destinations.HotwireNavDestination +import dev.hotwire.navigation.destinations.HotwireDestination import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -21,8 +21,8 @@ import kotlinx.serialization.Serializable */ class FormComponent( name: String, - private val delegate: BridgeDelegate -) : BridgeComponent(name, delegate) { + private val delegate: BridgeDelegate +) : BridgeComponent(name, delegate) { private val submitButtonItemId = 37 private var submitMenuItem: MenuItem? = null diff --git a/demo/src/main/kotlin/dev/hotwire/demo/bridge/MenuComponent.kt b/demo/src/main/kotlin/dev/hotwire/demo/bridge/MenuComponent.kt index e572d7b..b5c60ea 100644 --- a/demo/src/main/kotlin/dev/hotwire/demo/bridge/MenuComponent.kt +++ b/demo/src/main/kotlin/dev/hotwire/demo/bridge/MenuComponent.kt @@ -9,7 +9,7 @@ import dev.hotwire.core.bridge.BridgeComponent import dev.hotwire.core.bridge.BridgeDelegate import dev.hotwire.core.bridge.Message import dev.hotwire.demo.databinding.MenuComponentBottomSheetBinding -import dev.hotwire.navigation.destinations.HotwireNavDestination +import dev.hotwire.navigation.destinations.HotwireDestination import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -19,8 +19,8 @@ import kotlinx.serialization.Serializable */ class MenuComponent( name: String, - private val delegate: BridgeDelegate -) : BridgeComponent(name, delegate) { + private val delegate: BridgeDelegate +) : BridgeComponent(name, delegate) { private val fragment: Fragment get() = delegate.destination.fragment diff --git a/demo/src/main/kotlin/dev/hotwire/demo/bridge/OverflowMenuComponent.kt b/demo/src/main/kotlin/dev/hotwire/demo/bridge/OverflowMenuComponent.kt index 569ae83..018e42f 100644 --- a/demo/src/main/kotlin/dev/hotwire/demo/bridge/OverflowMenuComponent.kt +++ b/demo/src/main/kotlin/dev/hotwire/demo/bridge/OverflowMenuComponent.kt @@ -7,7 +7,7 @@ import dev.hotwire.core.bridge.BridgeComponent import dev.hotwire.core.bridge.BridgeDelegate import dev.hotwire.core.bridge.Message import dev.hotwire.demo.R -import dev.hotwire.navigation.destinations.HotwireNavDestination +import dev.hotwire.navigation.destinations.HotwireDestination import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -17,8 +17,8 @@ import kotlinx.serialization.Serializable */ class OverflowMenuComponent( name: String, - private val delegate: BridgeDelegate -) : BridgeComponent(name, delegate) { + private val delegate: BridgeDelegate +) : BridgeComponent(name, delegate) { private val fragment: Fragment get() = delegate.destination.fragment 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 index 4176505..0869b0a 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/config/HotwireNavigation.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/config/HotwireNavigation.kt @@ -4,7 +4,7 @@ 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.destinations.HotwireDestination import dev.hotwire.navigation.fragments.HotwireWebBottomSheetFragment import dev.hotwire.navigation.fragments.HotwireWebFragment import dev.hotwire.navigation.routing.AppNavigationRouteDecisionHandler @@ -26,8 +26,8 @@ internal object HotwireNavigation { ) @Suppress("UNCHECKED_CAST") - var registeredBridgeComponentFactories: List>> - get() = Hotwire.config.registeredBridgeComponentFactories as List>> + var registeredBridgeComponentFactories: List>> + get() = Hotwire.config.registeredBridgeComponentFactories as List>> set(value) { Hotwire.config.registeredBridgeComponentFactories = value } } @@ -43,7 +43,7 @@ fun Hotwire.registerRouteDecisionHandlers(decisionHandlers: List>>) { +fun Hotwire.registerBridgeComponents(factories: List>>) { config.registeredBridgeComponentFactories = factories } diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireNavDestination.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireDestination.kt similarity index 99% rename from navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireNavDestination.kt rename to navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireDestination.kt index 20a67c0..caa2352 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireNavDestination.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireDestination.kt @@ -25,7 +25,7 @@ import dev.hotwire.navigation.routing.Router * The primary interface that a navigable Fragment implements to provide the library with * the information it needs to properly navigate. */ -interface HotwireNavDestination : BridgeDestination { +interface HotwireDestination : BridgeDestination { /** * Gets the navigator instance associated with this destination. */ diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireNavDialogDestination.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireDialogDestination.kt similarity index 84% rename from navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireNavDialogDestination.kt rename to navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireDialogDestination.kt index e8ff79c..e734971 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireNavDialogDestination.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/destinations/HotwireDialogDestination.kt @@ -4,6 +4,6 @@ package dev.hotwire.navigation.destinations * The interface that a navigable DialogFragment implements to provide the library with * the information it needs to properly navigate. */ -interface HotwireNavDialogDestination { +interface HotwireDialogDestination { fun closeDialog() } diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireBottomSheetFragment.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireBottomSheetFragment.kt index 1f8b7f4..85c5db8 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireBottomSheetFragment.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireBottomSheetFragment.kt @@ -8,8 +8,8 @@ import androidx.appcompat.widget.Toolbar import com.google.android.material.bottomsheet.BottomSheetDialogFragment import dev.hotwire.core.turbo.config.title import dev.hotwire.navigation.R -import dev.hotwire.navigation.destinations.HotwireNavDestination -import dev.hotwire.navigation.destinations.HotwireNavDialogDestination +import dev.hotwire.navigation.destinations.HotwireDestination +import dev.hotwire.navigation.destinations.HotwireDialogDestination import dev.hotwire.navigation.navigator.Navigator import dev.hotwire.navigation.navigator.NavigatorHost @@ -20,7 +20,7 @@ import dev.hotwire.navigation.navigator.NavigatorHost * For web bottom sheet fragments, refer to [HotwireWebBottomSheetFragment]. */ abstract class HotwireBottomSheetFragment : BottomSheetDialogFragment(), - HotwireNavDestination, HotwireNavDialogDestination { + HotwireDestination, HotwireDialogDestination { override lateinit var navigator: Navigator internal lateinit var delegate: HotwireFragmentDelegate @@ -61,7 +61,7 @@ abstract class HotwireBottomSheetFragment : BottomSheetDialogFragment(), * Use [registerForActivityResult] with the appropriate * [androidx.activity.result.contract.ActivityResultContract] and its callback. * - * Turbo provides the [HotwireNavDestination.activityResultLauncher] interface + * Turbo provides the [HotwireDestination.activityResultLauncher] interface * to obtain registered result launchers from any destination. */ @Suppress("DEPRECATION") diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireFragment.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireFragment.kt index 6333cae..fd33d0a 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireFragment.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireFragment.kt @@ -9,7 +9,7 @@ import dev.hotwire.core.turbo.config.context import dev.hotwire.core.turbo.config.title import dev.hotwire.core.turbo.nav.TurboNavPresentationContext import dev.hotwire.navigation.R -import dev.hotwire.navigation.destinations.HotwireNavDestination +import dev.hotwire.navigation.destinations.HotwireDestination import dev.hotwire.navigation.navigator.Navigator import dev.hotwire.navigation.navigator.NavigatorHost import dev.hotwire.navigation.observers.HotwireWindowThemeObserver @@ -21,7 +21,7 @@ import dev.hotwire.navigation.session.SessionModalResult * * For web fragments, refer to [HotwireWebFragment]. */ -abstract class HotwireFragment : Fragment(), HotwireNavDestination { +abstract class HotwireFragment : Fragment(), HotwireDestination { override lateinit var navigator: Navigator internal lateinit var delegate: HotwireFragmentDelegate @@ -66,7 +66,7 @@ abstract class HotwireFragment : Fragment(), HotwireNavDestination { * Use [registerForActivityResult] with the appropriate * [androidx.activity.result.contract.ActivityResultContract] and its callback. * - * Turbo provides the [HotwireNavDestination.activityResultLauncher] interface + * Turbo provides the [HotwireDestination.activityResultLauncher] interface * to obtain registered result launchers from any destination. */ @Suppress("DEPRECATION") diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireFragmentDelegate.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireFragmentDelegate.kt index 05c1083..fbd0e01 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireFragmentDelegate.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireFragmentDelegate.kt @@ -1,7 +1,7 @@ package dev.hotwire.navigation.fragments import dev.hotwire.navigation.logging.logEvent -import dev.hotwire.navigation.destinations.HotwireNavDestination +import dev.hotwire.navigation.destinations.HotwireDestination import dev.hotwire.navigation.session.SessionModalResult import dev.hotwire.navigation.session.SessionViewModel import dev.hotwire.navigation.util.displayBackButton @@ -12,7 +12,7 @@ import dev.hotwire.navigation.util.displayBackButtonAsCloseIcon * to this class. Note: This class should not need to be used directly * from within your app. */ -class HotwireFragmentDelegate(private val navDestination: HotwireNavDestination) { +class HotwireFragmentDelegate(private val navDestination: HotwireDestination) { private val fragment = navDestination.fragment private val location = navDestination.location private val navigator = navDestination.navigator 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 4f93ee5..b4b0514 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 @@ -18,7 +18,7 @@ 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.destinations.HotwireNavDestination +import dev.hotwire.navigation.destinations.HotwireDestination import dev.hotwire.navigation.session.SessionModalResult import dev.hotwire.navigation.util.dispatcherProvider import dev.hotwire.navigation.views.TurboView @@ -32,7 +32,7 @@ import kotlin.random.Random */ internal class HotwireWebFragmentDelegate( private val delegate: HotwireFragmentDelegate, - private val navDestination: HotwireNavDestination, + private val navDestination: HotwireDestination, private val callback: HotwireWebFragmentCallback ) : SessionCallback, VisitDestination { @@ -129,8 +129,7 @@ internal class HotwireWebFragmentDelegate( } /** - * Should be called by the implementing Fragment during - * [dev.hotwire.core.turbo.nav.HotwireNavDestination.refresh] + * Should be called by the implementing Fragment during [HotwireDestination.refresh]. */ fun refresh(displayProgress: Boolean) { if (webView.url == null) return 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 59c965a..a819259 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 @@ -15,8 +15,8 @@ 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.HotwireNavigation -import dev.hotwire.navigation.destinations.HotwireNavDestination -import dev.hotwire.navigation.destinations.HotwireNavDialogDestination +import dev.hotwire.navigation.destinations.HotwireDestination +import dev.hotwire.navigation.destinations.HotwireDialogDestination import dev.hotwire.navigation.logging.logEvent import dev.hotwire.navigation.routing.Router import dev.hotwire.navigation.util.location @@ -28,10 +28,10 @@ class Navigator( private val navController = host.navController /** - * Retrieves the currently active [HotwireNavDestination] on the backstack. + * Retrieves the currently active [HotwireDestination] on the backstack. */ - val currentDestination: HotwireNavDestination - get() = host.childFragmentManager.primaryNavigationFragment as HotwireNavDestination? + val currentDestination: HotwireDestination + get() = host.childFragmentManager.primaryNavigationFragment as HotwireDestination? ?: throw IllegalStateException("No current destination found in NavigatorHost") /** @@ -74,7 +74,7 @@ class Navigator( fun pop() { navigateWhenReady { val currentFragment = currentDestination.fragment - if (currentFragment is HotwireNavDialogDestination) { + if (currentFragment is HotwireDialogDestination) { currentFragment.closeDialog() } else { navController.popBackStack() @@ -150,7 +150,7 @@ class Navigator( navigateWhenReady { val currentFragment = currentDestination.fragment - if (currentFragment is HotwireNavDialogDestination) { + if (currentFragment is HotwireDialogDestination) { currentFragment.closeDialog() } @@ -251,7 +251,7 @@ class Navigator( ) navigateWhenReady { - val isDialog = currentDestination.fragment is HotwireNavDialogDestination + val isDialog = currentDestination.fragment is HotwireDialogDestination if (isDialog) { // Pop the backstack before sending the modal result, since the // underlying fragment is still active and will receive the diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/observers/HotwireWindowThemeObserver.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/observers/HotwireWindowThemeObserver.kt index 4c6e91e..af847ec 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/observers/HotwireWindowThemeObserver.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/observers/HotwireWindowThemeObserver.kt @@ -9,10 +9,10 @@ import android.view.WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS import androidx.annotation.RequiresApi import androidx.lifecycle.DefaultLifecycleObserver import androidx.lifecycle.LifecycleOwner -import dev.hotwire.navigation.destinations.HotwireNavDestination +import dev.hotwire.navigation.destinations.HotwireDestination import dev.hotwire.navigation.util.animateColorTo -internal class HotwireWindowThemeObserver(val destination: HotwireNavDestination) : DefaultLifecycleObserver { +internal class HotwireWindowThemeObserver(val destination: HotwireDestination) : DefaultLifecycleObserver { private val window: Window? get() = destination.fragment.activity?.window