{"id":13902444,"url":"https://github.com/xeinebiu/android-suspend-dialogs","last_synced_at":"2025-07-24T22:35:27.846Z","repository":{"id":37711829,"uuid":"388505154","full_name":"xeinebiu/android-suspend-dialogs","owner":"xeinebiu","description":"A helper library for Android to display Dialogs by suspending the coroutine till finish of the dialog.","archived":false,"fork":false,"pushed_at":"2022-06-22T21:50:04.000Z","size":206,"stargazers_count":33,"open_issues_count":0,"forks_count":8,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-10T12:40:22.434Z","etag":null,"topics":["alert","android","coroutines-android","demo","dialog","kotlin","library","suspend"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xeinebiu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-22T15:10:55.000Z","updated_at":"2023-06-07T08:21:53.000Z","dependencies_parsed_at":"2022-08-27T05:41:13.089Z","dependency_job_id":null,"html_url":"https://github.com/xeinebiu/android-suspend-dialogs","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/xeinebiu/android-suspend-dialogs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xeinebiu%2Fandroid-suspend-dialogs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xeinebiu%2Fandroid-suspend-dialogs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xeinebiu%2Fandroid-suspend-dialogs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xeinebiu%2Fandroid-suspend-dialogs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xeinebiu","download_url":"https://codeload.github.com/xeinebiu/android-suspend-dialogs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xeinebiu%2Fandroid-suspend-dialogs/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266913751,"owners_count":24005584,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-24T02:00:09.469Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alert","android","coroutines-android","demo","dialog","kotlin","library","suspend"],"created_at":"2024-08-06T22:01:09.103Z","updated_at":"2025-07-24T22:35:27.796Z","avatar_url":"https://github.com/xeinebiu.png","language":"Kotlin","funding_links":[],"categories":["Kotlin"],"sub_categories":[],"readme":"# Android Suspendable Dialogs\n\nA helper library for Android to display Dialogs by suspending the coroutine till finish of the dialog.\n\n# Installation\n```\nallprojects {\n\trepositories {\n\t\t...\n\t\tmaven { url 'https://www.jitpack.io' }\n\t}\n}\n```\n\n```\ndependencies {\n    implementation 'com.github.xeinebiu:android-suspend-dialogs:1.6.2'\n}\n```\n    \n\n# Some Differences with and without suspend\n\n### Confirm\n\nThe below example shows how a normal dialog is shown without any suspension\n\n```kotlin\nMaterialAlertDialogBuilder(this@MainActivity)\n    .setTitle(\"Title\")\n    .setMessage(\"Message\")\n    .setPositiveButton(\"Positive\") { _, _ -\u003e\n        // code to execute\n    }\n    .setNegativeButton(\"Negative\") { _, _ -\u003e\n        // code to execute\n    }\n    .setNeutralButton(\"Neutral\") { _, _ -\u003e\n        // code to execute\n    }\n    .show()\n        \n    // this code is executed before the dialog is finished\n    println(\"Hello World\")\n```\n\nNow, using the suspend dialog, we can wait for the dialog to be finish after continue with rest of the code flow\n```kotlin\nval result = SuspendAlertDialog.confirm(\n    positiveButtonText = \"Positive\",\n    negativeButtonText = \"Negative\",\n    neutralButtonText = \"Neutral\"\n) {\n    MaterialAlertDialogBuilder(this@MainActivity)\n        .setTitle(\"Title\")\n        .setMessage(\"Message\")\n}\n\n// this line is executed after the dialog above is finish\ntvResult.text = result.toString()\n```\n\nIf you are fan of extension functions, the below approach can be used to achieve the same behavior as above.\n```kotlin\nval result = MaterialAlertDialogBuilder(this@MainActivity)\n    .setTitle(\"Title\")\n    .setMessage(\"Message\")\n    .confirm(\n        positiveButtonText = \"Save\",\n        negativeButtonText = \"Cancel\",\n        neutralButtonText = \"Neutral\",\n    )\n\ntvResult.text = result.toString()\n```\n\n### Alert\n\n```kotlin\nSuspendAlertDialog.alert(\"Ok\") {\n    MaterialAlertDialogBuilder(this@MainActivity).setTitle(\"Selected Option\")\n}\n\ntvResult.text = getString(R.string.alert_finished)\n```\n\nUsing extension function\n\n```kotlin\nMaterialAlertDialogBuilder(this@MainActivity)\n    .setTitle(\"Selected Option\")\n    .alert(\"Ok\")\n\ntvResult.text = getString(R.string.alert_finished)\n```\n\n### Multi Choice Items\n\n```kotlin\nval multiChoiceResult = SuspendAlertDialog.setMultiChoiceItems(\n        positiveButtonText = \"Save\",\n        negativeButtonText = \"Cancel\",\n        neutralButtonText = \"Minimize\",\n        items = SuspendAlertDialog.MultiChoiceItems(\n            items = listOf(\"Hello\", \"World\", \"Berlin\", \"Germany\"),\n            checked = listOf(false, false, false, false)\n        )\n) {\n    MaterialAlertDialogBuilder(this@MainActivity).setTitle(\"Title\")\n}\n\ntvResult.text = multiChoiceResult.toString()\n```\n\nUsing extension function\n\n```kotlin\nval result = MaterialAlertDialogBuilder(this@MainActivity)\n    .setTitle(\"Title\")\n    .setMultiChoiceItems(\n        positiveButtonText = \"Save\",\n        negativeButtonText = \"Cancel\",\n        neutralButtonText = \"Minimize\",\n        items = SuspendAlertDialog.MultiChoiceItems(\n            items = listOf(\"Hello\", \"World\", \"Berlin\", \"Germany\"),\n            checked = listOf(false, false, false, false)\n        )\n    )\n\ntvResult.text = result.toString()\n```\n\n### Single Choice Items\n\n```kotlin\nval singleChoiceResult = SuspendAlertDialog.setSingleChoiceItems(\n    positiveButtonText = \"Save\",\n    negativeButtonText = \"Cancel\",\n    neutralButtonText = \"Minimize\",\n    items = SuspendAlertDialog.SingleChoiceItems(\n        items = listOf(\"Hello\", \"World\", \"Berlin\", \"Germany\"),\n        selectedIndex = 1\n    )\n) {\n  MaterialAlertDialogBuilder(this@MainActivity).setTitle(\"Title\")\n}\n\ntvResult.text = singleChoiceResult.toString()\n```\n\nUsing extension function\n\n```kotlin\nval result = MaterialAlertDialogBuilder(this@MainActivity)\n    .setTitle(\"Title\")\n    .setSingleChoiceItems(\n        positiveButtonText = \"Save\",\n        negativeButtonText = \"Cancel\",\n        neutralButtonText = \"Minimize\",\n        items = SuspendAlertDialog.SingleChoiceItems(\n            items = listOf(\"Hello\", \"World\", \"Berlin\", \"Germany\"),\n            selectedIndex = 1\n        )\n    )\n\ntvResult.text = result.toString()\n```\n\n## Custom Dialogs (DialogFragment \u0026 BottomSheetDialogFragment)\n\nWhile above we read how to suspend calls to some dialogs, here we will discuss about suspend of calls to the DialogFragment and BottomSheetDialogFragment.\n\n### showAwait\n\nShow await suspends the call till the dialog is destroyed. Returns an Unit.\n\n```kotlin\nDemoDialogFragment().showAwait(\n\tfragmentManager = supportFragmentManager,\n\ttag = DemoDialogFragment::class.java.canonicalName\n)\n\ntvResult.text = \"${DemoDialogFragment::class.java.canonicalName} finished\"\n```\n\n### showAwaitResult\n\nDialogs that must return results, an implementation of `SuspendDialogResult` interface is a must. `SuspendDialogResult` provides a member called `result` which one is returned\nfrom the dialog after destroy. Make sure to assign a value to `result` before calling dismiss.\n\nFor more details, check the example app.\n\n```kotlin\nval result = DemoResultDialogFragment().showAwaitResult(\n\tfragmentManager = supportFragmentManager,\n\ttag = DemoResultDialogFragment::class.java.canonicalName\n)\ntvResult.text = result\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxeinebiu%2Fandroid-suspend-dialogs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxeinebiu%2Fandroid-suspend-dialogs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxeinebiu%2Fandroid-suspend-dialogs/lists"}