Repository: square/leakcanary
File: leakcanary-android-core/src/main/java/leakcanary/internal/activity/screen/AboutScreen.kt (Kotlin)

Code before:
import leakcanary.internal.HeapDumpPolicy.HeapDumpStatus.ENABLED
import leakcanary.internal.navigation.Screen
import leakcanary.internal.navigation.activity
import leakcanary.internal.navigation.inflate

internal class AboutScreen : Screen() {
  override fun createView(container: ViewGroup) =
    container.inflate(R.layout.leak_canary_about_screen).apply {
      activity.title =
        resources.getString(R.string.leak_canary_about_title, BuildConfig.LIBRARY_VERSION)
      val aboutTextView = findViewById<TextView>(R.id.leak_canary_about_text)
      aboutTextView.movementMethod = LinkMovementMethod.getInstance()
      val application = activity.application
      val appName = application.packageManager.getApplicationLabel(application.applicationInfo)
      val appPackageName = context.packageName

      aboutTextView.text = Html.fromHtml(
          String.format(
              resources.getString(R.string.leak_canary_about_message), appName, appPackageName,
              getHeapDumpStatusMessage(resources)
          )
      )
    }

  private fun getHeapDumpStatusMessage(resources: Resources): String {
    return when (HeapDumpPolicy.getHeapDumpStatus()) {
      ENABLED -> String.format(
          resources.getString(R.string.leak_canary_heap_dump_enabled)
      )

      DISABLED_DEBUGGER_ATTACHED -> String.format(
          resources.getString(R.string.leak_canary_heap_dump_disabled),
          resources.getString(R.string.leak_canary_heap_dump_disabled_build_non_debuggable)
      )

      DISABLED_CONFIG_CHANGED -> String.format(
          resources.getString(R.string.leak_canary_heap_dump_disabled),
          resources.getString(R.string.leak_canary_heap_dump_disabled_config_changed)
      )
    }
  }
}

Review comment (suggestion):
Nit: replace with expression body + no need to pass `resources`, since it can be accessed from the class instance.
```kotlin
private fun getHeapDumpStatusMessage() =
  when (HeapDumpPolicy.getHeapDumpStatus()) {
  ...
```

 


Code after:
import leakcanary.internal.activity.screen.AboutScreen.HeapDumpPolicy.HeapDumpStatus.ENABLED
import leakcanary.internal.navigation.Screen
import leakcanary.internal.navigation.activity
import leakcanary.internal.navigation.inflate

internal class AboutScreen : Screen() {
  override fun createView(container: ViewGroup) =
    container.inflate(R.layout.leak_canary_about_screen).apply {
      activity.title =
        resources.getString(R.string.leak_canary_about_title, BuildConfig.LIBRARY_VERSION)
      val aboutTextView = findViewById<TextView>(R.id.leak_canary_about_text)
      aboutTextView.movementMethod = LinkMovementMethod.getInstance()
      val application = activity.application
      val appName = application.packageManager.getApplicationLabel(application.applicationInfo)
      val appPackageName = context.packageName

      aboutTextView.text = Html.fromHtml(
          String.format(
              resources.getString(R.string.leak_canary_about_message), appName, appPackageName
          )
      )

      val heapDumpText = findViewById<TextView>(R.id.leak_canary_about_heap_dump_text)
      heapDumpText.text = getHeapDumpStatusMessage(resources)
    }

  private fun getHeapDumpStatusMessage(resources: Resources) =
    when (getHeapDumpStatus(resources)) {
      ENABLED -> resources.getString(R.string.leak_canary_heap_dump_enabled_text)
      DISABLED_DEBUGGER_ATTACHED -> String.format(
          resources.getString(R.string.leak_canary_heap_dump_disabled_text),
          resources.getString(R.string.leak_canary_heap_dump_disabled_build_non_debuggable)
      )
      DISABLED_BY_DEVELOPER -> String.format(
          resources.getString(R.string.leak_canary_heap_dump_disabled_text),
          resources.getString(R.string.leak_canary_heap_dump_disabled_by_app)
      )
      DISABLED_RUNNING_TESTS -> String.format(
          resources.getString(R.string.leak_canary_heap_dump_disabled_text),
          resources.getString(R.string.leak_canary_heap_dump_disabled_running_tests)
      )
    }

  private companion object HeapDumpPolicy {
    enum class HeapDumpStatus {
      ENABLED,
      DISABLED_DEBUGGER_ATTACHED,
      DISABLED_BY_DEVELOPER,
      DISABLED_RUNNING_TESTS
    }