Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
watch leaking support library fragments and their views
- Loading branch information
1 parent
1f6c971
commit 9a0961d
Showing
8 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
leakcanary-object-watcher-android-support-fragments/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
apply plugin: 'com.android.library' | ||
apply plugin: 'kotlin-android' | ||
|
||
dependencies { | ||
api project(':leakcanary-object-watcher-android') | ||
|
||
implementation deps.kotlin.stdlib | ||
// Optional dependency | ||
compileOnly deps.android_support | ||
} | ||
|
||
android { | ||
compileSdkVersion versions.compileSdk | ||
defaultConfig { | ||
minSdkVersion versions.minSdk | ||
consumerProguardFiles 'consumer-proguard-rules.pro' | ||
} | ||
lintOptions { | ||
disable 'GoogleAppIndexingWarning' | ||
error 'ObsoleteSdkInt' | ||
check 'Interoperability' | ||
} | ||
} | ||
|
||
apply from: rootProject.file('gradle/gradle-mvn-push.gradle') |
2 changes: 2 additions & 0 deletions
2
leakcanary-object-watcher-android-support-fragments/consumer-proguard-rules.pro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# AndroidSupportFragmentDestroyWatcher is loaded via reflection | ||
-keep class leakcanary.internal.AndroidSupportFragmentDestroyWatcher { *; } |
3 changes: 3 additions & 0 deletions
3
leakcanary-object-watcher-android-support-fragments/gradle.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
POM_ARTIFACT_ID=leakcanary-object-watcher-android-support-fragments | ||
POM_NAME=LeakCanary Object Watcher for Android extension: Android support library fragments support | ||
POM_PACKAGING=aar |
2 changes: 2 additions & 0 deletions
2
leakcanary-object-watcher-android-support-fragments/src/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.squareup.leakcanary.fragments.android_support" /> |
58 changes: 58 additions & 0 deletions
58
...pport-fragments/src/main/java/leakcanary/internal/AndroidSupportFragmentDestroyWatcher.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (C) 2018 Square, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package leakcanary.internal | ||
|
||
import android.app.Activity | ||
import android.support.v4.app.Fragment | ||
import android.support.v4.app.FragmentActivity | ||
import android.support.v4.app.FragmentManager | ||
import leakcanary.AppWatcher.Config | ||
import leakcanary.ObjectWatcher | ||
|
||
internal class AndroidSupportFragmentDestroyWatcher( | ||
private val objectWatcher: ObjectWatcher, | ||
private val configProvider: () -> Config | ||
) : (Activity) -> Unit { | ||
|
||
private val fragmentLifecycleCallbacks = object : FragmentManager.FragmentLifecycleCallbacks() { | ||
|
||
override fun onFragmentViewDestroyed( | ||
fm: FragmentManager, | ||
fragment: Fragment | ||
) { | ||
val view = fragment.view | ||
if (view != null && configProvider().watchFragmentViews) { | ||
objectWatcher.watch(view) | ||
} | ||
} | ||
|
||
override fun onFragmentDestroyed( | ||
fm: FragmentManager, | ||
fragment: Fragment | ||
) { | ||
if (configProvider().watchFragments) { | ||
objectWatcher.watch(fragment) | ||
} | ||
} | ||
} | ||
|
||
override fun invoke(activity: Activity) { | ||
if (activity is FragmentActivity) { | ||
val supportFragmentManager = activity.supportFragmentManager | ||
supportFragmentManager.registerFragmentLifecycleCallbacks(fragmentLifecycleCallbacks, true) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters