Skip to content

Commit

Permalink
Added possibility to set different text sizes in both swiping directi…
Browse files Browse the repository at this point in the history
…ons, thank God!
  • Loading branch information
kevingermainbusiness committed Apr 27, 2021
1 parent c3537b8 commit 035ec87
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 11 deletions.
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ when ItemTouchHelper.ACTION_STATE_SWIPE is triggered.

# How to get this project
**Step 1.** Add the jitpack repository to your ```project build.gradle``` file, like so:
```
```groovy
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext {
Expand Down Expand Up @@ -36,9 +36,9 @@ task clean(type: Delete) {
```

**Step 2.** Add the dependency in your ``` module build.gradle ``` file, like so:
```
```groovy
dependencies {
implementation 'com.github.kevingermainbusiness:ItemDecorator:1.0.6'
implementation 'com.github.kevingermainbusiness:ItemDecorator:1.0.7'
}
```
**That's it!**
Expand All @@ -63,7 +63,7 @@ ItemDecorator.Builder(c, recyclerView, viewHolder, dX, actionState)
.create()
.decorate()
```
Or if you just want to specify each values such as background color,text,text color,typeface,icon, icon tint color, just as seen above in the screenshots:
Or if you just want to specify each values such as background color,text,text color,text size,typeface,icon, icon tint color, just as seen above in the screenshots:
```kotlin
val colorAlert = ContextCompat.getColor(this@MainActivity, R.color.colorAlert)
val teal200 = ContextCompat.getColor(this@MainActivity, R.color.teal_200)
Expand All @@ -74,7 +74,8 @@ ItemDecorator.Builder(c, recyclerView, viewHolder, dX, actionState)
.setFromEndToStartIconTint(defaultWhiteColor)
.setFromStartToEndTypeface(Typeface.DEFAULT_BOLD)
.setFromEndToStartTypeface(Typeface.SANS_SERIF)
.setDefaultTextSize(size = 16f)
.setFromStartToEndTextSize(size = 16f)
.setFromEndToStartTextSize(size = 16f)
.setFromStartToEndTextColor(defaultWhiteColor)
.setFromEndToStartTextColor(defaultWhiteColor)
.setFromStartToEndIcon(R.drawable.ic_baseline_delete_24)
Expand Down
2 changes: 1 addition & 1 deletion recyclerview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ afterEvaluate {
// You can then customize attributes of the publication as shown below.
groupId = 'com.github.kevingermainbusiness'
artifactId = 'final'
version = '1.0.6'
version = '1.0.7'
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ data class ItemDecorator(
private var mTypefaceFromStartToEnd = Typeface.SANS_SERIF
private var mTypefaceFromEndToStart = Typeface.SANS_SERIF

private var mTextSizeFromStartToEnd = 14f
private var mTextSizeFromEndToStart = 14f

/* Default values */
private var mDefaultIconHorizontalMargin = 0
private var mDefaultTextSize = 14f
private var mDefaultTextUnit = TypedValue.COMPLEX_UNIT_SP

init {
Expand Down Expand Up @@ -165,7 +167,8 @@ data class ItemDecorator(
*/
fun setDefaultTextSize(unit: Int = TypedValue.COMPLEX_UNIT_SP, size: Float): Builder {
mDecorator.mDefaultTextUnit = unit
mDecorator.mDefaultTextSize = size
mDecorator.mTextSizeFromStartToEnd = size
mDecorator.mTextSizeFromEndToStart = size
return this
}

Expand Down Expand Up @@ -303,6 +306,44 @@ data class ItemDecorator(
return this
}

/**
* Sets the size of the text to be shown while swiping from start to end
*
* By default, the text size is 14f, you can change that by calling this method,
* and passing your size to the [size] parameter.
* @param unit the unit to convert from, (e.g. [TypedValue.COMPLEX_UNIT_SP])
* @param size the size to be set
* @since 1.0.7
* @return This instance of [Builder]
*/
fun setFromStartToEndTextSize(
unit: Int = TypedValue.COMPLEX_UNIT_SP,
size: Float
): Builder {
mDecorator.mDefaultTextUnit = unit
mDecorator.mTextSizeFromStartToEnd = size
return this
}

/**
* Sets the size of the text to be shown while swiping from end to start
*
* By default, the text size is 14f, you can change that by calling this method,
* and passing your size to the [size] parameter.
* @param unit the unit to convert from, (e.g. [TypedValue.COMPLEX_UNIT_SP])
* @param size the size to be set
* @since 1.0.7
* @return This instance of [Builder]
*/
fun setFromEndToStartTextSize(
unit: Int = TypedValue.COMPLEX_UNIT_SP,
size: Float
): Builder {
mDecorator.mDefaultTextUnit = unit
mDecorator.mTextSizeFromEndToStart = size
return this
}

/**
* Sets the Typeface of the text to be shown while swiping from start to end
* @param typeface the Typeface to be set (e.g. [Typeface.SANS_SERIF])
Expand Down Expand Up @@ -405,7 +446,7 @@ data class ItemDecorator(
textPaint.isAntiAlias = true
textPaint.textSize = TypedValue.applyDimension(
mDefaultTextUnit,
mDefaultTextSize,
mTextSizeFromStartToEnd,
recyclerView.context.resources.displayMetrics
)
textPaint.color = mTextColorFromStartToEnd
Expand Down Expand Up @@ -474,7 +515,7 @@ data class ItemDecorator(
textPaint.isAntiAlias = true
textPaint.textSize = TypedValue.applyDimension(
mDefaultTextUnit,
mDefaultTextSize,
mTextSizeFromEndToStart,
recyclerView.context.resources.displayMetrics
)
textPaint.color = mTextColorFromEndToStart
Expand Down
1 change: 0 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ dependencyResolutionManagement {
google()
mavenCentral()
mavenLocal()
// maven { url 'https://jitpack.io' }
}
}
rootProject.name = "ItemDecorator"
Expand Down

0 comments on commit 035ec87

Please sign in to comment.