瀏覽代碼

Inline extension functions

arkon 4 年之前
父節點
當前提交
d2b14bcfc4
共有 1 個文件被更改,包括 15 次插入4 次删除
  1. 15 4
      app/src/main/java/eu/kanade/tachiyomi/util/view/ViewExtensions.kt

+ 15 - 4
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<String>?, onClick: (item: String) -> Unit = {}) {
+inline fun ChipGroup.setChips(
+    items: List<String>?,
+    noinline onClick: (item: String) -> Unit = {}
+) {
     removeAllViews()
 
     items?.forEach { item ->