kotlin协程分享

作者: LSteven | 来源:发表于2019-04-13 14:26 被阅读76次

    上周在公司做了个分享,转成图片发吧


    coroutine.001.jpeg coroutine.002.jpeg coroutine.003.jpeg coroutine.004.jpeg coroutine.005.jpeg coroutine.006.jpeg coroutine.007.jpeg coroutine.008.jpeg coroutine.009.jpeg coroutine.010.jpeg coroutine.011.jpeg coroutine.012.jpeg coroutine.013.jpeg coroutine.014.jpeg
    suspend fun displayMyMultipleChoiceDialog(): MyDialogResult {
        lateinit var result: Continuation<MyDialogResult>
        AlertDialog.Builder(this)
            .setTitle(...string resource...)
        .setMessage(...string resource...)
        .setPositiveButton(...RETRY string..., { dialogInterface: DialogInterface, _: Int ->
            dialogInterface.dismiss()
            result.resume(MyDialogResult.RETRY)
        })
        .setNegativeButton(...CANCEL string..., { dialogInterface: DialogInterface, _: Int ->
            dialogInterface.dismiss()
            result.resume(MyDialogResult.CANCEL)
        })
        .setOnCancelListener {
            result.resume(MyDialogResult.CANCEL)
        }
        .create()
        .show()
    
        return suspendCoroutine {continuation -> result = continuation}
    }
    
    fun myPresenterMethod() {
        launchAsync {
            when (view.displayMyMultipleChoiceDialog()) {
                RETRY -> ...do something...
                CANCEL -> ...do something else...
            }
        }
    }
    

    btw最近准备看一下redex~ 希望能尽快出专题

    相关文章

      网友评论

        本文标题:kotlin协程分享

        本文链接:https://www.haomeiwen.com/subject/fjglwqtx.html