diff --git a/core/src/main/kotlin/dev/hotwire/core/navigation/fragments/HotwireBottomSheetFragment.kt b/core/src/main/kotlin/dev/hotwire/core/navigation/fragments/HotwireBottomSheetFragment.kt index f8bed62..da19d80 100644 --- a/core/src/main/kotlin/dev/hotwire/core/navigation/fragments/HotwireBottomSheetFragment.kt +++ b/core/src/main/kotlin/dev/hotwire/core/navigation/fragments/HotwireBottomSheetFragment.kt @@ -10,7 +10,6 @@ import dev.hotwire.core.R import dev.hotwire.core.navigation.navigator.Navigator import dev.hotwire.core.navigation.navigator.NavigatorHost import dev.hotwire.core.turbo.config.title -import dev.hotwire.core.turbo.delegates.TurboFragmentDelegate import dev.hotwire.core.turbo.nav.HotwireNavDestination import dev.hotwire.core.turbo.nav.HotwireNavDialogDestination @@ -23,12 +22,12 @@ import dev.hotwire.core.turbo.nav.HotwireNavDialogDestination abstract class HotwireBottomSheetFragment : BottomSheetDialogFragment(), HotwireNavDestination, HotwireNavDialogDestination { override lateinit var navigator: Navigator - internal lateinit var delegate: TurboFragmentDelegate + internal lateinit var delegate: HotwireFragmentDelegate override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) navigator = (parentFragment as NavigatorHost).navigator - delegate = TurboFragmentDelegate(this) + delegate = HotwireFragmentDelegate(this) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -113,7 +112,7 @@ abstract class HotwireBottomSheetFragment : BottomSheetDialogFragment(), return view?.findViewById(R.id.toolbar) } - final override fun delegate(): TurboFragmentDelegate { + final override fun delegate(): HotwireFragmentDelegate { return delegate } diff --git a/core/src/main/kotlin/dev/hotwire/core/navigation/fragments/HotwireFragment.kt b/core/src/main/kotlin/dev/hotwire/core/navigation/fragments/HotwireFragment.kt index 9a8c4df..d9735b9 100644 --- a/core/src/main/kotlin/dev/hotwire/core/navigation/fragments/HotwireFragment.kt +++ b/core/src/main/kotlin/dev/hotwire/core/navigation/fragments/HotwireFragment.kt @@ -10,7 +10,6 @@ import dev.hotwire.core.navigation.navigator.Navigator import dev.hotwire.core.navigation.navigator.NavigatorHost import dev.hotwire.core.turbo.config.context import dev.hotwire.core.turbo.config.title -import dev.hotwire.core.turbo.delegates.TurboFragmentDelegate import dev.hotwire.core.turbo.nav.HotwireNavDestination import dev.hotwire.core.turbo.nav.TurboNavPresentationContext import dev.hotwire.core.turbo.observers.HotwireWindowThemeObserver @@ -24,12 +23,12 @@ import dev.hotwire.core.turbo.session.SessionModalResult */ abstract class HotwireFragment : Fragment(), HotwireNavDestination { override lateinit var navigator: Navigator - internal lateinit var delegate: TurboFragmentDelegate + internal lateinit var delegate: HotwireFragmentDelegate override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) navigator = (parentFragment as NavigatorHost).navigator - delegate = TurboFragmentDelegate(this) + delegate = HotwireFragmentDelegate(this) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -125,7 +124,7 @@ abstract class HotwireFragment : Fragment(), HotwireNavDestination { return view?.findViewById(R.id.toolbar) } - final override fun delegate(): TurboFragmentDelegate { + final override fun delegate(): HotwireFragmentDelegate { return delegate } diff --git a/core/src/main/kotlin/dev/hotwire/core/turbo/delegates/TurboFragmentDelegate.kt b/core/src/main/kotlin/dev/hotwire/core/navigation/fragments/HotwireFragmentDelegate.kt similarity index 87% rename from core/src/main/kotlin/dev/hotwire/core/turbo/delegates/TurboFragmentDelegate.kt rename to core/src/main/kotlin/dev/hotwire/core/navigation/fragments/HotwireFragmentDelegate.kt index 59cc255..6d1c266 100644 --- a/core/src/main/kotlin/dev/hotwire/core/turbo/delegates/TurboFragmentDelegate.kt +++ b/core/src/main/kotlin/dev/hotwire/core/navigation/fragments/HotwireFragmentDelegate.kt @@ -1,7 +1,6 @@ -package dev.hotwire.core.turbo.delegates +package dev.hotwire.core.navigation.fragments import dev.hotwire.core.lib.logging.logEvent -import dev.hotwire.core.navigation.fragments.HotwireFragmentViewModel import dev.hotwire.core.turbo.nav.HotwireNavDestination import dev.hotwire.core.turbo.session.SessionModalResult import dev.hotwire.core.turbo.session.SessionViewModel @@ -13,7 +12,7 @@ import dev.hotwire.core.turbo.util.displayBackButtonAsCloseIcon * to this class. Note: This class should not need to be used directly * from within your app. */ -class TurboFragmentDelegate(private val navDestination: HotwireNavDestination) { +class HotwireFragmentDelegate(private val navDestination: HotwireNavDestination) { private val fragment = navDestination.fragment private val location = navDestination.location private val navigator = navDestination.navigator @@ -51,7 +50,7 @@ class TurboFragmentDelegate(private val navDestination: HotwireNavDestination) { } /** - * Provides a hook to Turbo when the Fragment has been started again after a dialog has + * Provides a hook when the Fragment has been started again after a dialog has * been dismissed/canceled and no result is passed back. */ fun onStartAfterDialogCancel() { @@ -59,7 +58,7 @@ class TurboFragmentDelegate(private val navDestination: HotwireNavDestination) { } /** - * Provides a hook to Turbo when a Fragment has been started again after receiving a + * Provides a hook when a Fragment has been started again after receiving a * modal result. Will navigate if the result indicates it should. */ fun onStartAfterModalResult(result: SessionModalResult) { @@ -70,7 +69,7 @@ class TurboFragmentDelegate(private val navDestination: HotwireNavDestination) { } /** - * Provides a hook to Turbo when the dialog has been canceled. If there is a modal + * Provides a hook when the dialog has been canceled. If there is a modal * result, an event will be created in [SessionViewModel] that can be observed. */ fun onDialogCancel() { @@ -81,7 +80,7 @@ class TurboFragmentDelegate(private val navDestination: HotwireNavDestination) { } /** - * Provides a hook to Turbo when the dialog has been dismissed. + * Provides a hook when the dialog has been dismissed. */ fun onDialogDismiss() { logEvent("fragment.onDialogDismiss", "location" to location) diff --git a/core/src/main/kotlin/dev/hotwire/core/navigation/fragments/HotwireWebBottomSheetFragment.kt b/core/src/main/kotlin/dev/hotwire/core/navigation/fragments/HotwireWebBottomSheetFragment.kt index 12a616e..e3a8d6d 100644 --- a/core/src/main/kotlin/dev/hotwire/core/navigation/fragments/HotwireWebBottomSheetFragment.kt +++ b/core/src/main/kotlin/dev/hotwire/core/navigation/fragments/HotwireWebBottomSheetFragment.kt @@ -10,7 +10,6 @@ import android.view.ViewGroup import androidx.activity.result.ActivityResultLauncher import dev.hotwire.core.R import dev.hotwire.core.bridge.BridgeDelegate -import dev.hotwire.core.turbo.delegates.TurboWebFragmentDelegate import dev.hotwire.core.turbo.errors.VisitError import dev.hotwire.core.turbo.nav.HotwireDestination import dev.hotwire.core.turbo.util.TURBO_REQUEST_CODE_FILES @@ -25,8 +24,8 @@ import dev.hotwire.core.turbo.views.TurboWebView * For native bottom sheet fragments, refer to [HotwireBottomSheetFragment]. */ @HotwireDestination(uri = "turbo://fragment/web/modal/sheet") -open class HotwireWebBottomSheetFragment : HotwireBottomSheetFragment(), TurboWebFragmentCallback { - private lateinit var webDelegate: TurboWebFragmentDelegate +open class HotwireWebBottomSheetFragment : HotwireBottomSheetFragment(), HotwireWebFragmentCallback { + private lateinit var webDelegate: HotwireWebFragmentDelegate private val bridgeDelegate by lazy { BridgeDelegate(location = location, destination = this) @@ -34,7 +33,7 @@ open class HotwireWebBottomSheetFragment : HotwireBottomSheetFragment(), TurboWe override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - webDelegate = TurboWebFragmentDelegate(delegate, this, this) + webDelegate = HotwireWebFragmentDelegate(delegate, this, this) } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { @@ -99,7 +98,7 @@ open class HotwireWebBottomSheetFragment : HotwireBottomSheetFragment(), TurboWe } // ---------------------------------------------------------------------------- - // TurboWebFragmentCallback interface + // HotwireWebFragmentCallback interface // ---------------------------------------------------------------------------- /** diff --git a/core/src/main/kotlin/dev/hotwire/core/navigation/fragments/HotwireWebFragment.kt b/core/src/main/kotlin/dev/hotwire/core/navigation/fragments/HotwireWebFragment.kt index 51f21a7..ec00647 100644 --- a/core/src/main/kotlin/dev/hotwire/core/navigation/fragments/HotwireWebFragment.kt +++ b/core/src/main/kotlin/dev/hotwire/core/navigation/fragments/HotwireWebFragment.kt @@ -9,7 +9,6 @@ import android.view.ViewGroup import androidx.activity.result.ActivityResultLauncher import dev.hotwire.core.R import dev.hotwire.core.bridge.BridgeDelegate -import dev.hotwire.core.turbo.delegates.TurboWebFragmentDelegate import dev.hotwire.core.turbo.errors.VisitError import dev.hotwire.core.turbo.nav.HotwireDestination import dev.hotwire.core.turbo.session.SessionModalResult @@ -25,8 +24,8 @@ import dev.hotwire.core.turbo.views.TurboWebView * For native fragments, refer to [HotwireFragment]. */ @HotwireDestination(uri = "turbo://fragment/web") -open class HotwireWebFragment : HotwireFragment(), TurboWebFragmentCallback { - private lateinit var webDelegate: TurboWebFragmentDelegate +open class HotwireWebFragment : HotwireFragment(), HotwireWebFragmentCallback { + private lateinit var webDelegate: HotwireWebFragmentDelegate private val bridgeDelegate by lazy { BridgeDelegate(location = location, destination = this) @@ -34,7 +33,7 @@ open class HotwireWebFragment : HotwireFragment(), TurboWebFragmentCallback { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - webDelegate = TurboWebFragmentDelegate(delegate, this, this) + webDelegate = HotwireWebFragmentDelegate(delegate, this, this) } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { @@ -117,7 +116,7 @@ open class HotwireWebFragment : HotwireFragment(), TurboWebFragmentCallback { } // ---------------------------------------------------------------------------- - // TurboWebFragmentCallback interface + // HotwireWebFragmentCallback interface // ---------------------------------------------------------------------------- /** diff --git a/core/src/main/kotlin/dev/hotwire/core/navigation/fragments/HotwireWebFragmentCallback.kt b/core/src/main/kotlin/dev/hotwire/core/navigation/fragments/HotwireWebFragmentCallback.kt index f4decda..4e39bd6 100644 --- a/core/src/main/kotlin/dev/hotwire/core/navigation/fragments/HotwireWebFragmentCallback.kt +++ b/core/src/main/kotlin/dev/hotwire/core/navigation/fragments/HotwireWebFragmentCallback.kt @@ -8,10 +8,10 @@ import dev.hotwire.core.turbo.views.TurboWebChromeClient import dev.hotwire.core.turbo.views.TurboWebView /** - * Callback interface to be implemented by a [TurboWebFragment], - * [TurboWebBottomSheetDialogFragment], or subclass. + * Callback interface to be implemented by a [HotwireWebFragment], + * [HotwireWebBottomSheetFragment], or subclass. */ -interface TurboWebFragmentCallback { +interface HotwireWebFragmentCallback { /** * The TurboView instance located in the Fragment's view. */ diff --git a/core/src/main/kotlin/dev/hotwire/core/turbo/delegates/TurboWebFragmentDelegate.kt b/core/src/main/kotlin/dev/hotwire/core/navigation/fragments/HotwireWebFragmentDelegate.kt similarity index 94% rename from core/src/main/kotlin/dev/hotwire/core/turbo/delegates/TurboWebFragmentDelegate.kt rename to core/src/main/kotlin/dev/hotwire/core/navigation/fragments/HotwireWebFragmentDelegate.kt index d4df528..ebb0364 100644 --- a/core/src/main/kotlin/dev/hotwire/core/turbo/delegates/TurboWebFragmentDelegate.kt +++ b/core/src/main/kotlin/dev/hotwire/core/navigation/fragments/HotwireWebFragmentDelegate.kt @@ -1,4 +1,4 @@ -package dev.hotwire.core.turbo.delegates +package dev.hotwire.core.navigation.fragments import android.content.Intent import android.graphics.Bitmap @@ -11,7 +11,6 @@ import androidx.lifecycle.lifecycleScope import androidx.lifecycle.whenStateAtLeast import dev.hotwire.core.turbo.config.pullToRefreshEnabled import dev.hotwire.core.turbo.errors.VisitError -import dev.hotwire.core.navigation.fragments.TurboWebFragmentCallback import dev.hotwire.core.turbo.nav.HotwireNavDestination import dev.hotwire.core.turbo.session.SessionCallback import dev.hotwire.core.turbo.session.SessionModalResult @@ -29,10 +28,10 @@ import kotlin.random.Random * Provides all the hooks for a web Fragment to delegate its lifecycle events * to this class. */ -internal class TurboWebFragmentDelegate( - private val delegate: TurboFragmentDelegate, +internal class HotwireWebFragmentDelegate( + private val delegate: HotwireFragmentDelegate, private val navDestination: HotwireNavDestination, - private val callback: TurboWebFragmentCallback + private val callback: HotwireWebFragmentCallback ) : SessionCallback { private val location = navDestination.location @@ -85,7 +84,7 @@ internal class TurboWebFragmentDelegate( } /** - * Provides a hook to Turbo when a fragment has been started again after receiving a + * Provides a hook when a fragment has been started again after receiving a * modal result. Will navigate if the result indicates it should. */ fun onStartAfterModalResult(result: SessionModalResult) { @@ -96,9 +95,9 @@ internal class TurboWebFragmentDelegate( } /** - * Provides a hook to Turbo when the fragment has been started again after a dialog has + * Provides a hook when the fragment has been started again after a dialog has * been dismissed/canceled and no result is passed back. Initializes all necessary views and - * executes the Turbo visit. + * executes the visit. */ fun onStartAfterDialogCancel() { initNavigationVisit() @@ -106,7 +105,7 @@ internal class TurboWebFragmentDelegate( } /** - * Provides a hook to Turbo when the dialog has been canceled. Detaches the WebView + * Provides a hook when the dialog has been canceled. Detaches the WebView * before navigation. */ fun onDialogCancel() { @@ -115,7 +114,7 @@ internal class TurboWebFragmentDelegate( } /** - * Provides a hook to Turbo when the dialog has been dismissed. Detaches the WebView + * Provides a hook when the dialog has been dismissed. Detaches the WebView * before navigation. */ fun onDialogDismiss() { @@ -145,7 +144,7 @@ internal class TurboWebFragmentDelegate( } /** - * Displays the error view that's implemented via [TurboWebFragmentCallback.createErrorView]. + * Displays the error view that's implemented via [HotwireWebFragmentCallback.createErrorView]. */ fun showErrorView(error: VisitError) { turboView?.addErrorView(callback.createErrorView(error)) @@ -352,7 +351,7 @@ internal class TurboWebFragmentDelegate( destinationIdentifier = identifier, restoreWithCachedSnapshot = restoreWithCachedSnapshot, reload = reload, - callback = this@TurboWebFragmentDelegate, + callback = this@HotwireWebFragmentDelegate, options = options.copy(snapshotHTML = snapshot) ) ) diff --git a/core/src/main/kotlin/dev/hotwire/core/turbo/delegates/TurboNestedFragmentDelegate.kt b/core/src/main/kotlin/dev/hotwire/core/navigation/navigator/NestedNavigatorHostDelegate.kt similarity index 79% rename from core/src/main/kotlin/dev/hotwire/core/turbo/delegates/TurboNestedFragmentDelegate.kt rename to core/src/main/kotlin/dev/hotwire/core/navigation/navigator/NestedNavigatorHostDelegate.kt index f3ff901..ebf8f9f 100644 --- a/core/src/main/kotlin/dev/hotwire/core/turbo/delegates/TurboNestedFragmentDelegate.kt +++ b/core/src/main/kotlin/dev/hotwire/core/navigation/navigator/NestedNavigatorHostDelegate.kt @@ -1,9 +1,7 @@ -package dev.hotwire.core.turbo.delegates +package dev.hotwire.core.navigation.navigator import androidx.annotation.IdRes import androidx.fragment.app.Fragment -import dev.hotwire.core.navigation.navigator.NavigatorHost -import dev.hotwire.core.navigation.navigator.Navigator /** * A simplified delegate that can be used when a [NavigatorHost] is nested @@ -15,10 +13,10 @@ import dev.hotwire.core.navigation.navigator.Navigator * * @property fragment The Fragment to bind this delegate to. * @param navigatorHostId The resource ID of the [NavigatorHost] - * instance hosted in your Activity's layout resource. + * instance hosted in your Fragment's layout resource. */ @Suppress("unused", "MemberVisibilityCanBePrivate") -class TurboNestedFragmentDelegate(val fragment: Fragment, navigatorHostId: Int) { +class NestedNavigatorHostDelegate(val fragment: Fragment, navigatorHostId: Int) { val navigatorHost by lazy { findNavigatorHost(navigatorHostId) } val navigator: Navigator diff --git a/core/src/main/kotlin/dev/hotwire/core/turbo/nav/HotwireNavDestination.kt b/core/src/main/kotlin/dev/hotwire/core/turbo/nav/HotwireNavDestination.kt index 5360642..2f9357b 100644 --- a/core/src/main/kotlin/dev/hotwire/core/turbo/nav/HotwireNavDestination.kt +++ b/core/src/main/kotlin/dev/hotwire/core/turbo/nav/HotwireNavDestination.kt @@ -16,8 +16,8 @@ import dev.hotwire.core.navigation.navigator.Navigator import dev.hotwire.core.navigation.routing.Router import dev.hotwire.core.turbo.config.PathConfigurationProperties import dev.hotwire.core.turbo.config.context -import dev.hotwire.core.turbo.delegates.TurboFragmentDelegate -import dev.hotwire.core.turbo.delegates.TurboNestedFragmentDelegate +import dev.hotwire.core.navigation.fragments.HotwireFragmentDelegate +import dev.hotwire.core.navigation.navigator.NestedNavigatorHostDelegate import dev.hotwire.core.turbo.visit.VisitAction /** @@ -71,7 +71,7 @@ interface HotwireNavDestination { /** * Gets the delegate instance that handles the Fragment's lifecycle events. */ - fun delegate(): TurboFragmentDelegate + fun delegate(): HotwireFragmentDelegate /** * Returns the [Toolbar] used for navigation by the given view. @@ -102,7 +102,7 @@ interface HotwireNavDestination { /** * Gets the navigator that will be used for navigating to `newLocation`. You should - * not have to override this, unless you're using a [TurboNestedFragmentDelegate] to provide + * not have to override this, unless you're using a [NestedNavigatorHostDelegate] to provide * sub-navigation within your current Fragment destination and would like custom behavior. */ fun navigatorForNavigation(newLocation: String): Navigator {