Skip to content

Commit

Permalink
Merge pull request #21 from rubensousa/dev
Browse files Browse the repository at this point in the history
1.3.1
  • Loading branch information
rubensousa committed Apr 3, 2021
2 parents d9cd822 + 63753d1 commit 8ec9391
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 37 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 1.3.1

#### LinearMarginDecoration

- Fixed margins being applied incorrectly when `addBeforeFirstPosition` and `addAfterLastPosition` were set

# 1.3.0

#### New DecorationLookup defaults
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Decorator is a library that helps creating composable margins and dividers in Re
## Install

```groovy
implementation 'io.cabriole:decorator:1.3.0'
implementation 'io.cabriole:decorator:x.x.x'
```

Replace x.x.x with the latest version available
Expand Down
2 changes: 1 addition & 1 deletion decorator/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
LIBRARY_VERSION=1.3.0
LIBRARY_VERSION=1.3.1
LIBRARY_GROUP=io.cabriole
LIBRARY_ARTIFACT=decorator
# POM info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,34 +221,26 @@ class LinearMarginDecoration(
if (position == 0) {
if (!inverted) {
if (position == itemCount - 1) {
if (addAfterLastPosition) {
outRect.bottom = bottomMargin
}
outRect.bottom = getEdgeMargin(addAfterLastPosition, bottomMargin)
} else {
outRect.bottom = bottomMargin / 2
}
if (addBeforeFirstPosition) {
outRect.top = topMargin
}
outRect.top = getEdgeMargin(addBeforeFirstPosition, topMargin)
} else {
if (position == itemCount - 1) {
if (addAfterLastPosition) {
outRect.top = topMargin
}
outRect.top = getEdgeMargin(addAfterLastPosition, topMargin)
} else {
outRect.top = topMargin / 2
}
if (addBeforeFirstPosition) {
outRect.bottom = bottomMargin
}
outRect.bottom = getEdgeMargin(addBeforeFirstPosition, bottomMargin)
}
} else if (position == itemCount - 1) {
if (!inverted) {
outRect.top = topMargin / 2
outRect.bottom = bottomMargin
outRect.bottom = getEdgeMargin(addAfterLastPosition, bottomMargin)
} else {
outRect.bottom = bottomMargin / 2
outRect.top = topMargin
outRect.top = getEdgeMargin(addAfterLastPosition, topMargin)
}
} else {
outRect.top = topMargin / 2
Expand All @@ -261,32 +253,27 @@ class LinearMarginDecoration(
private fun applyHorizontalOffsets(outRect: Rect, position: Int, itemCount: Int) {
if (position == 0) {
if (!inverted) {
if (addBeforeFirstPosition) {
outRect.left = leftMargin
if (position == itemCount - 1) {
outRect.right = getEdgeMargin(addAfterLastPosition, rightMargin)
} else {
outRect.right = rightMargin / 2
}
outRect.right = rightMargin / 2
outRect.left = getEdgeMargin(addBeforeFirstPosition, leftMargin)
} else {
if (addBeforeFirstPosition) {
outRect.right = rightMargin
if (position == itemCount - 1) {
outRect.left = getEdgeMargin(addAfterLastPosition, leftMargin)
} else {
outRect.left = leftMargin / 2
}
outRect.left = leftMargin / 2
outRect.right = getEdgeMargin(addBeforeFirstPosition, rightMargin)
}
}
if (position == itemCount - 1) {
} else if (position == itemCount - 1) {
if (!inverted) {
if (position != 0) {
outRect.left = leftMargin / 2
}
if (addAfterLastPosition) {
outRect.right = rightMargin
}
outRect.left = leftMargin / 2
outRect.right = getEdgeMargin(addAfterLastPosition, rightMargin)
} else {
if (position != 0) {
outRect.right = rightMargin / 2
}
if (addAfterLastPosition) {
outRect.left = leftMargin
}
outRect.right = rightMargin / 2
outRect.left = getEdgeMargin(addAfterLastPosition, leftMargin)
}
} else {
outRect.left = leftMargin / 2
Expand All @@ -296,4 +283,12 @@ class LinearMarginDecoration(
outRect.bottom = bottomMargin
}

private fun getEdgeMargin(apply: Boolean, margin: Int): Int {
return if (apply) {
margin
} else {
0
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ import io.cabriole.decorator.sample.extensions.dpToPx

class LinearMarginDelegate(private val resources: Resources) : DecorationDelegate() {

private var decoration = LinearMarginDecoration.create(resources.dpToPx(getDefaultSizeDp()))
private var decoration = LinearMarginDecoration.create(
resources.dpToPx(getDefaultSizeDp()),
addBeforeFirstPosition = false,
addAfterLastPosition = false
)

override fun getSize(): Int = decoration.getTopMargin()

Expand Down

0 comments on commit 8ec9391

Please sign in to comment.