Skip to content

Commit

Permalink
Add DSL shorthands for selection change listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxr1998 committed Sep 10, 2020
1 parent 10e72f0 commit c38ad0a
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,50 @@ inline fun TwoStatePreference.defaultOnCheckedChange(crossinline callback: (Bool
}
}

/**
* [SingleChoiceDialogPreference.OnSelectionChangeListener] shorthand.
* Supplies the changed selection, return value determines whether that state should be persisted
* to [SharedPreferences][android.content.SharedPreferences].
*/
inline fun SingleChoiceDialogPreference.onSelectionChange(crossinline callback: (String) -> Boolean) {
selectionChangeListener = SingleChoiceDialogPreference.OnSelectionChangeListener { _, selection ->
callback(selection)
}
}

/**
* [SingleChoiceDialogPreference.OnSelectionChangeListener] shorthand.
* Always persists the change to [SharedPreferences][android.content.SharedPreferences].
*/
inline fun SingleChoiceDialogPreference.defaultOnSelectionChange(crossinline callback: (String) -> Unit) {
selectionChangeListener = SingleChoiceDialogPreference.OnSelectionChangeListener { _, selection ->
callback(selection)
true
}
}

/**
* [MultiChoiceDialogPreference.OnSelectionChangeListener] shorthand.
* Supplies the changed selections, return value determines whether that state should be persisted
* to [SharedPreferences][android.content.SharedPreferences].
*/
inline fun MultiChoiceDialogPreference.onSelectionChange(crossinline callback: (Set<String>) -> Boolean) {
selectionChangeListener = MultiChoiceDialogPreference.OnSelectionChangeListener { _, selection ->
callback(selection)
}
}

/**
* [MultiChoiceDialogPreference.OnSelectionChangeListener] shorthand.
* Always persists the change to [SharedPreferences][android.content.SharedPreferences].
*/
inline fun MultiChoiceDialogPreference.defaultOnSelectionChange(crossinline callback: (Set<String>) -> Unit) {
selectionChangeListener = MultiChoiceDialogPreference.OnSelectionChangeListener { _, selection ->
callback(selection)
true
}
}

// Deprecated listener helpers

@Deprecated(
Expand Down

0 comments on commit c38ad0a

Please sign in to comment.