Created
March 31, 2019 20:06
-
-
Save pakoito/7802ab6a2389721519a1f0d6da691d31 to your computer and use it in GitHub Desktop.
Refactor
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
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) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, used here: https://github.com/handstandsam/ShoppingApp/pull/14/files