Skip to content

Commit

Permalink
Add optional extra button for custom actions
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkeppeler committed Sep 12, 2022
1 parent 0ac2713 commit 373697b
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ sealed class CalendarSelection : BaseSelection() {
*/
class Date(
override val withButtonView: Boolean = true,
override val extraButton: SelectionButton? = null,
override val negativeButton: SelectionButton? = null,
override val onNegativeClick: (() -> Unit)? = null,
override val positiveButton: SelectionButton? = null,
Expand All @@ -39,6 +40,7 @@ sealed class CalendarSelection : BaseSelection() {
* @param onSelectDates The listener that returns the selected dates.
*/
class Dates(
override val extraButton: SelectionButton? = null,
override val negativeButton: SelectionButton? = null,
override val onNegativeClick: (() -> Unit)? = null,
override val positiveButton: SelectionButton? = null,
Expand All @@ -57,6 +59,7 @@ sealed class CalendarSelection : BaseSelection() {
*/
class Period(
override val withButtonView: Boolean = true,
override val extraButton: SelectionButton? = null,
override val negativeButton: SelectionButton? = null,
override val onNegativeClick: (() -> Unit)? = null,
override val positiveButton: SelectionButton? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ sealed class ClockSelection : BaseSelection() {
/**
* Select a time with hours and minutes.
* @param withButtonView Show the dialog with the buttons view.
* @param extraButton An extra button that is aligned to the start of the dialog and can be used for a custom action.
* @param negativeButton The button that will be used as a negative button.
* @param onNegativeClick The listener that is invoked when the negative button is clicked.
* @param positiveButton The button that will be used as a positive button.
* @param onPositiveClick The listener that returns the selected hours and minutes.
*/
class HoursMinutes(
override val withButtonView: Boolean = false,
override val extraButton: SelectionButton? = null,
override val negativeButton: SelectionButton? = null,
override val onNegativeClick: (() -> Unit)? = null,
override val positiveButton: SelectionButton? = null,
Expand All @@ -29,13 +31,15 @@ sealed class ClockSelection : BaseSelection() {
/**
* Select a time with hours, minutes and seconds.
* @param withButtonView Show the dialog with the buttons view.
* @param extraButton An extra button that is aligned to the start of the dialog and can be used for a custom action.
* @param negativeButton The button that will be used as a negative button.
* @param onNegativeClick The listener that is invoked when the negative button is clicked.
* @param positiveButton The button that will be used as a positive button.
* @param onPositiveClick The listener that returns the selected hours, minutes and seconds.
*/
class HoursMinutesSeconds(
override val withButtonView: Boolean = false,
override val extraButton: SelectionButton? = null,
override val negativeButton: SelectionButton? = null,
override val onNegativeClick: (() -> Unit)? = null,
override val positiveButton: SelectionButton? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import com.maxkeppeker.sheets.core.models.base.BaseSelection
/**
* The selection configuration for the color dialog.
* @param selectedColor A color that is selected by default.
* @param extraButton An extra button that can be used for a custom action.
* @param onExtraButtonClick The listener that is invoked when the extra button is clicked.
* @param negativeButton The button that will be used as a negative button.
* @param onNegativeClick The listener that is invoked when the negative button is clicked.
* @param positiveButton The button that will be used as a positive button.
Expand All @@ -17,6 +19,8 @@ import com.maxkeppeker.sheets.core.models.base.BaseSelection
data class ColorSelection(
val selectedColor: SingleColor? = null,
override val withButtonView: Boolean = true,
override val extraButton: SelectionButton? = null,
override val onExtraButtonClick: (() -> Unit)? = null,
override val negativeButton: SelectionButton? = null,
override val onNegativeClick: (() -> Unit)? = null,
override val positiveButton: SelectionButton? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.maxkeppeker.sheets.core.models.base.BaseSelection
*/
class CoreSelection(
override val withButtonView: Boolean = true,
override val extraButton: SelectionButton? = null,
override val negativeButton: SelectionButton? = null,
override val onNegativeClick: (() -> Unit)? = null,
override val positiveButton: SelectionButton? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ package com.maxkeppeker.sheets.core.models.base
*/
abstract class BaseSelection {
open val withButtonView: Boolean = true
open val extraButton: SelectionButton? = null
open val onExtraButtonClick: (() -> Unit)? = null
open val negativeButton: SelectionButton? = null
open val positiveButton: SelectionButton? = null
open val onNegativeClick: (() -> Unit)? = null
open val positiveButton: SelectionButton? = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,10 @@ enum class ButtonStyle {
/**
* Filled button.
*/
FILLED
FILLED,

/**
* Outlined button.
*/
OUTLINED
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,26 @@ fun ButtonsComponent(
horizontalArrangement = Arrangement.End
) {

selection.extraButton?.let {
SelectionButtonComponent(
modifier = Modifier.wrapContentWidth(),
button = selection.extraButton,
onClick = { },
)
Spacer(modifier = Modifier.weight(1f))
}

SelectionButtonComponent(
modifier = Modifier
.wrapContentWidth()
.padding(end = dimensionResource(id = R.dimen.scd_normal_100)),
.padding(horizontal = dimensionResource(id = R.dimen.scd_normal_100)),
button = selection.negativeButton,
onClick = { onNegative(); onCancel() },
defaultText = stringResource(id = R.string.cancel)
)

SelectionButtonComponent(
modifier = Modifier
.wrapContentWidth(),
modifier = Modifier.wrapContentWidth(),
button = selection.positiveButton,
onClick = { onPositive(); onCancel() },
enabled = onPositiveValid,
Expand All @@ -72,7 +80,7 @@ private fun SelectionButtonComponent(
button: SelectionButton?,
onClick: () -> Unit,
enabled: Boolean = true,
defaultText: String
defaultText: String = ""
) {
val buttonContent: @Composable RowScope.() -> Unit = {
button?.icon?.let { icon ->
Expand Down Expand Up @@ -110,6 +118,14 @@ private fun SelectionButtonComponent(
content = buttonContent
)
}
button.type == ButtonStyle.OUTLINED -> {
OutlinedButton(
modifier = modifier,
onClick = onClick,
enabled = enabled,
content = buttonContent
)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ sealed class DateTimeSelection(
/**
* Select a date.
* @param withButtonView Show the dialog with the buttons view.
* @param extraButton An extra button that can be used for a custom action.
* @param onExtraButtonClick The listener that is invoked when the extra button is clicked.
* @param negativeButton The button that will be used as a negative button.
* @param onNegativeClick The listener that is invoked when the negative button is clicked.
* @param positiveButton The button that will be used as a positive button.
Expand All @@ -32,6 +34,8 @@ sealed class DateTimeSelection(
*/
data class Date(
override val withButtonView: Boolean = true,
override val extraButton: SelectionButton? = null,
override val onExtraButtonClick: (() -> Unit)? = null,
override val negativeButton: SelectionButton? = null,
override val onNegativeClick: (() -> Unit)? = null,
override val positiveButton: SelectionButton? = null,
Expand All @@ -44,6 +48,8 @@ sealed class DateTimeSelection(
/**
* Select a time.
* @param withButtonView Show the dialog with the buttons view.
* @param extraButton An extra button that can be used for a custom action.
* @param onExtraButtonClick The listener that is invoked when the extra button is clicked.
* @param negativeButton The button that will be used as a negative button.
* @param onNegativeClick The listener that is invoked when the negative button is clicked.
* @param positiveButton The button that will be used as a positive button.
Expand All @@ -53,6 +59,8 @@ sealed class DateTimeSelection(
*/
data class Time(
override val withButtonView: Boolean = true,
override val extraButton: SelectionButton? = null,
override val onExtraButtonClick: (() -> Unit)? = null,
override val negativeButton: SelectionButton? = null,
override val onNegativeClick: (() -> Unit)? = null,
override val positiveButton: SelectionButton? = null,
Expand All @@ -64,6 +72,8 @@ sealed class DateTimeSelection(
/**
* Select a date & time.
* @param withButtonView Show the dialog with the buttons view.
* @param extraButton An extra button that can be used for a custom action.
* @param onExtraButtonClick The listener that is invoked when the extra button is clicked.
* @param negativeButton The button that will be used as a negative button.
* @param onNegativeClick The listener that is invoked when the negative button is clicked.
* @param positiveButton The button that will be used as a positive button.
Expand All @@ -75,6 +85,8 @@ sealed class DateTimeSelection(
*/
data class DateTime(
override val withButtonView: Boolean = true,
override val extraButton: SelectionButton? = null,
override val onExtraButtonClick: (() -> Unit)? = null,
override val negativeButton: SelectionButton? = null,
override val onNegativeClick: (() -> Unit)? = null,
override val positiveButton: SelectionButton? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@

package com.maxkeppeler.sheets.duration.models

import com.maxkeppeker.sheets.core.models.base.SelectionButton
import com.maxkeppeker.sheets.core.models.base.BaseSelection
import com.maxkeppeker.sheets.core.models.base.SelectionButton

/**
* The selection configuration for the duration dialog.
* @param extraButton An extra button that can be used for a custom action.
* @param onExtraButtonClick The listener that is invoked when the extra button is clicked.
* @param negativeButton The button that will be used as a negative button.
* @param onNegativeClick The listener that is invoked when the negative button is clicked.
* @param positiveButton The button that will be used as a positive button.
* @param onPositiveClick The listener that returns the selected duration time in seconds.
*/
class DurationSelection(
override val extraButton: SelectionButton? = null,
override val onExtraButtonClick: (() -> Unit)? = null,
override val negativeButton: SelectionButton? = null,
override val onNegativeClick: (() -> Unit)? = null,
override val positiveButton: SelectionButton? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ sealed class EmojiSelection : BaseSelection() {
/**
* Select the emoji as unicode.
* @param withButtonView Show the dialog with the buttons view.
* @param extraButton An extra button that can be used for a custom action.
* @param onExtraButtonClick The listener that is invoked when the extra button is clicked.
* @param negativeButton The button that will be used as a negative button.
* @param onNegativeClick The listener that is invoked when the negative button is clicked.
* @param positiveButton The button that will be used as a positive button.
* @param onPositiveClick The listener that returns the selected emoji as unicode.
*/
class Unicode(
override val withButtonView: Boolean = true,
override val extraButton: SelectionButton? = null,
override val onExtraButtonClick: (() -> Unit)? = null,
override val negativeButton: SelectionButton? = null,
override val onNegativeClick: (() -> Unit)? = null,
override val positiveButton: SelectionButton? = null,
Expand All @@ -29,13 +33,17 @@ sealed class EmojiSelection : BaseSelection() {
/**
* Select the emoji.
* @param withButtonView Show the dialog with the buttons view.
* @param extraButton An extra button that can be used for a custom action.
* @param onExtraButtonClick The listener that is invoked when the extra button is clicked.
* @param negativeButton The button that will be used as a negative button.
* @param onNegativeClick The listener that is invoked when the negative button is clicked.
* @param positiveButton The button that will be used as a positive button.
* @param onPositiveClick The listener that returns the selected emoji.
*/
class Emoji(
override val withButtonView: Boolean = true,
override val extraButton: SelectionButton? = null,
override val onExtraButtonClick: (() -> Unit)? = null,
override val negativeButton: SelectionButton? = null,
override val onNegativeClick: (() -> Unit)? = null,
override val positiveButton: SelectionButton? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ import com.maxkeppeker.sheets.core.models.base.BaseSelection

/**
* The selection configuration for the info dialog.
* @param extraButton An extra button that can be used for a custom action.
* @param onExtraButtonClick The listener that is invoked when the extra button is clicked.
* @param negativeButton The button that will be used as a negative button.
* @param onNegativeClick The listener that is invoked when the negative button is clicked.
* @param positiveButton The button that will be used as a positive button.
* @param onPositiveClick The listener that is invoked when the positive button is clicked.
*/
class InfoSelection(
override val extraButton: SelectionButton? = null,
override val onExtraButtonClick: (() -> Unit)? = null,
override val negativeButton: SelectionButton? = null,
override val onNegativeClick: (() -> Unit)? = null,
override val positiveButton: SelectionButton? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ sealed class ListSelection(
* @param options The options that will be displayed.
* @param showRadioButtons Show the options with radio buttons.
* @param withButtonView Show the dialog with the buttons view.
* @param extraButton An extra button that can be used for a custom action.
* @param onExtraButtonClick The listener that is invoked when the extra button is clicked.
* @param negativeButton The button that will be used as a negative button.
* @param onNegativeClick The listener that is invoked when the negative button is clicked.
* @param positiveButton The button that will be used as a positive button.
Expand All @@ -28,6 +30,8 @@ sealed class ListSelection(
override val options: List<ListOption>,
val showRadioButtons: Boolean = false,
override val withButtonView: Boolean = true,
override val extraButton: SelectionButton? = null,
override val onExtraButtonClick: (() -> Unit)? = null,
override val negativeButton: SelectionButton? = null,
override val onNegativeClick: (() -> Unit)? = null,
override val positiveButton: SelectionButton? = null,
Expand All @@ -40,6 +44,8 @@ sealed class ListSelection(
* @param showCheckBoxes Show the options with check boxes.
* @param minChoices The minimum amount of choices that are allowed.
* @param maxChoices The maximum amount of choices that are allowed.
* @param extraButton An extra button that can be used for a custom action.
* @param onExtraButtonClick The listener that is invoked when the extra button is clicked.
* @param negativeButton The button that will be used as a negative button.
* @param onNegativeClick The listener that is invoked when the negative button is clicked.
* @param positiveButton The button that will be used as a positive button.
Expand All @@ -50,6 +56,8 @@ sealed class ListSelection(
val showCheckBoxes: Boolean = false,
@IntRange(from = 1L, to = 90L) val minChoices: Int? = null,
@IntRange(from = 3L, to = 90L) val maxChoices: Int? = null,
override val extraButton: SelectionButton? = null,
override val onExtraButtonClick: (() -> Unit)? = null,
override val negativeButton: SelectionButton? = null,
override val onNegativeClick: (() -> Unit)? = null,
override val positiveButton: SelectionButton? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ sealed class OptionSelection(
* Single-choice selection for the list dialog.
* @param options The options that will be displayed.
* @param withButtonView Show the dialog with the buttons view.
* @param extraButton An extra button that can be used for a custom action.
* @param onExtraButtonClick The listener that is invoked when the extra button is clicked.
* @param negativeButton The button that will be used as a negative button.
* @param onNegativeClick The listener that is invoked when the negative button is clicked.
* @param positiveButton The button that will be used as a positive button.
Expand All @@ -26,6 +28,8 @@ sealed class OptionSelection(
class Single(
override val options: List<Option>,
override val withButtonView: Boolean = true,
override val extraButton: SelectionButton? = null,
override val onExtraButtonClick: (() -> Unit)? = null,
override val negativeButton: SelectionButton? = null,
override val onNegativeClick: (() -> Unit)? = null,
override val positiveButton: SelectionButton? = null,
Expand All @@ -38,6 +42,8 @@ sealed class OptionSelection(
* @param minChoices The minimum amount of choices that are allowed.
* @param maxChoices The maximum amount of choices that are allowed.
* @param maxChoicesStrict Allow the user to temporarily select more options than maximum choices.
* @param extraButton An extra button that can be used for a custom action.
* @param onExtraButtonClick The listener that is invoked when the extra button is clicked.
* @param negativeButton The button that will be used as a negative button.
* @param onNegativeClick The listener that is invoked when the negative button is clicked.
* @param positiveButton The button that will be used as a positive button.
Expand All @@ -48,6 +54,8 @@ sealed class OptionSelection(
@IntRange(from = 1L, to = 90L) val minChoices: Int? = null,
@IntRange(from = 3L, to = 90L) val maxChoices: Int? = null,
val maxChoicesStrict: Boolean = true,
override val extraButton: SelectionButton? = null,
override val onExtraButtonClick: (() -> Unit)? = null,
override val negativeButton: SelectionButton? = null,
override val onNegativeClick: (() -> Unit)? = null,
override val positiveButton: SelectionButton? = null,
Expand Down

0 comments on commit 373697b

Please sign in to comment.