diff --git a/README.md b/README.md index 7c70307..92c15c2 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,29 @@ Step 2. Add the dependency The following examples was inspired by [Google's definition of BottomSheet](https://material.io/guidelines/components/bottom-sheets.html#bottom-sheets-specs). ### #1 +Yes/No chooser + Example #1 image. +```kotlin + fun runExampleYesNo(view: View) { + bottomSheet { + clickableItem { + titleRes = R.string.yes + onClicked = { toast(title.toString()) } + } + clickableItem { + titleRes = R.string.no + onClicked = { toast(title.toString()) } + } + }.show() + } +``` + + +### #2 +Example #1 image. + ```kotlin fun runExample1(view: View) { bottomSheet { @@ -63,8 +84,8 @@ The following examples was inspired by [Google's definition of BottomSheet](http } ``` -### #2 -Example #2 image. +### #3 +Example #2 image. ```kotlin fun runExample2(view: View) { @@ -105,10 +126,10 @@ The following examples was inspired by [Google's definition of BottomSheet](http ``` -### #3 +### #4 Custom items -Example #3 image. +Example #3 image. ```kotlin fun runExample3(view: View) { @@ -148,4 +169,4 @@ Custom items 2. Provide `bottomSheet(...)` with an action which supposed to configure the BottomSheet. 3. Call `bottomSheetBuilder.show()` to actually show the BottomSheet. -For more information about available options check KDoc [here](https://github.com/allco/BottomSheetLib/blob/master/bottomsheet/src/main/java/com/allco/ui/bottomsheet/BottomSheetBuilder.kt) \ No newline at end of file +For more information about available options check KDoc [here](https://github.com/allco/BottomSheetLib/blob/master/bottomsheet/src/main/java/com/allco/ui/bottomsheet/BottomSheetBuilder.kt) diff --git a/bottomsheet/src/main/java/com/allco/ui/bottomsheet/BottomSheetBuilder.kt b/bottomsheet/src/main/java/com/allco/ui/bottomsheet/BottomSheetBuilder.kt index 8ac0d1c..c8654d2 100644 --- a/bottomsheet/src/main/java/com/allco/ui/bottomsheet/BottomSheetBuilder.kt +++ b/bottomsheet/src/main/java/com/allco/ui/bottomsheet/BottomSheetBuilder.kt @@ -8,6 +8,7 @@ import android.graphics.drawable.Drawable import android.support.annotation.ColorRes import android.support.annotation.DrawableRes import android.support.annotation.StringRes +import android.support.annotation.StyleRes import android.support.v4.app.Fragment /** @@ -86,17 +87,19 @@ class BottomSheetSettings { /** * Represents unclickable item with title - * @property title the text which will be shown as a title + * @param title the text which will be shown as a title + * @param textAppearanceRes a text appearance style resource for the title */ data class TitleItem( override var title: String? = null, - @StringRes var titleRes: Int? = null + @StringRes var titleRes: Int? = null, + @StyleRes override var textAppearanceRes: Int? = R.style.BottomSheetLib_Title_DefaultTextAppearance ) : Item, TitleViewModel /** * Represents the horizontal line item aka divider - * @property leftOffset blank gap from left side in pixels - * @property rightOffset blank gap from right side in pixels + * @param leftOffset blank gap from left side in pixels + * @param rightOffset blank gap from right side in pixels */ data class DividerItem( override var leftOffset: Int? = null, @@ -105,8 +108,8 @@ class BottomSheetSettings { /** * Represents an item with custom layout - * @property layoutRes id of layout from resource - * @property onBind action which will be called every time when the [layoutRes] is supposed to be populated with actual data. + * @param layoutRes id of layout from resource + * @param onBind action which will be called every time when the [layoutRes] is supposed to be populated with actual data. */ data class CustomItem( var layoutRes: Int? = null, @@ -116,12 +119,13 @@ class BottomSheetSettings { /** * Represents an clickable item which can optionally can have a title and an icon. * The icon will be fitted in the 24dp x 24dp square. - * @property title the text of the item - * @property iconRes resource id of a drawable which is supposed to be used as as an icon - * @property iconResTintColor resource id of a color which will be used fot tinting [iconRes] - * @property iconDrawable a [Drawable] which will be used as an icon overrides [iconRes] - * @property onClicked an action which will be invoked is the user tapped the item - * @property dismissOnClick if `false` then the BottomSheet will not be dismissed automatically if the user tapped the item + * @param title the text of the item + * @param iconRes resource id of a drawable which is supposed to be used as as an icon + * @param iconResTintColor resource id of a color which will be used fot tinting [iconRes] + * @param iconDrawable a [Drawable] which will be used as an icon overrides [iconRes] + * @param onClicked an action which will be invoked is the user tapped the item + * @param textAppearanceRes a text appearance style resource for the [title] + * @param dismissOnClick if `false` then the BottomSheet will not be dismissed automatically if the user tapped the item */ data class ClickableItem( override var title: String? = null, @@ -131,6 +135,7 @@ class BottomSheetSettings { override var onClicked: (() -> Unit)? = null, @DrawableRes override var iconRes: Int? = null, @ColorRes override var iconResTintColor: Int = R.color.bottom_sheet_item_text_title, + @StyleRes override var textAppearanceRes: Int? = R.style.BottomSheetLib_ClickableItem_DefaultTextAppearance, var dismissOnClick: Boolean = true ) : Item, ClickableViewModel diff --git a/bottomsheet/src/main/java/com/allco/ui/bottomsheet/ViewModels.kt b/bottomsheet/src/main/java/com/allco/ui/bottomsheet/ViewModels.kt index 2aa0d0e..eab8d61 100644 --- a/bottomsheet/src/main/java/com/allco/ui/bottomsheet/ViewModels.kt +++ b/bottomsheet/src/main/java/com/allco/ui/bottomsheet/ViewModels.kt @@ -7,6 +7,7 @@ import com.allco.ui.recyclerView.ObserverBasedAdapter interface TitleViewModel { var title: String? + var textAppearanceRes: Int? } interface DividerViewModel { @@ -20,10 +21,11 @@ interface ClickableViewModel { var iconDrawable: Drawable? var iconResTintColor: Int var iconRes: Int? + var textAppearanceRes: Int? var onClicked: (() -> Unit)? } -class TitleViewModelImpl(data: BottomSheetSettings.TitleItem) : TitleViewModel by data, ObserverBasedAdapter.Item { +class TitleViewModelImpl(val data: BottomSheetSettings.TitleItem) : TitleViewModel by data, ObserverBasedAdapter.Item { override val layout = R.layout.bottom_sheet_list_item_title } diff --git a/bottomsheet/src/main/res/layout/bottom_sheet_list_item.xml b/bottomsheet/src/main/res/layout/bottom_sheet_list_item.xml index d3cf6cf..ef2334e 100644 --- a/bottomsheet/src/main/res/layout/bottom_sheet_list_item.xml +++ b/bottomsheet/src/main/res/layout/bottom_sheet_list_item.xml @@ -28,8 +28,7 @@ android:paddingLeft="@dimen/bottom_sheet_padding_default" android:paddingRight="@dimen/bottom_sheet_padding_default" android:text="@{model.title}" - android:textAppearance="@style/TextAppearance.AppCompat.Subhead" - android:textColor="@color/bottom_sheet_item_text" + android:textAppearance="@{model.textAppearanceRes}" bind:compatLeftDrawable="@{model.iconDrawable}" bind:compatLeftDrawableRes="@{model.iconRes}" bind:compatLeftDrawableResTintColor="@{model.iconResTintColor}" diff --git a/bottomsheet/src/main/res/layout/bottom_sheet_list_item_title.xml b/bottomsheet/src/main/res/layout/bottom_sheet_list_item_title.xml index ea86f54..3e7a473 100644 --- a/bottomsheet/src/main/res/layout/bottom_sheet_list_item_title.xml +++ b/bottomsheet/src/main/res/layout/bottom_sheet_list_item_title.xml @@ -23,8 +23,7 @@ android:paddingLeft="@dimen/bottom_sheet_padding_default" android:paddingRight="@dimen/bottom_sheet_padding_default" android:text="@{model.title}" - android:textAppearance="@style/TextAppearance.AppCompat.Title" - android:textColor="@color/bottom_sheet_item_text_title" + android:textAppearance="@{safeUnbox(model.textAppearanceRes)}" tools:text="Title" /> diff --git a/bottomsheet/src/main/res/values/styles.xml b/bottomsheet/src/main/res/values/styles.xml new file mode 100644 index 0000000..3de2166 --- /dev/null +++ b/bottomsheet/src/main/res/values/styles.xml @@ -0,0 +1,18 @@ + + + + + + + + \ No newline at end of file