### Koin Setup and Compose Integration Example Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/koin-modules.md Provides a complete example of setting up Koin with toolkitModule and injecting dependencies within a Compose screen. ```kotlin fun setupKoin() { startKoin { modules(toolkitModule) } } @Composable fun MyScreen() { val dispatcherProvider: DispatcherProvider = koinInject() val repository: AboutRepository = koinInject() val appScope: ApplicationScope = koinInject() LaunchedEffect(Unit) { repository.developer .flowOn(dispatcherProvider.io) .collect { println("Developer: ${it.name}") } } } ``` -------------------------------- ### Android Application Setup Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/configuration.md The toolkit automatically configures Android-specific implementations when running on Android. No explicit setup is needed beyond the basic Koin setup. ```kotlin // In your MainActivity or Application class class MyApplication : Application() { override fun onCreate() { super.onCreate() setupKoin() } } ``` -------------------------------- ### Koin Dependency Injection Setup Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/configuration.md Include the toolkitModule in your Koin setup to configure the toolkit's dependencies. ```kotlin fun setupKoin() { startKoin { modules( toolkitModule, // Add the toolkit module // Your app's modules... ) } } ``` -------------------------------- ### JVM Application Setup Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/configuration.md For JVM applications, ensure desktop support is available and necessary permissions are granted for URL launching. ```kotlin // In your main function fun main() { setupKoin() // Start your application } ``` -------------------------------- ### Gravatar Usage Example Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/about-model.md Shows how to create a Gravatar instance and retrieve its image URL with a specified size. ```kotlin val gravatar = Developer.Picture.Gravatar("abc123def456") val url = gravatar.getImageUrl(256) // Returns URL with s=256 parameter ``` -------------------------------- ### Initialize Koin with Modules Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/koin-modules.md Set up Koin by providing your application's modules in the main entry point. This should be done once when your application starts. ```kotlin fun main() { startKoin { modules( toolkitModule, // Your app's modules... ) } } ``` -------------------------------- ### Configure Koin for Toolkit Integration Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/INDEX.md Start the Koin dependency injection framework and include the pre-configured toolkitModule for easy integration. ```kotlin startKoin { modules(toolkitModule) } ``` -------------------------------- ### UrlLaunchResult Failure.Error Handling Example Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/types.md Shows how to catch and log the exception when a UrlLaunchResult.Failure.Error occurs. ```kotlin when (result) { is UrlLaunchResult.Failure.Error -> { log("Error: ${result.exception.message}") } } ``` -------------------------------- ### Include toolkitModule in Koin Setup Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/configuration.md Ensure the `toolkitModule` is included when setting up Koin to resolve `DispatcherProvider` issues. ```kotlin startKoin { modules(toolkitModule) // Add this } ``` -------------------------------- ### Displaying Link Icon Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/about-model.md Example of how to retrieve and display the icon for a developer link using its 'icon' property. ```kotlin val link = Developer.Link( name = "GitHub", url = "https://github.com/yasanglass" ) val painter = painterResource(resource = link.icon) Image(painter, contentDescription = link.name) ``` -------------------------------- ### Full Developer Links Usage Example Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/about-model.md Demonstrates how to group and display all developer links by their category, showing the name, type, and URL for each link. ```kotlin val developer = Developer() developer.links .groupBy { it.group } .forEach { (group, links) -> println("=== $group ===") links.forEach { link -> println("${link.name} (${link.type}): ${link.url}") } } ``` -------------------------------- ### Custom ViewAction Implementation Example Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/types.md Demonstrates implementing the `ViewAction` interface for a custom sealed interface, defining actions such as navigation or showing a snackbar. ```kotlin sealed interface MyAction : ViewAction { data class NavigateTo(val screen: String) : MyAction data class ShowSnackbar(val message: String) : MyAction } ``` -------------------------------- ### UrlLaunchResult Pattern Matching Example Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/types.md Demonstrates how to use a when expression to handle different outcomes of UrlLaunchResult. ```kotlin when (result) { is UrlLaunchResult.Success -> println("URL launched") else -> {} } ``` -------------------------------- ### Custom ViewState Implementation Example Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/types.md Shows how to implement the `ViewState` interface for a custom state data class, including loading and data properties. ```kotlin data class MyState( val isLoading: Boolean = false, val data: List = emptyList(), ) : ViewState ``` -------------------------------- ### Complete Toolkit Configuration with Koin Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/configuration.md Set up Koin for dependency injection in your application, including the toolkitModule and optional overrides for dispatchers or repositories. This example also shows how to inject dependencies and observe ViewModel state in a Compose screen. ```kotlin // In your main app file fun configureToolkit() { startKoin { modules( // Add toolkit module (includes all dependencies) toolkitModule, // Optional: override specific dependencies module { // Custom dispatcher provider single { MyDispatcherProvider() } // Custom repository single { CustomAboutRepository() } }, // Your app's modules appModule, ) } } // In Compose @Composable fun MyScreen() { val viewModel = remember { HomeViewModel() } val state by viewModel.viewState.collectAsStateWithLifecycle() val dispatcherProvider: DispatcherProvider = koinInject() val repository: AboutRepository = koinInject() ViewActionEffect(viewModel.viewAction) { action -> when (action) { is HomeAction.NavigateTo -> navigate(action.route) is HomeAction.ShowMessage -> showMessage(action.text) } } // UI content } ``` -------------------------------- ### Toolkit Koin Module Setup Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/koin-modules.md Defines the main Koin module for the Toolkit library, including core dependencies and platform-specific modules. ```kotlin @OptIn(InternalToolkitApi::class) public val toolkitModule: Module = module { includes(platformModule) single { createDefaultDispatcherProvider() } single { CoroutineScope(SupervisorJob() + get().default) } factoryOf(::AboutRepositoryImpl) } ``` -------------------------------- ### Collect Developer Information Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/about-repository.md Example of how to collect and display developer information from the AboutRepository. Ensure AboutRepository is injected via Koin. ```kotlin val repository: AboutRepository = koinInject() repository.developer.collect { println("Developer: ${it.name}") println("Bio: ${it.biography}") it.links.forEach { println("${it.name}: ${it.url}") } } ``` -------------------------------- ### Handling Unsupported Failure with Callback Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/errors.md This example demonstrates handling an Unsupported failure using a callback lambda. It provides a fallback mechanism when URL launching is not possible on the device. ```kotlin urlLauncher.launch("https://example.com") { failure -> when (failure) { is UrlLaunchResult.Failure.Unsupported -> { // Fallback: show URL in UI, copy to clipboard, etc. showUserMessage("Cannot open URL on this device") } else -> {} } } ``` -------------------------------- ### UrlLaunchResult isSuccess Usage Example Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/types.md Demonstrates checking the `isSuccess` property of a UrlLaunchResult to determine if the URL launch was successful. ```kotlin val result = urlLauncher.launch("https://example.com") if (result.isSuccess) { println("Success") } ``` -------------------------------- ### LoadingIndicatorPreview with Boolean States Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/compose-preview.md An example of a composable preview that uses BooleanPreviewParameterProvider to conditionally display a loading indicator or content. ```kotlin @Preview @Composable fun LoadingIndicatorPreview( @PreviewParameter(BooleanPreviewParameterProvider::class) isVisible: Boolean, ) { if (isVisible) { CircularProgressIndicator() } else { Text("Content loaded") } } ``` -------------------------------- ### UrlLaunchResult Failure.Unsupported Data Object Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/types.md Indicates that the current platform does not support launching URLs, for example, if no browser is available. ```kotlin public data object Unsupported : UrlLaunchResult.Failure ``` -------------------------------- ### Using VerticalAnimatedVisibility Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/compose-layout.md Demonstrates how to use the VerticalAnimatedVisibility composable to toggle the visibility of content with a button click. This example shows basic usage with a Text composable. ```kotlin var expanded by remember { mutableStateOf(false) } VerticalAnimatedVisibility( visible = expanded, modifier = Modifier.fillMaxWidth(), ) { Text("Expanded content") } Button(onClick = { expanded = !expanded }) { Text("Toggle") } ``` -------------------------------- ### firstBlocking() Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/core-coroutines.md Blocking extension to get the first value from a Flow. Only available on non-web platforms. ```APIDOC ## firstBlocking() ### Description Blocking extension to get the first value from a Flow. Only available on non-web platforms. ### Signature ```kotlin public fun Flow.firstBlocking(): T ``` ### Generics | Generic | Constraint | Description | |---------|-----------|-------------| | T | None | The type of the values emitted by the flow | ### Return Type `T` Suspends until the first value is emitted, then returns it. Uses `runBlocking` internally. ### Availability Non-Web Platforms only (Android, JVM, iOS) ### Example ```kotlin val value: Int = flowOf(1, 2, 3).firstBlocking() // Returns 1 ``` ### Note This function uses `runBlocking` which should be used carefully in production code, as it blocks the current thread. ``` -------------------------------- ### Handling Error Failure with Callback Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/errors.md This example shows how to handle an Error failure using a callback. It logs the error to an analytics service and informs the user about the unexpected issue. ```kotlin urlLauncher.launch("https://example.com") { failure -> when (failure) { is UrlLaunchResult.Failure.Error -> { analytics.logError("url_launch_error", failure.exception) showUserMessage("An unexpected error occurred") } else -> {} } } ``` -------------------------------- ### CheckboxPreview with Nullable Boolean States Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/compose-preview.md An example composable preview using NullableBooleanPreviewParameterProvider to represent checked, unchecked, and indeterminate states of a checkbox. ```kotlin @Preview @Composable fun CheckboxPreview( @PreviewParameter(NullableBooleanPreviewParameterProvider::class) isChecked: Boolean?, ) { when (isChecked) { true -> Icon(Icons.Filled.Check, "Checked") false -> Icon(Icons.Outlined.Check, "Unchecked") null -> Icon(Icons.Default.IndeterminateCheckBox, "Indeterminate") } } ``` -------------------------------- ### Custom ViewEvent Implementation Example Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/types.md Illustrates implementing the `ViewEvent` interface for a custom sealed interface, defining events like loading data by ID or refreshing data. ```kotlin sealed interface MyEvent : ViewEvent { data class LoadData(val id: String) : MyEvent data object RefreshData : MyEvent } ``` -------------------------------- ### Updating and Getting ViewState in ToolkitViewModel Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/compose-viewmodel.md Illustrates updating the view state and immediately retrieving the new state value using updateAndGetViewState. ```kotlin val newState = viewModel.updateAndGetViewState { copy(counter = counter + 1) } println("New counter: ${newState.counter}") ``` -------------------------------- ### ToolkitViewModel Usage Example Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/configuration.md Extend ToolkitViewModel to create your own ViewModels for Compose applications. Define your state, events, and actions to manage UI logic and data flow. ```kotlin data class HomeState(val isLoading: Boolean = false, val items: List = emptyList()) : ViewState sealed interface HomeEvent : ViewEvent { data class LoadData(val id: String) : HomeEvent data object RefreshData : HomeEvent } sealed interface HomeAction : ViewAction { data class NavigateTo(val route: String) : HomeAction data class ShowMessage(val text: String) : HomeAction } class HomeViewModel : ToolkitViewModel() { override fun defaultViewState(): HomeState = HomeState() override suspend fun onViewEvent(event: HomeEvent) { when (event) { is HomeEvent.LoadData -> loadData(event.id) HomeEvent.RefreshData -> refreshData() } } } ``` -------------------------------- ### Implementing onViewEvent in ToolkitViewModel Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/compose-viewmodel.md Provides an example of implementing the abstract suspend function onViewEvent to handle incoming view events within a concrete ViewModel. ```kotlin override suspend fun onViewEvent(event: MyEvent) { when (event) { is MyEvent.LoadData -> loadData(event.id) is MyEvent.RefreshData -> refreshData() } } ``` -------------------------------- ### Getting and Updating ViewState in ToolkitViewModel Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/compose-viewmodel.md Shows how to retrieve the old view state before applying a transformation and updating the state using getAndUpdateViewState. ```kotlin val oldState = viewModel.getAndUpdateViewState { copy(counter = counter + 1) } println("Old counter: ${oldState.counter}") ``` -------------------------------- ### Get Result Value or Default, Rethrow Cancellation Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/core-coroutines.md Use `getOrElseOrRethrowCancellation` to get a Result's value or a default from an `onFailure` function. It rethrows on cancellation and executes the handler for other failures. ```kotlin public suspend fun Result.getOrElseOrRethrowCancellation(onFailure: (Throwable) -> T): T ``` ```kotlin val result: Result = performOperation() val value = result.getOrElseOrRethrowCancellation { error -> log("Operation failed: $error") 0 // Default value } ``` -------------------------------- ### Developer Instance Usage Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/about-model.md Demonstrates how to create a Developer instance and access its properties, including iterating through the links. ```kotlin val developer = Developer() println("Name: ${developer.name}") println("Bio: ${developer.biography}") developer.links.forEach { link -> println("${link.name}: ${link.url}") } ``` -------------------------------- ### Opt-in to ExperimentalToolkitApi Usage Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/core-annotations.md Shows how to opt-in to using APIs annotated with ExperimentalToolkitApi, either on a per-function basis or at the file level. ```kotlin @OptIn(ExperimentalToolkitApi::class) fun myFunction() { experimentalFunction() } ``` ```kotlin @file:OptIn(ExperimentalToolkitApi::class) package my.package ``` -------------------------------- ### launch(url: String) Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/core-url-launcher.md Launches the given URL in the system's default browser or application. It returns a result indicating success or failure. ```APIDOC ## launch(url: String) ### Description Launches the given URL in the system's default browser or application. ### Method `suspend fun` ### Parameters #### Path Parameters - **url** (String) - Required - The URL to launch ### Return Type `UrlLaunchResult` - Returns a sealed interface indicating success or failure of the launch attempt. ### Example ```kotlin val urlLauncher: UrlLauncher = koinInject() val result = urlLauncher.launch("https://example.com") when (result) { is UrlLaunchResult.Success -> println("URL launched successfully") is UrlLaunchResult.Failure.InvalidUrl -> println("Invalid URL format") is UrlLaunchResult.Failure.Unsupported -> println("No browser available") is UrlLaunchResult.Failure.Error -> println("Error: ${result.exception.message}") } ``` ``` -------------------------------- ### Launch URL with UrlLauncher Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/INDEX.md Use the UrlLauncher to open a given URL and handle the different launch results, including success, invalid URL, unsupported platform, or other errors. ```kotlin val urlLauncher: UrlLauncher = koinInject() val result = urlLauncher.launch("https://example.com") when (result) { is UrlLaunchResult.Success -> showSuccess() is UrlLaunchResult.Failure.InvalidUrl -> showInvalidUrl() is UrlLaunchResult.Failure.Unsupported -> showUnsupported() is UrlLaunchResult.Failure.Error -> showError(result.exception) } ``` -------------------------------- ### Injecting DispatcherProvider Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/koin-modules.md Demonstrates how to inject the DispatcherProvider singleton using koinInject(). ```kotlin val dispatcherProvider: DispatcherProvider = koinInject() ``` -------------------------------- ### Injecting ApplicationScope Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/koin-modules.md Shows how to inject the ApplicationScope singleton for launching long-running background tasks. ```kotlin val appScope: ApplicationScope = koinInject() appScope.launch { // Background task for app lifetime } ``` -------------------------------- ### Using BooleanPreviewParameterProvider in Compose Preview Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/compose-preview.md Demonstrates how to use BooleanPreviewParameterProvider with @Preview and @PreviewParameter to generate previews for different boolean states of a composable. ```kotlin @Preview @Composable fun MyComponentPreview( @PreviewParameter(BooleanPreviewParameterProvider::class) isEnabled: Boolean, ) { MyComponent(enabled = isEnabled) } ``` -------------------------------- ### launch(url: String, onFailure: (UrlLaunchResult.Failure) -> Unit) Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/core-url-launcher.md Launches the given URL with an optional failure callback. The success of the launch is ignored when this overload is used. ```APIDOC ## launch(url: String, onFailure: (UrlLaunchResult.Failure) -> Unit) ### Description Launches the given URL with an optional failure callback. Success is ignored. ### Method `suspend fun` ### Parameters #### Path Parameters - **url** (String) - Required - The URL to launch - **onFailure** ( (UrlLaunchResult.Failure) -> Unit ) - Required - Callback invoked on launch failure ### Return Type `Unit` ### Example ```kotlin val urlLauncher: UrlLauncher = koinInject() urlLauncher.launch("https://example.com") { failure -> when (failure) { is UrlLaunchResult.Failure.InvalidUrl -> handleInvalidUrl() is UrlLaunchResult.Failure.Unsupported -> handleUnsupported() is UrlLaunchResult.Failure.Error -> handleError(failure.exception) } } ``` ``` -------------------------------- ### MockUrlLauncher Implementation Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/configuration.md A sample implementation of the UrlLauncher interface for testing. It defines specific behaviors for launching URLs based on their format. ```kotlin class MockUrlLauncher : UrlLauncher { override suspend fun launch(url: String): UrlLaunchResult { return when { url.isEmpty() -> UrlLaunchResult.Failure.InvalidUrl url.startsWith("https://") -> UrlLaunchResult.Success else -> UrlLaunchResult.Failure.Unsupported } } } ``` -------------------------------- ### Get a Function to Send View Events Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/compose-viewmodel.md Composable that returns a function to send view events, managing the coroutine scope. Requires a ToolkitViewModel. ```kotlin @Composable public fun rememberSendViewEvent( viewModel: ToolkitViewModel, ): ((E) -> Unit) ``` ```kotlin @Composable fun MyScreen(viewModel: MyViewModel) { val sendEvent = rememberSendViewEvent(viewModel) Button(onClick = { sendEvent(MyEvent.UserClicked) }) { Text("Click me") } } ``` -------------------------------- ### Add Core Module and Use Directly Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/INDEX.md Include only the core module if Compose is not needed, and use components directly without Koin by manually instantiating them. ```kotlin implementation("glass.yasan.toolkit:core:1.7.15") // Use directly without Koin if preferred val dispatcher = DefaultDispatcherProvider() val launcher = UrlLauncherImpl(dispatcher) // Platform-dependent constructor ``` -------------------------------- ### Launch URL with Result Handling Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/core-url-launcher.md Launches a URL and handles the result, checking for success or various failure types. Use this when you need to know the outcome of the URL launch. ```kotlin val urlLauncher: UrlLauncher = koinInject() val result = urlLauncher.launch("https://example.com") when (result) { is UrlLaunchResult.Success -> println("URL launched successfully") is UrlLaunchResult.Failure.InvalidUrl -> println("Invalid URL format") is UrlLaunchResult.Failure.Unsupported -> println("No browser available") is UrlLaunchResult.Failure.Error -> println("Error: ${result.exception.message}") } ``` -------------------------------- ### Injecting AboutRepository Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/koin-modules.md Demonstrates injecting the AboutRepository factory using koinInject(). ```kotlin val repository: AboutRepository = koinInject() ``` -------------------------------- ### Custom AboutRepository Implementation (Singleton) Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/configuration.md Alternatively, configure your custom AboutRepository as a singleton if a single instance is desired throughout the application. ```kotlin module { single { YourAboutRepositoryImpl() } } ``` -------------------------------- ### Get First Flow Value Blocking Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/core-coroutines.md Use `firstBlocking` to retrieve the first value from a Flow on non-web platforms. This method blocks the current thread and should be used with caution. ```kotlin public fun Flow.firstBlocking(): T ``` ```kotlin val value: Int = flowOf(1, 2, 3).firstBlocking() // Returns 1 ``` -------------------------------- ### Inject and Launch Tasks with ApplicationScope Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/configuration.md Properly inject the `ApplicationScope` before launching tasks to ensure they execute correctly. Tasks may not run if the scope is not properly initialized. ```kotlin val scope: ApplicationScope = koinInject() // Must inject first scope.launch { /* tasks won't run if scope is not properly initialized */ } ``` -------------------------------- ### Inject Dependencies in Composables Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/koin-modules.md Use the `koinInject()` function to retrieve instances of your Koin-managed dependencies within Jetpack Compose UI components. Ensure Koin has been started before calling this. ```kotlin @Composable fun MyScreen() { val dispatcher: DispatcherProvider = koinInject() val repository: AboutRepository = koinInject() // ... } ``` -------------------------------- ### ToolkitViewModel Methods Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/compose-viewmodel.md Provides methods for initializing state, updating the view state, and handling view events. Includes abstract methods that require implementation. ```APIDOC ## Methods ### defaultViewState() **Description:** Abstract method that must be implemented to provide the initial view state. **Return Type:** `S` **Implementation Required:** Yes ### updateViewState(transform: S.() -> S) **Description:** Updates the view state by applying a transformation function. **Parameters:** - **transform** (S.() -> S) - Required - Lambda that receives current state and returns new state **Return Type:** `Unit` ### updateAndGetViewState(transform: S.() -> S) **Description:** Updates the view state and returns the new state value. **Parameters:** - **transform** (S.() -> S) - Required - Lambda that receives current state and returns new state **Return Type:** `S` (the new state after transformation) ### getAndUpdateViewState(transform: S.() -> S) **Description:** Returns the old view state before applying the transformation. **Parameters:** - **transform** (S.() -> S) - Required - Lambda that receives current state and returns new state **Return Type:** `S` (the old state before transformation) ### sendViewEvent(event: E) **Description:** Sends a view event to be processed. Events are buffered and processed sequentially. **Parameters:** - **event** (E) - Required - The event to send **Return Type:** `Unit` **Requires Opt-In:** `@OptIn(DelicateViewEventApi::class)` required ### onViewEvent(event: E) **Description:** Abstract suspend function that must be implemented to handle view events. **Return Type:** `Unit` **Implementation Required:** Yes ``` -------------------------------- ### Get Result Value or Null, Rethrow Cancellation Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/core-coroutines.md Use `getOrNullOrRethrowCancellation` to safely extract a value from a Result. It returns null for non-cancellation failures and rethrows if the failure is a coroutine cancellation. ```kotlin public suspend fun Result.getOrNullOrRethrowCancellation(): T? ``` ```kotlin val result: Result = try { Result.success(fetchData()) } catch (e: Exception) { Result.failure(e) } val data = result.getOrNullOrRethrowCancellation() // Rethrows on cancellation, returns null on other errors ``` -------------------------------- ### Using NullableBooleanPreviewParameterProvider in Compose Preview Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/compose-preview.md Demonstrates how to use NullableBooleanPreviewParameterProvider with @Preview and @PreviewParameter to generate previews for nullable boolean states. ```kotlin @Preview @Composable fun MyComponentPreview( @PreviewParameter(NullableBooleanPreviewParameterProvider::class) state: Boolean?, ) { MyComponent(state = state) } ``` -------------------------------- ### Log URL Launch Events with Analytics Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/errors.md Log URL launch outcomes, including success and specific failure types, using an analytics service. ```kotlin val result = urlLauncher.launch("https://example.com") when (result) { is UrlLaunchResult.Success -> { analytics.logEvent("url_opened", mapOf("url" to url)) } is UrlLaunchResult.Failure.InvalidUrl -> { analytics.logError("invalid_url", mapOf("url" to url)) } is UrlLaunchResult.Failure.Unsupported -> { analytics.logEvent("url_launch_unsupported") } is UrlLaunchResult.Failure.Error -> { analytics.logError("url_launch_error", mapOf("exception" to result.exception.message)) } } ``` -------------------------------- ### Get Value or Default, Rethrow Cancellation with getOrElseOrRethrowCancellation() Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/errors.md Extract a value from a Result, providing a fallback handler for errors, while ensuring coroutine cancellations are rethrown. This combines error handling with cancellation support. ```kotlin val result: Result = performOperation() val value = result.getOrElseOrRethrowCancellation { error -> log("Operation failed: $error") -1 // Default value } ``` -------------------------------- ### Use DispatcherProvider for Coroutine Launching Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/core-coroutines.md Shows how to use the `DispatcherProvider` to launch coroutines on specific dispatchers for I/O or CPU-intensive operations. ```kotlin val dispatcherProvider: DispatcherProvider = koinInject() launch(dispatcherProvider.io) { // I/O operation val data = fetchData() } launch(dispatcherProvider.default) { // CPU-intensive operation val result = complexCalculation(data) } ``` -------------------------------- ### Convert Flow to StateFlow (Eagerly) Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/compose-viewmodel.md Converts a Flow to a StateFlow using an eager sharing strategy. This is useful when you want the StateFlow to start emitting immediately and maintain its state for the entire ViewModel lifetime. ```kotlin val count: Flow = flowOf(1, 2, 3) val countState = count.stateInEagerly(0) ``` -------------------------------- ### Implementing defaultViewState in ToolkitViewModel Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/compose-viewmodel.md Shows the required implementation of the abstract defaultViewState() method to provide the initial state for a concrete ViewModel. ```kotlin class MyViewModel : ToolkitViewModel() { override fun defaultViewState(): MyState = MyState() } ``` -------------------------------- ### Get Value or Null, Rethrow Cancellation with getOrNullOrRethrowCancellation() Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/errors.md Safely extract a value from a Result, returning null on expected failures but rethrowing on coroutine cancellation. This is useful for graceful error recovery while respecting cancellation. ```kotlin val result: Result = try { Result.success(fetchData()) } catch (e: Exception) { Result.failure(e) } val data = result.getOrNullOrRethrowCancellation() // data is String? (null if failed but not cancelled) // Rethrows if cancelled ``` -------------------------------- ### Convert Flow to StateFlow (Lazily) Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/compose-viewmodel.md Converts a Flow to a StateFlow using a lazy sharing strategy. The StateFlow will only start collecting from the upstream Flow when there are active collectors, making it efficient for resources that shouldn't be active unnecessarily. ```kotlin val data = someFlow.stateInLazily(default) ``` -------------------------------- ### Launch URL with Failure Callback Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/core-url-launcher.md Launches a URL and provides a callback function that is invoked only if the launch fails. Use this when you only need to handle errors and don't require a success notification. ```kotlin val urlLauncher: UrlLauncher = koinInject() urlLauncher.launch("https://example.com") { failure -> when (failure) { is UrlLaunchResult.Failure.InvalidUrl -> handleInvalidUrl() is UrlLaunchResult.Failure.Unsupported -> handleUnsupported() is UrlLaunchResult.Failure.Error -> handleError(failure.exception) } } ``` -------------------------------- ### Use ApplicationScope for Long-Running Tasks Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/core-coroutines.md Demonstrates how to inject and use `ApplicationScope` for launching background tasks that should persist for the application's lifetime. ```kotlin val appScope: ApplicationScope = koinInject() appScope.launch { // Long-running task that lives for app lifetime } ``` -------------------------------- ### Configure Toolkit in Application Class Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/configuration.md Configure the toolkit within your Application class's `onCreate` method to ensure Android context is available for context-dependent services. ```kotlin class MyApp : Application() { override fun onCreate() { super.onCreate() configureToolkit() } } ``` -------------------------------- ### Using ApplicationScope Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/configuration.md Access the ApplicationScope singleton to launch long-running background tasks that should live for the application's lifetime. ```kotlin val appScope: ApplicationScope = koinInject() appScope.launch { while (true) { // Periodic background task delay(5000) doBackgroundWork() } } ``` -------------------------------- ### Complete About Screen Composable Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/about-compose.md This Composable function builds the complete About screen by integrating a banner, content, and scroll functionality. It relies on Koin for dependency injection of AboutRepository and UrlLauncher, and uses Kepko Theme for styling. ```kotlin import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.material3.Divider import androidx.compose.material3.Surface import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp @Composable fun CompleteAboutScreen() { Column( modifier = Modifier .fillMaxSize() .verticalScroll(rememberScrollState()), horizontalAlignment = Alignment.CenterHorizontally, ) { // Header with banner Surface(modifier = Modifier.fillMaxWidth()) { ToolkitDeveloperBanner() } Divider() // Full developer content ToolkitDeveloperContent( modifier = Modifier .weight(1f) .padding(16.dp), onTrackDeveloperLinkClick = { link -> logAnalytics("developer_link", link.name) } ) } } ``` -------------------------------- ### AboutRepositoryImpl Implementation Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/about-repository.md The default implementation of AboutRepository. It emits a predefined Developer object. This is an internal API and should be accessed via dependency injection. ```kotlin @InternalToolkitApi public class AboutRepositoryImpl : AboutRepository { public override val developer: Flow = flowOf(Developer()) } ``` -------------------------------- ### Custom AboutRepository Implementation (Factory) Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/configuration.md Replace the default AboutRepository with your own implementation by defining it as a factory in your Koin modules. ```kotlin startKoin { modules( module { factoryOf { YourAboutRepositoryImpl() } // Rest of config } ) } ``` -------------------------------- ### Sending a ViewEvent with ToolkitViewModel Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/compose-viewmodel.md Demonstrates how to send a view event using sendViewEvent, which requires opting into the DelicateViewEventApi. ```kotlin @OptIn(DelicateViewEventApi::class) viewModel.sendViewEvent(MyEvent.UserClicked) ``` -------------------------------- ### Handle UrlLaunchResult with Callback Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/errors.md Handle URL launch results asynchronously using a callback function that processes failure cases. ```kotlin urlLauncher.launch("https://example.com") { failure -> when (failure) { is UrlLaunchResult.Failure.InvalidUrl -> handleInvalidUrl() is UrlLaunchResult.Failure.Unsupported -> handleUnsupported() is UrlLaunchResult.Failure.Error -> handleError(failure.exception) } } ``` -------------------------------- ### Apply ExperimentalToolkitApi to Functions and Types Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/core-annotations.md Demonstrates how to apply the ExperimentalToolkitApi annotation to functions and sealed interfaces to mark them as experimental. ```kotlin @ExperimentalToolkitApi public fun experimentalFunction() { // Implementation } @ExperimentalToolkitApi public sealed interface ExperimentalType { // Type definition } ``` -------------------------------- ### BooleanPreviewParameterProvider Implementation Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/compose-preview.md Provides a Sequence of Boolean values (true, false) for Compose previews. Use this to test composables with different boolean states. ```kotlin public class BooleanPreviewParameterProvider : PreviewParameterProvider { override val values: Sequence } ``` -------------------------------- ### FlowToStateFlow Conversion Strategies Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/configuration.md Configure Flow-to-StateFlow conversion using stateInEagerly or stateInWhileSubscribed within your ToolkitViewModel. Customize initial values and subscription timeouts as needed. ```kotlin class DataViewModel : ToolkitViewModel() { val dataState = dataFlow.stateInEagerly( initialValue = emptyList() ) val expensiveState = expensiveFlow.stateInWhileSubscribed( stopTimeout = 10.seconds, replayExpiration = Duration.INFINITE, initialValue = default ) } ``` -------------------------------- ### Create a Spacer with Height and Width Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/compose-layout.md Use Spacer to create a composable with explicit height and width dimensions. Apply an optional modifier for further customization. ```kotlin @Composable public fun Spacer( height: Dp, width: Dp, modifier: Modifier = Modifier, ) ``` ```kotlin Spacer(height = 16.dp, width = 8.dp) ``` -------------------------------- ### Display Toolkit Developer Profile Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/about-compose.md Composable that displays the toolkit developer's profile with links and biography. Fetches data from AboutRepository and uses UrlLauncher for opening URLs. Invokes an analytics callback before launching links. ```kotlin @Composable public fun ToolkitDeveloperContent( modifier: Modifier = Modifier, onTrackDeveloperLinkClick: (Developer.Link) -> Unit, ) ``` ```kotlin @Composable fun AboutScreen() { ToolkitDeveloperContent( modifier = Modifier.fillMaxSize(), onTrackDeveloperLinkClick = { link -> analytics.logEvent("developer_link_clicked", mapOf( "link_name" to link.name, "link_type" to link.type.toString() )) } ) } ``` -------------------------------- ### Injecting AboutRepository Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/configuration.md Inject the AboutRepository, which is configured as a factory by default, providing a new instance on each request. ```kotlin val repository: AboutRepository = koinInject() // Later, get another instance val anotherRepository: AboutRepository = koinInject() // New instance ``` -------------------------------- ### UrlLauncherImpl JVM Implementation Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/core-url-launcher.md The JVM-specific implementation of UrlLauncherImpl. It utilizes the Desktop API to browse URLs and requires desktop support. ```kotlin public actual class UrlLauncherImpl(private val dispatcherProvider: DispatcherProvider) : UrlLauncher ``` -------------------------------- ### Including Platform Module Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/koin-modules.md Includes the platformModule, which provides platform-specific dependencies like UrlLauncher and dispatchers. ```kotlin includes(platformModule) ``` -------------------------------- ### Display Developer Profile with ToolkitDeveloperContent Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/INDEX.md Use the ToolkitDeveloperContent composable to display developer information and log clicks on developer links for analytics. ```kotlin @Composable fun AboutScreen() { ToolkitDeveloperContent( onTrackDeveloperLinkClick = { link -> analytics.log("link_click", link.name) } ) } ``` -------------------------------- ### Using ToolkitViewModel State in Compose Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/compose-viewmodel.md Demonstrates how to observe the viewState StateFlow from a ToolkitViewModel within a Composable function using collectAsStateWithLifecycle. ```kotlin class MyViewModel : ToolkitViewModel() { // State is exposed as a StateFlow } // In Compose @Composable fun MyScreen(viewModel: MyViewModel) { val state by viewModel.viewState.collectAsStateWithLifecycle() // Use state } ``` -------------------------------- ### Usage Pattern of ResolvableString Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/compose-string.md Demonstrates how to use `ResolvableString` in a Composable function, accepting different variants and resolving them for display. This pattern allows for flexible string handling. ```kotlin @OptIn(ExperimentalToolkitApi::class) @Composable fun MyScreen( titleSource: ResolvableString, descriptionSource: ResolvableString, ) { Column { Text(titleSource.resolve(), fontSize = 20.sp) Text(descriptionSource.resolve()) } } // Can be called with any variant MyScreen( titleSource = ResolvableString.Resource(Res.string.title), descriptionSource = ResolvableString.Literal("Static description") ) ``` -------------------------------- ### MVVM with ToolkitViewModel Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/INDEX.md Implement a ViewModel using ToolkitViewModel for managing state, handling events, and emitting actions in a Jetpack Compose application. ```kotlin class MyViewModel : ToolkitViewModel() { override fun defaultViewState() = MyState() override suspend fun onViewEvent(event: MyEvent) { when (event) { is MyEvent.Action1 -> updateViewState { copy(field = "value") } } } } @Composable fun MyScreen(viewModel: MyViewModel) { val state by viewModel.viewState.collectAsStateWithLifecycle() ViewActionEffect(viewModel.viewAction) { action -> when (action) { is MyAction.Navigate -> navigate(action.route) } } } ``` -------------------------------- ### ToolkitDeveloperContent Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/about-compose.md Composable that displays the toolkit developer's profile with links and biography. It fetches data from AboutRepository and uses UrlLauncher to open links, invoking an analytics callback before each launch. ```APIDOC ## ToolkitDeveloperContent ### Description Composable that displays the toolkit developer's profile with links and biography. It fetches data from AboutRepository and uses UrlLauncher to open links, invoking an analytics callback before each launch. ### Parameters #### Path Parameters - **modifier** (Modifier) - Optional - Optional modifier for layout - **onTrackDeveloperLinkClick** ((Developer.Link) -> Unit) - Required - Callback invoked before launching a link, for analytics ### Behavior 1. Fetches developer information from `AboutRepository` via Koin injection 2. Fetches `UrlLauncher` from Koin for opening URLs 3. Displays developer biography and profile picture 4. Shows links grouped by category (Standalone, Contact, Community, Creations, Social) 5. Invokes the analytics callback before launching each link 6. Launches URLs using the platform-specific `UrlLauncher` ### Dependencies (via Koin) - `AboutRepository` — Source of developer data - `UrlLauncher` — Opens URLs on the current platform ### UI Structure ``` Column (centered) ├── Developer Picture (128dp) ├── Biography Text └── Link Sections (grouped by category) ├── Standalone Links ├── Contact Links ├── Community Links ├── Creations Links └── Social Links ``` ### Example ```kotlin @Composable fun AboutScreen() { ToolkitDeveloperContent( modifier = Modifier.fillMaxSize(), onTrackDeveloperLinkClick = { link -> analytics.logEvent("developer_link_clicked", mapOf( "link_name" to link.name, "link_type" to link.type.toString() )) } ) } ``` ``` -------------------------------- ### Check UrlLaunchResult Success with Helper Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/errors.md Use the isSuccess helper to conditionally execute code based on the success of a URL launch operation. ```kotlin val result = urlLauncher.launch("https://example.com") if (result.isSuccess) { onSuccess() } else { when (result) { is UrlLaunchResult.Failure -> handleFailure(result) else -> {} } } ``` -------------------------------- ### Add Yasan Glass Toolkit Dependencies Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/configuration.md Add the Yasan Glass Toolkit core module and optional modules like compose, about, or koin to your project's build.gradle.kts file. Ensure you are using the latest version. ```kotlin dependencies { // Core module (required) implementation("glass.yasan.toolkit:core:1.7.15") // Compose utilities (optional) implementation("glass.yasan.toolkit:compose:1.7.15") // About module (optional) implementation("glass.yasan.toolkit:about:1.7.15") // Koin integration (optional, but recommended) implementation("glass.yasan.toolkit:koin:1.7.15") } ``` -------------------------------- ### Mock UrlLauncher for Testing Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/configuration.md Configure Koin to use a mock implementation of UrlLauncher for testing purposes. This allows you to control URL launching behavior during tests. ```kotlin startKoin { modules( module { single { MockUrlLauncher() } } ) } ``` -------------------------------- ### Using DispatcherProvider Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/configuration.md Inject and use the DispatcherProvider to manage coroutine dispatchers for UI updates, I/O operations, and CPU-intensive tasks. ```kotlin val dispatcherProvider: DispatcherProvider = koinInject() // Use dispatchers launch(dispatcherProvider.main) { updateUI() } launch(dispatcherProvider.io) { fetchData() } launch(dispatcherProvider.default) { heavyComputation() } ``` -------------------------------- ### Use Toolkit Components in Compose Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/INDEX.md Inject and use toolkit components, such as UrlLauncher, within a Jetpack Compose screen after Koin configuration. ```kotlin @Composable fun MyScreen() { val launcher: UrlLauncher = koinInject() // Use toolkit components } ``` -------------------------------- ### Display Minimal Developer Branding Banner Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/about-compose.md Composable that displays a minimal developer branding banner with just the logo. Use for lightweight branding in headers or footers. ```kotlin @Composable public fun ToolkitDeveloperBanner( modifier: Modifier = Modifier, ) ``` ```kotlin @Composable fun AppHeader() { Surface( modifier = Modifier.fillMaxWidth(), color = MaterialTheme.colorScheme.surface, ) { ToolkitDeveloperBanner( modifier = Modifier.padding(16.dp) ) } } ``` -------------------------------- ### Declare DefaultDispatcherProvider and Creator Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/core-coroutines.md Declares the `DefaultDispatcherProvider` as an `expect` class and a factory function `createDefaultDispatcherProvider` for platform-specific implementations. ```kotlin public expect class DefaultDispatcherProvider : DispatcherProvider { override val main: CoroutineDispatcher override val io: CoroutineDispatcher override val default: CoroutineDispatcher override val unconfined: CoroutineDispatcher } public expect fun createDefaultDispatcherProvider(): DefaultDispatcherProvider ``` -------------------------------- ### UrlLaunchResult Success Data Object Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/types.md Indicates that a URL was successfully launched. Use this when the launch operation completes without issues. ```kotlin public data object Success : UrlLaunchResult ``` -------------------------------- ### ToolkitDeveloperBanner Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/about-compose.md Composable that displays a minimal developer branding banner with just the logo. It's a lightweight element suitable for headers or footers. ```APIDOC ## ToolkitDeveloperBanner ### Description Composable that displays a minimal developer branding banner with just the logo. It's a lightweight element suitable for headers or footers. ### Parameters #### Path Parameters - **modifier** (Modifier) - Optional - Optional modifier for layout ### UI Structure ``` Column (centered) └── Developer Logo Horizontal (48dp height) ``` ### Use Case Lightweight branding element for headers or footers. ### Example ```kotlin @Composable fun AppHeader() { Surface( modifier = Modifier.fillMaxWidth(), color = MaterialTheme.colorScheme.surface, ) { ToolkitDeveloperBanner( modifier = Modifier.padding(16.dp) ) } } ``` ``` -------------------------------- ### AboutRepository Interface Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/about-repository.md Defines the contract for accessing developer information. Use this interface to retrieve a Flow of developer details. ```kotlin public interface AboutRepository { public val developer: Flow } ``` -------------------------------- ### Spacer(height, width) Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/compose-layout.md Creates a spacer composable with specified height and width dimensions. It accepts an optional modifier for further customization. ```APIDOC ## Spacer(height, width) ### Description Creates a spacer with both width and height dimensions. It accepts an optional modifier to apply custom styling or behavior. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Parameters - **height** (Dp) - Required - Height of the spacer - **width** (Dp) - Required - Width of the spacer - **modifier** (Modifier) - Optional - Optional modifier to apply ### Request Example ```kotlin Spacer(height = 16.dp, width = 8.dp) ``` ### Response #### Success Response (200) - **Unit** - This function does not return a value. #### Response Example ``` // No explicit return value ``` ``` -------------------------------- ### UrlLaunchResult isSuccess Property Check Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/types.md Provides a quick boolean check for the success of a URL launch operation without needing explicit pattern matching. ```kotlin public val isSuccess: Boolean get() = this is Success ``` -------------------------------- ### Custom DispatcherProvider Configuration Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/configuration.md Override the default DispatcherProvider with a custom implementation by providing your own module to Koin. ```kotlin startKoin { modules( module { single { MyCustomDispatcherProvider() } // Rest of toolkit setup (other dependencies) } ) } ``` -------------------------------- ### NullableBooleanPreviewParameterProvider Implementation Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/compose-preview.md Provides a Sequence of nullable Boolean values (true, false, null) for Compose previews. Use this for optional properties or tri-state components. ```kotlin public class NullableBooleanPreviewParameterProvider : PreviewParameterProvider { override val values: Sequence } ``` -------------------------------- ### Android Platform Context with Koin Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/koin-modules.md Koin automatically provides the Android `Context` when using the platform module. No explicit injection is typically needed for `Context` itself in Android applications. ```kotlin // Android: Context is provided by Koin automatically // The platform module handles Android-specific setup ``` -------------------------------- ### Updating ViewState in ToolkitViewModel Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/compose-viewmodel.md Demonstrates how to update the view state by applying a transformation function to the current state using updateViewState. ```kotlin viewModel.updateViewState { copy(isLoading = true) } ``` -------------------------------- ### Apply InternalToolkitApi to Implementations Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/core-annotations.md Demonstrates applying the InternalToolkitApi annotation to an expect class implementation to signify it's internal to the toolkit. ```kotlin @InternalToolkitApi public expect class UrlLauncherImpl : UrlLauncher ``` -------------------------------- ### ViewAction Marker Interface Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/types.md A marker interface for view actions in the MVVM pattern, providing type-safe actions for `ToolkitViewModel`. ```kotlin public interface ViewAction ``` -------------------------------- ### AboutRepository Factory Registration Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/api-reference/koin-modules.md Registers AboutRepository as a factory, meaning a new instance is created each time it's requested. It uses AboutRepositoryImpl as the implementation. ```kotlin factoryOf(::AboutRepositoryImpl) ``` -------------------------------- ### Detecting and Logging Error Failure Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/errors.md Use this snippet to detect an Error failure, which indicates an unexpected exception during URL launching. It logs the exception details for debugging. ```kotlin val result = urlLauncher.launch(url) when (result) { is UrlLaunchResult.Failure.Error -> { log("Exception: ${result.exception}") log("Message: ${result.exception.message}") result.exception.printStackTrace() } else -> {} } ``` -------------------------------- ### UrlLaunchResult Failure.Error Data Class Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/types.md Represents a failure due to an unexpected exception that occurred during the URL launching process. ```kotlin public data class Error(val exception: Exception) : UrlLaunchResult.Failure ``` -------------------------------- ### UrlLaunchResult Sealed Interface Source: https://github.com/yasanglass/toolkit/blob/main/_autodocs/types.md Represents the outcome of attempting to launch a URL. It includes success and various failure states. ```kotlin public sealed interface UrlLaunchResult { public val isSuccess: Boolean get() = this is Success public data object Success : UrlLaunchResult public sealed interface Failure : UrlLaunchResult { public data object InvalidUrl : Failure public data object Unsupported : Failure public data class Error(val exception: Exception) : Failure } } ```