Repository: skyline-emu/skyline
File: app/src/main/java/emu/skyline/input/onscreen/OnScreenEditActivity.kt (Kotlin)

Code before:
            fabMapping[R.drawable.ic_close]!!.animate().rotation(if (fullEditVisible) 0f else 45f)
        }
    }

    private fun toggleFabVisibility(visible : Boolean) {
        actions.forEach {
            if (it.first != R.drawable.ic_close)
                if (visible) fabMapping[it.first]!!.show()
                else fabMapping[it.first]!!.hide()
        }
    }

    private val editAction = {
        editMode = true
        binding.onScreenControllerView.setEditMode(true)
        toggleFabVisibility(false)
    }

    private val toggleAction : () -> Unit = {
        val buttonProps = binding.onScreenControllerView.getButtonProps()
        val checkArray = buttonProps.map { it.second }.toBooleanArray()

        MaterialAlertDialogBuilder(this)
                .setMultiChoiceItems(buttonProps.map {
                    val longText = getString(it.first.long!!)
                    if (it.first.short == longText) longText else "$longText: ${it.first.short}"
                }.toTypedArray(), checkArray) { _, which, isChecked ->
                    checkArray[which] = isChecked
                }.setPositiveButton(R.string.confirm) { _, _ ->
                    buttonProps.forEachIndexed { index, pair ->
                        if (checkArray[index] != pair.second)
                            binding.onScreenControllerView.setButtonEnabled(pair.first, checkArray[index])
                    }
                }.setNegativeButton(R.string.cancel, null)
                .setOnDismissListener { fullScreen() }
                .show()
    }

    private val actions : List<Pair<Int, () -> Unit>> = listOf(
            Pair(R.drawable.ic_restore, { binding.onScreenControllerView.resetControls() }),
            Pair(R.drawable.ic_toggle, toggleAction),
            Pair(R.drawable.ic_edit, editAction),
            Pair(R.drawable.ic_zoom_out, { binding.onScreenControllerView.decreaseScale() }),
            Pair(R.drawable.ic_zoom_in, { binding.onScreenControllerView.increaseScale() }),
            Pair(R.drawable.ic_opacity_minus) { binding.onScreenControllerView.decreaseOpacity() },
            Pair(R.drawable.ic_opacity_plus) { binding.onScreenControllerView.increaseOpacity() },
            Pair(R.drawable.ic_close, closeAction)
    )

    private val fabMapping = mutableMapOf<Int, FloatingActionButton>()


Review comment (suggestion):
Here you'd want to make an enumeration of all colors with a meaningful name (Black, White, Teal, Lime Green, etc...), then use it to compose the array of colors. Doing it like this makes it very hard to see what colors you have in there without having too look them up.

Code after:
            editMode = false
        } else {
            fullEditVisible = !fullEditVisible
            toggleFabVisibility(fullEditVisible)
            fabMapping[R.drawable.ic_close]!!.animate().rotation(if (fullEditVisible) 0f else 45f)
        }
    }

    private fun toggleFabVisibility(visible : Boolean) {
        fabMapping.forEach { (id, fab) ->
            if (id != R.drawable.ic_close) {
                if (visible) fab.show()
                else fab.hide()
            }
        }
    }

    private val editAction = {
        editMode = true
        binding.onScreenControllerView.setEditMode(true)
        toggleFabVisibility(false)
    }

    private val toggleAction : () -> Unit = {
        val buttonProps = binding.onScreenControllerView.getButtonProps()
        val checkArray = buttonProps.map { it.second }.toBooleanArray()

        MaterialAlertDialogBuilder(this)
            .setMultiChoiceItems(buttonProps.map {
                val longText = getString(it.first.long!!)
                if (it.first.short == longText) longText else "$longText: ${it.first.short}"
            }.toTypedArray(), checkArray) { _, which, isChecked ->
                checkArray[which] = isChecked
            }.setPositiveButton(R.string.confirm) { _, _ ->
                buttonProps.forEachIndexed { index, pair ->
                    if (checkArray[index] != pair.second)
                        binding.onScreenControllerView.setButtonEnabled(pair.first, checkArray[index])
                }
            }.setNegativeButton(R.string.cancel, null)
            .setOnDismissListener { fullScreen() }
            .show()
    }

    private val paletteAction : () -> Unit = {
        DoubleColorPicker(this@OnScreenEditActivity).apply {
            setTitle(this@OnScreenEditActivity.getString(R.string.osc_background_color))
            setDefaultColorButton(binding.onScreenControllerView.getBackGroundColor())
            setRoundColorButton(true)
            setColors(*SwitchColors.colors.toIntArray())
            setDefaultDoubleColorButton(binding.onScreenControllerView.getTextColor())
            setSecondTitle(this@OnScreenEditActivity.getString(R.string.osc_text_color))