From d2b14bcfc45f64470e7fb7f2829c9ea8b7a7ec83 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 25 Jul 2020 12:12:44 -0400 Subject: [PATCH] Inline extension functions --- .../tachiyomi/util/view/ViewExtensions.kt | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt index 1948c05d3..a215ea01d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt @@ -33,7 +33,11 @@ fun View.getCoordinates() = Point((left + right) / 2, (top + bottom) / 2) * @param length the duration of the snack. * @param f a function to execute in the snack, allowing for example to define a custom action. */ -inline fun View.snack(message: String, length: Int = Snackbar.LENGTH_LONG, f: Snackbar.() -> Unit = {}): Snackbar { +inline fun View.snack( + message: String, + length: Int = Snackbar.LENGTH_LONG, + f: Snackbar.() -> Unit = {} +): Snackbar { val snack = Snackbar.make(this, message, length) snack.f() snack.show() @@ -56,7 +60,11 @@ inline fun View.setTooltip(@StringRes stringRes: Int) { * @param initMenu function to execute when the menu after is inflated. * @param onMenuItemClick function to execute when a menu item is clicked. */ -fun View.popupMenu(@MenuRes menuRes: Int, initMenu: (Menu.() -> Unit)? = null, onMenuItemClick: MenuItem.() -> Boolean) { +inline fun View.popupMenu( + @MenuRes menuRes: Int, + noinline initMenu: (Menu.() -> Unit)? = null, + noinline onMenuItemClick: MenuItem.() -> Boolean +) { val popup = PopupMenu(context, this, Gravity.NO_GRAVITY, R.attr.actionOverflowMenuStyle, 0) popup.menuInflater.inflate(menuRes, popup.menu) @@ -73,7 +81,7 @@ fun View.popupMenu(@MenuRes menuRes: Int, initMenu: (Menu.() -> Unit)? = null, o * * @param recycler [RecyclerView] that the FAB should shrink/extend in response to. */ -fun ExtendedFloatingActionButton.shrinkOnScroll(recycler: RecyclerView): RecyclerView.OnScrollListener { +inline fun ExtendedFloatingActionButton.shrinkOnScroll(recycler: RecyclerView): RecyclerView.OnScrollListener { val listener = object : RecyclerView.OnScrollListener() { override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { if (dy <= 0) { @@ -93,7 +101,10 @@ fun ExtendedFloatingActionButton.shrinkOnScroll(recycler: RecyclerView): Recycle * @param items List of strings that are shown as individual chips. * @param onClick Optional on click listener for each chip. */ -fun ChipGroup.setChips(items: List?, onClick: (item: String) -> Unit = {}) { +inline fun ChipGroup.setChips( + items: List?, + noinline onClick: (item: String) -> Unit = {} +) { removeAllViews() items?.forEach { item ->