{"id":20930510,"url":"https://github.com/liangjingkanji/interval","last_synced_at":"2025-04-04T21:10:18.385Z","repository":{"id":45386117,"uuid":"513602144","full_name":"liangjingkanji/Interval","owner":"liangjingkanji","description":"Android计时器工具, 倒计时/正计时/开始/暂停/继续/结束/取消","archived":false,"fork":false,"pushed_at":"2024-12-08T02:47:59.000Z","size":136,"stargazers_count":171,"open_issues_count":4,"forks_count":18,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T20:11:13.643Z","etag":null,"topics":["android","countdown","interval"],"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/liangjingkanji.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-13T16:53:43.000Z","updated_at":"2025-03-23T08:23:15.000Z","dependencies_parsed_at":"2025-03-28T20:10:49.563Z","dependency_job_id":"8148a538-35b9-4056-be3f-06c9ae481ecc","html_url":"https://github.com/liangjingkanji/Interval","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/liangjingkanji%2FInterval","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liangjingkanji%2FInterval/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liangjingkanji%2FInterval/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liangjingkanji%2FInterval/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/liangjingkanji","download_url":"https://codeload.github.com/liangjingkanji/Interval/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247249532,"owners_count":20908212,"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":["android","countdown","interval"],"created_at":"2024-11-18T21:34:38.986Z","updated_at":"2025-04-04T21:10:18.367Z","avatar_url":"https://github.com/liangjingkanji.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e \u003cstrong\u003e强大的Android计时器\u003c/strong\u003e \u003c/p\u003e\n\n\u003cbr\u003e\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://user-images.githubusercontent.com/21078112/178807127-6859cae5-290d-4350-bbde-cecca9e30276.png\" width=\"400\"/\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://github.com/liangjingkanji/Interval/releases/download/1.0.3/interval.apk\"\u003e下载体验\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://jitpack.io/#liangjingkanji/Interval\"\u003e\u003cimg src=\"https://jitpack.io/v/liangjingkanji/Interval.svg\"/\u003e\u003c/a\u003e\n\u003cimg src=\"https://img.shields.io/badge/language-kotlin-orange.svg\"/\u003e\n\u003cimg src=\"https://img.shields.io/badge/license-Apache-blue\"/\u003e\n\u003cimg src=\"https://raw.githubusercontent.com/liangjingkanji/liangjingkanji/master/img/group.svg\"/\u003e\n\u003c/p\u003e\n\n\n\u003cbr\u003e\n\u003cp align=\"center\"\u003e\n\u003cimg align=\"center\" src=\"https://user-images.githubusercontent.com/21078112/178810331-69eb172c-4fda-4342-9f56-b51b4f11b45b.jpg\" width=\"250\"/\u003e\n\u003c/p\u003e\n\n\u003cbr\u003e\n\n本工具为弥补Android没有完善的计时器而生, 使用协程Coroutine实现计时功能, 本工具从[Net](https://github.com/liangjingkanji/Net/)中剥离单独发布仓库, 如果已经依赖Net无需再依赖此工具\n\n\n## 特点\n\n- [x] 倒计时/正计时\n- [x] 开始/暂停/继续/结束/取消/重置\n- [x] 定时/结束事件\n- [x] 初始间隔/每次间隔\n- [x] 动态修改计数器\n- [x] 生命周期自动取消\n- [x] 页面不可见暂停/可见继续\n\n\n## 使用\n\n监听轮询器\n\n```kotlin\n// 自定义计数器个数的轮询器\ninterval = Interval(100, 1, TimeUnit.SECONDS).life(this)\n// 每秒回调一次, 不会自动结束\ninterval = Interval(1, TimeUnit.SECONDS)\n// 倒计时轮询器, 当[start]]比[end]值大, 且end不等于-1时, 即为倒计时\ninterval = Interval(1, 1, TimeUnit.SECONDS, 5).life(this)\n\ninterval.subscribe {\n    tvFragment.text = it.toString()\n}.finish {\n    tvFragment.text = \"计时完成\" // 最后一位数时同时回调 subscribe/finish\n}.start()\n```\n\n## 函数\n\n使用的函数非常简单\n\n| Interval方法 | 描述 |\n|-|-|\n| start | 开始轮询器 |\n| stop | 停止 |\n| cancel | 取消, 区别于stop, 此函数执行后并不会回调finish |\n| pause | 暂停 |\n| resume | 继续 |\n| reset | 重置 |\n| switch | 切换开关 |\n| count | 当前计数器 |\n| end | 结束计数器 |\n| state | 当前状态 |\n| subscribe | 每次计时都会执行该回调 |\n| finish | 当计时器完成时执行该回调, 执行stop后也会回调 |\n| life | 指定生命周期自动取消轮询器 |\n| onlyResumed | 当界面不可见时暂停, 当界面可见时继续 |\n\n\n\n\n## 安装\n\n添加远程仓库根据创建项目的 Android Studio 版本有所不同\n\nAndroid Studio Arctic Fox以下创建的项目 在项目根目录的 build.gradle 添加仓库\n\n```groovy\nallprojects {\n    repositories {\n        // ...\n        maven { url 'https://jitpack.io' }\n    }\n}\n```\n\nAndroid Studio Arctic Fox以上创建的项目 在项目根目录的 settings.gradle 添加仓库\n\n```kotlin\ndependencyResolutionManagement {\n    repositories {\n        // ...\n        maven { url 'https://jitpack.io' }\n    }\n}\n```\n\n然后在 module 的 build.gradle 添加依赖框架\n\n```groovy\nimplementation \"org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0\" // 协程(版本自定)\nimplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0'\n\nimplementation 'com.github.liangjingkanji:Interval:1.0.3'\n```\n\n\n\n## License\n\n```\nMIT License\n\nCopyright (c) 2023 劉強東\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliangjingkanji%2Finterval","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliangjingkanji%2Finterval","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliangjingkanji%2Finterval/lists"}