Glimpse: Only send ContentObserver callbacks when Job is active
Change-Id: I83dfe71285e2ee1b38087ae3537a8fadc6d32ca3
This commit is contained in:
parent
d61b281506
commit
3107835489
|
@ -20,6 +20,7 @@ import kotlinx.coroutines.channels.awaitClose
|
|||
import kotlinx.coroutines.flow.callbackFlow
|
||||
import kotlinx.coroutines.flow.conflate
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.isActive
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.R)
|
||||
fun ContentResolver.createDeleteRequest(vararg uris: Uri) = IntentSenderRequest.Builder(
|
||||
|
@ -41,7 +42,9 @@ fun ContentResolver.createTrashRequest(value: Boolean, vararg uris: Uri) =
|
|||
fun ContentResolver.uriFlow(uri: Uri) = callbackFlow {
|
||||
val observer = object : ContentObserver(Handler(Looper.getMainLooper())) {
|
||||
override fun onChange(selfChange: Boolean) {
|
||||
trySend(Unit)
|
||||
if (isActive) {
|
||||
trySend(Unit)
|
||||
}
|
||||
}
|
||||
}
|
||||
registerContentObserver(uri, true, observer)
|
||||
|
|
Loading…
Reference in New Issue