Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Refactor
private fun loggedInMenuUi(menu: Menu, rootView: View, checkoutCartStream: Stream<Bla>, startActivity: () -> Unit) {
val alertMenuItem = menu.findItem(R.id.activity_main_alerts_menu_item)
val rootView = (alertMenuItem.actionView as FrameLayout).apply {
setOnClickListener {
startActivity()
}
}
val redCircle: FrameLayout = rootView.findViewById(R.id.view_alert_red_circle)
val countTextView: TextView = rootView.findViewById(R.id.view_alert_count_textview)
suspend fun updateItemCount(itemsInCart: List<Item>) {
withContext(Dispatchers.Main) {
val itemsInCartCount = itemsInCart.size
if (itemsInCartCount == 0) {
redCircle.visibility = View.GONE
} else {
redCircle.visibility = View.VISIBLE
countTextView.text = itemsInCartCount.toString()
}
}
}
launch {
checkoutCart
.itemsInCartStream()
.consumeEach { itemsInCart ->
updateItemCount(itemsInCart)
}
}
}
@handstandsam
Copy link

handstandsam commented Mar 31, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment