Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
allco committed Aug 17, 2018
2 parents 288ba3f + 90d6d25 commit d726806
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 22 deletions.
31 changes: 26 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<img src="doc/example1.png" alt="Example #1 image." width=400 />

```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
<img src="doc/example2.png" alt="Example #1 image." width=400 />

```kotlin
fun runExample1(view: View) {
bottomSheet {
Expand Down Expand Up @@ -63,8 +84,8 @@ The following examples was inspired by [Google's definition of BottomSheet](http
}
```

### #2
<img src="doc/example2.png" alt="Example #2 image." width=400 />
### #3
<img src="doc/example3.png" alt="Example #2 image." width=400 />

```kotlin
fun runExample2(view: View) {
Expand Down Expand Up @@ -105,10 +126,10 @@ The following examples was inspired by [Google's definition of BottomSheet](http

```

### #3
### #4
Custom items

<img src="doc/example3.png" alt="Example #3 image." width=400 />
<img src="doc/example4.png" alt="Example #3 image." width=400 />

```kotlin
fun runExample3(view: View) {
Expand Down Expand Up @@ -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)
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)
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.allco.ui.recyclerView.ObserverBasedAdapter

interface TitleViewModel {
var title: String?
var textAppearanceRes: Int?
}

interface DividerViewModel {
Expand All @@ -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
}

Expand Down
3 changes: 1 addition & 2 deletions bottomsheet/src/main/res/layout/bottom_sheet_list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

/>
Expand Down
18 changes: 18 additions & 0 deletions bottomsheet/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="BottomSheetLib" />

<style name="BottomSheetLib.Title" />

<style name="BottomSheetLib.Title.DefaultTextAppearance" parent="TextAppearance.AppCompat.Title">
<item name="android:textColor">@color/bottom_sheet_item_text_title</item>
</style>

<style name="BottomSheetLib.ClickableItem" />

<style name="BottomSheetLib.ClickableItem.DefaultTextAppearance" parent="TextAppearance.AppCompat.Subhead">
<item name="android:textColor">@color/bottom_sheet_item_text</item>
</style>

</resources>

0 comments on commit d726806

Please sign in to comment.