Skip to content

Commit 79952f7

Browse files
committed
接入Paging改写动态页面
1 parent 762ba4e commit 79952f7

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

app/src/main/java/com/fmt/github/ext/XPopupExt.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import androidx.lifecycle.MutableLiveData
66
import com.fmt.github.AppContext
77
import com.fmt.github.R
88
import com.lxj.xpopup.XPopup
9+
import kotlinx.coroutines.suspendCancellableCoroutine
910
import kotlin.coroutines.resume
10-
import kotlin.coroutines.suspendCoroutine
1111

1212
//回调转协程
1313
suspend fun showConfirmPopup(context: Context, title: String, message: String) =
14-
suspendCoroutine<Boolean> { continuation ->
14+
suspendCancellableCoroutine<Boolean> { continuation -> //Continuation(本质还是回调接口),kotlin编译器的黑魔法帮我们做了封装处理了
1515
XPopup.Builder(context)
1616
.asConfirm(
1717
title,
@@ -22,7 +22,11 @@ suspend fun showConfirmPopup(context: Context, title: String, message: String) =
2222
{ continuation.resume(false) },
2323
false
2424
)
25-
.show()
25+
.show().also { popupView ->
26+
continuation.invokeOnCancellation {//在协程取消时,隐藏对话框
27+
popupView.dismiss()
28+
}
29+
}
2630
}
2731

2832
fun createSortReposPopup(context: Context): LiveData<SortOption> {

0 commit comments

Comments
 (0)