AlertView icon indicating copy to clipboard operation
AlertView copied to clipboard

Cancelable

Open crm76 opened this issue 7 years ago • 1 comments

It would be nice to control if it's cancelable. For my needs, I quickly changed show() to return the DialogFragment so I could set isCancelable like so...

val alert = AlertView("Title", "Message", AlertStyle.DIALOG)
var dialog = alert.show(this)
dialog.isCancelable = false


fun show(activity: AppCompatActivity) : android.support.v4.app.DialogFragment {
    var result : android.support.v4.app.DialogFragment

    when (style) {
        AlertStyle.BOTTOM_SHEET -> {
            val bottomSheet = BottomSheetFragment(title, message, actions, style, theme)
            bottomSheet.show(activity.supportFragmentManager, bottomSheet.tag)
            result = bottomSheet
        }
        AlertStyle.IOS -> {
            val bottomSheet = BottomSheetFragment(title, message, actions, style, theme)
            bottomSheet.show(activity.supportFragmentManager, bottomSheet.tag)
            result = bottomSheet
        }
        AlertStyle.DIALOG -> {
            val bottomSheet = DialogFragment(title, message, actions, theme)
            bottomSheet.show(activity.supportFragmentManager, bottomSheet.tag)
            result = bottomSheet
        }
    }
    
    return result
}

Thank you for the project.

crm76 avatar Jul 12 '18 18:07 crm76

You can simply set cancelable:

fun show(activity: AppCompatActivity, cancelable:Boolean) { when (style) { AlertStyle.BOTTOM_SHEET -> { val bottomSheet = BottomSheetFragment(title, message, actions, style, theme) bottomSheet.show(activity.supportFragmentManager, bottomSheet.tag) bottomSheet.isCancelable=cancelable

        }
        AlertStyle.IOS -> {
            val bottomSheet = BottomSheetFragment(title, message, actions, style, theme)
            bottomSheet.show(activity.supportFragmentManager, bottomSheet.tag)
            bottomSheet.isCancelable=cancelable
        }
        AlertStyle.DIALOG -> {
            val bottomSheet = DialogFragment(title, message, actions, theme)
            bottomSheet.show(activity.supportFragmentManager, bottomSheet.tag)
            bottomSheet.isCancelable=cancelable
        }
    }
}

om79 avatar Jun 11 '19 01:06 om79