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

Code before:
              AlertDialog.Builder(context)
                  .setIcon(android.R.drawable.ic_dialog_alert)
                  .setTitle(R.string.leak_canary_delete_all)
                  .setMessage(R.string.leak_canary_delete_all_leaks_title)
                  .setPositiveButton(android.R.string.ok) { _, _ ->
                    HeapAnalysisTable.deleteAll(db, context)
                    listView.adapter =
                      SimpleListAdapter(R.layout.leak_canary_leak_row, emptyList<Any>()) { _, _ -> }
                  }
                  .setNegativeButton(android.R.string.cancel, null)
                  .show()
              true
            }
      }

      val projections = HeapAnalysisTable.retrieveAll(db)

      listView.setOnItemClickListener { _, _, position, _ ->
        val projection = projections[position]
        val analysisScreen = if (projection.exceptionSummary != null)
          HeapAnalysisFailureScreen(projection.id)
        else
          HeapAnalysisSuccessScreen(projection.id)
        goTo(analysisScreen)
      }

      listView.adapter =
        SimpleListAdapter(R.layout.leak_canary_leak_row, projections) { view, position ->
          val titleView = view.findViewById<TextView>(R.id.leak_canary_row_text)
          val timeView = view.findViewById<TextView>(R.id.leak_canary_row_time)
          val index = count - position

          val projection = getItem(position)

          timeView.text = DateUtils.formatDateTime(
              view.context, projection.createdAtTimeMillis,
              DateUtils.FORMAT_SHOW_TIME or DateUtils.FORMAT_SHOW_DATE
          )

          titleView.text = "$index. " + (projection.exceptionSummary
          // TODO Handle singular
              ?: "${projection.retainedInstanceCount} retained instances")
        }
    }

}

Review comment (suggestion):
@pyricau changed this so items in the list show up in order. Did you want them showing in reverse though? This seemed pretty intentional.

Code after:
                    HeapAnalysisTable.deleteAll(db, context)
                    listView.adapter =
                      SimpleListAdapter(R.layout.leak_canary_leak_row, emptyList<Any>()) { _, _ -> }
                  }
                  .setNegativeButton(android.R.string.cancel, null)
                  .show()
              true
            }
      }

      val projections = HeapAnalysisTable.retrieveAll(db)

      listView.setOnItemClickListener { _, _, position, _ ->
        val projection = projections[position]
        val analysisScreen = if (projection.exceptionSummary != null)
          HeapAnalysisFailureScreen(projection.id)
        else
          HeapAnalysisSuccessScreen(projection.id)
        goTo(analysisScreen)
      }

      listView.adapter =
        SimpleListAdapter(R.layout.leak_canary_leak_row, projections) { view, position ->
          val titleView = view.findViewById<TextView>(R.id.leak_canary_row_text)
          val timeView = view.findViewById<TextView>(R.id.leak_canary_row_time)
          val index = position + 1

          val projection = getItem(position)

          timeView.text = DateUtils.formatDateTime(
              view.context, projection.createdAtTimeMillis,
              DateUtils.FORMAT_SHOW_TIME or DateUtils.FORMAT_SHOW_DATE
          )

          val title =
            when {
              projection.exceptionSummary != null -> projection.exceptionSummary
              else -> {
                val quantityFormat = resources.getQuantityString(
                    R.plurals.leak_canary_heap_analysis_list_retained_instances,
                    projection.retainedInstanceCount
                )
                String.format(
                    quantityFormat,
                    projection.retainedInstanceCount
                )
              }
            }
          titleView.text = String.format("$index. %s", title)
        }
    }