<lambda>null1package leakcanary.internal.activity.screen 2 3 import android.text.Html 4 import android.text.method.LinkMovementMethod 5 import android.view.ViewGroup 6 import android.widget.Switch 7 import android.widget.TextView 8 import com.squareup.leakcanary.core.BuildConfig 9 import com.squareup.leakcanary.core.R 10 import leakcanary.internal.HeapDumpControl 11 import leakcanary.internal.HeapDumpControl.ICanHazHeap.Nope 12 import leakcanary.internal.HeapDumpControl.ICanHazHeap.Yup 13 import leakcanary.internal.InternalLeakCanary 14 import leakcanary.internal.navigation.Screen 15 import leakcanary.internal.navigation.activity 16 import leakcanary.internal.navigation.inflate 17 18 internal class AboutScreen : Screen() { 19 override fun createView(container: ViewGroup) = 20 container.inflate(R.layout.leak_canary_about_screen) 21 .apply { 22 activity.title = 23 resources.getString(R.string.leak_canary_about_title, BuildConfig.LIBRARY_VERSION) 24 val aboutTextView = findViewById<TextView>(R.id.leak_canary_about_text) 25 aboutTextView.movementMethod = LinkMovementMethod.getInstance() 26 val application = activity.application 27 val appName = application.packageManager.getApplicationLabel(application.applicationInfo) 28 val appPackageName = context.packageName 29 30 aboutTextView.text = Html.fromHtml( 31 String.format( 32 resources.getString(R.string.leak_canary_about_message), appName, appPackageName 33 ) 34 ) 35 36 val heapDumpTextView = findViewById<TextView>(R.id.leak_canary_about_heap_dump_text) 37 updateHeapDumpTextView(heapDumpTextView) 38 val heapDumpSwitchView = 39 findViewById<Switch>(R.id.leak_canary_about_heap_dump_switch_button) 40 heapDumpSwitchView.isChecked = InternalLeakCanary.dumpEnabledInAboutScreen 41 heapDumpSwitchView.setOnCheckedChangeListener { _, checked -> 42 // Updating the value wouldn't normally immediately trigger a heap dump, however 43 // by updating the view we also have a side effect of querying which will notify 44 // the heap dumper if the value has become positive. 45 InternalLeakCanary.dumpEnabledInAboutScreen = checked 46 updateHeapDumpTextView(heapDumpTextView) 47 } 48 } 49 50 private fun updateHeapDumpTextView(view: TextView) { 51 view.text = when (val iCanHasHeap = HeapDumpControl.iCanHasHeap()) { 52 is Yup -> view.resources.getString(R.string.leak_canary_heap_dump_enabled_text) 53 is Nope -> view.resources.getString( 54 R.string.leak_canary_heap_dump_disabled_text, iCanHasHeap.reason() 55 ) 56 } 57 } 58 } 59