Skip to content

Commit

Permalink
Consolidate LeakCanary modules
Browse files Browse the repository at this point in the history
Now that LeakCanary 2.0 is stable it's time we simplified things. I thought about keeping two separate modules for each of the versions, but I figure while DebugDrawer isn't 1.0 yet we can take the hit of the breaking change.

Also this PR bumps a few dependencies. It's been a while!
  • Loading branch information
chris-horner committed Dec 13, 2019
1 parent 65c9381 commit 226d8a6
Show file tree
Hide file tree
Showing 17 changed files with 69 additions and 147 deletions.
17 changes: 8 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@ buildscript {
ext.versions = [
'compile_sdk' : 29,
'min_sdk' : 21,
'android_gradle_plugin' : '3.5.1',
'kotlin' : '1.3.50',
'android_gradle_plugin' : '3.5.3',
'kotlin' : '1.3.61',
'maven_publish_plugin' : '0.8.0',
'coroutines' : '1.3.2',
'coroutines' : '1.3.3',
'appcompat' : '1.1.0',
'androidx_core' : '1.1.0',
'drawerlayout' : '1.0.0',
'material' : '1.1.0-beta01',
'material' : '1.1.0-beta02',
'lifecycle' : '2.1.0',
'leakcanary' : '1.6.3',
'leakcanary2' : '2.0-beta-3',
'moshi' : '1.8.0',
'okhttp' : '4.2.0',
'retrofit' : '2.6.1',
'leakcanary' : '2.0',
'moshi' : '1.9.2',
'okhttp' : '4.2.2',
'retrofit' : '2.7.0',
'retrofit_coroutines' : '0.9.2',
'picasso' : '2.71828',
'process_phoenix' : '2.0.0',
Expand Down
17 changes: 1 addition & 16 deletions debugdrawer-leakcanary/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>

<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="au.com.gridstone.debugdrawer.leakcanary"
>

<application>

<!-- Prevent LeakCanary from creating a launcher icon. The debug drawer will provide access. -->
<activity android:name="com.squareup.leakcanary.internal.DisplayLeakActivity">
<intent-filter tools:node="removeAll"/>
</activity>

</application>

</manifest>
<manifest package="au.com.gridstone.debugdrawer.leakcanary"/>
Original file line number Diff line number Diff line change
@@ -1,27 +1,45 @@
package au.com.gridstone.debugdrawer.leakcanary

import android.content.Intent
import android.content.Context
import android.content.Context.MODE_PRIVATE
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.Switch
import au.com.gridstone.debugdrawer.DebugDrawerModule
import com.squareup.leakcanary.internal.DisplayLeakActivity
import leakcanary.LeakCanary

/**
* Displays a button in the drawer to open LeakCanary's leak list activity. Note that including this
* module in your project removes the LeakCanary launcher icon, effectively making the debug
* drawer the main entry point into your leak list.
*/
class LeakCanaryModule : DebugDrawerModule {
object LeakCanaryModule : DebugDrawerModule {

private const val SHARED_PREFS_NAME = "DebugDrawer_LeakCanary"
private const val KEY_ENABLE_HEAP_DUMPS = "enableHeapDumps"

override fun onAttach(context: Context) {
val sharedPrefs = context.getSharedPreferences(SHARED_PREFS_NAME, MODE_PRIVATE)
val enableHeapDumps = sharedPrefs.getBoolean(KEY_ENABLE_HEAP_DUMPS, true)
LeakCanary.config = LeakCanary.config.copy(dumpHeap = enableHeapDumps)
}

override fun onCreateView(parent: ViewGroup): View {
val button = Button(parent.context)
button.setText(R.string.drawer_leakcanaryButton)
val inflater = LayoutInflater.from(parent.context)
val view: View = inflater.inflate(R.layout.drawer_leakcanary, parent, false)

val sharedPrefs = parent.context.getSharedPreferences(SHARED_PREFS_NAME, MODE_PRIVATE)
val enableHeapDumps = sharedPrefs.getBoolean(KEY_ENABLE_HEAP_DUMPS, true)

val toggle: Switch = view.findViewById(R.id.drawer_leakcanaryToggle)
toggle.isChecked = enableHeapDumps
toggle.setOnCheckedChangeListener { _, checked ->
LeakCanary.config = LeakCanary.config.copy(dumpHeap = checked)
sharedPrefs.edit().putBoolean(KEY_ENABLE_HEAP_DUMPS, checked).apply()
}

val button: Button = view.findViewById(R.id.drawer_leakcanaryViewButton)
button.setOnClickListener {
val intent = Intent(parent.context, DisplayLeakActivity::class.java)
parent.context.startActivity(intent)
parent.context.startActivity(LeakCanary.newLeakDisplayActivityIntent())
}

return button
return view
}
}
3 changes: 2 additions & 1 deletion debugdrawer-leakcanary/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>

<resources>
<string name="drawer_leakcanaryButton">Leak analysis</string>
<string name="drawer_leakcanaryButton">View leaks</string>
<string name="drawer_leakcanaryToggleLabel">Enable heap dumps</string>
</resources>
32 changes: 0 additions & 32 deletions debugdrawer-leakcanary2/build.gradle

This file was deleted.

4 changes: 0 additions & 4 deletions debugdrawer-leakcanary2/gradle.properties

This file was deleted.

3 changes: 0 additions & 3 deletions debugdrawer-leakcanary2/src/main/AndroidManifest.xml

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions debugdrawer-leakcanary2/src/main/res/values/public.xml

This file was deleted.

6 changes: 0 additions & 6 deletions debugdrawer-leakcanary2/src/main/res/values/strings.xml

This file was deleted.

3 changes: 2 additions & 1 deletion sample-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${versions.kotlin}"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:${versions.coroutines}"
debugImplementation project(':debugdrawer')
debugImplementation project(':debugdrawer-leakcanary2')
debugImplementation project(':debugdrawer-leakcanary')
debugImplementation project(':debugdrawer-retrofit')
debugImplementation project(':debugdrawer-okhttp-logger')
debugImplementation project(':debugdrawer-timber')
Expand All @@ -48,6 +48,7 @@ dependencies {
implementation "androidx.lifecycle:lifecycle-extensions:${versions.lifecycle}"
debugImplementation "com.squareup.leakcanary:leakcanary-android:${versions.leakcanary2}"
implementation "com.squareup.moshi:moshi:${versions.moshi}"
implementation "com.squareup.moshi:moshi-kotlin:${versions.moshi}"
implementation "com.squareup.okhttp3:okhttp:${versions.okhttp}"
implementation "com.squareup.retrofit2:retrofit:${versions.retrofit}"
implementation "com.squareup.retrofit2:converter-moshi:${versions.retrofit}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import au.com.gridstone.debugdrawer.retrofit.RetrofitModule
import au.com.gridstone.debugdrawer.sampleapp.HttpConfiguration.API_URL
import au.com.gridstone.debugdrawer.timber.TimberModule
import com.jakewharton.retrofit2.adapter.kotlin.coroutines.CoroutineCallAdapterFactory
import com.squareup.moshi.Moshi
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import retrofit2.Retrofit
import retrofit2.converter.moshi.MoshiConverterFactory
import retrofit2.mock.MockRetrofit
Expand Down Expand Up @@ -47,10 +49,14 @@ object AppConfiguration {
.addInterceptor(httpLogger.interceptor)
.build()

val moshi = Moshi.Builder()
.add(KotlinJsonAdapterFactory())
.build()

val retrofit = Retrofit.Builder()
.baseUrl(currentEndpoint.url)
.client(httpClient)
.addConverterFactory(MoshiConverterFactory.create())
.addConverterFactory(MoshiConverterFactory.create(moshi))
.addCallAdapterFactory(CoroutineCallAdapterFactory())
.build()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ data class Game(val id: Long,
val aliases: String?,
val deck: String,
val image: Image,
val original_release_date: String,
val original_release_date: String?,
val platforms: List<Platform>)

data class Platform(val name: String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import android.app.Application
import android.view.ViewGroup
import au.com.gridstone.debugdrawer.sampleapp.HttpConfiguration.API_URL
import com.jakewharton.retrofit2.adapter.kotlin.coroutines.CoroutineCallAdapterFactory
import com.squareup.moshi.Moshi
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import retrofit2.Retrofit
import retrofit2.converter.moshi.MoshiConverterFactory

Expand All @@ -13,13 +15,21 @@ import retrofit2.converter.moshi.MoshiConverterFactory
*/
object AppConfiguration {

val api: GamesApi = Retrofit.Builder()
.baseUrl(API_URL)
.client(HttpConfiguration.client)
.addConverterFactory(MoshiConverterFactory.create())
.addCallAdapterFactory(CoroutineCallAdapterFactory())
.build()
.create(GamesApi::class.java)
val api: GamesApi

init {
val moshi = Moshi.Builder()
.add(KotlinJsonAdapterFactory())
.build()

api = Retrofit.Builder()
.baseUrl(API_URL)
.client(HttpConfiguration.client)
.addConverterFactory(MoshiConverterFactory.create(moshi))
.addCallAdapterFactory(CoroutineCallAdapterFactory())
.build()
.create(GamesApi::class.java)
}

// Keep this method to match debug implementation.
fun init(app: Application) {}
Expand Down
1 change: 0 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ include ':debugdrawer'
include ':sample-app'
include ':simple-sample-app'
include ':debugdrawer-leakcanary'
include ':debugdrawer-leakcanary2'
include ':debugdrawer-retrofit'
include ':debugdrawer-timber'
include ':debugdrawer-okhttp-logger'

0 comments on commit 226d8a6

Please sign in to comment.