{"id":13607943,"url":"https://github.com/adrielcafe/kaptain","last_synced_at":"2025-04-23T16:34:04.384Z","repository":{"id":149190524,"uuid":"250125515","full_name":"adrielcafe/kaptain","owner":"adrielcafe","description":"👨‍✈️ multi-module navigation on Android has never been so easier!","archived":false,"fork":false,"pushed_at":"2021-08-09T02:29:40.000Z","size":181,"stargazers_count":27,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-07T13:38:28.668Z","etag":null,"topics":["activity","android","android-library","kotlin","kotlin-library","module","multi-module","navigation","navigator"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/adrielcafe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"ko_fi":"adrielcafe"}},"created_at":"2020-03-26T00:47:12.000Z","updated_at":"2024-02-02T08:45:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"27ac9b79-1101-4c9b-ab7c-065c97ad9987","html_url":"https://github.com/adrielcafe/kaptain","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrielcafe%2Fkaptain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrielcafe%2Fkaptain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrielcafe%2Fkaptain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adrielcafe%2Fkaptain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adrielcafe","download_url":"https://codeload.github.com/adrielcafe/kaptain/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223930293,"owners_count":17227046,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["activity","android","android-library","kotlin","kotlin-library","module","multi-module","navigation","navigator"],"created_at":"2024-08-01T19:01:23.012Z","updated_at":"2024-11-10T08:27:06.438Z","avatar_url":"https://github.com/adrielcafe.png","language":"Kotlin","funding_links":["https://ko-fi.com/adrielcafe"],"categories":["Kotlin"],"sub_categories":[],"readme":"[![JitPack](https://img.shields.io/jitpack/v/github/adrielcafe/kaptain.svg?style=for-the-badge)](https://jitpack.io/#adrielcafe/kaptain)\n[![Github Actions](https://img.shields.io/github/workflow/status/adrielcafe/kaptain/main/master?style=for-the-badge)](https://github.com/adrielcafe/kaptain/actions)\n[![Android API](https://img.shields.io/badge/api-14%2B-yellowgreen.svg?style=for-the-badge)](https://android-arsenal.com/api?level=14)\n[![Kotlin](https://img.shields.io/github/languages/top/adrielcafe/kaptain.svg?style=for-the-badge\u0026color=orange)](https://kotlinlang.org/)\n[![ktlint](https://img.shields.io/badge/code%20style-%E2%9D%A4-FF4081.svg?style=for-the-badge)](https://ktlint.github.io/)\n[![License MIT](https://img.shields.io/github/license/adrielcafe/kaptain.svg?style=for-the-badge\u0026color=yellow)](https://opensource.org/licenses/MIT)\n\n# Kaptain\nKaptain is a small, dependencyless and easy to use Android library that helps you to navigate between activities spread over several modules.\n\n## Usage\n\nGiven the following project structure:\n```\n/app\n  MyApplication.kt\n/feature-a\n  FeatureAActivity.kt\n/feature-b\n  FeatureBActivity.kt\n/feature-shared\n  Destination.kt\n```\n\n* `app` module imports all modules below\n* `feature-a` and `feature-b` imports only `feature-shared`\n* `feature-shared` imports nothing\n\n### 1. Define destinations\nFirst, you must list all possible destinations (Activities) of your app. Create a `sealed class` that implements the `KaptainDestination` interface.\n\nOptionally, you can add arguments to your destination using a `data class`.\n\n```kotlin\nsealed class Destination : KaptainDestination {\n\n    object FeatureA : Destination()\n    data class FeatureB(val message: String) : Destination()\n}\n```\n\n### 2. Create a Kaptain instance\nNext, create a new Kaptain instance and associate your destinations with the corresponding Activities. \n\n```kotlin\nclass MyApplication : Application() {\n    \n    val kaptain = Kaptain {\n        add\u003cDestination.FeatureA, FeatureAActivity\u003e()\n        add\u003cDestination.FeatureB, FeatureBActivity\u003e()\n    }\n}\n```\n\nIdeally, you should inject this instance as a **singleton** using a DI library. Check the [sample app](https://github.com/adrielcafe/kaptain/blob/master/sample/src/main/java/cafe/adriel/kaptain/sample/App.kt) for an example using [Koin](https://github.com/InsertKoinIO/koin/).\n\n### 3. Navigate between activities\nNow you can navigate to any Activity, from any module:\n\n```kotlin\nclass FeatureAActivity : AppCompatActivity() {\n\n    fun goToFeatureB() {\n        kaptain.navigate(\n            activity = this,\n            destination = Destination.FeatureB(message = \"Ahoy!\"),\n            requestCode = 0x123 // Optional\n        )\n    }\n}\n```\n\n### 4. Retrieve a destination content\nAfter arrive at your destination, you can retrieve it's content:\n\n```kotlin\nclass FeatureBActivity : AppCompatActivity() {\n\n    override fun onCreate(savedInstanceState: Bundle?) {\n        super.onCreate(savedInstanceState)\n        setContentView(R.layout.activity_feature_b)\n\n        val importantMessage = kaptain.fromIntent\u003cDestination.FeatureB\u003e(this)?.message\n    }\n}\n```\n\n## Dynamic feature modules\nKaptain works great with [dynamic features](https://developer.android.com/guide/app-bundle/dynamic-delivery)!\n\n### 1. Add destinations on demand\nYou can add/remove destinations at any time:\n\n```kotlin\nkaptain.add\u003cDestination.DynamicFeatureA, DynamicFeatureAActivity\u003e()\nkaptain.remove\u003cDestination.DynamicFeatureB\u003e()\n```\n\n### 2. Make sure the destination exists before navigating\n```kotlin\nif (kaptain.has\u003cDestination.DynamicFeatureA\u003e) {\n    kaptain.navigate(this, Destination.DynamicFeatureA)\n}\n```\n\n## Import to your project\n1. Add the JitPack repository in your root build.gradle at the end of repositories:\n```gradle\nallprojects {\n    repositories {\n        maven { url 'https://jitpack.io' }\n    }\n}\n```\n\n2. Next, add the library to your module:\n```gradle\ndependencies {\n    implementation \"com.github.adrielcafe.kaptain:kaptain:$currentVersion\"\n}\n```\nCurrent version: [![JitPack](https://img.shields.io/jitpack/v/github/adrielcafe/kaptain.svg?style=flat-square)](https://jitpack.io/#adrielcafe/kaptain)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadrielcafe%2Fkaptain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadrielcafe%2Fkaptain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadrielcafe%2Fkaptain/lists"}