Skip to content

Commit

Permalink
ref: moved setOnItemSelectedListener to companion object in ProductEd…
Browse files Browse the repository at this point in the history
…itNutritionFactsFragment.kt
  • Loading branch information
VaiTon committed Aug 10, 2021
1 parent 15d1498 commit ecfcd5b
Showing 1 changed file with 16 additions and 16 deletions.
Expand Up @@ -138,22 +138,6 @@ class ProductEditNutritionFactsFragment : ProductEditFragment() {
}


private fun Spinner.setOnItemSelectedListener(
block: (
parent: AdapterView<*>?,
view: View?,
position: Int,
id: Long
) -> Unit
) {
this.onItemSelectedListener = object : OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) =
block(parent, view, position, id)

override fun onNothingSelected(parent: AdapterView<*>?) = Unit // This is not possible
}
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

Expand Down Expand Up @@ -987,5 +971,21 @@ class ProductEditNutritionFactsFragment : ProductEditFragment() {
return if (UNIT_DV == unit || UNIT_IU == unit) 0F
else UnitUtils.convertToGrams(value, unit)
}

private fun Spinner.setOnItemSelectedListener(
block: (
parent: AdapterView<*>?,
view: View?,
position: Int,
id: Long
) -> Unit
) {
this.onItemSelectedListener = object : OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) =
block(parent, view, position, id)

override fun onNothingSelected(parent: AdapterView<*>?) = Unit // This is not possible
}
}
}
}

0 comments on commit ecfcd5b

Please sign in to comment.