package com.develop.food.base.widgets

import androidx.activity.OnBackPressedCallback

interface IBackPressed {
    fun onBackPressed(controller: Controller)
}

interface Controller {
    fun setEnable(enable: Boolean)
}

/**
 * 将OnBackPressedCallback转化为接口友好式的接入
 */
class BackPressedAdapter(
    private val delegate: IBackPressed
): OnBackPressedCallback(true), Controller {

    override fun handleOnBackPressed() {
        delegate.onBackPressed(this)
    }

    override fun setEnable(enable: Boolean) {
        isEnabled = enable
    }
}