package com.ysnows.base.ext

import android.app.Activity
import android.content.Context
import android.view.View
import android.widget.Toast
import androidx.fragment.app.Fragment
import com.qmuiteam.qmui.widget.dialog.QMUIDialog
import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction
import com.ysnows.base.utils.Toasts


fun Activity.toast(message: CharSequence?, time: Int = Toast.LENGTH_SHORT) {
    Toasts.toast(this, message, time)
}

fun Activity.toast(ResId: Int, time: Int = Toast.LENGTH_SHORT) {
    Toasts.toast(this, this.getString(ResId), time)
}

fun Context.toast(message: CharSequence?, time: Int = Toast.LENGTH_SHORT) {
    Toasts.toast(this, message, time)
}

fun Context.toast(ResId: Int, time: Int = Toast.LENGTH_SHORT) {
    Toasts.toast(this, this.getString(ResId), time)
}

fun Fragment.toast(message: CharSequence?, time: Int = Toast.LENGTH_SHORT) {
    Toasts.toast(this.context, message, time)
}

fun Fragment.toast(ResId: Int, time: Int = Toast.LENGTH_SHORT) {
    Toasts.toast(this.context, this.getString(ResId), time)
}

fun View.toast(message: CharSequence?, time: Int = Toast.LENGTH_SHORT) {
    Toasts.toast(this.context, message, time)
}

fun View.toast(ResId: Int, time: Int = Toast.LENGTH_SHORT) {
    Toasts.toast(this.context, this.context.getString(ResId), time)
}


fun Activity.message(message: CharSequence?, title: CharSequence? = "温馨提示", positiveBtnName: CharSequence? = "确定", negativeBtnName: CharSequence? = "取消", positiveAction: QMUIDialogAction.ActionListener? = null, negativeAction: QMUIDialogAction.ActionListener? = null, negativeEnable: Boolean = false): QMUIDialog? {
    return Toasts.message(this, message, title, positiveBtnName, negativeBtnName, positiveAction, negativeAction, negativeEnable)
}

fun Fragment.message(message: CharSequence?, title: CharSequence? = "温馨提示", positiveBtnName: CharSequence? = "确定", negativeBtnName: CharSequence? = "取消", positiveAction: QMUIDialogAction.ActionListener? = null, negativeAction: QMUIDialogAction.ActionListener? = null, negativeEnable: Boolean = false): QMUIDialog? {
    return Toasts.message(this.context, message, title, positiveBtnName, negativeBtnName, positiveAction, negativeAction, negativeEnable)
}

fun Activity.message(ResId: Int, title: CharSequence? = "温馨提示", positiveBtnName: CharSequence? = "确定", negativeBtnName: CharSequence? = "取消", positiveAction: QMUIDialogAction.ActionListener? = null, negativeAction: QMUIDialogAction.ActionListener? = null, negativeEnable: Boolean = false): QMUIDialog? {
    return Toasts.message(this, this.getString(ResId), title, positiveBtnName, negativeBtnName, positiveAction, negativeAction, negativeEnable)
}

fun Fragment.message(ResId: Int, title: CharSequence? = "温馨提示", positiveBtnName: CharSequence? = "确定", negativeBtnName: CharSequence? = "取消", positiveAction: QMUIDialogAction.ActionListener? = null, negativeAction: QMUIDialogAction.ActionListener? = null, negativeEnable: Boolean = false): QMUIDialog? {
    return Toasts.message(this.context, this.getString(ResId), title, positiveBtnName, negativeBtnName, positiveAction, negativeAction, negativeEnable)
}