├── .envrc.template ├── .github └── workflows │ └── maven-publish.yml ├── .gitignore ├── LICENSE ├── LifecycleDispose2 ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ └── java │ └── com │ └── wada811 │ └── lifecycledispose │ └── LifecycleDispose.kt ├── LifecycleDispose3 ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ └── java │ └── com │ └── wada811 │ └── lifecycledispose │ └── LifecycleDispose.kt ├── README.md ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── publish-module.gradle ├── publish-root.gradle ├── renovate.json ├── settings.gradle └── test ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src ├── main ├── AndroidManifest.xml └── java │ └── com │ └── wada811 │ └── lifecycledispose │ └── test │ ├── DisposeActivity.kt │ ├── DisposeNoViewFragment.kt │ ├── DisposeStrategy.kt │ ├── DisposeViewFragment.kt │ └── FragmentLifecycleEvent.kt └── test └── java └── com └── wada811 └── lifecycledispose └── test ├── ActivityTest.kt ├── NoViewFragmentTest.kt └── ViewFragmentTest.kt /.envrc.template: -------------------------------------------------------------------------------- 1 | export OSSRH_USERNAME= 2 | export OSSRH_PASSWORD= 3 | export SONATYPE_STAGING_PROFILE_ID= 4 | export SIGNING_KEY_ID= 5 | export SIGNING_PASSWORD= 6 | export SIGNING_KEY= 7 | -------------------------------------------------------------------------------- /.github/workflows/maven-publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish to MavenCentral 2 | 3 | on: 4 | release: 5 | types: [ released ] 6 | 7 | jobs: 8 | publish: 9 | name: Publish to MavenCentral 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Check out code 13 | uses: actions/checkout@v4 14 | - name: Set up JDK 11 15 | uses: actions/setup-java@v3 16 | with: 17 | distribution: adopt 18 | java-version: 11 19 | 20 | - name: Publish to MavenCentral 21 | run: ./gradlew --max-workers 1 publishReleasePublicationToMavenLocal publishReleasePublicationToSonatypeRepository closeAndReleaseSonatypeStagingRepository 22 | env: 23 | OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }} 24 | OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} 25 | SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }} 26 | SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }} 27 | SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} 28 | SIGNING_KEY: ${{ secrets.SIGNING_KEY }} 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.gitignore.io/api/macos,android,intellij+iml,androidstudio 3 | # Edit at https://www.gitignore.io/?templates=macos,android,intellij+iml,androidstudio 4 | 5 | ### Android ### 6 | # Built application files 7 | *.apk 8 | *.ap_ 9 | *.aab 10 | 11 | # Files for the ART/Dalvik VM 12 | *.dex 13 | 14 | # Java class files 15 | *.class 16 | 17 | # Generated files 18 | bin/ 19 | gen/ 20 | out/ 21 | 22 | # Gradle files 23 | .gradle/ 24 | build/ 25 | 26 | # Local configuration file (sdk path, etc) 27 | local.properties 28 | 29 | # Proguard folder generated by Eclipse 30 | proguard/ 31 | 32 | # Log Files 33 | *.log 34 | 35 | # Android Studio Navigation editor temp files 36 | .navigation/ 37 | 38 | # Android Studio captures folder 39 | captures/ 40 | 41 | # IntelliJ 42 | *.iml 43 | .idea/* 44 | 45 | # Keystore files 46 | # Uncomment the following lines if you do not want to check your keystore files in. 47 | #*.jks 48 | #*.keystore 49 | 50 | # External native build folder generated in Android Studio 2.2 and later 51 | .externalNativeBuild 52 | 53 | # Google Services (e.g. APIs or Firebase) 54 | google-services.json 55 | 56 | # Freeline 57 | freeline.py 58 | freeline/ 59 | freeline_project_description.json 60 | 61 | # fastlane 62 | fastlane/report.xml 63 | fastlane/Preview.html 64 | fastlane/screenshots 65 | fastlane/test_output 66 | fastlane/readme.md 67 | 68 | ### Android Patch ### 69 | gen-external-apklibs 70 | 71 | ### AndroidStudio ### 72 | # Covers files to be ignored for android development using Android Studio. 73 | 74 | # Built application files 75 | 76 | # Files for the ART/Dalvik VM 77 | 78 | # Java class files 79 | 80 | # Generated files 81 | 82 | # Gradle files 83 | .gradle 84 | 85 | # Signing files 86 | .signing/ 87 | 88 | # Local configuration file (sdk path, etc) 89 | 90 | # Proguard folder generated by Eclipse 91 | 92 | # Log Files 93 | 94 | # Android Studio 95 | /*/build/ 96 | /*/local.properties 97 | /*/out 98 | /*/*/build 99 | /*/*/production 100 | *.ipr 101 | *~ 102 | *.swp 103 | 104 | # Android Patch 105 | 106 | # External native build folder generated in Android Studio 2.2 and later 107 | 108 | # NDK 109 | obj/ 110 | 111 | # IntelliJ IDEA 112 | *.iws 113 | /out/ 114 | 115 | # User-specific configurations 116 | .idea/caches/ 117 | .idea/libraries/ 118 | .idea/shelf/ 119 | .idea/.name 120 | .idea/compiler.xml 121 | .idea/copyright/profiles_settings.xml 122 | .idea/encodings.xml 123 | .idea/misc.xml 124 | .idea/modules.xml 125 | .idea/scopes/scope_settings.xml 126 | .idea/vcs.xml 127 | .idea/jsLibraryMappings.xml 128 | .idea/datasources.xml 129 | .idea/dataSources.ids 130 | .idea/sqlDataSources.xml 131 | .idea/dynamic.xml 132 | .idea/uiDesigner.xml 133 | 134 | # OS-specific files 135 | .DS_Store 136 | .DS_Store? 137 | ._* 138 | .Spotlight-V100 139 | .Trashes 140 | ehthumbs.db 141 | Thumbs.db 142 | 143 | # Legacy Eclipse project files 144 | .classpath 145 | .project 146 | .cproject 147 | .settings/ 148 | 149 | # Mobile Tools for Java (J2ME) 150 | .mtj.tmp/ 151 | 152 | # Package Files # 153 | *.war 154 | *.ear 155 | 156 | # virtual machine crash logs (Reference: http://www.java.com/en/download/help/error_hotspot.xml) 157 | hs_err_pid* 158 | 159 | ## Plugin-specific files: 160 | 161 | # mpeltonen/sbt-idea plugin 162 | .idea_modules/ 163 | 164 | # JIRA plugin 165 | atlassian-ide-plugin.xml 166 | 167 | # Mongo Explorer plugin 168 | .idea/mongoSettings.xml 169 | 170 | # Crashlytics plugin (for Android Studio and IntelliJ) 171 | com_crashlytics_export_strings.xml 172 | crashlytics.properties 173 | crashlytics-build.properties 174 | fabric.properties 175 | 176 | ### AndroidStudio Patch ### 177 | 178 | !/gradle/wrapper/gradle-wrapper.jar 179 | 180 | ### Intellij+iml ### 181 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm 182 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 183 | 184 | # User-specific stuff 185 | .idea/**/workspace.xml 186 | .idea/**/tasks.xml 187 | .idea/**/usage.statistics.xml 188 | .idea/**/dictionaries 189 | .idea/**/shelf 190 | 191 | # Generated files 192 | .idea/**/contentModel.xml 193 | 194 | # Sensitive or high-churn files 195 | .idea/**/dataSources/ 196 | .idea/**/dataSources.ids 197 | .idea/**/dataSources.local.xml 198 | .idea/**/sqlDataSources.xml 199 | .idea/**/dynamic.xml 200 | .idea/**/uiDesigner.xml 201 | .idea/**/dbnavigator.xml 202 | 203 | # Gradle 204 | .idea/**/gradle.xml 205 | .idea/**/libraries 206 | 207 | # Gradle and Maven with auto-import 208 | # When using Gradle or Maven with auto-import, you should exclude module files, 209 | # since they will be recreated, and may cause churn. Uncomment if using 210 | # auto-import. 211 | # .idea/modules.xml 212 | # .idea/*.iml 213 | # .idea/modules 214 | 215 | # CMake 216 | cmake-build-*/ 217 | 218 | # Mongo Explorer plugin 219 | .idea/**/mongoSettings.xml 220 | 221 | # File-based project format 222 | 223 | # IntelliJ 224 | 225 | # mpeltonen/sbt-idea plugin 226 | 227 | # JIRA plugin 228 | 229 | # Cursive Clojure plugin 230 | .idea/replstate.xml 231 | 232 | # Crashlytics plugin (for Android Studio and IntelliJ) 233 | 234 | # Editor-based Rest Client 235 | .idea/httpRequests 236 | 237 | # Android studio 3.1+ serialized cache file 238 | .idea/caches/build_file_checksums.ser 239 | 240 | ### Intellij+iml Patch ### 241 | # Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023 242 | 243 | modules.xml 244 | 245 | ### macOS ### 246 | # General 247 | .AppleDouble 248 | .LSOverride 249 | 250 | # Icon must end with two \r 251 | Icon 252 | 253 | # Thumbnails 254 | 255 | # Files that might appear in the root of a volume 256 | .DocumentRevisions-V100 257 | .fseventsd 258 | .TemporaryItems 259 | .VolumeIcon.icns 260 | .com.apple.timemachine.donotpresent 261 | 262 | # Directories potentially created on remote AFP share 263 | .AppleDB 264 | .AppleDesktop 265 | Network Trash Folder 266 | Temporary Items 267 | .apdisk 268 | 269 | # End of https://www.gitignore.io/api/macos,android,intellij+iml,androidstudio 270 | 271 | .envrc 272 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2019 wada811 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /LifecycleDispose2/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /LifecycleDispose2/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.library' 3 | id 'com.diffplug.spotless' 4 | id 'org.jetbrains.kotlin.android' 5 | } 6 | 7 | ext { 8 | PUBLISH_GROUP_ID = 'com.wada811.lifecycledispose' 9 | PUBLISH_ARTIFACT_ID = 'lifecycledispose2' 10 | PUBLISH_VERSION = '4.0.0' 11 | } 12 | 13 | apply from: "${rootDir}/publish-module.gradle" 14 | 15 | android { 16 | namespace "com.wada811.lifecycledispose" 17 | compileSdkVersion 33 18 | defaultConfig { 19 | minSdkVersion 21 20 | targetSdkVersion 33 21 | } 22 | compileOptions { 23 | sourceCompatibility JavaVersion.VERSION_11 24 | targetCompatibility JavaVersion.VERSION_11 25 | } 26 | kotlinOptions { 27 | jvmTarget = JavaVersion.VERSION_11.toString() 28 | } 29 | } 30 | 31 | dependencies { 32 | implementation "org.jetbrains.kotlin:kotlin-stdlib:1.9.10" 33 | implementation "io.reactivex.rxjava2:rxkotlin:2.4.0" 34 | implementation 'io.reactivex.rxjava2:rxjava:2.2.21' 35 | implementation "androidx.fragment:fragment:1.6.1" 36 | } 37 | -------------------------------------------------------------------------------- /LifecycleDispose2/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /LifecycleDispose2/src/main/java/com/wada811/lifecycledispose/LifecycleDispose.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("unused") 2 | 3 | package com.wada811.lifecycledispose 4 | 5 | import androidx.fragment.app.Fragment 6 | import androidx.fragment.app.FragmentActivity 7 | import androidx.lifecycle.Lifecycle 8 | import androidx.lifecycle.Lifecycle.Event 9 | import androidx.lifecycle.Lifecycle.Event.ON_DESTROY 10 | import androidx.lifecycle.Lifecycle.Event.ON_PAUSE 11 | import androidx.lifecycle.Lifecycle.Event.ON_START 12 | import androidx.lifecycle.Lifecycle.Event.ON_STOP 13 | import androidx.lifecycle.Lifecycle.State.CREATED 14 | import androidx.lifecycle.Lifecycle.State.DESTROYED 15 | import androidx.lifecycle.Lifecycle.State.INITIALIZED 16 | import androidx.lifecycle.Lifecycle.State.RESUMED 17 | import androidx.lifecycle.Lifecycle.State.STARTED 18 | import androidx.lifecycle.LifecycleEventObserver 19 | import androidx.lifecycle.LifecycleOwner 20 | import io.reactivex.disposables.Disposable 21 | 22 | /** 23 | * Dispose on corresponding lifecycle event. 24 | * 25 | * ``` 26 | * | Subscribe | Lifecycle.State | Dispose | 27 | * | --------- | --------------- | --------- | 28 | * | onCreate | INITIALIZED | onDestroy | 29 | * | onStart | CREATED | onStop | 30 | * | onResume | STARTED | onPause | 31 | * | onPause | STARTED | onDestroy | 32 | * | onStop | CREATED | onDestroy | 33 | * | onDestroy | DESTROYED | onDestroy | 34 | * ``` 35 | */ 36 | fun T.disposeOnLifecycle(activity: FragmentActivity): T = 37 | disposeOnLifecycleEvent( 38 | activity, 39 | when (activity.lifecycle.currentState) { 40 | INITIALIZED -> ON_DESTROY // onCreate 41 | CREATED -> ON_STOP // onStart, onStop 42 | STARTED, RESUMED -> ON_PAUSE // onResume, onPause 43 | DESTROYED -> ON_DESTROY // onDestroy 44 | } 45 | ) 46 | 47 | fun T.disposeOnStop(activity: FragmentActivity): T = disposeOnLifecycleEvent(activity, ON_STOP) 48 | fun T.disposeOnPause(activity: FragmentActivity): T = disposeOnLifecycleEvent(activity, ON_PAUSE) 49 | fun T.disposeOnDestroy(activity: FragmentActivity): T = disposeOnLifecycleEvent(activity, ON_DESTROY) 50 | 51 | private fun T.disposeOnLifecycleEvent(activity: FragmentActivity, lifecycleEvent: Event): T = 52 | disposeOnLifecycleEvents({ activity.lifecycle }, { listOf(lifecycleEvent, ON_DESTROY) }) 53 | 54 | /** 55 | * Dispose on corresponding lifecycle event. 56 | * 57 | * ``` 58 | * | Subscribe | ViewLifecycle.State | Dispose | Lifecycle.State | Dispose | 59 | * | ------------- | --------------------- | ------------- | --------------- | ------------- | 60 | * | onAttach | IllegalStateException | onDestroy | INITIALIZED | onDestroy | 61 | * | onCreate | IllegalStateException | onDestroy | INITIALIZED | onDestroy | 62 | * | onCreateView | IllegalStateException | onDestroyView | CREATED | onDestroy | 63 | * | onViewCreated | INITIALIZED | onDestroyView | not called | not called | 64 | * | onStart | CREATED | onStop | CREATED | onStop | 65 | * | onResume | STARTED | onPause | STARTED | onPause | 66 | * | onPause | STARTED | onDestroyView | STARTED | onDestroy | 67 | * | onStop | CREATED | onDestroyView | CREATED | onDestroy | 68 | * | onDestroyView | DESTROYED | onDestroyView | not called | not called | 69 | * | onDestroy | IllegalStateException | onDestroy | DESTROYED | onDestroy | 70 | * ``` 71 | */ 72 | fun T.disposeOnLifecycle(fragment: Fragment): T = 73 | disposeOnLifecycleEvent( 74 | fragment, 75 | when (fragment.viewLifecycleOrLifecycle.currentState) { 76 | INITIALIZED -> ON_DESTROY // onAttach, onCreate, onViewCreated 77 | CREATED -> if (fragment.viewLifecycleOwnerLiveData.value != null) ON_STOP else null // onCreateView: ON_DESTROY, onStart, onStop: ON_STOP 78 | STARTED, RESUMED -> ON_PAUSE // onResume, onPause 79 | DESTROYED -> ON_DESTROY // onDestroyView, onDestroy 80 | } 81 | ) 82 | 83 | fun T.disposeOnStop(fragment: Fragment): T = disposeOnLifecycleEvent(fragment, ON_STOP) 84 | fun T.disposeOnPause(fragment: Fragment): T = disposeOnLifecycleEvent(fragment, ON_PAUSE) 85 | fun T.disposeOnDestroy(fragment: Fragment): T = disposeOnLifecycleEvent(fragment, ON_DESTROY) 86 | 87 | private fun T.disposeOnLifecycleEvent(fragment: Fragment, lifecycleEvent: Event?): T = 88 | disposeOnLifecycleEvents( 89 | { fragment.viewLifecycleOrLifecycle }, 90 | { listOf(lifecycleEvent ?: if (fragment.viewLifecycleOwnerLiveData.value != null) ON_DESTROY else ON_STOP, ON_DESTROY) } 91 | ) 92 | 93 | private val Fragment.viewLifecycleOrLifecycle: Lifecycle 94 | get() = if (viewLifecycleOwnerLiveData.value != null) viewLifecycleOwner.lifecycle else lifecycle 95 | 96 | private fun T.disposeOnLifecycleEvents(lifecycle: () -> Lifecycle, lifecycleEvents: () -> List): T = 97 | if (lifecycle().currentState == DESTROYED) safeDispose() else doOnLifecycleEvents(lifecycle, lifecycleEvents) { safeDispose() } 98 | 99 | private fun T.doOnLifecycleEvents( 100 | lifecycle: () -> Lifecycle, 101 | lifecycleEvents: () -> List, 102 | onEvent: T.() -> Unit 103 | ): T = this.also { 104 | lifecycle().addObserver(object : LifecycleEventObserver { 105 | override fun onStateChanged(source: LifecycleOwner, event: Event) { 106 | if (event == ON_START) { 107 | source.lifecycle.removeObserver(this) 108 | lifecycle().addObserver(object : LifecycleEventObserver { 109 | override fun onStateChanged(source: LifecycleOwner, event: Event) { 110 | if (event in lifecycleEvents()) { 111 | source.lifecycle.removeObserver(this) 112 | onEvent() 113 | } 114 | } 115 | }) 116 | } else if (event in lifecycleEvents()) { 117 | source.lifecycle.removeObserver(this) 118 | onEvent() 119 | } 120 | } 121 | }) 122 | } 123 | 124 | private fun T.safeDispose(): T = this.also { 125 | if (!isDisposed) { 126 | dispose() 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /LifecycleDispose3/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /LifecycleDispose3/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.library' 3 | id 'com.diffplug.spotless' 4 | id 'org.jetbrains.kotlin.android' 5 | } 6 | 7 | ext { 8 | PUBLISH_GROUP_ID = 'com.wada811.lifecycledispose' 9 | PUBLISH_ARTIFACT_ID = 'lifecycledispose3' 10 | PUBLISH_VERSION = '4.0.0' 11 | } 12 | 13 | apply from: "${rootDir}/publish-module.gradle" 14 | 15 | android { 16 | namespace "com.wada811.lifecycledispose" 17 | compileSdkVersion 33 18 | defaultConfig { 19 | minSdkVersion 21 20 | targetSdkVersion 33 21 | } 22 | compileOptions { 23 | sourceCompatibility JavaVersion.VERSION_11 24 | targetCompatibility JavaVersion.VERSION_11 25 | } 26 | kotlinOptions { 27 | jvmTarget = JavaVersion.VERSION_11.toString() 28 | } 29 | } 30 | 31 | dependencies { 32 | implementation "org.jetbrains.kotlin:kotlin-stdlib:1.9.10" 33 | implementation "io.reactivex.rxjava3:rxkotlin:3.0.1" 34 | implementation 'io.reactivex.rxjava3:rxjava:3.1.8' 35 | implementation "androidx.fragment:fragment:1.6.1" 36 | } 37 | -------------------------------------------------------------------------------- /LifecycleDispose3/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /LifecycleDispose3/src/main/java/com/wada811/lifecycledispose/LifecycleDispose.kt: -------------------------------------------------------------------------------- 1 | @file:Suppress("unused") 2 | 3 | package com.wada811.lifecycledispose 4 | 5 | import androidx.fragment.app.Fragment 6 | import androidx.fragment.app.FragmentActivity 7 | import androidx.lifecycle.Lifecycle 8 | import androidx.lifecycle.Lifecycle.Event 9 | import androidx.lifecycle.Lifecycle.Event.ON_DESTROY 10 | import androidx.lifecycle.Lifecycle.Event.ON_PAUSE 11 | import androidx.lifecycle.Lifecycle.Event.ON_START 12 | import androidx.lifecycle.Lifecycle.Event.ON_STOP 13 | import androidx.lifecycle.Lifecycle.State.CREATED 14 | import androidx.lifecycle.Lifecycle.State.DESTROYED 15 | import androidx.lifecycle.Lifecycle.State.INITIALIZED 16 | import androidx.lifecycle.Lifecycle.State.RESUMED 17 | import androidx.lifecycle.Lifecycle.State.STARTED 18 | import androidx.lifecycle.LifecycleEventObserver 19 | import androidx.lifecycle.LifecycleOwner 20 | import io.reactivex.rxjava3.disposables.Disposable 21 | 22 | /** 23 | * Dispose on corresponding lifecycle event. 24 | * 25 | * ``` 26 | * | Subscribe | Lifecycle.State | Dispose | 27 | * | --------- | --------------- | --------- | 28 | * | onCreate | INITIALIZED | onDestroy | 29 | * | onStart | CREATED | onStop | 30 | * | onResume | STARTED | onPause | 31 | * | onPause | STARTED | onDestroy | 32 | * | onStop | CREATED | onDestroy | 33 | * | onDestroy | DESTROYED | onDestroy | 34 | * ``` 35 | */ 36 | fun T.disposeOnLifecycle(activity: FragmentActivity): T = 37 | disposeOnLifecycleEvent(activity, when (activity.lifecycle.currentState) { 38 | INITIALIZED -> ON_DESTROY // onCreate 39 | CREATED -> ON_STOP // onStart, onStop 40 | STARTED, RESUMED -> ON_PAUSE // onResume, onPause 41 | DESTROYED -> ON_DESTROY // onDestroy 42 | }) 43 | 44 | fun T.disposeOnStop(activity: FragmentActivity): T = disposeOnLifecycleEvent(activity, ON_STOP) 45 | fun T.disposeOnPause(activity: FragmentActivity): T = disposeOnLifecycleEvent(activity, ON_PAUSE) 46 | fun T.disposeOnDestroy(activity: FragmentActivity): T = disposeOnLifecycleEvent(activity, ON_DESTROY) 47 | 48 | private fun T.disposeOnLifecycleEvent(activity: FragmentActivity, lifecycleEvent: Event): T = 49 | disposeOnLifecycleEvents({ activity.lifecycle }, { listOf(lifecycleEvent, ON_DESTROY) }) 50 | 51 | /** 52 | * Dispose on corresponding lifecycle event. 53 | * 54 | * ``` 55 | * | Subscribe | ViewLifecycle.State | Dispose | Lifecycle.State | Dispose | 56 | * | ------------- | --------------------- | ------------- | --------------- | ------------- | 57 | * | onAttach | IllegalStateException | onDestroy | INITIALIZED | onDestroy | 58 | * | onCreate | IllegalStateException | onDestroy | INITIALIZED | onDestroy | 59 | * | onCreateView | IllegalStateException | onDestroyView | CREATED | onDestroy | 60 | * | onViewCreated | INITIALIZED | onDestroyView | not called | not called | 61 | * | onStart | CREATED | onStop | CREATED | onStop | 62 | * | onResume | STARTED | onPause | STARTED | onPause | 63 | * | onPause | STARTED | onDestroyView | STARTED | onDestroy | 64 | * | onStop | CREATED | onDestroyView | CREATED | onDestroy | 65 | * | onDestroyView | DESTROYED | onDestroyView | not called | not called | 66 | * | onDestroy | IllegalStateException | onDestroy | DESTROYED | onDestroy | 67 | * ``` 68 | */ 69 | fun T.disposeOnLifecycle(fragment: Fragment): T = 70 | disposeOnLifecycleEvent(fragment, when (fragment.viewLifecycleOrLifecycle.currentState) { 71 | INITIALIZED -> ON_DESTROY // onAttach, onCreate, onViewCreated 72 | CREATED -> if (fragment.viewLifecycleOwnerLiveData.value != null) ON_STOP else null // onCreateView: ON_DESTROY, onStart, onStop: ON_STOP 73 | STARTED, RESUMED -> ON_PAUSE // onResume, onPause 74 | DESTROYED -> ON_DESTROY // onDestroyView, onDestroy 75 | }) 76 | 77 | fun T.disposeOnStop(fragment: Fragment): T = disposeOnLifecycleEvent(fragment, ON_STOP) 78 | fun T.disposeOnPause(fragment: Fragment): T = disposeOnLifecycleEvent(fragment, ON_PAUSE) 79 | fun T.disposeOnDestroy(fragment: Fragment): T = disposeOnLifecycleEvent(fragment, ON_DESTROY) 80 | 81 | private fun T.disposeOnLifecycleEvent(fragment: Fragment, lifecycleEvent: Event?): T = 82 | disposeOnLifecycleEvents( 83 | { fragment.viewLifecycleOrLifecycle }, 84 | { listOf(lifecycleEvent ?: if (fragment.viewLifecycleOwnerLiveData.value != null) ON_DESTROY else ON_STOP, ON_DESTROY) } 85 | ) 86 | 87 | private val Fragment.viewLifecycleOrLifecycle: Lifecycle 88 | get() = if (viewLifecycleOwnerLiveData.value != null) viewLifecycleOwner.lifecycle else lifecycle 89 | 90 | private fun T.disposeOnLifecycleEvents(lifecycle: () -> Lifecycle, lifecycleEvents: () -> List): T = 91 | if (lifecycle().currentState == DESTROYED) safeDispose() else doOnLifecycleEvents(lifecycle, lifecycleEvents) { safeDispose() } 92 | 93 | private fun T.doOnLifecycleEvents( 94 | lifecycle: () -> Lifecycle, 95 | lifecycleEvents: () -> List, 96 | onEvent: T.() -> Unit 97 | ): T = this.also { 98 | lifecycle().addObserver(object : LifecycleEventObserver { 99 | override fun onStateChanged(source: LifecycleOwner, event: Event) { 100 | if (event == ON_START) { 101 | source.lifecycle.removeObserver(this) 102 | lifecycle().addObserver(object : LifecycleEventObserver { 103 | override fun onStateChanged(source: LifecycleOwner, event: Event) { 104 | if (event in lifecycleEvents()) { 105 | source.lifecycle.removeObserver(this) 106 | onEvent() 107 | } 108 | } 109 | }) 110 | } else if (event in lifecycleEvents()) { 111 | source.lifecycle.removeObserver(this) 112 | onEvent() 113 | } 114 | } 115 | }) 116 | } 117 | 118 | private fun T.safeDispose(): T = this.also { 119 | if (!isDisposed) { 120 | dispose() 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | LifecycleDispose 2 | ===== 3 | 4 | `LifecycleDispose` dispose RxJava streams on lifecycle down event that corresponding to Activity/Fragment's lifecycle state when subscribe using [Android Architecture Components Lifecycle](https://developer.android.com/topic/libraries/architecture/lifecycle). 5 | 6 | ![Lifecycle State](https://developer.android.com/images/topic/libraries/architecture/lifecycle-states.svg) 7 | 8 | ## Usage 9 | ### disposeOnPause 10 | Dispose when onPause is called. 11 | 12 | ```kotlin 13 | Observable.interval(1, TimeUnit.SECONDS) 14 | .subscribe() 15 | .disposeOnPause(this) // `this` is FragmentActivity or Fragment 16 | ``` 17 | 18 | ### disposeOnStop 19 | Dispose when onStop is called. 20 | 21 | ```kotlin 22 | Observable.interval(1, TimeUnit.SECONDS) 23 | .subscribe() 24 | .disposeOnStop(this) // `this` is FragmentActivity or Fragment 25 | ``` 26 | 27 | ### disposeOnDestroy 28 | Dispose when onDestroy is called. 29 | If Fragment has view, dispose when onDestroyView is called. 30 | 31 | ```kotlin 32 | Observable.interval(1, TimeUnit.SECONDS) 33 | .subscribe() 34 | .disposeOnDestroy(this) // `this` is FragmentActivity or Fragment 35 | ``` 36 | 37 | ### disposeOnLifecycle 38 | Dispose on lifecycle down event that corresponding to Activity/Fragment's lifecycle state. See next section. 39 | 40 | ```kotlin 41 | Observable.interval(1, TimeUnit.SECONDS) 42 | .subscribe() 43 | .disposeOnLifecycle(this) // `this` is FragmentActivity or Fragment 44 | ``` 45 | 46 | ## Lifecycle down event that corresponding to Activity/Fragment's lifecycle state 47 | ### Activity 48 | 49 | **Table 1** Corresponding between Activity's lifecycle state and Lifecycle down event. 50 | 51 | | Subscribe | Lifecycle.State | Lifecycle.Event | Dispose | 52 | |-----------|-----------------|-----------------|-----------| 53 | | onCreate | INITIALIZED | ON_DESTROY | onDestroy | 54 | | onStart | CREATED | ON_STOP | onStop | 55 | | onResume | STARTED | ON_PAUSE | onPause | 56 | | onPause | STARTED | ON_DESTROY | onDestroy | 57 | | onStop | CREATED | ON_DESTROY | onDestroy | 58 | | onDestroy | DESTROYED | ON_DESTROY | onDestroy | 59 | 60 | 61 | ### Fragment 62 | 63 | **Table 2** Corresponding between Fragment's lifecycle state and Lifecycle down event. 64 | 65 | | Subscribe | ViewLifecycle.State | Dispose | Lifecycle.State | Dispose | 66 | |---------------|-----------------------|---------------|-----------------|------------| 67 | | onAttach | IllegalStateException | onDestroy | INITIALIZED | onDestroy | 68 | | onCreate | IllegalStateException | onDestroy | INITIALIZED | onDestroy | 69 | | onCreateView | IllegalStateException | onDestroyView | CREATED | onDestroy | 70 | | onViewCreated | INITIALIZED | onDestroyView | not called | not called | 71 | | onStart | CREATED | onStop | CREATED | onStop | 72 | | onResume | STARTED | onPause | STARTED | onPause | 73 | | onPause | STARTED | onDestroyView | STARTED | onDestroy | 74 | | onStop | CREATED | onDestroyView | CREATED | onDestroy | 75 | | onDestroyView | DESTROYED | onDestroyView | not called | not called | 76 | | onDestroy | IllegalStateException | onDestroy | DESTROYED | onDestroy | 77 | 78 | ## Gradle 79 | 80 | ### LifecycleDispose2 81 | 82 | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.wada811.lifecycledispose/lifecycledispose2/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.wada811.lifecycledispose/lifecycledispose2) 83 | 84 | ```groovy 85 | repositories { 86 | mavenCentral() 87 | } 88 | 89 | dependencies { 90 | implementation 'com.wada811.lifecycledispose:lifecycledispose2:x.y.z' 91 | } 92 | ``` 93 | 94 | ### LifecycleDispose3 95 | 96 | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.wada811.lifecycledispose/lifecycledispose3/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.wada811.lifecycledispose/lifecycledispose3) 97 | 98 | ```groovy 99 | repositories { 100 | mavenCentral() 101 | } 102 | 103 | dependencies { 104 | implementation 'com.wada811.lifecycledispose:lifecycledispose3:x.y.z' 105 | } 106 | ``` 107 | 108 | ## License 109 | 110 | Copyright (C) 2019 wada811 111 | 112 | Licensed under the Apache License, Version 2.0 113 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' version '8.1.2' apply false 3 | id 'com.android.library' version '8.1.2' apply false 4 | id "com.diffplug.spotless" version "6.22.0" apply false 5 | id 'org.jetbrains.kotlin.android' version '1.9.10' apply false 6 | id "io.github.gradle-nexus.publish-plugin" version "1.3.0" 7 | } 8 | 9 | apply from: "${rootDir}/publish-root.gradle" 10 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Settings specified in this file will override any Gradle settings 4 | # configured through the IDE. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | org.gradle.daemon=true 8 | # Specifies the JVM arguments used for the daemon process. 9 | # The setting is particularly useful for tweaking memory settings. 10 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 11 | org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 12 | # When configured, Gradle will run in incubating parallel mode. 13 | # This option should only be used with decoupled projects. More details, visit 14 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 15 | org.gradle.parallel=true 16 | org.gradle.caching=true 17 | org.gradle.configureondemand=true 18 | # Kotlin code style for this project: "official" or "obsolete": 19 | kotlin.code.style=official 20 | # Kapt improvements 21 | # https://blog.jetbrains.com/kotlin/2018/08/kotlin-1-2-60-is-out/ 22 | kapt.use.worker.api=truerenovate.json 23 | # Faster Gradle builds by parallelizing tasks 24 | # https://blog.jetbrains.com/kotlin/2019/01/kotlin-1-3-20-released/ 25 | # For Android, the debug and release build types can be compiled in parallel. 26 | kotlin.parallel.tasks.in.project=true 27 | # Compile avoidance for kapt 28 | kapt.include.compile.classpath=false 29 | # Incremental annotation processing in KAPT 30 | # https://blog.jetbrains.com/kotlin/2019/04/kotlin-1-3-30-released/ 31 | kapt.incremental.apt=true 32 | # Incremental annotation processing for DataBinding 33 | # https://developer.android.com/studio/releases/gradle-plugin#incremental_ap 34 | android.databinding.incremental=true 35 | # AndroidX package structure to make it clearer which packages are bundled with the 36 | # Android operating system, and which are packaged with your app"s APK 37 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 38 | android.useAndroidX=true 39 | # Automatically convert third-party libraries to use AndroidX 40 | android.enableJetifier=true 41 | # Cacheable unit tests 42 | # https://developer.android.com/studio/releases/gradle-plugin#cacheable_tests 43 | android.testConfig.useRelativePath=true 44 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wada811/LifecycleDispose/77bf8d4c1c417a4cf948e28a9897b37c1e598cbb/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip 4 | networkTimeout=10000 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | # This is normally unused 84 | # shellcheck disable=SC2034 85 | APP_BASE_NAME=${0##*/} 86 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 147 | # shellcheck disable=SC3045 148 | MAX_FD=$( ulimit -H -n ) || 149 | warn "Could not query maximum file descriptor limit" 150 | esac 151 | case $MAX_FD in #( 152 | '' | soft) :;; #( 153 | *) 154 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 155 | # shellcheck disable=SC3045 156 | ulimit -n "$MAX_FD" || 157 | warn "Could not set maximum file descriptor limit to $MAX_FD" 158 | esac 159 | fi 160 | 161 | # Collect all arguments for the java command, stacking in reverse order: 162 | # * args from the command line 163 | # * the main class name 164 | # * -classpath 165 | # * -D...appname settings 166 | # * --module-path (only if needed) 167 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 168 | 169 | # For Cygwin or MSYS, switch paths to Windows format before running java 170 | if "$cygwin" || "$msys" ; then 171 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 172 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 173 | 174 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 175 | 176 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 177 | for arg do 178 | if 179 | case $arg in #( 180 | -*) false ;; # don't mess with options #( 181 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 182 | [ -e "$t" ] ;; #( 183 | *) false ;; 184 | esac 185 | then 186 | arg=$( cygpath --path --ignore --mixed "$arg" ) 187 | fi 188 | # Roll the args list around exactly as many times as the number of 189 | # args, so each arg winds up back in the position where it started, but 190 | # possibly modified. 191 | # 192 | # NB: a `for` loop captures its iteration list before it begins, so 193 | # changing the positional parameters here affects neither the number of 194 | # iterations, nor the values presented in `arg`. 195 | shift # remove old arg 196 | set -- "$@" "$arg" # push replacement arg 197 | done 198 | fi 199 | 200 | # Collect all arguments for the java command; 201 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 202 | # shell script including quotes and variable substitutions, so put them in 203 | # double quotes to make sure that they get re-expanded; and 204 | # * put everything else in single quotes, so that it's not re-expanded. 205 | 206 | set -- \ 207 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 208 | -classpath "$CLASSPATH" \ 209 | org.gradle.wrapper.GradleWrapperMain \ 210 | "$@" 211 | 212 | # Stop when "xargs" is not available. 213 | if ! command -v xargs >/dev/null 2>&1 214 | then 215 | die "xargs is not available" 216 | fi 217 | 218 | # Use "xargs" to parse quoted args. 219 | # 220 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 221 | # 222 | # In Bash we could simply go: 223 | # 224 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 225 | # set -- "${ARGS[@]}" "$@" 226 | # 227 | # but POSIX shell has neither arrays nor command substitution, so instead we 228 | # post-process each arg (as a line of input to sed) to backslash-escape any 229 | # character that might be a shell metacharacter, then use eval to reverse 230 | # that process (while maintaining the separation between arguments), and wrap 231 | # the whole thing up as a single "set" statement. 232 | # 233 | # This will of course break if any of these variables contains a newline or 234 | # an unmatched quote. 235 | # 236 | 237 | eval "set -- $( 238 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 239 | xargs -n1 | 240 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 241 | tr '\n' ' ' 242 | )" '"$@"' 243 | 244 | exec "$JAVACMD" "$@" 245 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 48 | echo. 49 | echo Please set the JAVA_HOME variable in your environment to match the 50 | echo location of your Java installation. 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 62 | echo. 63 | echo Please set the JAVA_HOME variable in your environment to match the 64 | echo location of your Java installation. 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /publish-module.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'maven-publish' 2 | apply plugin: 'signing' 3 | 4 | android { 5 | publishing { 6 | singleVariant('release') { 7 | withSourcesJar() 8 | } 9 | } 10 | } 11 | 12 | signing { 13 | useInMemoryPgpKeys( 14 | rootProject.ext["signing.keyId"], 15 | rootProject.ext["signing.key"], 16 | rootProject.ext["signing.password"], 17 | ) 18 | sign publishing.publications 19 | } 20 | 21 | group = PUBLISH_GROUP_ID 22 | version = PUBLISH_VERSION 23 | 24 | afterEvaluate { 25 | publishing { 26 | publications { 27 | release(MavenPublication) { 28 | groupId PUBLISH_GROUP_ID 29 | artifactId PUBLISH_ARTIFACT_ID 30 | version PUBLISH_VERSION 31 | 32 | // Two artifacts, the `aar` (or `jar`) and the sources 33 | if (project.plugins.findPlugin("com.android.library")) { 34 | from components.release 35 | } else { 36 | from components.java 37 | } 38 | 39 | pom { 40 | name = PUBLISH_ARTIFACT_ID 41 | description = 'Dispose automatically RxJava streams using AAC Lifecycle..' 42 | url = 'https://github.com/wada811/LifecycleDispose' 43 | 44 | licenses { 45 | license { 46 | name = 'The Apache License, Version 2.0' 47 | url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' 48 | } 49 | } 50 | developers { 51 | developer { 52 | id = 'wada811' 53 | name = 'WADA Takumi' 54 | email = 'at.wada811@gmail.com' 55 | } 56 | } 57 | scm { 58 | connection = 'scm:git:github.com/wada811/LifecycleDispose.git' 59 | developerConnection = 'scm:git:ssh://github.com/wada811/LifecycleDispose.git' 60 | url = 'https://github.com/wada811/LifecycleDispose/tree/master' 61 | } 62 | } 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /publish-root.gradle: -------------------------------------------------------------------------------- 1 | ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME') 2 | ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD') 3 | ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID') 4 | ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID') 5 | ext["signing.password"] = System.getenv('SIGNING_PASSWORD') 6 | ext["signing.key"] = System.getenv('SIGNING_KEY') 7 | 8 | nexusPublishing { 9 | repositories { 10 | sonatype { 11 | stagingProfileId = sonatypeStagingProfileId 12 | username = ossrhUsername 13 | password = ossrhPassword 14 | nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) 15 | snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "config:base" 4 | ], 5 | "dependencyDashboard": true, 6 | "packageRules": [ 7 | { 8 | "groupName": "Android Gradle Plugin", 9 | "matchPackagePatterns": [ 10 | "com\\.android\\.application", 11 | "com\\.android\\.library" 12 | ] 13 | }, 14 | { 15 | "groupName": "Kotlin", 16 | "matchPackagePatterns": [ 17 | "^org\\.jetbrains\\.kotlin" 18 | ] 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | gradlePluginPortal() 4 | google() 5 | mavenCentral() 6 | } 7 | } 8 | dependencyResolutionManagement { 9 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) 10 | repositories { 11 | google() 12 | mavenCentral() 13 | } 14 | } 15 | rootProject.name = "LifecycleDispose" 16 | include ':LifecycleDispose2' 17 | include ':LifecycleDispose3' 18 | include ':test' 19 | -------------------------------------------------------------------------------- /test/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /test/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'kotlin-android' 3 | 4 | android { 5 | namespace "com.wada811.lifecycledispose.test" 6 | compileSdkVersion 33 7 | defaultConfig { 8 | minSdkVersion 21 9 | targetSdkVersion 33 10 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 11 | } 12 | compileOptions { 13 | sourceCompatibility JavaVersion.VERSION_11 14 | targetCompatibility JavaVersion.VERSION_11 15 | } 16 | kotlinOptions { 17 | jvmTarget = JavaVersion.VERSION_11.toString() 18 | } 19 | testOptions { 20 | unitTests.includeAndroidResources = true 21 | } 22 | } 23 | 24 | dependencies { 25 | implementation "org.jetbrains.kotlin:kotlin-stdlib:1.8.0" 26 | implementation project(":LifecycleDispose3") 27 | implementation "io.reactivex.rxjava3:rxkotlin:3.0.0" 28 | implementation 'io.reactivex.rxjava3:rxjava:3.0.5' 29 | implementation "androidx.fragment:fragment-ktx:1.5.5" 30 | debugImplementation 'androidx.fragment:fragment-testing:1.5.5' 31 | 32 | testImplementation 'junit:junit:4.13.2' 33 | 34 | // Core library 35 | testImplementation 'androidx.test:core-ktx:1.5.0' 36 | 37 | // AndroidJUnitRunner, JUnit Rules and RobolectricRunner 38 | testImplementation 'androidx.test:runner:1.5.1' 39 | testImplementation 'androidx.test:rules:1.5.0' 40 | testImplementation 'org.robolectric:robolectric:4.9' 41 | 42 | // Assertions 43 | testImplementation 'androidx.test.ext:junit:1.1.4' 44 | testImplementation 'androidx.test.ext:junit-ktx:1.1.4' 45 | testImplementation 'androidx.test.ext:truth:1.5.0' 46 | testImplementation 'com.google.truth:truth:1.1.3' 47 | } 48 | -------------------------------------------------------------------------------- /test/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /test/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /test/src/main/java/com/wada811/lifecycledispose/test/DisposeActivity.kt: -------------------------------------------------------------------------------- 1 | package com.wada811.lifecycledispose.test 2 | 3 | import android.content.Intent 4 | import android.os.Bundle 5 | import androidx.fragment.app.FragmentActivity 6 | import androidx.lifecycle.Lifecycle 7 | import androidx.lifecycle.Lifecycle.Event.ON_CREATE 8 | import androidx.lifecycle.Lifecycle.Event.ON_DESTROY 9 | import androidx.lifecycle.Lifecycle.Event.ON_PAUSE 10 | import androidx.lifecycle.Lifecycle.Event.ON_RESUME 11 | import androidx.lifecycle.Lifecycle.Event.ON_START 12 | import androidx.lifecycle.Lifecycle.Event.ON_STOP 13 | import io.reactivex.rxjava3.core.Observable 14 | import java.util.concurrent.TimeUnit.SECONDS 15 | 16 | class DisposeActivity : FragmentActivity() { 17 | companion object { 18 | fun createIntent( 19 | disposeStrategy: DisposeStrategy, 20 | subscribeWhenLifecycleEvent: Lifecycle.Event 21 | ) = Intent("com.wada811.lifecycledispose.test.ACTION_TEST").also { 22 | it.putExtra(DisposeActivity::disposeStrategy.name, disposeStrategy.ordinal) 23 | it.putExtra(DisposeActivity::subscribeWhenLifecycleEvent.name, subscribeWhenLifecycleEvent.ordinal) 24 | } 25 | } 26 | 27 | val disposeStrategy: DisposeStrategy by lazy { 28 | DisposeStrategy.values()[intent.getIntExtra(this::disposeStrategy.name, -1)] 29 | } 30 | val subscribeWhenLifecycleEvent: Lifecycle.Event by lazy { 31 | Lifecycle.Event.values()[intent.getIntExtra(this::subscribeWhenLifecycleEvent.name, -1)] 32 | } 33 | var disposedLifecycleState: Lifecycle.State? = null 34 | 35 | private fun subscribe(event: Lifecycle.Event) { 36 | println("state: ${lifecycle.currentState}, event: $event") 37 | if (subscribeWhenLifecycleEvent == event) { 38 | disposeStrategy.dispose( 39 | this, 40 | Observable.interval(1, SECONDS) 41 | .doOnDispose { disposedLifecycleState = lifecycle.currentState } 42 | .subscribe() 43 | ) 44 | } 45 | } 46 | 47 | override fun onCreate(savedInstanceState: Bundle?) { 48 | super.onCreate(savedInstanceState) 49 | subscribe(ON_CREATE) 50 | } 51 | 52 | override fun onStart() { 53 | super.onStart() 54 | subscribe(ON_START) 55 | } 56 | 57 | override fun onResume() { 58 | super.onResume() 59 | subscribe(ON_RESUME) 60 | } 61 | 62 | override fun onPause() { 63 | super.onPause() 64 | subscribe(ON_PAUSE) 65 | } 66 | 67 | override fun onStop() { 68 | super.onStop() 69 | subscribe(ON_STOP) 70 | } 71 | 72 | override fun onDestroy() { 73 | super.onDestroy() 74 | subscribe(ON_DESTROY) 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /test/src/main/java/com/wada811/lifecycledispose/test/DisposeNoViewFragment.kt: -------------------------------------------------------------------------------- 1 | package com.wada811.lifecycledispose.test 2 | 3 | import android.content.Context 4 | import android.os.Bundle 5 | import androidx.fragment.app.Fragment 6 | import androidx.lifecycle.Lifecycle 7 | import io.reactivex.rxjava3.core.Observable 8 | import java.util.concurrent.TimeUnit.SECONDS 9 | 10 | class DisposeNoViewFragment : Fragment() { 11 | companion object { 12 | fun createBundle( 13 | disposeStrategy: DisposeStrategy, 14 | subscribeWhenLifecycleEvent: FragmentLifecycleEvent 15 | ) = Bundle().also { 16 | it.putInt(DisposeNoViewFragment::disposeStrategy.name, disposeStrategy.ordinal) 17 | it.putInt(DisposeNoViewFragment::subscribeWhenLifecycleEvent.name, subscribeWhenLifecycleEvent.ordinal) 18 | } 19 | } 20 | 21 | val disposeStrategy: DisposeStrategy by lazy { 22 | DisposeStrategy.values()[requireArguments().getInt(this::disposeStrategy.name, -1)] 23 | } 24 | val subscribeWhenLifecycleEvent: FragmentLifecycleEvent by lazy { 25 | FragmentLifecycleEvent.values()[requireArguments().getInt(this::subscribeWhenLifecycleEvent.name, -1)] 26 | } 27 | var disposedLifecycleState: Lifecycle.State? = null 28 | 29 | private fun subscribe(event: FragmentLifecycleEvent) { 30 | println("state: ${lifecycle.currentState}, event: $event") 31 | if (subscribeWhenLifecycleEvent == event) { 32 | disposeStrategy.dispose( 33 | this, 34 | Observable.interval(1, SECONDS) 35 | .doOnSubscribe { println("subscribe: ${lifecycle.currentState}") } 36 | .doOnDispose { println("dispose: ${lifecycle.currentState}") } 37 | .doOnDispose { disposedLifecycleState = lifecycle.currentState } 38 | .subscribe() 39 | ) 40 | } 41 | } 42 | 43 | override fun onAttach(context: Context) { 44 | super.onAttach(context) 45 | subscribe(FragmentLifecycleEvent.OnAttach) 46 | } 47 | 48 | override fun onCreate(savedInstanceState: Bundle?) { 49 | super.onCreate(savedInstanceState) 50 | subscribe(FragmentLifecycleEvent.OnCreate) 51 | } 52 | 53 | override fun onStart() { 54 | super.onStart() 55 | subscribe(FragmentLifecycleEvent.OnStart) 56 | } 57 | 58 | override fun onResume() { 59 | super.onResume() 60 | subscribe(FragmentLifecycleEvent.OnResume) 61 | } 62 | 63 | override fun onPause() { 64 | super.onPause() 65 | subscribe(FragmentLifecycleEvent.OnPause) 66 | } 67 | 68 | override fun onStop() { 69 | super.onStop() 70 | subscribe(FragmentLifecycleEvent.OnStop) 71 | } 72 | 73 | override fun onDestroy() { 74 | super.onDestroy() 75 | subscribe(FragmentLifecycleEvent.OnDestroy) 76 | } 77 | } -------------------------------------------------------------------------------- /test/src/main/java/com/wada811/lifecycledispose/test/DisposeStrategy.kt: -------------------------------------------------------------------------------- 1 | package com.wada811.lifecycledispose.test 2 | 3 | import androidx.fragment.app.Fragment 4 | import androidx.fragment.app.FragmentActivity 5 | import com.wada811.lifecycledispose.disposeOnDestroy 6 | import com.wada811.lifecycledispose.disposeOnLifecycle 7 | import com.wada811.lifecycledispose.disposeOnPause 8 | import com.wada811.lifecycledispose.disposeOnStop 9 | import io.reactivex.rxjava3.disposables.Disposable 10 | 11 | enum class DisposeStrategy { 12 | OnLifecycle { 13 | override fun dispose(activity: FragmentActivity, disposable: Disposable) { 14 | disposable.disposeOnLifecycle(activity) 15 | } 16 | 17 | override fun dispose(fragment: Fragment, disposable: Disposable) { 18 | disposable.disposeOnLifecycle(fragment) 19 | } 20 | }, 21 | OnPause { 22 | override fun dispose(activity: FragmentActivity, disposable: Disposable) { 23 | disposable.disposeOnPause(activity) 24 | } 25 | 26 | override fun dispose(fragment: Fragment, disposable: Disposable) { 27 | disposable.disposeOnPause(fragment) 28 | } 29 | }, 30 | OnStop { 31 | override fun dispose(activity: FragmentActivity, disposable: Disposable) { 32 | disposable.disposeOnStop(activity) 33 | } 34 | 35 | override fun dispose(fragment: Fragment, disposable: Disposable) { 36 | disposable.disposeOnStop(fragment) 37 | } 38 | }, 39 | OnDestroy { 40 | override fun dispose(activity: FragmentActivity, disposable: Disposable) { 41 | disposable.disposeOnDestroy(activity) 42 | } 43 | 44 | override fun dispose(fragment: Fragment, disposable: Disposable) { 45 | disposable.disposeOnDestroy(fragment) 46 | } 47 | }, 48 | ; 49 | 50 | abstract fun dispose(activity: FragmentActivity, disposable: Disposable) 51 | abstract fun dispose(fragment: Fragment, disposable: Disposable) 52 | } -------------------------------------------------------------------------------- /test/src/main/java/com/wada811/lifecycledispose/test/DisposeViewFragment.kt: -------------------------------------------------------------------------------- 1 | package com.wada811.lifecycledispose.test 2 | 3 | import android.content.Context 4 | import android.os.Bundle 5 | import android.view.LayoutInflater 6 | import android.view.View 7 | import android.view.ViewGroup 8 | import androidx.fragment.app.Fragment 9 | import androidx.lifecycle.Lifecycle 10 | import io.reactivex.rxjava3.core.Observable 11 | import java.util.concurrent.TimeUnit.SECONDS 12 | 13 | class DisposeViewFragment : Fragment() { 14 | companion object { 15 | fun createBundle( 16 | disposeStrategy: DisposeStrategy, 17 | subscribeWhenLifecycleEvent: FragmentLifecycleEvent 18 | ) = Bundle().also { 19 | it.putInt(DisposeViewFragment::disposeStrategy.name, disposeStrategy.ordinal) 20 | it.putInt(DisposeViewFragment::subscribeWhenLifecycleEvent.name, subscribeWhenLifecycleEvent.ordinal) 21 | } 22 | } 23 | 24 | val disposeStrategy: DisposeStrategy by lazy { 25 | DisposeStrategy.values()[requireArguments().getInt(this::disposeStrategy.name, -1)] 26 | } 27 | val subscribeWhenLifecycleEvent: FragmentLifecycleEvent by lazy { 28 | FragmentLifecycleEvent.values()[requireArguments().getInt(this::subscribeWhenLifecycleEvent.name, -1)] 29 | } 30 | var disposedLifecycleState: Lifecycle.State? = null 31 | 32 | private val currentState: String 33 | get() = if (viewLifecycleOwnerLiveData.value != null) "${viewLifecycleOwner.lifecycle.currentState}" else "IllegalStateException" 34 | 35 | private fun subscribe(event: FragmentLifecycleEvent) { 36 | println("state: $currentState, event: $event") 37 | if (subscribeWhenLifecycleEvent == event) { 38 | disposeStrategy.dispose( 39 | this, 40 | Observable.interval(1, SECONDS) 41 | .doOnSubscribe { println("subscribe: $currentState") } 42 | .doOnDispose { println("dispose: $currentState") } 43 | .doOnDispose { disposedLifecycleState = if (viewLifecycleOwnerLiveData.value != null) viewLifecycleOwner.lifecycle.currentState else lifecycle.currentState } 44 | .subscribe() 45 | ) 46 | } 47 | } 48 | 49 | override fun onAttach(context: Context) { 50 | super.onAttach(context) 51 | subscribe(FragmentLifecycleEvent.OnAttach) 52 | } 53 | 54 | override fun onCreate(savedInstanceState: Bundle?) { 55 | super.onCreate(savedInstanceState) 56 | subscribe(FragmentLifecycleEvent.OnCreate) 57 | } 58 | 59 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { 60 | subscribe(FragmentLifecycleEvent.OnCreateView) 61 | return View(requireContext()) 62 | } 63 | 64 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 65 | super.onViewCreated(view, savedInstanceState) 66 | subscribe(FragmentLifecycleEvent.OnViewCreated) 67 | } 68 | 69 | override fun onStart() { 70 | super.onStart() 71 | subscribe(FragmentLifecycleEvent.OnStart) 72 | } 73 | 74 | override fun onResume() { 75 | super.onResume() 76 | subscribe(FragmentLifecycleEvent.OnResume) 77 | } 78 | 79 | override fun onPause() { 80 | super.onPause() 81 | subscribe(FragmentLifecycleEvent.OnPause) 82 | } 83 | 84 | override fun onStop() { 85 | super.onStop() 86 | subscribe(FragmentLifecycleEvent.OnStop) 87 | } 88 | 89 | override fun onDestroyView() { 90 | super.onDestroyView() 91 | subscribe(FragmentLifecycleEvent.OnDestroyView) 92 | } 93 | 94 | override fun onDestroy() { 95 | super.onDestroy() 96 | subscribe(FragmentLifecycleEvent.OnDestroy) 97 | } 98 | } -------------------------------------------------------------------------------- /test/src/main/java/com/wada811/lifecycledispose/test/FragmentLifecycleEvent.kt: -------------------------------------------------------------------------------- 1 | package com.wada811.lifecycledispose.test 2 | 3 | enum class FragmentLifecycleEvent { 4 | OnAttach, 5 | OnCreate, 6 | OnCreateView, 7 | OnViewCreated, 8 | OnStart, 9 | OnResume, 10 | OnPause, 11 | OnStop, 12 | OnDestroyView, 13 | OnDestroy 14 | } -------------------------------------------------------------------------------- /test/src/test/java/com/wada811/lifecycledispose/test/ActivityTest.kt: -------------------------------------------------------------------------------- 1 | package com.wada811.lifecycledispose.test 2 | 3 | import android.os.Build 4 | import androidx.lifecycle.Lifecycle 5 | import androidx.lifecycle.Lifecycle.Event.ON_CREATE 6 | import androidx.lifecycle.Lifecycle.Event.ON_DESTROY 7 | import androidx.lifecycle.Lifecycle.Event.ON_PAUSE 8 | import androidx.lifecycle.Lifecycle.Event.ON_RESUME 9 | import androidx.lifecycle.Lifecycle.Event.ON_START 10 | import androidx.lifecycle.Lifecycle.Event.ON_STOP 11 | import androidx.lifecycle.Lifecycle.State.CREATED 12 | import androidx.lifecycle.Lifecycle.State.DESTROYED 13 | import androidx.lifecycle.Lifecycle.State.STARTED 14 | import androidx.test.core.app.ActivityScenario 15 | import com.google.common.truth.Truth 16 | import org.junit.Test 17 | import org.junit.runner.RunWith 18 | import org.robolectric.ParameterizedRobolectricTestRunner 19 | import org.robolectric.annotation.Config 20 | 21 | /** 22 | * Test disposing on corresponding lifecycle event. 23 | * 24 | * @see Handling Lifecycles with Lifecycle-Aware Components | Android Developers 25 | */ 26 | @Config(sdk = [Build.VERSION_CODES.P]) 27 | @RunWith(ParameterizedRobolectricTestRunner::class) 28 | class ActivityTest( 29 | private val disposeStrategy: DisposeStrategy, 30 | private val subscribeLifecycleEvent: Lifecycle.Event, 31 | private val expectedLifecycleState: Lifecycle.State 32 | ) { 33 | 34 | @Test 35 | fun test() { 36 | var activity: DisposeActivity? = null 37 | ActivityScenario.launch(DisposeActivity.createIntent( 38 | disposeStrategy, 39 | subscribeLifecycleEvent 40 | )).use { scenario -> 41 | scenario.onActivity { activity = it } 42 | scenario.moveToState(DESTROYED) 43 | Truth.assertThat(activity!!.disposedLifecycleState).isEqualTo(expectedLifecycleState) 44 | activity = null 45 | } 46 | } 47 | 48 | 49 | companion object { 50 | @Suppress("unused") 51 | @JvmStatic 52 | @ParameterizedRobolectricTestRunner.Parameters(name = "Strategy: {0}, subscribe: {1}, dispose: {2}") 53 | fun parameters(): Iterable> { 54 | val parameters = mutableListOf>() 55 | // OnLifecycle 56 | parameters.add(arrayOf(DisposeStrategy.OnLifecycle, ON_CREATE, DESTROYED)) 57 | parameters.add(arrayOf(DisposeStrategy.OnLifecycle, ON_START, CREATED)) 58 | parameters.add(arrayOf(DisposeStrategy.OnLifecycle, ON_RESUME, STARTED)) 59 | parameters.add(arrayOf(DisposeStrategy.OnLifecycle, ON_PAUSE, DESTROYED)) 60 | parameters.add(arrayOf(DisposeStrategy.OnLifecycle, ON_STOP, DESTROYED)) 61 | parameters.add(arrayOf(DisposeStrategy.OnLifecycle, ON_DESTROY, DESTROYED)) 62 | // OnPause 63 | parameters.add(arrayOf(DisposeStrategy.OnPause, ON_CREATE, STARTED)) 64 | parameters.add(arrayOf(DisposeStrategy.OnPause, ON_START, STARTED)) 65 | parameters.add(arrayOf(DisposeStrategy.OnPause, ON_RESUME, STARTED)) 66 | parameters.add(arrayOf(DisposeStrategy.OnPause, ON_PAUSE, DESTROYED)) 67 | parameters.add(arrayOf(DisposeStrategy.OnPause, ON_STOP, DESTROYED)) 68 | parameters.add(arrayOf(DisposeStrategy.OnPause, ON_DESTROY, DESTROYED)) 69 | // OnStop 70 | parameters.add(arrayOf(DisposeStrategy.OnStop, ON_CREATE, CREATED)) 71 | parameters.add(arrayOf(DisposeStrategy.OnStop, ON_START, CREATED)) 72 | parameters.add(arrayOf(DisposeStrategy.OnStop, ON_RESUME, CREATED)) 73 | parameters.add(arrayOf(DisposeStrategy.OnStop, ON_PAUSE, CREATED)) 74 | parameters.add(arrayOf(DisposeStrategy.OnStop, ON_STOP, DESTROYED)) 75 | parameters.add(arrayOf(DisposeStrategy.OnStop, ON_DESTROY, DESTROYED)) 76 | // OnDestroy 77 | parameters.add(arrayOf(DisposeStrategy.OnDestroy, ON_CREATE, DESTROYED)) 78 | parameters.add(arrayOf(DisposeStrategy.OnDestroy, ON_START, DESTROYED)) 79 | parameters.add(arrayOf(DisposeStrategy.OnDestroy, ON_RESUME, DESTROYED)) 80 | parameters.add(arrayOf(DisposeStrategy.OnDestroy, ON_PAUSE, DESTROYED)) 81 | parameters.add(arrayOf(DisposeStrategy.OnDestroy, ON_STOP, DESTROYED)) 82 | parameters.add(arrayOf(DisposeStrategy.OnDestroy, ON_DESTROY, DESTROYED)) 83 | return parameters 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /test/src/test/java/com/wada811/lifecycledispose/test/NoViewFragmentTest.kt: -------------------------------------------------------------------------------- 1 | package com.wada811.lifecycledispose.test 2 | 3 | import android.os.Build 4 | import androidx.fragment.app.testing.FragmentScenario 5 | import androidx.lifecycle.Lifecycle 6 | import androidx.lifecycle.Lifecycle.State.CREATED 7 | import androidx.lifecycle.Lifecycle.State.DESTROYED 8 | import androidx.lifecycle.Lifecycle.State.STARTED 9 | import com.google.common.truth.Truth 10 | import com.wada811.lifecycledispose.test.FragmentLifecycleEvent.OnAttach 11 | import com.wada811.lifecycledispose.test.FragmentLifecycleEvent.OnCreate 12 | import com.wada811.lifecycledispose.test.FragmentLifecycleEvent.OnDestroy 13 | import com.wada811.lifecycledispose.test.FragmentLifecycleEvent.OnPause 14 | import com.wada811.lifecycledispose.test.FragmentLifecycleEvent.OnResume 15 | import com.wada811.lifecycledispose.test.FragmentLifecycleEvent.OnStart 16 | import com.wada811.lifecycledispose.test.FragmentLifecycleEvent.OnStop 17 | import org.junit.Test 18 | import org.junit.runner.RunWith 19 | import org.robolectric.ParameterizedRobolectricTestRunner 20 | import org.robolectric.annotation.Config 21 | 22 | /** 23 | * Test disposing on corresponding lifecycle event. 24 | * 25 | * @see Handling Lifecycles with Lifecycle-Aware Components | Android Developers 26 | */ 27 | @Config(sdk = [Build.VERSION_CODES.P]) 28 | @RunWith(ParameterizedRobolectricTestRunner::class) 29 | class NoViewFragmentTest( 30 | private val disposeStrategy: DisposeStrategy, 31 | private val subscribeLifecycleEvent: FragmentLifecycleEvent, 32 | private val expectedLifecycleState: Lifecycle.State 33 | ) { 34 | @Test 35 | fun test() { 36 | var fragment: DisposeNoViewFragment? = null 37 | val scenario = FragmentScenario.launch( 38 | DisposeNoViewFragment::class.java, 39 | DisposeNoViewFragment.createBundle( 40 | disposeStrategy, 41 | subscribeLifecycleEvent 42 | ) 43 | ) 44 | scenario.onFragment { fragment = it } 45 | scenario.moveToState(DESTROYED) 46 | Truth.assertThat(fragment!!.disposedLifecycleState).isEqualTo(expectedLifecycleState) 47 | fragment = null 48 | } 49 | 50 | companion object { 51 | @Suppress("unused") 52 | @JvmStatic 53 | @ParameterizedRobolectricTestRunner.Parameters(name = "Strategy: {0}, subscribe: {1}, dispose: {2}") 54 | fun parameters(): Iterable> { 55 | val parameters = mutableListOf>() 56 | // OnLifecycle 57 | parameters.add(arrayOf(DisposeStrategy.OnLifecycle, OnAttach, DESTROYED)) 58 | parameters.add(arrayOf(DisposeStrategy.OnLifecycle, OnCreate, DESTROYED)) 59 | parameters.add(arrayOf(DisposeStrategy.OnLifecycle, OnStart, CREATED)) 60 | parameters.add(arrayOf(DisposeStrategy.OnLifecycle, OnResume, STARTED)) 61 | parameters.add(arrayOf(DisposeStrategy.OnLifecycle, OnPause, DESTROYED)) 62 | parameters.add(arrayOf(DisposeStrategy.OnLifecycle, OnStop, DESTROYED)) 63 | parameters.add(arrayOf(DisposeStrategy.OnLifecycle, OnDestroy, DESTROYED)) 64 | // OnPause 65 | parameters.add(arrayOf(DisposeStrategy.OnPause, OnAttach, STARTED)) 66 | parameters.add(arrayOf(DisposeStrategy.OnPause, OnCreate, STARTED)) 67 | parameters.add(arrayOf(DisposeStrategy.OnPause, OnStart, STARTED)) 68 | parameters.add(arrayOf(DisposeStrategy.OnPause, OnResume, STARTED)) 69 | parameters.add(arrayOf(DisposeStrategy.OnPause, OnPause, DESTROYED)) 70 | parameters.add(arrayOf(DisposeStrategy.OnPause, OnStop, DESTROYED)) 71 | parameters.add(arrayOf(DisposeStrategy.OnPause, OnDestroy, DESTROYED)) 72 | // OnStop 73 | parameters.add(arrayOf(DisposeStrategy.OnStop, OnAttach, CREATED)) 74 | parameters.add(arrayOf(DisposeStrategy.OnStop, OnCreate, CREATED)) 75 | parameters.add(arrayOf(DisposeStrategy.OnStop, OnStart, CREATED)) 76 | parameters.add(arrayOf(DisposeStrategy.OnStop, OnResume, CREATED)) 77 | parameters.add(arrayOf(DisposeStrategy.OnStop, OnPause, CREATED)) 78 | parameters.add(arrayOf(DisposeStrategy.OnStop, OnStop, DESTROYED)) 79 | parameters.add(arrayOf(DisposeStrategy.OnStop, OnDestroy, DESTROYED)) 80 | // OnDestroy 81 | parameters.add(arrayOf(DisposeStrategy.OnDestroy, OnAttach, DESTROYED)) 82 | parameters.add(arrayOf(DisposeStrategy.OnDestroy, OnCreate, DESTROYED)) 83 | parameters.add(arrayOf(DisposeStrategy.OnDestroy, OnStart, DESTROYED)) 84 | parameters.add(arrayOf(DisposeStrategy.OnDestroy, OnResume, DESTROYED)) 85 | parameters.add(arrayOf(DisposeStrategy.OnDestroy, OnPause, DESTROYED)) 86 | parameters.add(arrayOf(DisposeStrategy.OnDestroy, OnStop, DESTROYED)) 87 | parameters.add(arrayOf(DisposeStrategy.OnDestroy, OnDestroy, DESTROYED)) 88 | return parameters 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /test/src/test/java/com/wada811/lifecycledispose/test/ViewFragmentTest.kt: -------------------------------------------------------------------------------- 1 | package com.wada811.lifecycledispose.test 2 | 3 | import android.os.Build 4 | import androidx.fragment.app.testing.FragmentScenario 5 | import androidx.lifecycle.Lifecycle 6 | import androidx.lifecycle.Lifecycle.State.CREATED 7 | import androidx.lifecycle.Lifecycle.State.DESTROYED 8 | import androidx.lifecycle.Lifecycle.State.STARTED 9 | import com.google.common.truth.Truth 10 | import com.wada811.lifecycledispose.test.FragmentLifecycleEvent.OnAttach 11 | import com.wada811.lifecycledispose.test.FragmentLifecycleEvent.OnCreate 12 | import com.wada811.lifecycledispose.test.FragmentLifecycleEvent.OnCreateView 13 | import com.wada811.lifecycledispose.test.FragmentLifecycleEvent.OnDestroy 14 | import com.wada811.lifecycledispose.test.FragmentLifecycleEvent.OnDestroyView 15 | import com.wada811.lifecycledispose.test.FragmentLifecycleEvent.OnPause 16 | import com.wada811.lifecycledispose.test.FragmentLifecycleEvent.OnResume 17 | import com.wada811.lifecycledispose.test.FragmentLifecycleEvent.OnStart 18 | import com.wada811.lifecycledispose.test.FragmentLifecycleEvent.OnStop 19 | import com.wada811.lifecycledispose.test.FragmentLifecycleEvent.OnViewCreated 20 | import org.junit.Test 21 | import org.junit.runner.RunWith 22 | import org.robolectric.ParameterizedRobolectricTestRunner 23 | import org.robolectric.annotation.Config 24 | 25 | /** 26 | * Test disposing on corresponding lifecycle event. 27 | * 28 | * @see Handling Lifecycles with Lifecycle-Aware Components | Android Developers 29 | */ 30 | @Config(sdk = [Build.VERSION_CODES.P]) 31 | @RunWith(ParameterizedRobolectricTestRunner::class) 32 | class ViewFragmentTest( 33 | private val disposeStrategy: DisposeStrategy, 34 | private val subscribeLifecycleEvent: FragmentLifecycleEvent, 35 | private val expectedLifecycleState: Lifecycle.State 36 | ) { 37 | @Test 38 | fun test() { 39 | var fragment: DisposeViewFragment? = null 40 | val scenario = FragmentScenario.launch( 41 | DisposeViewFragment::class.java, 42 | DisposeViewFragment.createBundle( 43 | disposeStrategy, 44 | subscribeLifecycleEvent 45 | ) 46 | ) 47 | scenario.onFragment { fragment = it } 48 | scenario.moveToState(DESTROYED) 49 | Truth.assertThat(fragment!!.disposedLifecycleState).isEqualTo(expectedLifecycleState) 50 | fragment = null 51 | } 52 | 53 | companion object { 54 | @Suppress("unused") 55 | @JvmStatic 56 | @ParameterizedRobolectricTestRunner.Parameters(name = "Strategy: {0}, subscribe: {1}, dispose: {2}") 57 | fun parameters(): Iterable> { 58 | val parameters = mutableListOf>() 59 | // OnLifecycle 60 | parameters.add(arrayOf(DisposeStrategy.OnLifecycle, OnAttach, DESTROYED)) 61 | parameters.add(arrayOf(DisposeStrategy.OnLifecycle, OnCreate, DESTROYED)) 62 | parameters.add(arrayOf(DisposeStrategy.OnLifecycle, OnCreateView, DESTROYED)) 63 | parameters.add(arrayOf(DisposeStrategy.OnLifecycle, OnViewCreated, DESTROYED)) 64 | parameters.add(arrayOf(DisposeStrategy.OnLifecycle, OnStart, CREATED)) 65 | parameters.add(arrayOf(DisposeStrategy.OnLifecycle, OnResume, STARTED)) 66 | parameters.add(arrayOf(DisposeStrategy.OnLifecycle, OnPause, DESTROYED)) 67 | parameters.add(arrayOf(DisposeStrategy.OnLifecycle, OnStop, DESTROYED)) 68 | parameters.add(arrayOf(DisposeStrategy.OnLifecycle, OnDestroyView, DESTROYED)) 69 | parameters.add(arrayOf(DisposeStrategy.OnLifecycle, OnDestroy, DESTROYED)) 70 | // OnPause 71 | parameters.add(arrayOf(DisposeStrategy.OnPause, OnAttach, STARTED)) 72 | parameters.add(arrayOf(DisposeStrategy.OnPause, OnCreate, STARTED)) 73 | parameters.add(arrayOf(DisposeStrategy.OnPause, OnCreateView, STARTED)) 74 | parameters.add(arrayOf(DisposeStrategy.OnPause, OnViewCreated, STARTED)) 75 | parameters.add(arrayOf(DisposeStrategy.OnPause, OnStart, STARTED)) 76 | parameters.add(arrayOf(DisposeStrategy.OnPause, OnResume, STARTED)) 77 | parameters.add(arrayOf(DisposeStrategy.OnPause, OnPause, DESTROYED)) 78 | parameters.add(arrayOf(DisposeStrategy.OnPause, OnStop, DESTROYED)) 79 | parameters.add(arrayOf(DisposeStrategy.OnPause, OnDestroyView, DESTROYED)) 80 | parameters.add(arrayOf(DisposeStrategy.OnPause, OnDestroy, DESTROYED)) 81 | // OnStop 82 | parameters.add(arrayOf(DisposeStrategy.OnStop, OnAttach, CREATED)) 83 | parameters.add(arrayOf(DisposeStrategy.OnStop, OnCreate, CREATED)) 84 | parameters.add(arrayOf(DisposeStrategy.OnStop, OnCreateView, CREATED)) 85 | parameters.add(arrayOf(DisposeStrategy.OnStop, OnViewCreated, CREATED)) 86 | parameters.add(arrayOf(DisposeStrategy.OnStop, OnStart, CREATED)) 87 | parameters.add(arrayOf(DisposeStrategy.OnStop, OnResume, CREATED)) 88 | parameters.add(arrayOf(DisposeStrategy.OnStop, OnPause, CREATED)) 89 | parameters.add(arrayOf(DisposeStrategy.OnStop, OnStop, DESTROYED)) 90 | parameters.add(arrayOf(DisposeStrategy.OnStop, OnDestroyView, DESTROYED)) 91 | parameters.add(arrayOf(DisposeStrategy.OnStop, OnDestroy, DESTROYED)) 92 | // OnDestroy 93 | parameters.add(arrayOf(DisposeStrategy.OnDestroy, OnAttach, DESTROYED)) 94 | parameters.add(arrayOf(DisposeStrategy.OnDestroy, OnCreate, DESTROYED)) 95 | parameters.add(arrayOf(DisposeStrategy.OnDestroy, OnCreateView, DESTROYED)) 96 | parameters.add(arrayOf(DisposeStrategy.OnDestroy, OnViewCreated, DESTROYED)) 97 | parameters.add(arrayOf(DisposeStrategy.OnDestroy, OnStart, DESTROYED)) 98 | parameters.add(arrayOf(DisposeStrategy.OnDestroy, OnResume, DESTROYED)) 99 | parameters.add(arrayOf(DisposeStrategy.OnDestroy, OnPause, DESTROYED)) 100 | parameters.add(arrayOf(DisposeStrategy.OnDestroy, OnStop, DESTROYED)) 101 | parameters.add(arrayOf(DisposeStrategy.OnDestroy, OnDestroyView, DESTROYED)) 102 | parameters.add(arrayOf(DisposeStrategy.OnDestroy, OnDestroy, DESTROYED)) 103 | return parameters 104 | } 105 | } 106 | } 107 | --------------------------------------------------------------------------------