Last active
December 7, 2018 20:00
-
-
Save lion4ik/7346759585e4d12bd0f9cb90f791edfe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeClass { | |
private val channel: BroadcastChannel<List<Purchase>> = BroadcastChannel(Channel.CONFLATED) | |
override fun onPurchasesUpdated(responseCode: Int, purchases: MutableList<Purchase>?) { | |
GlobalScope.launch { | |
purchases?.run { channel.send(toList()) } | |
} | |
} | |
fun getPurchasesUpdatesChannel(): ReceiveChannel<List<Purchase>> = channel.openSubscription() | |
} | |
---using | |
somewhere in another class... | |
private val billingManager: SomeClass = SomeClass() | |
init { | |
launch(coroutineContext + coroutineExceptionHandler) { | |
billingManager.getPurchasesUpdatesChannel().consumeEach { purchases -> | |
if (purchases.isEmpty()) { | |
if (questionRepository.hasSections()) { | |
questionRepository.removeSections() | |
} | |
} else { | |
if (!questionRepository.hasSections()) { | |
purchases.find { it.sku == SKU_ITEM }?.run { downloadTest(this) } | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment