{"id":27402310,"url":"https://github.com/hi-dhl/ktkit","last_synced_at":"2025-10-30T00:34:57.071Z","repository":{"id":38686927,"uuid":"391529628","full_name":"hi-dhl/KtKit","owner":"hi-dhl","description":"KtKit 小巧而实用，用 Kotlin 语言编写的工具库（长期更新中）","archived":false,"fork":false,"pushed_at":"2021-09-28T06:39:44.000Z","size":268,"stargazers_count":154,"open_issues_count":2,"forks_count":17,"subscribers_count":5,"default_branch":"main","last_synced_at":"2023-11-07T15:24:36.184Z","etag":null,"topics":["activity","fragment","kotlin"],"latest_commit_sha":null,"homepage":"https://ktkit.hi-dhl.com","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hi-dhl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-01T04:56:06.000Z","updated_at":"2023-10-09T11:01:45.000Z","dependencies_parsed_at":"2022-07-11T02:18:14.889Z","dependency_job_id":null,"html_url":"https://github.com/hi-dhl/KtKit","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hi-dhl%2FKtKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hi-dhl%2FKtKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hi-dhl%2FKtKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hi-dhl%2FKtKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hi-dhl","download_url":"https://codeload.github.com/hi-dhl/KtKit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248820311,"owners_count":21166647,"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","fragment","kotlin"],"created_at":"2025-04-14T04:25:06.652Z","updated_at":"2025-10-30T00:34:56.977Z","avatar_url":"https://github.com/hi-dhl.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# \u003cp align=\"center\"\u003e KtKit \u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\nKtKit 小巧而实用，用 Kotlin 语言编写的工具库（长期更新中）\u003cbr/\u003e\n\u003ca href=\"https://ktkit.hi-dhl.com\"\u003eKtKit 在线阅读：https://ktkit.hi-dhl.com\u003c/a\u003e \n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://github.com/hi-dhl\"\u003e\u003cimg src=\"https://img.shields.io/badge/GitHub-dhl-4BC51D.svg?style=flat\"\u003e\u003c/a\u003e  \u0026nbsp; \u003cimg src=\"https://img.shields.io/badge/language-kotlin-orange.svg\"/\u003e \u0026nbsp; \u003ca href=\"https://search.maven.org/search?q=g:%22com.hi-dhl%22%20AND%20a:%22ktkit%22\"\u003e\u003cimg src=\"https://img.shields.io/maven-central/v/com.hi-dhl/ktkit.svg?label=Maven%20Central\"/\u003e\u003c/a\u003e \u0026nbsp; \u003ca href=\"https://oss.sonatype.org/content/repositories/snapshots/com/hi-dhl/ktkit\"\u003e\u003cimg src=\"https://img.shields.io/badge/SNAPSHOT-v1.0.2-9933CC.svg?style=flat\"\u003e\u003c/a\u003e \u0026nbsp; \u003cimg src=\"https://img.shields.io/badge/platform-android-lightgrey.svg\"/\u003e \n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e 如果图片无法查看，请点击这里查看 \u003ca href=\"http://img.hi-dhl.com/intent-act.png\"\u003e 图例\u003c/a\u003e\n\u003cimage src=\"http://img.hi-dhl.com/intent-act.png\" width = 700px/\u003e\n\u003c/p\u003e\n\n## 关于 KtKit\n\nKtKit 是用 Kotlin 语言编写的工具库，包含了项目中常用的一系列工具，是 Jetpack ktx 系列的补充，涉及到了很多从 Kotlin 源码、Jetpack ktx、anko 等等知名的开源项目中学习的技巧，包含了 Kotlin 委托属性、高阶函数、扩展函数、内联、注解的使用等等，再次感谢以下项目提供的思路。\n\n* Kotlin 官方 API\n* [anko](https://github.com/Kotlin/anko)\n* [FlowBinding](https://github.com/ReactiveCircus/FlowBinding)\n* Google Jetpack ktx\n\n但是目前还不是很完善，正在陆续将一些常用的功能，结合着 Kotlin 的高级函数的特性，不仅让代码可读性更强，使用更加简单，而且还可以帮助我们解决项目中常见的问题。\n\n## Download\n\n**正式版本: 此版本包含稳定版本的 API** \n\n[![Maven Central](https://img.shields.io/maven-central/v/com.hi-dhl/ktkit.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.hi-dhl%22%20AND%20a:%22ktkit%22)\n\n```\n// Project 级别的 `build.gradle`\nallprojects {\n    repositories {\n        mavenCentral()\n    }\n}\n\n// 模块级 `build.gradle`\ndependencies {\n    implementation \"com.hi-dhl:ktkit:${ktkitVersion}\"\n}\n```\n \n**快照版本: 此版本包含最新的 API，版本号点击 [snapshots](https://oss.sonatype.org/content/repositories/snapshots/com/hi-dhl/ktkit/) 前往查看**\n\n\u003ca href=\"https://oss.sonatype.org/content/repositories/snapshots/com/hi-dhl/ktkit\"\u003e\u003cimg src=\"https://img.shields.io/badge/SNAPSHOT-v1.0.2-9933CC.svg?style=flat\"\u003e\u003c/a\u003e\n\n\n```\n// Project 级别的 `build.gradle`\nallprojects {\n    repositories {\n        maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }\n    }\n}\n\n// 模块级 `build.gradle`\ndependencies {\n    implementation \"com.hi-dhl:ktkit:${ktkitVersion}\"\n}\n```\n\n**如果这个仓库对你有帮助，请在仓库右上角帮我 star 一下，非常感谢你的支持，同时也欢迎你提交 PR**  ❤️❤️❤️\n\n项目中引用了 spotless 插件，执行 `./gradlew spotlessApply`  会将 Java 、Kotlin 、xml 、gradle 、md 、gitignore 等等文件按照官方标准去格式化。这也是 Google 提交代码的时候，推荐的方式。\n\n## 如何使用\n\n**在 Activity 或者 Fragment 中获取传递过来的参数**\n\n以下两种方式根据实际情况使用即可\n\n```\n// 方式一： 不带默认值\nprivate val userPassword by intent\u003cString\u003e(KEY_USER_PASSWORD)\n\n// 方式二：带默认值：如果获取失败，返回一个默认值\nprivate val userName by intent\u003cString\u003e(KEY_USER_NAME) {\n    \"公众号：ByteCode\"\n}\n```\n\n**Activity 之间跳转 及传递参数**\n\n以下两种方式根据实际情况使用即可\n\n```\n// 方式一\ncontext.startActivity\u003cProfileActivity\u003e {\n    arrayOf(\n            KEY_USER_NAME to \"ByteCode\",\n            KEY_USER_PASSWORD to \"1024\",\n            KEY_PEOPLE_PARCELIZE to PeopleModel(\"hi-dhl\")\n    )\n}\n\n// 方式二\ncontext.startActivity\u003cProfileActivity\u003e(\n        KEY_USER_NAME to \"ByteCode\",\n        KEY_USER_PASSWORD to \"1024\"\n)\n```\n\n**Activity 之间跳转 及传递参数 和 回传结果**\n以下两种方式根据实际情况使用即可\n\n```\n// 方式一\ncontext.startActivityForResult\u003cProfileActivity\u003e(KEY_REQUEST_CODE,\n        KEY_USER_NAME to \"ByteCode\",\n        KEY_USER_PASSWORD to \"1024\",\n        KEY_PEOPLE_PARCELIZE to PeopleModel(\"hi-dhl\")\n)\n\n// 方式二\ncontext.startActivityForResult\u003cProfileActivity\u003e(KEY_REQUEST_CODE) {\n    arrayOf(\n            KEY_USER_NAME to \"ByteCode\",\n            KEY_USER_PASSWORD to \"1024\",\n            KEY_PEOPLE_PARCELIZE to PeopleModel(\"hi-dhl\")\n    )\n}\n```\n\n**回传结果**\n\n```\n// 方式一\nsetActivityResult(Activity.RESULT_OK) {\n   arrayOf(\n            KEY_RESULT to \"success\"\n    )\n}\n                    \n// 方式二\nsetActivityResult(\n        Activity.RESULT_OK,\n        KEY_RESULT to \"success\",\n        KEY_USER_NAME to \"ByteCode\"\n)\n```\n\n**Fragment 跳转 及 传递参数**\n\n```\n// 方式一\nfun newInstance1(): Fragment {\n    return LoginFragment().makeBundle(\n            ProfileActivity.KEY_USER_NAME to \"ByteCode\",\n            ProfileActivity.KEY_USER_PASSWORD to \"1024\",\n            ProfileActivity.KEY_PEOPLE_PARCELIZE to PeopleModel(\"hi-dhl\")\n    )\n}\n\n// 方式二\nfun newInstance2(): Fragment {\n    return LoginFragment().makeBundle {\n        arrayOf(\n                KEY_USER_NAME to \"ByteCode\",\n                KEY_USER_PASSWORD to \"1024\",\n                KEY_PEOPLE_PARCELIZE to PeopleModel(\"hi-dhl\")\n        )\n    }\n}\n```\n\n**一行代码实现点击事件，避免内存泄露**\n\nKtKit 提供了常用的三个 API：单击事件、延迟第一次点击事件、防止多次点击\n\n**单击事件**\n\n```\nview.click(lifecycleScope) { showShortToast(\"公众号：ByteCode\" }\n```\n\n\n**延迟第一次点击事件**\n\n```\n// 默认延迟时间是 500ms\nview.clickDelayed(lifecycleScope){ showShortToast(\"公众号：ByteCode\" }\n\n// or\nview.clickDelayed(lifecycleScope, 1000){ showShortToast(\"公众号：ByteCode\") }\n```\n\n\n**防止多次点击**\n\n```\n// 默认间隔时间是 500ms\nview.clickTrigger(lifecycleScope){ showShortToast(\"公众号：ByteCode\") }\n\n// or\nview.clickTrigger(lifecycleScope, 1000){ showShortToast(\"公众号：ByteCode\") }\n```\n\n更多 API 使用方式点击这里前往查看 [在线文档](https://ktkit.hi-dhl.com)\n\n### 联系我\n\n* 个人微信：hi-dhl\n* 公众号：ByteCode，包含 Jetpack ，Kotlin ，Android 10 系列源码，译文，LeetCode / 剑指 Offer / 多线程 / 国内外大厂算法题 等等一系列文章\n\n\u003cimg src='http://cdn.51git.cn/2020-10-20-151047.png' width = 350px/\u003e\n\n---\n\n最后推荐我一直在更新维护的项目和网站：\n\n* 计划建立一个最全、最新的 AndroidX Jetpack 相关组件的实战项目 以及 相关组件原理分析文章，正在逐渐增加 Jetpack 新成员，仓库持续更新，欢迎前去查看：[AndroidX-Jetpack-Practice](https://github.com/hi-dhl/AndroidX-Jetpack-Practice)\n\n* LeetCode / 剑指 offer / 国内外大厂面试题 / 多线程 题解，语言 Java 和 kotlin，包含多种解法、解题思路、时间复杂度、空间复杂度分析\u003cbr/\u003e\n\n    \u003cimage src=\"http://cdn.51git.cn/2020-10-04-16017884626310.jpg\" width = \"500px\"/\u003e\n  \n    * 剑指 offer 及国内外大厂面试题解：[在线阅读](https://offer.hi-dhl.com)\n    * LeetCode 系列题解：[在线阅读](https://leetcode.hi-dhl.com)\n\n* 最新 Android 10 源码分析系列文章，了解系统源码，不仅有助于分析问题，在面试过程中，对我们也是非常有帮助的，仓库持续更新，欢迎前去查看 [Android10-Source-Analysis](https://github.com/hi-dhl/Android10-Source-Analysis)\n\n* 整理和翻译一系列精选国外的技术文章，每篇文章都会有**译者思考**部分，对原文的更加深入的解读，仓库持续更新，欢迎前去查看 [Technical-Article-Translation](https://github.com/hi-dhl/Technical-Article-Translation)\n\n* 「为互联网人而设计，国内国外名站导航」涵括新闻、体育、生活、娱乐、设计、产品、运营、前端开发、Android 开发等等网址，欢迎前去查看 [为互联网人而设计导航网站](https://site.51git.cn)\n\n## License\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhi-dhl%2Fktkit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhi-dhl%2Fktkit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhi-dhl%2Fktkit/lists"}