All Projects → xeinebiu → android-suspend-dialogs

xeinebiu / android-suspend-dialogs

Licence: MIT license
A helper library for Android to display Dialogs by suspending the coroutine till finish of the dialog.

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to android-suspend-dialogs

Alerttoast
Create Apple-like alerts & toasts using SwiftUI
Stars: ✭ 151 (+371.88%)
Mutual labels:  alert, dialog
vue2-dialog
A mobile Vue plugin for VueDialog
Stars: ✭ 21 (-34.37%)
Mutual labels:  alert, dialog
Bdialog
Extend the Bootstrap Modal features, making dialog more functions and easier to use, dialog type including modal, alert, mask and toast types
Stars: ✭ 174 (+443.75%)
Mutual labels:  alert, dialog
V Dialogs
A simple and clean instructional dialog plugin for Vue2, dialog type including Modal, Alert, Mask and Toast
Stars: ✭ 121 (+278.13%)
Mutual labels:  alert, dialog
Nativepopup
Clone of Apple iOS App's feedback popup, and easily customizable.
Stars: ✭ 247 (+671.88%)
Mutual labels:  alert, dialog
Jquery Confirm
A multipurpose plugin for alert, confirm & dialog, with extended features.
Stars: ✭ 1,776 (+5450%)
Mutual labels:  alert, dialog
Pmalertcontroller
PMAlertController is a great and customizable alert that can substitute UIAlertController
Stars: ✭ 2,397 (+7390.63%)
Mutual labels:  alert, dialog
Jbox
jBox is a jQuery plugin that makes it easy to create customizable tooltips, modal windows, image galleries and more.
Stars: ✭ 1,251 (+3809.38%)
Mutual labels:  alert, dialog
Jh flutter demo
a flutter demo
Stars: ✭ 229 (+615.63%)
Mutual labels:  alert, dialog
Alertview
A library to create simple alerts easily with some customization.
Stars: ✭ 222 (+593.75%)
Mutual labels:  alert, dialog
Jxpopupview
一个轻量级的自定义视图弹出框架
Stars: ✭ 117 (+265.63%)
Mutual labels:  alert, dialog
alert
Cross-platform, isomorphic alert, for Node and browser (previously alert-node)
Stars: ✭ 27 (-15.62%)
Mutual labels:  alert, dialog
Angular Confirm
A multipurpose plugin for alert, confirm & dialog for angular1
Stars: ✭ 114 (+256.25%)
Mutual labels:  alert, dialog
Alertifyjs
A javascript framework for developing pretty browser dialogs and notifications.
Stars: ✭ 1,922 (+5906.25%)
Mutual labels:  alert, dialog
Customalertviewdialogue
Custom AlertView Dialogue is the world's most advanced alert view library. Custom AlertView Dialogue includes simple message popups, confirmation alerts, selector popups, action sheet bottom menus, and input/feedback contact forms.
Stars: ✭ 100 (+212.5%)
Mutual labels:  alert, dialog
Sweetalert2
A beautiful, responsive, highly customizable and accessible (WAI-ARIA) replacement for JavaScript's popup boxes. Zero dependencies.
Stars: ✭ 13,929 (+43428.13%)
Mutual labels:  alert, dialog
Ng Popups
🎉 Alert, confirm and prompt dialogs for Angular. Simple as that.
Stars: ✭ 80 (+150%)
Mutual labels:  alert, dialog
Alertjs
Dialog Builder allows you to create fully customisable dialogs and popups in Dynamics 365.
Stars: ✭ 80 (+150%)
Mutual labels:  alert, dialog
Wc Messagebox
基于 Vue 2.0 开发的 Alert, Toast, Confirm 插件, UI仿照 iOS 原生
Stars: ✭ 203 (+534.38%)
Mutual labels:  alert, dialog
react-st-modal
Simple and flexible modal dialog component for React JS
Stars: ✭ 41 (+28.13%)
Mutual labels:  alert, dialog

Android Suspendable Dialogs

A helper library for Android to display Dialogs by suspending the coroutine till finish of the dialog.

Installation

allprojects {
	repositories {
		...
		maven { url 'https://www.jitpack.io' }
	}
}
dependencies {
    implementation 'com.github.xeinebiu:android-suspend-dialogs:1.6.2'
}

Some Differences with and without suspend

Confirm

The below example shows how a normal dialog is shown without any suspension

MaterialAlertDialogBuilder(this@MainActivity)
    .setTitle("Title")
    .setMessage("Message")
    .setPositiveButton("Positive") { _, _ ->
        // code to execute
    }
    .setNegativeButton("Negative") { _, _ ->
        // code to execute
    }
    .setNeutralButton("Neutral") { _, _ ->
        // code to execute
    }
    .show()
        
    // this code is executed before the dialog is finished
    println("Hello World")

Now, using the suspend dialog, we can wait for the dialog to be finish after continue with rest of the code flow

val result = SuspendAlertDialog.confirm(
    positiveButtonText = "Positive",
    negativeButtonText = "Negative",
    neutralButtonText = "Neutral"
) {
    MaterialAlertDialogBuilder(this@MainActivity)
        .setTitle("Title")
        .setMessage("Message")
}

// this line is executed after the dialog above is finish
tvResult.text = result.toString()

If you are fan of extension functions, the below approach can be used to achieve the same behavior as above.

val result = MaterialAlertDialogBuilder(this@MainActivity)
    .setTitle("Title")
    .setMessage("Message")
    .confirm(
        positiveButtonText = "Save",
        negativeButtonText = "Cancel",
        neutralButtonText = "Neutral",
    )

tvResult.text = result.toString()

Alert

SuspendAlertDialog.alert("Ok") {
    MaterialAlertDialogBuilder(this@MainActivity).setTitle("Selected Option")
}

tvResult.text = getString(R.string.alert_finished)

Using extension function

MaterialAlertDialogBuilder(this@MainActivity)
    .setTitle("Selected Option")
    .alert("Ok")

tvResult.text = getString(R.string.alert_finished)

Multi Choice Items

val multiChoiceResult = SuspendAlertDialog.setMultiChoiceItems(
        positiveButtonText = "Save",
        negativeButtonText = "Cancel",
        neutralButtonText = "Minimize",
        items = SuspendAlertDialog.MultiChoiceItems(
            items = listOf("Hello", "World", "Berlin", "Germany"),
            checked = listOf(false, false, false, false)
        )
) {
    MaterialAlertDialogBuilder(this@MainActivity).setTitle("Title")
}

tvResult.text = multiChoiceResult.toString()

Using extension function

val result = MaterialAlertDialogBuilder(this@MainActivity)
    .setTitle("Title")
    .setMultiChoiceItems(
        positiveButtonText = "Save",
        negativeButtonText = "Cancel",
        neutralButtonText = "Minimize",
        items = SuspendAlertDialog.MultiChoiceItems(
            items = listOf("Hello", "World", "Berlin", "Germany"),
            checked = listOf(false, false, false, false)
        )
    )

tvResult.text = result.toString()

Single Choice Items

val singleChoiceResult = SuspendAlertDialog.setSingleChoiceItems(
    positiveButtonText = "Save",
    negativeButtonText = "Cancel",
    neutralButtonText = "Minimize",
    items = SuspendAlertDialog.SingleChoiceItems(
        items = listOf("Hello", "World", "Berlin", "Germany"),
        selectedIndex = 1
    )
) {
  MaterialAlertDialogBuilder(this@MainActivity).setTitle("Title")
}

tvResult.text = singleChoiceResult.toString()

Using extension function

val result = MaterialAlertDialogBuilder(this@MainActivity)
    .setTitle("Title")
    .setSingleChoiceItems(
        positiveButtonText = "Save",
        negativeButtonText = "Cancel",
        neutralButtonText = "Minimize",
        items = SuspendAlertDialog.SingleChoiceItems(
            items = listOf("Hello", "World", "Berlin", "Germany"),
            selectedIndex = 1
        )
    )

tvResult.text = result.toString()

Custom Dialogs (DialogFragment & BottomSheetDialogFragment)

While above we read how to suspend calls to some dialogs, here we will discuss about suspend of calls to the DialogFragment and BottomSheetDialogFragment.

showAwait

Show await suspends the call till the dialog is destroyed. Returns an Unit.

DemoDialogFragment().showAwait(
	fragmentManager = supportFragmentManager,
	tag = DemoDialogFragment::class.java.canonicalName
)

tvResult.text = "${DemoDialogFragment::class.java.canonicalName} finished"

showAwaitResult

Dialogs that must return results, an implementation of SuspendDialogResult interface is a must. SuspendDialogResult provides a member called result which one is returned from the dialog after destroy. Make sure to assign a value to result before calling dismiss.

For more details, check the example app.

val result = DemoResultDialogFragment().showAwaitResult(
	fragmentManager = supportFragmentManager,
	tag = DemoResultDialogFragment::class.java.canonicalName
)
tvResult.text = result
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].